All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpHitFinderStandard_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file OpHitFinderStandard.cc
3 /// \author A. Falcone
4 ////////////////////////////////////////////////////////////////////////
5 
6 #include <cmath>
8 #include "art/Utilities/ToolMacros.h"
9 #include "art/Framework/Principal/Handle.h"
10 #include "art_root_io/TFileService.h"
11 #include "messagefacility/MessageLogger/MessageLogger.h"
12 #include "cetlib_except/exception.h"
13 #include "TF1.h"
14 #include "TGraph.h"
15 #include "TMath.h"
16 
17 #include <fstream>
18 #include <algorithm> // std::minmax_element()
19 
20 namespace light
21 {
22 
24 {
25 public:
26  explicit OpHitFinderStandard(const fhicl::ParameterSet& pset);
27 
29 
30  void configure(const fhicl::ParameterSet& pset) override;
31  void outputHistograms(art::TFileDirectory&) const override;
32 
33  void FindOpHits(const raw::OpDetWaveform&, OpHitVec&) const override;
34 
35 private:
36  double fSPEArea; //conversion between phe and Adc*ns
37  double fHitThreshold;
39 };
40 
41 //----------------------------------------------------------------------
42 // Constructor.
43 OpHitFinderStandard::OpHitFinderStandard(const fhicl::ParameterSet& pset)
44 {
45  configure(pset);
46 }
47 
49 {
50 }
51 
52 void OpHitFinderStandard::configure(const fhicl::ParameterSet& pset)
53 {
54  fHitThreshold = pset.get< double >("HitThreshold");
55  fSPEArea = pset.get< double >("SPEArea");
56  fBaselineSample = pset.get< int >("BaselineSample");
57 
58  return;
59 }
60 
61 
63  OpHitVec& opHitVec) const
64 {
65  int chNumber = opDetWaveform.ChannelNumber();
66  std::cout << "Photon channel: " << chNumber << std::endl;
67  // Load pulses into WaveformVector
68  //std::vector < short_t > WaveformVector = wvf.Waveform();
69 
70  int grsize = opDetWaveform.size();
71 
72  //std::vector<Double_t> TimeVector;
73  //std::vector<Double_t> ADCVector;
74 
75  //TimeVector.size()= grsize;
76  //ADCVector.size()= grsize;
77 
78  double TimeVector[10000];
79  double ADCVector[10000];
80 
81  unsigned short frame;
82  double Area;
83  double fasttotal;
84  double time_abs;
85  double FWHM;
86  double phelec;
87 
88  double baseline=0;
89 
90  for (int btime =0; btime< fBaselineSample; btime++)
91  {
92  baseline = baseline+ opDetWaveform[btime];
93  }
94 
95  baseline = baseline/fBaselineSample;
96 
97  std::cout << "Baseline " << baseline << std::endl;
98 
99 
100  for (int wtime=0; wtime< grsize; wtime++)
101  {
102  TimeVector[wtime] = wtime;
103  ADCVector[wtime] = -(opDetWaveform[wtime]-baseline);
104  }
105 
106  TGraph *gr = new TGraph(grsize,TimeVector,ADCVector);
107 
108  int n_graph = gr->GetN();
109  double *y_graph = gr->GetY();
110 
111  int min_time = TMath::LocMax(n_graph,y_graph);
112  double min_time_to_put = TMath::LocMax(n_graph,y_graph);
113  double min = y_graph[min_time];
114  double min_to_put = min;
115 
116  std::cout << "Min " << min << std::endl;
117 
118  if (min>fHitThreshold)
119  {
120  TF1 *funz= new TF1("funz", "pol1(0)", min_time-2.0, min_time);
121 
122  gr->Fit("funz","R");
123 
124  double start_moment = funz->GetX(baseline, 0, min_time);
125 
126  std::cout << "Start " << start_moment << std::endl;
127 
128  TF1 *gauss_start= new TF1("gauss_start", "gaus", min_time-5.0, min_time);
129  TF1 *gauss_end = new TF1("gauss_end", "gaus", min_time, min_time+10);
130 
131  gauss_start->SetParameter(1,min_time);
132  gauss_end->SetParameter(1,min_time);
133 
134  gr->Fit("gauss_start","R");
135 
136  double Constant1 = gauss_start->GetParameter(0);
137  //double Mean1 = gauss_start->GetParameter(1);
138  double Sigma1 = gauss_start->GetParameter(2);
139 
140  std::cout << "GaussParam 00 " << gauss_start->GetParameter(0) << "GaussParam 01 " << gauss_start->GetParameter(1) << "GaussParam 02 " << gauss_start->GetParameter(2) << std::endl;
141 
142  gr->Fit("gauss_end","R");
143 
144  double Constant2 = gauss_end->GetParameter(0);
145  //double Mean2 = gauss_end->GetParameter(1);
146  double Sigma2 = gauss_end->GetParameter(2);
147 
148  std::cout << "GaussParam 10 " << gauss_end->GetParameter(0) << "GaussParam 11 " << gauss_end->GetParameter(1) << "GaussParam 12 " << gauss_end->GetParameter(2) << std::endl;
149 
150  frame = 1;
151  Area = ((Constant1*Sigma1)/2 + (Constant2*Sigma2)/2)*sqrt(2*3.14159);
152  fasttotal = 3/4;
153  time_abs = sqrt(min_time_to_put);
154  FWHM = 2.35*((Sigma1+Sigma2)/2);
155  phelec = Area/fSPEArea;
156 
157  // recob::OpHit adcVec(chNumber, min_time_to_put, time_abs, frame, FWHM, Area, min_to_put, phelec, fasttotal);//including hit info
158  // pulseVecPtr->emplace_back(std::move(adcVec));
159 
160  funz->~TF1();
161  gauss_start->~TF1();
162  gauss_end->~TF1();
163  gr->~TGraph();
164  }
165  else
166  {
167  //std::cout << "No OpHit in channel " << chNumber << std::endl;
168  min_time_to_put=0;
169  min_to_put=0;
170  Area=0;
171  frame=0;
172  fasttotal=0;
173  time_abs=0;
174  FWHM=0;
175  phelec=0;
176  }
177 
178  recob::OpHit opHit(chNumber, min_time_to_put, time_abs, frame, FWHM, Area, min_to_put, phelec, fasttotal);
179 
180  opHitVec.push_back(recob::OpHit());
181  opHitVec.back() = opHit;
182 
183  return;
184 }
185 
186 void OpHitFinderStandard::outputHistograms(art::TFileDirectory& histDir) const
187 {
188  // It is assumed that the input TFileDirectory has been set up to group histograms into a common
189  // folder at the calling routine's level. Here we create one more level of indirection to keep
190  // histograms made by this tool separate.
191 /*
192  std::string dirName = "OpHitFinderPlane_" + std::to_string(fPlane);
193 
194  art::TFileDirectory dir = histDir.mkdir(dirName.c_str());
195 
196  auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
197  double samplingRate = detprop->SamplingRate();
198  double numBins = fOpHitFinderVec.size();
199  double maxFreq = 500. / samplingRate;
200  std::string histName = "OpHitFinderPlane_" + std::to_string(fPlane);
201 
202  TH1D* hist = dir.make<TH1D>(histName.c_str(), "OpHitFinder;Frequency(MHz)", numBins, 0., maxFreq);
203 
204  for(int bin = 0; bin < numBins; bin++)
205  {
206  double freq = maxFreq * double(bin + 0.5) / double(numBins);
207 
208  hist->Fill(freq, fOpHitFinderVec.at(bin).Re());
209  }
210 */
211 
212  return;
213 }
214 
215 DEFINE_ART_CLASS_TOOL(OpHitFinderStandard)
216 }
OpHitFinderStandard(const fhicl::ParameterSet &pset)
void configure(const fhicl::ParameterSet &pset) override
void outputHistograms(art::TFileDirectory &) const override
BEGIN_PROLOG baseline
This provides an interface for tools which are tasked with finding the baselines in input waveforms...
void FindOpHits(const raw::OpDetWaveform &, OpHitVec &) const override
std::vector< recob::OpHit > OpHitVec
Definition: IOpHitFinder.h:26
BEGIN_PROLOG could also be cout