test_nomchanresp.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Units.h"
2 #include "WireCellUtil/Testing.h"
3 
4 /// needed to pretend like we are doing WCT internals
9 
10 
11 #include "TCanvas.h"
12 #include "TGraph.h"
13 #include "TH1F.h"
14 #include "TAxis.h"
15 
16 #include <vector>
17 #include <string>
18 #include <iostream>
19 
20 using namespace WireCell;
24 
25 using namespace std;
26 
27 int main(int argc, char* argv[])
28 {
29  // user code should never do this
30  {
32  pm.add("WireCellSigProc");
33  }
34 
35  Binning binning(100,0,10*us);
36 
37  /// The typename of the component to use here. Normally this is
38  /// given in the configuration for whatever component wants to use
39  /// the channel response.
40  const std::string ncr_tn = "NominalChannelResponse";
41 
42 
43  /// User code should never do this but in this test we will abuse
44  /// the configuration mechanism to reuse the same component to
45  /// draw many responses.
46  auto incrcfg = Factory::lookup<IConfigurable>(ncr_tn);
47  auto cfg = incrcfg->default_configuration();
48  cfg["nbins"] = binning.nbins();
49  cfg["tmin"] = binning.min();
50  cfg["tmax"] = binning.max();
51  incrcfg->configure(cfg);
52 
53  /// Finally, we pretend to be user code.
54  auto ncr = Factory::find<IChannelResponse>(ncr_tn);
55 
56  const double GU = mV/fC;
57 
58  const std::vector<double> gains{7.8*GU, 14*GU};
59  const std::vector<double> shapes{0.5*us,1.0*us,2.0*us,3.0*us};
60 
61  std::vector<TGraph*> graphs;
62 
63  for (auto gain : gains) {
64  cfg["gain"] = gain;
65  for (auto shape : shapes) {
66  cfg["shaping"] = shape;
67 
68  /// WARNING: user code should never call configure(). We
69  /// are abusing the system here to keep this test short.
70  incrcfg->configure(cfg);
71  /// Users: do not do this.
72 
73  auto wave = ncr->channel_response(0);
74  const int nbins = wave.size();
75  cerr << nbins << " " << binning.nbins() << endl;
76  Assert(nbins == binning.nbins());
77  TGraph* g = new TGraph(binning.nbins());
78  for (int ind=0; ind<binning.nbins(); ++ind) {
79  g->SetPoint(ind, binning.center(ind)/us, wave[ind]/GU);
80  }
81  graphs.push_back(g);
82  }
83  }
84 
85  const int colors[] = {1,2,4,6};
86  TCanvas c("c","c",500,500);
87  auto frame = c.DrawFrame(0.0, 0.0, 10.0, 15.0);
88  frame->SetTitle("Nominal Channel Response various gains/shaping");
89  frame->GetXaxis()->SetTitle("time [us]");
90  frame->GetYaxis()->SetTitle("gain [mV/fC]");
91  for (size_t ind=0; ind<graphs.size(); ++ind) {
92  TGraph* g = graphs[ind];
93  g->SetLineColor(colors[ind%4]);
94  g->SetMarkerColor(colors[ind%4]);
95  g->Draw("C*");
96  }
97  c.Print(Form("%s.pdf", argv[0]), "pdf");
98 
99  return 0;
100 }
double center(int ind) const
Definition: Binning.h:86
std::string string
Definition: nybbler.cc:12
STL namespace.
static const double mV
Definition: Units.h:180
static const double g
Definition: Units.h:145
cfg
Definition: dbjson.py:29
static PluginManager & instance()
int main(int argc, char *argv[])
double max() const
Definition: Binning.h:52
#define Assert
Definition: Testing.h:7
float fC
Definition: units.py:113
double min() const
Definition: Binning.h:47
static const double fC
Definition: Units.h:113
Definition: Main.h:22
static const double us
Definition: Units.h:101
static const double us
Definition: Units.h:105
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
int nbins() const
Definition: Binning.h:42
QTextStream & endl(QTextStream &s)