Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared noise model #255

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions cfg/pgrapher/experiment/dune-vd/sim.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,31 @@ function(params, tools) {
},
uses: [anode, tools.dft] + if std.type(csdb) == "null" then [] else [csdb],
},
local noise_models = [make_noise_model(anode) for anode in tools.anodes],

local mega_anode = {
type: 'MegaAnodePlane',
name: 'meganodes',
data: {
anodes_tn: [wc.tn(anode) for anode in tools.anodes],
},
},

local add_noise = function(model) g.pnode({
local add_noise = function(model, name="") g.pnode({
type: "AddNoise",
name: "addnoise%s"%[model.name],
name: "addnoise%s"%[name],
data: {
rng: wc.tn(tools.random),
dft: wc.tn(tools.dft),
model: wc.tn(model),
nsamples: params.daq.nticks,
nsamples: params.daq.nticks,
replacement_percentage: 0.02, // random optimization
}}, nin=1, nout=1, uses=[tools.random, tools.dft, model]),

local noises = [add_noise(model) for model in noise_models],
// TODO: make this an option?
local use_shared_model = true,
local noises = if use_shared_model == true
then [add_noise(make_noise_model(mega_anode), anode.name) for anode in tools.anodes]
else [add_noise(make_noise_model(anode), anode.name) for anode in tools.anodes],

local digitizers = [
sim.digitizer(anode, name="digitizer%d"%anode.data.ident, tag="orig%d"%anode.data.ident)
Expand Down
2 changes: 2 additions & 0 deletions gen/inc/WireCellGen/EmpiricalNoiseModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <vector>
#include <unordered_map>
#include <mutex>

namespace WireCell {
namespace Gen {
Expand Down Expand Up @@ -90,6 +91,7 @@ namespace WireCell {
int get_nsamples() { return m_nsamples; };

private:
mutable std::mutex m_mutex_cache;
IAnodePlane::pointer m_anode;
IChannelStatus::pointer m_chanstat;
IDFT::pointer m_dft;
Expand Down
1 change: 1 addition & 0 deletions gen/src/EmpiricalNoiseModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ Gen::EmpiricalNoiseModel::channel_spectrum(int chid) const
}
}

std::lock_guard<std::mutex> lock(m_mutex_cache);
// get truncated wire length for cache
int ilen = 0;
auto chlen = m_chid_to_intlen.find(chid);
Expand Down