19 #include <unordered_set> 22 // example OmniChannelNoiseDB configuration. 24 local wc = import "wirecell.jsonnet"; 27 anode: "AnodePlane:0", 31 // channel groups is a 2D list. Each element is one group of 32 // channels which should be considered together for coherent noise 34 groups: [std.range(g*48, (g+1)*48-1) for g in std.range(0,171)], 36 // Default channel info which is used if not overriden by one of 37 // the channel_info objects (below) for a given channel. 39 nominal_baseline: 0.0, // adc count 40 gain_correction: 1.0, // unitless 41 response_offset: 79, // ticks? 42 pad_window_front: 20, // ticks? 43 pad_window_back: 10, // ticks? 44 min_rms_cut: 1.0, // units??? 45 max_rms_cut: 5.0, // units??? 47 // parameter used to make "rcrc" spectrum 48 rcrc: 1.0*wc.millisecond, 50 // parameters used to make "config" spectrum 53 // list to make "noise" spectrum mask 56 // field response waveform to make "response" spectrum 61 // overide defaults for specific channels. If an info is 62 // mentioned for a particular channel in multiple objects, last 67 channels: 4, // single channel 68 nominal_baseline: 400, 71 channels: [1,42,69], // explicit list 72 nominal_baseline: 2048.0, // adc count 74 from: {gain: 7.8*wc.mV/wc.fC, shaping: 1.0*wc.us}, 75 to: {gain: 14.0*wc.mV/wc.fC, shaping: 2.0*wc.us}, 79 channels: { first: 1, last: 4 }, // inclusive range. 80 // could also use Jsonnet's std.range(first,last): 81 // channels: std.range(1,4), 82 nominal_baseline: 400.0, 85 channels: {first: 0, last: 2047,}, 86 freqmasks: [ // masks in frequency domain. 87 { value: 1.0, lobin: 0, hibin: $.nsamples-1 }, 88 { value: 0.0, lobin: 169, hibin: 173 }, 89 { value: 0.0, lobin: 513, hibin: 516 }, 93 // All channels in a given anode wire plane. Note, if 94 // used, the anode plane must be added to top level 95 // configuration sequence. The "channels" can be 96 // specified by the other means. 97 channels: { wpid: wc.WirePlaneId(wc.Ulayer) }, 99 // the average response to use that of the wpid. 100 wpid: wc.WirePlaneId(wc.Ulayer) 101 // or as a raw waveform: 102 // waveform: [time-domain samples assumed to be at tick sampling period] 103 // waveformid: <uniquenumber> 119 typedef std::vector<WireCell::IChannelNoiseDatabase::filter_t>
filter_bag_t;
125 cerr <<
"No specs for \"" << name <<
"\"\n";
128 cerr <<
"plot spec \"" << name <<
"\" size=" << specs.size() <<
endl;
131 std::vector<TGraph*> graphs;
132 std::vector<float>
tmp;
133 for (
const auto& spec : specs) {
134 TGraph*
graph =
new TGraph();
135 graphs.push_back(graph);
136 for (
size_t ind=0; ind< spec.size(); ++ind) {
137 double amp =
std::abs(spec.at(ind));
138 graph->SetPoint(ind, ind, amp);
142 auto mme = std::minmax_element(tmp.begin(), tmp.end());
143 float ymin = *mme.first;
144 float ymax = *mme.second;
147 int colors[ncolors] = {1,2,4,6,8};
148 for (
size_t igraph = 0; igraph<graphs.size(); ++igraph) {
149 TGraph*
graph = graphs[igraph];
150 graph->SetLineColor(colors[igraph%ncolors]);
151 graph->SetLineWidth(2);
154 auto frame = graph->GetHistogram();
155 frame->SetTitle(name.c_str());
156 frame->GetXaxis()->SetTitle(
"frequency bins");
157 frame->GetYaxis()->SetTitle(
"amplitude");
159 frame->SetMinimum(ymin);
160 frame->SetMaximum(ymax);
161 cerr << name <<
" ymin=" << ymin <<
", ymax=" << ymax <<
endl;
174 const std::string pcr_filename =
"microboone-channel-responses-v1.json.bz2";
180 cerr <<
"testing with " << argv[1] <<
endl;
182 extvar[
"detector"] =
"uboone";
185 for (
auto jone : cfg) {
186 string the_type = jone[
"type"].asString();
187 if (the_type ==
"wclsChannelNoiseDB" || the_type ==
"OmniChannelNoiseDB") {
196 cerr <<
"testing with build in config text\n";
199 cfg[
"anode"] = anode_tns[0];
201 auto icfg = Factory::lookup_tn<IConfigurable>(
"OmniChannelNoiseDB");
202 auto def = icfg->default_configuration();
204 icfg->configure(cfg);
207 auto anode = Factory::find_tn<IAnodePlane>(anode_tns[0]);
208 const int nchannels = anode->channels().size();
210 auto idb = Factory::find_tn<IChannelNoiseDatabase>(
"OmniChannelNoiseDB");
212 gStyle->SetOptStat(0);
213 TCanvas canvas(
"canvas",
"canvas",500,500);
215 string pdfname = Form(
"%s.pdf",argv[0]);
217 canvas.Print((pdfname+
"[").c_str(),
"pdf");
220 double tick = idb->sample_time();
221 cerr <<
"tick = " << tick/
units::us <<
" us.\n";
223 std::vector<std::string> scalar_names{
224 "nominal baseline",
"gain correction",
"response offset",
"pad window front",
"pad window back",
225 "min rms cut",
"max rms cut",
"rcrc sum",
"config sum",
"noise sum",
"response sum"};
227 const int nscalars = 11;
228 std::vector<TGraph*> scalars;
229 for (
int ind=0; ind<11; ++ind) { scalars.push_back(
new TGraph); }
230 for (
int ch=0; ch<nchannels; ++ch) {
231 scalars[0]->SetPoint(ch, ch, idb->nominal_baseline(ch));
232 scalars[1]->SetPoint(ch, ch, idb->gain_correction(ch));
233 scalars[2]->SetPoint(ch, ch, idb->response_offset(ch));
234 scalars[3]->SetPoint(ch, ch, idb->pad_window_front(ch));
235 scalars[4]->SetPoint(ch, ch, idb->pad_window_back(ch));
236 scalars[5]->SetPoint(ch, ch, idb->min_rms_cut(ch));
237 scalars[6]->SetPoint(ch, ch, idb->max_rms_cut(ch));
246 for (
size_t ind=0; ind<nscalars; ++ind) {
247 TGraph*
graph = scalars[ind];
248 graph->SetName(scalar_names[ind].c_str());
249 graph->SetLineColor(2);
250 graph->SetLineWidth(3);
253 auto frame = graph->GetHistogram();
254 frame->SetTitle(scalar_names[ind].c_str());
255 frame->GetXaxis()->SetTitle(
"channels");
256 canvas.Print(pdfname.c_str(),
"pdf");
259 canvas.Print((pdfname+
"]").c_str(),
"pdf");
void plot_spec(const filter_bag_t &specs, const std::string &name)
Configuration update(Configuration &a, Configuration &b)
Merge dictionary b into a, return a.
const std::string config_text
def graph(desc, maker=maker)
std::map< std::string, std::string > externalvars_t
std::vector< WireCell::IChannelNoiseDatabase::filter_t > filter_bag_t
int main(int argc, char *argv[])
std::vector< std::string > anode_loader(std::string detector)
Json::Value load(const std::string &filename, const externalvars_t &extvar=externalvars_t(), const externalvars_t &extcode=externalvars_t())
Json::Value loads(const std::string &text, const externalvars_t &extvar=externalvars_t(), const externalvars_t &extcode=externalvars_t())
Json::Value Configuration
QTextStream & endl(QTextStream &s)