test_response.cxx
Go to the documentation of this file.
2 
3 #include "WireCellUtil/Units.h"
4 #include "WireCellUtil/Binning.h"
6 
7 #include "TCanvas.h"
8 #include "TH1F.h"
9 
10 #include <algorithm>
11 
12 using namespace WireCell;
13 
14 struct Plotter {
15  TCanvas canvas;
18  : canvas("test_response", "Response functions", 500,500)
19  , filename(fname)
20  {
21  canvas.Print((filename+"[").c_str(), "pdf");
22  }
24  canvas.Print((filename+"]").c_str(), "pdf");
25  }
26  void operator()() {
27  canvas.Print(filename.c_str(), "pdf");
28  }
29 };
30 
31 std::pair<TH1F*,TH1F*> plot_response(Plotter& plt, double gain_unit = units::mV/units::fC);
32 std::pair<TH1F*,TH1F*> plot_response(Plotter& plt, double gain_unit)
33 {
34  const double gain1 = 7.8*gain_unit;
35  const double gain2 = 14.0*gain_unit;
36  const double shaping1 = 1.0*units::us;
37  const double shaping2 = 2.0*units::us;
38  const double tmax = 10.0*units::us;
39  const double tick = 0.05*units::us;
40 
41  const Binning bins(tmax/tick, 0, tmax);
42 
43  Response::ColdElec ce1(gain1, shaping1);
44  Response::ColdElec ce2(gain2, shaping2);
45 
46  // exercise the generator
47  Waveform::realseq_t res1 = ce1.generate(bins);
48  Waveform::realseq_t res2 = ce2.generate(bins);
49 
50  TH1F* resp1 = new TH1F("resp1","Cold Electronics Response at 1us shaping",
51  bins.nbins(), bins.min()/units::us, bins.max()/units::us);
52  TH1F* resp2 = new TH1F("resp2","Cold Electronics Response at 2us shaping",
53  bins.nbins(), bins.min()/units::us, bins.max()/units::us);
54  resp1->SetLineColor(2);
55  resp2->SetLineColor(4);
56  for (size_t ind=0; ind<res1.size(); ++ind) {
57  const double t_us = bins.center(ind) / units::us;
58  resp1->Fill(t_us, res1[ind] / gain_unit);
59  resp2->Fill(t_us, res2[ind] / gain_unit);
60  }
61 
62  plt.canvas.Clear();
63  auto pad = &plt.canvas;
64  pad->SetGridx();
65  pad->SetGridy();
66  TH1F* frame = pad->DrawFrame(0,0,10,15,"Cold Electronics Response Functions (1us,7.8mV/fC and 2us,14.0mV/fC)");
67  frame->SetXTitle("Time (microsecond)");
68  if (gain_unit == units::mV/units::fC) {
69  frame->SetYTitle("Gain (mV/fC)");
70  }
71  else {
72  frame->SetYTitle("Gain");
73  }
74  resp1->Draw("hist,same");
75  resp2->Draw("hist,same");
76 
77  plt();
78 
79  return std::make_pair(resp1, resp2);
80 }
81 
82 void plot_ratio(Plotter& plt, TH1F* one, TH1F* two, const std::string& title)
83 {
84  TH1F* rat = (TH1F*)two->Clone("rat");
85  rat->Divide(one);
86 
87  plt.canvas.Clear();
88  auto pad = &plt.canvas;
89  pad->SetGridx();
90  pad->SetGridy();
91 
92  const double eps = 0.01;
93  TH1F* frame = pad->DrawFrame(0,1-eps,10,1+eps,title.c_str());
94  frame->SetXTitle("Time (microsecond)");
95  frame->SetYTitle("gain ratio");
96  pad->SetGridx();
97  pad->SetGridy();
98  rat->SetLineColor(1);
99  rat->Draw("hist,same");
100 
101  plt();
102 }
103 
104 int main(int argc, char* argv[])
105 {
106  {
107  Plotter plt(Form("%s.pdf", argv[0]));
108  auto units = plot_response(plt);
109  auto anons = plot_response(plt, 1.0);
110  plot_ratio(plt, units.first, anons.first, "Ratio for 1us, 7.8mV/fC");
111  plot_ratio(plt, units.second, anons.second, "Ratio for 2us, 14.0V/fC");
112  }
113 }
void operator()()
Sequence< real_t > realseq_t
Definition: Waveform.h:31
double center(int ind) const
Definition: Binning.h:86
std::string string
Definition: nybbler.cc:12
static const double mV
Definition: Units.h:180
A functional object caching gain and shape.
Definition: Response.h:165
const double tick
double max() const
Definition: Binning.h:52
Plotter(const std::string &fname)
WireCell::Waveform::realseq_t generate(const WireCell::Waveform::Domain &domain, int nsamples)
FIXME: eradicate Domain in favor of Binning.
Definition: Response.cxx:303
std::string filename
double min() const
Definition: Binning.h:47
void plot_ratio(Plotter &plt, TH1F *one, TH1F *two, const std::string &title)
static const double fC
Definition: Units.h:113
Definition: Main.h:22
int main(int argc, char *argv[])
std::pair< TH1F *, TH1F * > plot_response(Plotter &plt, double gain_unit=units::mV/units::fC)
static const double us
Definition: Units.h:105
TCanvas canvas
int nbins() const
Definition: Binning.h:42