Typedefs | Functions | Variables
test_omnicndb.cxx File Reference
#include "WireCellSigProc/OmniChannelNoiseDB.h"
#include "WireCellUtil/Persist.h"
#include "WireCellUtil/PluginManager.h"
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/NamedFactory.h"
#include "WireCellIface/IAnodePlane.h"
#include "WireCellIface/IConfigurable.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TStyle.h"
#include "TH1F.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include "anode_loader.h"

Go to the source code of this file.

Typedefs

typedef std::vector< WireCell::IChannelNoiseDatabase::filter_tfilter_bag_t
 

Functions

void plot_spec (const filter_bag_t &specs, const std::string &name)
 
int main (int argc, char *argv[])
 

Variables

const std::string config_text
 

Typedef Documentation

Definition at line 119 of file test_omnicndb.cxx.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

User code should never do this.

Definition at line 170 of file test_omnicndb.cxx.

171 {
172  /// User code should never do this.
173  auto anode_tns = anode_loader("uboone");
174  const std::string pcr_filename = "microboone-channel-responses-v1.json.bz2";
175 
176  {
178 
179  if (argc > 1) {
180  cerr << "testing with " << argv[1] << endl;
182  extvar["detector"] = "uboone";
183  cfg = Persist::load(argv[1], extvar);
184  if (cfg.isArray()) { // probably a full configuration
185  for (auto jone : cfg) {
186  string the_type = jone["type"].asString();
187  if (the_type == "wclsChannelNoiseDB" || the_type == "OmniChannelNoiseDB") {
188  //cerr << "Found my config\n" << jone << "\n";
189  cfg = jone["data"];
190  break;
191  }
192  }
193  }
194  }
195  else {
196  cerr << "testing with build in config text\n";
198  }
199  cfg["anode"] = anode_tns[0];
200 
201  auto icfg = Factory::lookup_tn<IConfigurable>("OmniChannelNoiseDB");
202  auto def = icfg->default_configuration();
203  cfg = update(def, cfg);
204  icfg->configure(cfg);
205  }
206 
207  auto anode = Factory::find_tn<IAnodePlane>(anode_tns[0]);
208  const int nchannels = anode->channels().size();
209 
210  auto idb = Factory::find_tn<IChannelNoiseDatabase>("OmniChannelNoiseDB");
211 
212  gStyle->SetOptStat(0);
213  TCanvas canvas("canvas","canvas",500,500);
214 
215  string pdfname = Form("%s.pdf",argv[0]);
216 
217  canvas.Print((pdfname+"[").c_str(),"pdf");
218  canvas.SetGridx(1);
219  canvas.SetGridy(1);
220  double tick = idb->sample_time();
221  cerr << "tick = " << tick/units::us << " us.\n";
222 
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"};
226 
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));
238 
239  scalars[7]->SetPoint(ch, ch, std::abs(Waveform::sum(idb->rcrc(ch))));
240  scalars[8]->SetPoint(ch, ch, std::abs(Waveform::sum(idb->config(ch))));
241  scalars[9]->SetPoint(ch, ch, std::abs(Waveform::sum(idb->noise(ch))));
242  scalars[10]->SetPoint(ch, ch, std::abs(Waveform::sum(idb->response(ch))));
243 
244  }
245 
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);
251  graph->Draw("AL");
252 
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");
257  }
258 
259  canvas.Print((pdfname+"]").c_str(), "pdf");
260 
261 
262  return 0;
263 }
Configuration update(Configuration &a, Configuration &b)
Merge dictionary b into a, return a.
const std::string config_text
std::string string
Definition: nybbler.cc:12
def graph(desc, maker=maker)
Definition: apa.py:294
std::map< std::string, std::string > externalvars_t
Definition: Persist.h:69
cfg
Definition: dbjson.py:29
const double tick
std::vector< std::string > anode_loader(std::string detector)
Definition: anode_loader.h:35
T abs(T value)
IFrame::pointer sum(std::vector< IFrame::pointer > frames, int ident)
Definition: FrameUtil.cxx:15
static const double us
Definition: Units.h:101
Json::Value Configuration
Definition: Configuration.h:50
QTextStream & endl(QTextStream &s)
def load(filename, jpath="depos")
Definition: depos.py:34
void plot_spec ( const filter_bag_t specs,
const std::string name 
)

Definition at line 122 of file test_omnicndb.cxx.

123 {
124  if (specs.empty()) {
125  cerr << "No specs for \"" << name << "\"\n";
126  return;
127  }
128  cerr << "plot spec \"" << name << "\" size=" << specs.size() << endl;
129 
130 
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);
139  tmp.push_back(amp);
140  }
141  }
142  auto mme = std::minmax_element(tmp.begin(), tmp.end());
143  float ymin = *mme.first;
144  float ymax = *mme.second;
145 
146  const int ncolors=5;
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);
152 
153  if (!igraph) {
154  auto frame = graph->GetHistogram();
155  frame->SetTitle(name.c_str());
156  frame->GetXaxis()->SetTitle("frequency bins");
157  frame->GetYaxis()->SetTitle("amplitude");
158  graph->Draw("AL");
159  frame->SetMinimum(ymin);
160  frame->SetMaximum(ymax);
161  cerr << name << " ymin=" << ymin << ", ymax=" << ymax << endl;
162  }
163  else {
164  graph->Draw("L");
165  }
166  }
167 }
static QCString name
Definition: declinfo.cpp:673
def graph(desc, maker=maker)
Definition: apa.py:294
uint size() const
Definition: qcstring.h:201
T abs(T value)
string tmp
Definition: languages.py:63
QTextStream & endl(QTextStream &s)

Variable Documentation

const std::string config_text

Definition at line 21 of file test_omnicndb.cxx.