ICEBERGPDSSPMonitor_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ICEBERGPDSSPMonitor
3 // Plugin Type: analyzer (art v3_02_06)
4 // File: ICEBERGPDSSPMonitor_module.cc
5 //
6 // Generated at Wed Oct 9 23:18:50 2019 by Biswaranjan Behera using cetskelgen
7 // from cetlib version v3_07_02.
8 ////////////////////////////////////////////////////////////////////////
9 
10 // ROOT includes
11 #include "TH1.h"
12 #include "TH1D.h"
13 #include "TH2.h"
14 #include "TGraph.h"
15 #include "TTree.h"
16 
17 // LArSoft includes
22 
23 // Framework includes
31 #include "fhiclcpp/ParameterSet.h"
33 #include "canvas/Persistency/Common/FindManyP.h"
37 #include "art_root_io/TFileService.h"
38 #include "art_root_io/TFileDirectory.h"
39 
40 // C++ Includes
41 #include <memory>
42 #include <map>
43 #include <vector>
44 #include <set>
45 
46 
47 namespace icebergpd {
48  class ICEBERGPDSSPMonitor;
49 }
50 
51 
53 public:
54  explicit ICEBERGPDSSPMonitor(fhicl::ParameterSet const& pset);
55  // The compiler-generated destructor is fine for non-base
56  // classes without bare pointers or other resource use.
57 
58  // Plugins should not be copied or assigned.
63 
64  // Required functions.
65  void analyze(art::Event const& evt) override;
66 
67 private:
68 
69  // Declare member data here.
70  // The parameters we'll read from the .fcl file.
71 
72  std::string fOpDetWaveformModuleLabel; // Input tag for OpDetWaveform
73  std::string fOpHitModuleLabel; // Input tag for OpHit
74 
75  double fSampleFreq; // Sampling frequency in MHz
76 
77  // Map to store how many waveforms are on one optical channel
78  std::map< int, TH1D* > avgWaveforms;
79  std::map< int, int > countWaveform;
80  std::map<size_t,TH2D*> persistent_waveform_;
81 
82  std::map< size_t, TH2D* > Waveforms;
83 
84  std::map< int, TH1F* > maxadchist;
85  std::map< int, int > ADC;
86  std::map< int, int > maxadc;
87  std::map< int, int > threshold;
88  // std::map< int, int > PEdist;
92  //std::map<int, int>::iterator it;
93 
94  // Implementation of required member function here.
96 
97 
98  // TH2F* smear = tfs->make<TH2F>("smear", ";S-arapuca; X-arapuca;", 100, 1800, 18000, 100, 1800,18000);
99  // TH2F* smear = new TH2F("smear", ";S-arapuca; X-arapuca;", 100, 1800, 18000, 100, 1800,18000);
100 
101  TTree * fADCTree;
102  Float_t fmaxadc3;
103  Float_t fmaxadc7;
104  Float_t fdistpe;
105  Float_t fpedestal;
106  Float_t fthres3;
107  Float_t fthres7;
108  Float_t fpe3;
109  Float_t fpe7;
110 
111  Float_t fadc3;
112  Float_t fadc7;
113 
114  float fbaseline3;
115  float fbaseline7;
116 
117  std::vector< Int_t > fadcval7;
118  std::vector< Int_t > fadcval3;
119 };
120 
121 
123  : EDAnalyzer{pset} // ,
124  // More initializers here.
125 {
126  // Call appropriate consumes<>() for any products to be retrieved by this module.
127  fOpDetWaveformModuleLabel = pset.get<std::string>("OpDetWaveformLabel");
128  fOpHitModuleLabel = pset.get<std::string>("OpHitLabel");
129 
130  fADCTree = tfs->make<TTree>("ADCTree","ADCTree");
131  fADCTree->Branch("Channel7", &fmaxadc7, "Channel7/F");
132  fADCTree->Branch("Channel3", &fmaxadc3, "Channel3/F");
133  fADCTree->Branch("distpe", &fdistpe, "distpe/F");
134  fADCTree->Branch("pedestal", &fpedestal, "pedestal/F");
135  fADCTree->Branch("thres3", &fthres3, "thres3/F");
136  fADCTree->Branch("thres7", &fthres7, "thres7/F");
137  fADCTree->Branch("PE7", &fpe7, "PE7/F");
138  fADCTree->Branch("PE3", &fpe3, "PE3/F");
139  fADCTree->Branch("ADC7", &fadc7, "ADC7/F");
140  fADCTree->Branch("ADC3", &fadc3, "ADC3/F");
141  fADCTree->Branch("Baseline3", &fbaseline3, "Baseline3/F");
142  fADCTree->Branch("Baseline7", &fbaseline7, "Baseline7/F");
143  fADCTree->Branch("adcval7", &fadcval7);
144  fADCTree->Branch("adcval3", &fadcval3);
145 }
146 
148 {
149 
150  // Get Ophit from the event
151  auto OpHitHandle = evt.getHandle< std::vector< recob::OpHit > >(fOpHitModuleLabel);
152 
153  // Get OpDetWaveforms from the event
154  auto OpDetWaveformHandle = evt.getHandle< std::vector< raw::OpDetWaveform > >(fOpDetWaveformModuleLabel);
155 
156  // std::cout<< "Event #" << evt.id().event() <<"\t" << OpDetWaveformHandle->size() << std::endl;
157 
158  // Obtain parameters from DetectorClocksService
159  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
160  fSampleFreq = clockData.OpticalClock().Frequency();
161 
162  int n = 0; int ntick = 0; int three = 0; int seven = 0;// float adc = 0;
163  long int adcmax = 0; long int adcval = 0; long int adcval3 = 0, adcval7 = 0, sig_adcval3 = 0, sig_adcval7 = 0;
164 
165  double sumthres7 = 0, pedist3 = 0, pedist7 = 0, thres = 0, thres3 = 0, thres7 = 0;
166  maxadc[3] = 0.0;
167  maxadc[7] = 0.0;
168  for (size_t i = 0; i < OpDetWaveformHandle->size(); i++)
169  {
170  // This was probably required to overcome the "const" problem
171  // with OpDetPulse::Waveform()
172  art::Ptr< raw::OpDetWaveform > waveformPtr(OpDetWaveformHandle, i);
173  // raw::OpDetWaveform pulse = *waveformPtr;
174 
175  int channel = waveformPtr->ChannelNumber();
176  //std::cout<< "channel # -------" << channel << std::endl;
177  if (channel ==3) three++;
178  if (channel ==7) seven++;
179  // channel 3 is S-ARAPUCA and channel 7 is X-ARAPUCA
180  if(channel != 3 && channel != 7) continue;
181  //if(channel != 3) continue;
182  // std::cout<< "Event #" << evt.id().event() << "\t ............"<<std::endl;
183 
184 
185  /*
186  // Create the TH1 if it doesn't exist
187  if (avgWaveforms.find(channel) == avgWaveforms.end() ) {
188  TString histName = TString::Format("avgwaveform_channel_%03i", channel);
189  avgWaveforms[channel] = tfs->make< TH1D >(histName, ";t (us);", waveformPtr->size(), 0, double(waveformPtr->size()) / fSampleFreq);
190  // avgWaveforms[channel] = tfs->make< TH1D >(histName, ";time sample;", waveformPtr->size(), 0, double(waveformPtr->size()));
191  }
192  // Add this waveform to this histogram
193  for (size_t tick = 0; tick < waveformPtr->size(); tick++) {
194  avgWaveforms[channel]->Fill(double(tick)/fSampleFreq, waveformPtr->at(tick));
195  //avgWaveforms[channel]->Fill(waveformPtr->at(tick));
196  }
197  */
198 
199  // Count number of waveforms on each channel
201 
202 
203  if (Waveforms.find(channel) == Waveforms.end())
204  {
205  //TString histName = TString::Format("waveform_channel_%03i", channel);
206  Waveforms[channel] = tfs->make<TH2D>(Form("waveform_%d",channel),Form("waveform_%d",channel), 2000,0,2000, 20000, 0, 20000);
207  //pwave->SetTitle(Form("Persistent waveform - Channel %d",channel));
208  // pwave->GetYaxis()->SetTitle("ADC value");
209  // pwave->GetXaxis()->SetTitle("Time sample");
210  // persistent_waveform_[channel] = pwave;
211  // std::cout << persistent_waveform_.find(channel)->second << std::endl;
212  }
213 
214 
215 
216  for (size_t tick = 0; tick < waveformPtr->size(); tick++) {
217  //avgWaveforms[channel]->Fill(double(tick)/fSampleFreq, waveformPtr->at(tick));
218  Waveforms[channel]->Fill(tick+1, waveformPtr->at(tick));
219  adcval = waveformPtr->at(tick);
220  ADC[channel] = adcval;
221  adcmax = std::max(adcmax, adcval);
222 
223  if (channel == 3) {
224  fadcval3 .emplace_back(waveformPtr->at(tick));
225  if (tick <= 700){thres += adcval; n++; adcval3 = waveformPtr->at(tick) - 1587;
226  thres3 += adcval3;
227  }
228  if (tick < 1300 && tick > 790){
229  sig_adcval3 = waveformPtr->at(tick) - 1587;
230  pedist3 += sig_adcval3;}}
231  // if (channel == 3) {
232  //if (adcval < 1586) continue;
233  //}
234 
235  if (channel == 7) {
236  fadcval7 .emplace_back(waveformPtr->at(tick));
237  if (tick <= 700){sumthres7 += adcval; ntick++; adcval7 = waveformPtr->at(tick) - 1524; thres7 += adcval7;}//if (adcval < 1586) continue;
238  if (tick < 1300 && tick > 790){
239  sig_adcval7 = waveformPtr->at(tick) -1524;
240  pedist7 += sig_adcval7;}}
241  //}
242  // std::cout << "adcvalue \t"<< adcval <<"\t adcmax \t"<< adcmax <<std::endl;
243 
244  }
245 
246  //if (channel == 3)
247  fthres3 = thres3;
248  //if (channel == 7)
249  fthres7 = thres7;
250 // std::cout <<"\t thres3 \t"<< thres3 <<std::endl;
251  fpe3 = pedist3;
252  fpe7 = pedist7;
253  fbaseline3 = thres/n;
254  fbaseline7 = sumthres7/ntick;
255 
256 
257 
258  // std::cout << "Event #" << evt.id().event() <<"\t" << n << "\t"<< thres <<"\t"<< thres/n <<std::endl;
259  if (maxadchist.find(channel) == maxadchist.end()){
260  TString histname = TString::Format("Maxadc_channel_%03i", channel);
261  maxadchist[channel] = tfs->make<TH1F>(histname,";Maximum ADC; Events", 50, 0,20000);
262  }
263 
264  maxadchist[channel]->Fill(adcmax);
265 
266  for (adcit = ADC.begin(); adcit != ADC.end(); ++adcit) {
267  //std::cout << '\t' << adcit->first
268  // << '\t' << adcit->second << std::endl;
269  if (adcit->first == 3 ) fadc3 = adcit->second;
270  if (adcit->first == 7 ) fadc7 = adcit->second;
271  }
272 
273  maxadc[channel] = adcmax;
274  //threshold[channel] = thres;
275  //PEdist[channel] = pedist;
276 
277  //std::cout<<channel<<
278  // smear->Fill( maxadc(3).second, maxadc(7).second);
279  //
280 
281 
282 
283  // std::cout<< "Event #........." << evt.id().event() <<"\t" << OpDetWaveformHandle->size() << "\t"<<channel<< std::endl;
284  }
285  // fdistpe = pedist;
286  //fpedestal = sumthres;
287  // std::cout << sumthres << "\t" << pedist <<std::endl;
288  for (itr = maxadc.begin(); itr != maxadc.end(); ++itr) {
289  // std::cout << '\t' << itr->first
290  // << '\t' << itr->second << std::endl;
291  if (itr->first == 3 ) fmaxadc3 = itr->second;
292  if (itr->first == 7 ) fmaxadc7 = itr->second;
293  }
294 
295 
296 
297  //for (i = threshold.begin(); i != threshold.end(); ++i) {
298  // std::cout << '\t' << i->first
299  // << '\t' << i->second << std::endl;
300  //if (i->first == 3 ) fthres3 = i->second;
301  //if (i->first == 7 ) fthres7 = i->second;
302  //}
303 
304  // for (it = PEdist.begin(); it != PEdist.end(); ++it) {
305  // std::cout << '\t' << it->first
306  // << '\t' << it->second << std::endl;
307  //if (it->first == 3 ) fpe3 = it->second;
308  //if (it->first == 7 ) fpe7 = it->second;
309  //}
310 
311 
312 
313  fADCTree->Fill();
314  fadcval3.clear();
315  fadcval7.clear();
316  // std::cout << n << "\t" << three << "\t" << seven << "\t" <<"\t adcmax \t"<< adcmax << std::endl;
317 
318  /*
319  if (persistent_waveform_.find(channel) == persistent_waveform_.end())
320  {
321  TH2D* pwave = tfs->make<TH2D>(Form("persistent_waveform_%d",channel),Form("persistent_waveform_%d",channel), 500,0, 2000, 20000, 0, 20000);
322  pwave->SetTitle(Form("Persistent waveform - Channel %d",channel));
323  pwave->GetYaxis()->SetTitle("ADC value");
324  pwave->GetXaxis()->SetTitle("Time sample");
325  persistent_waveform_[channel] = pwave;
326  // std::cout << persistent_waveform_.find(channel)->second << std::endl;
327  }
328 
329  TH2D *pwavep = persistent_waveform_[channel];
330 
331  for (size_t iadc=0; iadc < waveformPtr->size(); ++iadc)
332  {
333 
334  auto adcval = waveformPtr->at(iadc);
335  //adc_values_->Fill(adcval);
336  // std::cout << iadc <<"\t" << adcval << "\t" << nADC << std::endl;
337  ///> Save the waveforms for all traces like an oscilloscope
338  pwavep->Fill(iadc,adcval,1); // (x,y,weight=1)
339  // hist->SetBinContent(iadc+1,adcval);
340  }
341 
342  }
343 */
344 
345 
346 }
347 
348 
intermediate_table::iterator iterator
std::map< size_t, TH2D * > persistent_waveform_
Format
Definition: utils.h:7
Channel_t ChannelNumber() const
Definition: OpDetWaveform.h:65
std::map< int, int >::iterator i
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
ICEBERGPDSSPMonitor(fhicl::ParameterSet const &pset)
uint8_t channel
Definition: CRTFragment.hh:201
std::map< int, int >::iterator adcit
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
ICEBERGPDSSPMonitor & operator=(ICEBERGPDSSPMonitor const &)=delete
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::map< int, int >::iterator itr
void analyze(art::Event const &evt) override
std::void_t< T > n
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
static int max(int a, int b)
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:7
Definition: fwd.h:31