SignalShapingDUNE10ktTest_module.cc
Go to the documentation of this file.
1 //
2 // Name: SignalShapingDUNE10ktTest.h
3 //
4 // Purpose: SignalShapingDUNE10ktTest module. Test convolution/deconvolution.
5 //
6 // Created: 28-Nov-2011 H. Greenlee
7 
8 #include <vector>
9 #include <iostream>
10 #include <cmath>
11 
14 #include "art_root_io/TFileService.h"
15 
18 
19 #include "TComplex.h"
20 #include "TFile.h"
21 #include "TH1D.h"
22 #include "TH2D.h"
23 
24 // Local functions.
25 
26 namespace {
27 
28  // Fill histogram from vector (set underflow/overflow bins to zero).
29 
30  void vector_to_hist(const std::vector<double>& v, TH1D* h)
31  {
32  assert(h != 0);
33  int nvec = v.size();
34  int nbins = h->GetNbinsX();
35  int nfill = std::min(nvec, nbins);
36  h->SetBinContent(0, 0.);
37  int zerobin = h->GetXaxis()->FindBin(0.);
38  for(int i=1; i<=nfill; ++i) {
39  if(i >= zerobin)
40  h->SetBinContent(i, v[i - zerobin]);
41  else
42  h->SetBinContent(i, v[i - zerobin + nvec]);
43  }
44  for(int i=nfill+1; i<=nbins+1; ++i)
45  h->SetBinContent(i, 0.);
46  }
47 
48  // Fill vector with initial delta-function at bin d.
49 
50  void fill_delta(std::vector<double>& v, int d)
51  {
52  int n = v.size();
53  assert(d >= 0 && d < n);
54  for(int i=0; i<n; ++i)
55  v[i] = 0.;
56  v[d] = 1.;
57  }
58 }
59 
60 namespace util
61 {
63  {
64  public:
65 
66  // Constructor, destructor.
67 
68  explicit SignalShapingDUNE10ktTest(fhicl::ParameterSet const& pset);
70 
71  // Overrides.
72 
73  void beginJob();
74  void analyze(const art::Event& evt);
75 
76  };
77 
79 
81  : EDAnalyzer(pset)
82  {}
83 
85  {
86  // Get services.
87 
91 
92  int nticks = fft->FFTSize();
93  std::cout << "Number of ticks = " << nticks << std::endl;
94 
95  // Make collection plane histograms.
96 
97  art::TFileDirectory dirc = tfs->mkdir("Collection", "Collection");
98  int nhist = std::min(200, nticks);
99  int nfilt = std::min(5000, nticks/2);
100  int nkern = nticks/2;
101 
102  // Make input pulse.
103 
104  std::vector<double> tinc(nticks, 0.);
105  fill_delta(tinc, nhist/2);
106  TH1D* hinc = dirc.make<TH1D>("input", "Collection Input", nhist+1, -0.5, nhist+0.5);
107  vector_to_hist(tinc, hinc);
108 
109  // Convoluted pulse.
110 
111  std::vector<double> tconvc(tinc);
112  sss->Convolute(6000, tconvc);
113  TH1D* hconvc = dirc.make<TH1D>("conv", "Collection Convoluted", nhist+1, -0.5, nhist+0.5);
114  vector_to_hist(tconvc, hconvc);
115 
116  // Deconvoluted pulse.
117 
118  std::vector<double> tdeconvc(tconvc);
119  sss->Deconvolute(6000, tdeconvc);
120  TH1D* hdeconvc = dirc.make<TH1D>("deconv", "Collection Deconvoluted", nhist+1, -0.5, nhist+0.5);
121  vector_to_hist(tdeconvc, hdeconvc);
122 
123  // Get collection response function and fill histogram.
124 
125  const std::vector<double>& respc = sss->SignalShaping(6000).Response();
126  TH1D* hrfc = dirc.make<TH1D>("resp", "Collection Response", nhist+1, -nhist/2-0.5, nhist/2+0.5);
127  vector_to_hist(respc, hrfc);
128 
129  // Get collection convolution kernel and fill histogram.
130 
131  const std::vector<TComplex>& kernc = sss->SignalShaping(6000).ConvKernel();
132  std::vector<double> kernrc(kernc.size());
133  for(unsigned int i=0; i<kernrc.size(); ++i)
134  kernrc[i] = kernc[i].Rho();
135  TH1D* hkernc = dirc.make<TH1D>("kern", "Collection Convolution Kernel", nkern+1, -0.5, nkern+0.5);
136  hkernc->SetMinimum(0.);
137  vector_to_hist(kernrc, hkernc);
138 
139  // Get collection filter function and fill histogram.
140 
141  const std::vector<TComplex>& filtc = sss->SignalShaping(6000).Filter();
142  std::vector<double> filtrc(filtc.size());
143  for(unsigned int i=0; i<filtrc.size(); ++i)
144  filtrc[i] = filtc[i].Re();
145  TH1D* hffc = dirc.make<TH1D>("filt", "Collection Filter", nfilt+1, -0.5, nfilt+0.5);
146  vector_to_hist(filtrc, hffc);
147 
148  // Make induction plane histograms.
149 
150  art::TFileDirectory diri = tfs->mkdir("Induction", "Induction");
151 
152  // Make input pulse.
153 
154  std::vector<double> tini(nticks, 0.);
155  fill_delta(tini, nhist/2);
156  TH1D* hini = diri.make<TH1D>("input", "Induction Input", nhist+1, -0.5, nhist+0.5);
157  vector_to_hist(tini, hini);
158 
159  // Convoluted pulse.
160 
161  std::vector<double> tconvi(tini);
162  sss->Convolute(0, tconvi);
163  TH1D* hconvi = diri.make<TH1D>("conv", "Induction Convoluted", nhist+1, -0.5, nhist+0.5);
164  vector_to_hist(tconvi, hconvi);
165 
166  // Deconvoluted pulse.
167 
168  std::vector<double> tdeconvi(tconvi);
169  sss->Deconvolute(0, tdeconvi);
170  TH1D* hdeconvi = diri.make<TH1D>("deconv", "Induction Deconvoluted", nhist+1, -0.5, nhist+0.5);
171  vector_to_hist(tdeconvi, hdeconvi);
172 
173  // Get induction response function and fill histogram.
174 
175  const std::vector<double>& respi = sss->SignalShaping(0).Response();
176  TH1D* hrfi = diri.make<TH1D>("resp", "Induction Response", nhist+1, -nhist/2-0.5, nhist/2+0.5);
177  vector_to_hist(respi, hrfi);
178 
179  // Get induction convolution kernel and fill histogram.
180 
181  const std::vector<TComplex>& kerni = sss->SignalShaping(0).ConvKernel();
182  std::vector<double> kernri(kerni.size());
183  for(unsigned int i=0; i<kernri.size(); ++i)
184  kernri[i] = kerni[i].Rho();
185  TH1D* hkerni = diri.make<TH1D>("kern", "Induction Convolution Kernel", nkern+1, -0.5, nkern+0.5);
186  hkerni->SetMinimum(0.);
187  vector_to_hist(kernri, hkerni);
188 
189  // Get induction filter function and fill histogram.
190 
191  const std::vector<TComplex>& filti = sss->SignalShaping(0).Filter();
192  std::vector<double> filtri(filti.size());
193  for(unsigned int i=0; i<filtri.size(); ++i)
194  filtri[i] = filti[i].Re();
195  TH1D* hffi = diri.make<TH1D>("filt", "Induction Filter", nfilt+1, -0.5, nfilt+0.5);
196  vector_to_hist(filtri, hffi);
197  }
198 
200  {}
201 
203  {}
204 }
Namespace for general, non-LArSoft-specific utilities.
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
const std::vector< double > & Response() const
Definition: SignalShaping.h:77
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
int FFTSize() const
Definition: LArFFT.h:69
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::void_t< T > n
double Rho
Definition: doAna.cpp:13
const std::vector< TComplex > & Filter() const
Definition: SignalShaping.h:80
SignalShapingDUNE10ktTest(fhicl::ParameterSet const &pset)
void Deconvolute(detinfo::DetectorClocksData const &clockData, unsigned int channel, std::vector< T > &func) const
const util::SignalShaping & SignalShaping(unsigned int channel) const
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void Convolute(detinfo::DetectorClocksData const &clockData, unsigned int channel, std::vector< T > &func) const
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< TComplex > & ConvKernel() const
Definition: SignalShaping.h:79
QTextStream & endl(QTextStream &s)