Functions
test_noisesource.cxx File Reference
#include "WireCellGen/EmpiricalNoiseModel.h"
#include "WireCellUtil/ExecMon.h"
#include "WireCellUtil/Persist.h"
#include "WireCellUtil/String.h"
#include "WireCellUtil/Units.h"
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/PluginManager.h"
#include "WireCellUtil/NamedFactory.h"
#include "WireCellIface/IRandom.h"
#include "WireCellIface/IChannelSpectrum.h"
#include "WireCellIface/IFrameSource.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TStyle.h"
#include "TH2F.h"
#include <cstdlib>
#include <string>
#include "anode_loader.h"

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 27 of file test_noisesource.cxx.

28 {
29  std::string detector = "uboone";
30  if (argc > 1) {
31  detector = argv[1];
32  }
33  auto anode_tns = anode_loader(detector);
34 
35  string filenames[3] = {
36  "microboone-noise-spectra-v2.json.bz2",
37  };
38 
39 
40  ExecMon em;
41 
42  const int nticks = 1000;
43  const double tick = 0.5*units::us;
44  const double readout_time = nticks*tick;
45 
46  // In a real WCT application all this configuration is done by
47  // wire-cell (or hosting application) and driven by user
48  // configuration files. Here we have to expose some tedium.
49  {
50  auto icfg = Factory::lookup<IConfigurable>("Random");
51  icfg->configure(icfg->default_configuration());
52  }
53  {
54  auto icfg = Factory::lookup<IConfigurable>("StaticChannelStatus");
55  auto cfg = icfg->default_configuration();
56  cfg["anode"] = anode_tns[0];
57  icfg->configure(cfg);
58  }
59  {
60  auto icfg = Factory::lookup<IConfigurable>("EmpiricalNoiseModel");
61  auto cfg = icfg->default_configuration();
62  cfg["spectra_file"] = filenames[0];
63  cfg["period"] = tick;
64  cfg["nsamples"] = nticks;
65  cfg["anode"] = anode_tns[0];
66  icfg->configure(cfg);
67  }
68  {
69  auto icfg = Factory::lookup<IConfigurable>("NoiseSource");
70  auto cfg = icfg->default_configuration();
71  cfg["anode"] = anode_tns[0];
72  cfg["model"] = "EmpiricalNoiseModel";
73  cfg["rng"] = "Random";
74  cfg["readout_time"] = readout_time;
75  cfg["m_nsamples"] = nticks;
76  icfg->configure(cfg);
77  }
78 
79  em("configuration done");
80 
81  auto noisesrc = Factory::lookup<IFrameSource>("NoiseSource");
82 
83  IFrame::pointer frame;
84 
85  bool ok = (*noisesrc)(frame);
86  em("got noise frame");
87  Assert(ok);
88 
89  // WARNING: if you are reading this for ideas of how to use frames
90  // and traces beware that, for brevity, this test assumes the
91  // frame is a filled in rectangle of channels X ticks and with
92  // indexed channel numbers. In general this is not true!
93 
94  auto traces = frame->traces();
95  const int ntraces = traces->size();
96 
97  std::cout << nticks << " " << traces->at(0)->charge().size() << std::endl;
98 
99  Assert(nticks == traces->at(0)->charge().size());
100 
101  string tfilename = Form("%s.root", argv[0]);
102  cerr << tfilename << endl;
103  TFile* rootfile = TFile::Open(tfilename.c_str(), "recreate");
104  //TCanvas* canvas = new TCanvas("c","canvas",1000,1000);
105  //gStyle->SetOptStat(0);
106  TH2F* hist = new TH2F("noise","Noise Frame",nticks,0,nticks,ntraces,0,ntraces);
107  for (auto trace : *traces) {
108  int chid = trace->channel();
109  const auto& qvec = trace->charge();
110  for (int ind=0; ind<nticks; ++ind) {
111  // convert to ADC ...
112  hist->Fill(ind+0.5, chid+0.5, qvec[ind]/units::mV * 4096/2000.);
113  }
114  }
115  em("filled histogram");
116  hist->Write();
117  rootfile->Close();
118  em("closed ROOT file");
119 
120  cerr << em.summary() << endl;
121 
122 
123  return 0;
124 }
std::string string
Definition: nybbler.cc:12
cfg
Definition: dbjson.py:29
const double tick
const int nticks
std::vector< std::string > anode_loader(std::string detector)
Definition: anode_loader.h:35
#define Assert
Definition: Testing.h:7
static const double us
Definition: Units.h:101
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124
std::string summary() const
Return summary up to now.
Definition: ExecMon.cxx:21
QTextStream & endl(QTextStream &s)
const double readout_time