Functions
test_nomchanresp.cxx File Reference
#include "WireCellUtil/Units.h"
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/PluginManager.h"
#include "WireCellUtil/NamedFactory.h"
#include "WireCellIface/IChannelResponse.h"
#include "WireCellIface/IConfigurable.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TH1F.h"
#include "TAxis.h"
#include <vector>
#include <string>
#include <iostream>

Go to the source code of this file.

Functions

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

Function Documentation

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

The typename of the component to use here. Normally this is given in the configuration for whatever component wants to use the channel response.

User code should never do this but in this test we will abuse the configuration mechanism to reuse the same component to draw many responses.

Finally, we pretend to be user code.

WARNING: user code should never call configure(). We are abusing the system here to keep this test short.

Users: do not do this.

Definition at line 27 of file test_nomchanresp.cxx.

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 }
std::string string
Definition: nybbler.cc:12
const std::string instance
static const double g
Definition: Units.h:145
cfg
Definition: dbjson.py:29
#define Assert
Definition: Testing.h:7
float fC
Definition: units.py:113
static const double us
Definition: Units.h:101
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
QTextStream & endl(QTextStream &s)