LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LEDCalibrationAna_module.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 // Ben Jones, MIT, 2013
3 //
4 // This ana module extracts pedestals and gains from
5 // LED calibration run data (incomplete)
6 //
7 
8 
9 #ifndef LEDCalibrationAna_H
10 #define LEDCalibrationAna_H 1
11 
12 // LArSoft includes
19 
20 // Framework includes
24 #include "fhiclcpp/ParameterSet.h"
32 
33 // ROOT includes
34 #include "TH1.h"
35 #include "THStack.h"
36 #include "TF1.h"
37 #include "TLorentzVector.h"
38 #include "TVector3.h"
39 #include <TTree.h>
40 
41 // C++ Includes
42 #include <map>
43 #include <vector>
44 #include <iostream>
45 #include <cstring>
46 #include <sstream>
47 #include "math.h"
48 #include <climits>
49 
50 namespace opdet {
51 
53  public:
54 
55  // Standard constructor and destructor for an ART module.
57  virtual ~LEDCalibrationAna();
58 
59  void beginJob();
60 
61  void endJob();
62 
63  // The analyzer routine, called once per event.
64  void analyze (const art::Event&);
65 
66  private:
67 
68  // The parameters we'll read from the .fcl file.
69  std::string fInputModule; // Input tag for OpDet collection
70  uint32_t fTriggerChannel;
72  float fMaxTimeMean;
74  float fAreaDivs;
75  float fAreaMin;
76  float fAreaMax;
78 
82  TTree * fPulseTree;
84  Float_t fPeak;
85  Float_t fPedRMS;
86  Float_t fPedMean;
87  Float_t fArea;
88  Float_t fTBegin;
89  Float_t fTEnd;
90  Float_t fTMax;
91  Float_t fOffset;
92  Int_t fEventID;
93  Int_t fRunID;
94  Int_t fChannel;
95  Int_t fShaper;
96 
97  uint32_t ShaperToChannel(uint32_t Shaper);
98 
100 
101  std::map<uint32_t, std::vector<double> > fAreas;
102 
103 
104 
105  };
106 
107 
108 }
109 
110 #endif
111 
112 namespace opdet {
113 
114  //-----------------------------------------------------------------------
115  // Constructor
117  : EDAnalyzer(pset),
118  fPulseRecoMgr(),
119  fThreshAlg(),
120  fPedAlg()
121  {
122  // Indicate that the Input Module comes from .fcl
123  fInputModule = pset.get<std::string>("InputModule");
124  fTriggerChannel = pset.get<uint32_t> ("TriggerChannel");
125  fTriggerDelay = pset.get<uint32_t> ("TriggerDelay");
126  fCoincThreshold = pset.get<float> ("CoincThreshold");
127  fMaxTimeThresh = pset.get<float> ("MaxTimeThresh");
128  fMaxTimeMean = pset.get<float> ("MaxTimeMean");
129  fAreaMin = pset.get<float> ("AreaMin");
130  fAreaMax = pset.get<float> ("AreaMax");
131  fAreaDivs = pset.get<float> ("AreaDivs");
132  fMakeNonCoincTree=pset.get<bool> ("MakeNonCoincTree");
133 
136 
138 
139  fPulseTree = tfs->make<TTree>("fPulseTree","fPulseTree");
140  fPulseTree->Branch("Area", &fArea, "Area/F");
141  fPulseTree->Branch("Peak", &fPeak, "Peak/F");
142  fPulseTree->Branch("TBegin", &fTBegin, "TBegin/F");
143  fPulseTree->Branch("TEnd", &fTEnd, "TEnd/F");
144  fPulseTree->Branch("TMax", &fTMax, "TMax/F");
145  fPulseTree->Branch("Channel", &fChannel, "Channel/I");
146  fPulseTree->Branch("Shaper", &fShaper, "Shaper/I");
147  fPulseTree->Branch("PedMean", &fPedMean, "PedMean/F");
148  fPulseTree->Branch("PedRMS", &fPedRMS, "PedRMS/F");
149  fPulseTree->Branch("Offset", &fOffset, "Offset/F");
150  fPulseTree->Branch("EventID", &fEventID, "EventID/I");
151  fPulseTree->Branch("RunID", &fRunID, "RunID/I");
152 
153  fPulseTreeNonCoinc = tfs->make<TTree>("fPulseTreeNonCoinc","fPulseTreeNonCoinc");
154  fPulseTreeNonCoinc->Branch("Area", &fArea, "Area/F");
155  fPulseTreeNonCoinc->Branch("Peak", &fPeak, "Peak/F");
156  fPulseTreeNonCoinc->Branch("TBegin", &fTBegin, "TBegin/F");
157  fPulseTreeNonCoinc->Branch("TEnd", &fTEnd, "TEnd/F");
158  fPulseTreeNonCoinc->Branch("TMax", &fTMax, "TMax/F");
159  fPulseTreeNonCoinc->Branch("Channel", &fChannel, "Channel/I");
160  fPulseTreeNonCoinc->Branch("Shaper", &fShaper, "Shaper/I");
161  fPulseTreeNonCoinc->Branch("PedMean", &fPedMean, "PedMean/F");
162  fPulseTreeNonCoinc->Branch("PedRMS", &fPedRMS, "PedRMS/F");
163  fPulseTreeNonCoinc->Branch("EventID", &fEventID, "EventID/I");
164  fPulseTreeNonCoinc->Branch("RunID", &fRunID, "RunID/I");
165 
166  }
167 
168  //-----------------------------------------------------------------------
169  // Destructor
171  {}
172 
173  //-----------------------------------------------------------------------
175  {
176  }
177 
178  //-----------------------------------------------------------------------
180  {
182 
183  for(auto it = fAreas.begin(); it!=fAreas.end(); ++it)
184  {
185  uint32_t Channel = it->first;
186 
187  std::stringstream histname;
188  histname.flush();
189  histname<<"ch"<<Channel<<"area";
190 
191  TH1D * HistArea = tfs->make<TH1D>(histname.str().c_str(), histname.str().c_str(), fAreaDivs, fAreaMin, fAreaMax);
192 
193  for(size_t j=0; j!=it->second.size(); ++j)
194  {
195  HistArea->Fill(it->second.at(j));
196  }
197 
198  std::stringstream fitname;
199  fitname.flush();
200  fitname<<"ch"<<Channel<<"fit";
201 
202  double Max = HistArea->GetMaximum();
203  double Mid = HistArea->GetBinContent(fAreaDivs/2.);
204 
205  TF1 * GausFit = new TF1(fitname.str().c_str(),
206  "gaus(0)+gaus(3)+gaus(6)",
207  fAreaMin,
208  fAreaMax);
209 
210  GausFit->SetParameters(Mid, (fAreaMin+fAreaMax)/2., (fAreaMax-fAreaMin)/2.,
211  Max, 0, (fAreaMin+fAreaMax)/8.,
212  Max/5., 0, (fAreaMin+fAreaMax)/4.);
213 
214 
215  GausFit->SetParLimits(0,0,1.1*Max);
216  GausFit->SetParLimits(1,0,fAreaMax);
217  GausFit->SetParLimits(2,0,fAreaMax);
218 
219  GausFit->SetParLimits(3,0,1.1*Max);
220  GausFit->FixParameter(4,0);
221  GausFit->SetParLimits(5,0,(fAreaMin+fAreaMax)/2.);
222 
223  GausFit->SetParLimits(6,0,1.1*Max);
224  GausFit->FixParameter(7,0);
225  GausFit->SetParLimits(8,0,(fAreaMin+fAreaMax)/2.);
226 
227 
228  HistArea->Fit(GausFit);
229 
230  double Mean = GausFit->GetParameter(1);
231  double Width = GausFit->GetParameter(2);
232 
233  double MeanErr = GausFit->GetParError(1);
234  double WidthErr = GausFit->GetParError(2);
235 
236  double NPE = pow(Mean,2)/pow(Width,2);
237  double SPEScale = Mean / NPE;
238 
239  double NPEError = NPE * pow(2.*(pow(MeanErr/Mean,2) + pow(WidthErr/Width,2)),0.5);
240  double SPEError = SPEScale * pow(2.*pow(WidthErr/Width,2) + pow(MeanErr/Mean,2),0.5);
241 
242  std::cout <<"Channel " << Channel<< ":\tSPE Scale \t"<<SPEScale<<"\t +/- \t" << SPEError<<",\t NPE \t" << NPE<<"\t +/- \t"<< NPEError <<std::endl;
243  }
244 
245  }
246 
247 
248 
249  //-----------------------------------------------------------------------
251  {
252 
253  auto const* ts = lar::providerFrom<detinfo::DetectorClocksService>();
254 
255 
256  fRunID=evt.run();
257  fEventID=evt.event();
258 
260 
261  // Create a handle for our vector of pulses
263 
264  // Read in WaveformHandle
265  evt.getByLabel(fInputModule, OpDetWaveformHandle);
266 
267  std::map<uint32_t, std::vector<int> > OrgOpDigitByChannel;
268 
269  for(size_t i=0; i!=OpDetWaveformHandle->size(); ++i)
270  {
271  OrgOpDigitByChannel[ShaperToChannel(OpDetWaveformHandle->at(i).ChannelNumber())].push_back(i);
272  }
273 
274  std::vector<uint32_t> FrameNumbersForTrig;
275  std::vector<uint32_t> TimeSlicesForTrig;
276 
277  for(size_t i=0; i!=OrgOpDigitByChannel[fTriggerChannel].size(); ++i)
278  {
279  double TimeStamp = OpDetWaveformHandle->at(OrgOpDigitByChannel[ fTriggerChannel][i] ).TimeStamp();
280  uint32_t Frame = ts->OpticalClock().Frame(TimeStamp);
281  uint32_t TimeSlice = ts->OpticalClock().Sample(TimeStamp);
282  FrameNumbersForTrig.push_back(Frame);
283  TimeSlicesForTrig.push_back(TimeSlice);
284  }
285 
286  for(size_t i=0; i!=OpDetWaveformHandle->size(); ++i)
287  {
288  double TimeStamp = OpDetWaveformHandle->at(i).TimeStamp();
289  uint32_t Frame = ts->OpticalClock().Frame(TimeStamp);
290  uint32_t TimeSlice = ts->OpticalClock().Sample(TimeStamp);
291  fShaper = OpDetWaveformHandle->at(i).ChannelNumber();
293 
294 
295  if(uint32_t(fChannel) != fTriggerChannel)
296  {
297  for(size_t j=0; j!=FrameNumbersForTrig.size(); ++j)
298  {
299  if( (Frame == FrameNumbersForTrig.at(j))
300  && (fabs(TimeSlice - TimeSlicesForTrig.at(j) - fTriggerDelay)<fCoincThreshold))
301  {
302 
303 
304  const raw::OpDetWaveform& wf = OpDetWaveformHandle->at(i);
305 
306  //fPulseRecoMgr.RecoPulse(wf);
308 
309  size_t NPulses = fThreshAlg.GetNPulse();
310 
311  fOffset = TimeSlice-TimeSlicesForTrig.at(j);
312  //fPedMean = fThreshAlg.PedMean();
313  //fPedRMS = fThreshAlg.PedRms();
314 
315  for(size_t k=0; k!=NPulses; ++k)
316  {
318  {
319 
327 
328  fPulseTree->Fill();
329 
330  fAreas[fChannel].push_back(fArea);
331  }
332  else if(fMakeNonCoincTree)
333  {
339 
340  fPulseTreeNonCoinc->Fill();
341  }
342  }
343  }
344  }
345  }
346  }
347 
348  }
349 
350  //---------------------------------
351  uint32_t LEDCalibrationAna::ShaperToChannel(uint32_t Shaper)
352  {
353  static std::map<uint32_t, uint32_t> ShaperToChannelMap;
354  if(ShaperToChannelMap.size()==0)
355  {
356 
357  // temporary
358  for(size_t i=0; i!=40; ++i)
359  {
360  ShaperToChannelMap[i]=i;
361  }
362  }
363 
364  return ShaperToChannelMap[Shaper];
365  }
366 
367 
368 } // namespace opdet
369 
370 namespace opdet {
372 }
pmtana::AlgoThreshold fThreshAlg
void AddRecoAlgo(pmtana::PMTPulseRecoBase *algo, PMTPedestalBase *ped_algo=nullptr)
A method to set pulse reconstruction algorithm.
void analyze(const art::Event &)
size_t GetNPulse() const
A getter for the number of reconstructed pulses from the input waveform.
pmtana::PulseRecoManager fPulseRecoMgr
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
bool Reconstruct(const pmtana::Waveform_t &) const
Implementation of ana_base::analyze method.
T get(std::string const &key) const
Definition: ParameterSet.h:231
EventNumber_t event() const
Definition: Event.h:67
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Class definition file of AlgoThreshold.
void SetDefaultPedAlgo(pmtana::PMTPedestalBase *algo)
A method to set a choice of pedestal estimation method.
std::map< uint32_t, std::vector< double > > fAreas
Class definition file of PedAlgoEdges.
uint32_t ShaperToChannel(uint32_t Shaper)
LEDCalibrationAna(const fhicl::ParameterSet &)
RunNumber_t run() const
Definition: Event.h:77
const pulse_param & GetPulse(size_t index=0) const
art framework interface to geometry description
Class definition file of PulseRecoManager.