All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnaProducer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: AnaProducer
3 // Module Type: analyzer
4 // File: AnaProducer_module.cc
5 // Description: Makes a tree with waveform information.
6 ////////////////////////////////////////////////////////////////////////
7 
8 #include "art/Framework/Core/EDAnalyzer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 
13 #include "canvas/Utilities/Exception.h"
14 
15 #include "sbndaq-artdaq-core/Overlays/Common/BernCRTFragment.hh"
16 #include "artdaq-core/Data/Fragment.hh"
17 #include "artdaq-core/Data/ContainerFragment.hh"
18 #include "sbndaq-artdaq-core/Overlays/FragmentType.hh"
19 
20 #include "sbndaq-artdaq-core/Overlays/Common/BernCRTTranslator.hh"
21 
22 //#include "art/Framework/Services/Optional/TFileService.h"
23 #include "art_root_io/TFileService.h"
24 #include "TH1F.h"
25 #include "TNtuple.h"
26 
27 #include <algorithm>
28 #include <cassert>
29 #include <cmath>
30 #include <fstream>
31 #include <iomanip>
32 #include <vector>
33 #include <map>
34 #include <iostream>
35 
40 
41 using std::vector;
42 using std::map;
43 
44 namespace icarus {
45  namespace crt {
46  class AnaProducer;
47  }
48 }
49 
50 class icarus::crt::AnaProducer : public art::EDAnalyzer {
51 
52 public:
53  struct Config {
54 
55  // Save some typing:
56  using Name = fhicl::Name;
57  using Comment = fhicl::Comment;
58 
59  fhicl::Atom<float> PeThresh {
60  Name("peThreshold"),
61  Comment("used for determining if a channel is above the discriminator threshold")
62  };
63 
64  // One Atom for each parameter
65  fhicl::Atom<std::string> CalFile {
66  Name("calFile"),
67  Comment("Full path to calibration file")
68  };
69  // One Atom for each parameter
70  fhicl::Atom<bool> Calibrate {
71  Name("calibrate"),
72  Comment("calibrate the data (true) or read from cal file (false)")
73  };
74 
75  fhicl::Atom<uint8_t> Region {
76  Name("region"),
77  Comment("CRT region e.g. north (n) or west (w)")
78  };
79  fhicl::Atom<uint8_t> Layer {
80  Name("layer"),
81  Comment("CRT layer inner (i) or outer (o)")
82  };
83 
84  fhicl::Sequence<uint8_t> MacsNI {
85  Name("macsNI"),
86  Comment("mac addresses for each FEB in the north, inner daisychain")
87  };
88  fhicl::Sequence<uint8_t> MacsNO {
89  Name("macsNO"),
90  Comment("mac addresses for each FEB in the north, outer daisychain")
91  };
92  fhicl::Sequence<uint8_t> MacsWI {
93  Name("macsWI"),
94  Comment("mac addresses for each FEB in the west, inner daisychain")
95  };
96  fhicl::Sequence<uint8_t> MacsWO {
97  Name("macsWO"),
98  Comment("mac addresses for each FEB in the west, outer daisychain")
99  };
100 
101  };
102 
103  using Parameters = art::EDAnalyzer::Table<Config>;
104 
105  explicit AnaProducer(Parameters const& config); // explicit doesn't allow for copy initialization
106  virtual ~AnaProducer();
107 
108  virtual void beginJob();
109  virtual void analyze(art::Event const & evt);
110  virtual void endJob();
111 
112 
113 private:
114  string pFile;
116  vector<uint8_t> pMacs;
117  float pPeThresh;
118 
119  map<uint8_t,vector<TH1F*>*> fMacToHistos;
120  map<uint8_t,vector<TH1F*>*> fMacToPEHistos;
121 
123 
124  //rawTree
125  //data payload
126  uint8_t fMac5; //last 8 bits of FEB mac5 address
127  uint16_t fFlags;
128  uint16_t fLostcpu;
129  uint16_t fLostfpga;
130  uint32_t fTs0;
131  uint32_t fTs1;
132  uint16_t fAdc[32];
133  uint32_t fCoinc;
134 
135  //metadata
136  uint64_t fRun_start_time;
138  uint64_t fThis_poll_end;
140  uint64_t fLast_poll_end;
142  uint32_t fFeb_in_poll;
144 
145  //information from fragment header
146  uint32_t fSequence_id;
148 
149  //anaTree
150  bool fIsNoise;
151  uint8_t fMaxChan;
152  float fMaxPE;
153  float fTotPE;
154  float fPE[32];
155  uint8_t fNChanAbove;
156  bool fAbove[32];
157  uint64_t fT0;
158  int fRegion;
159  int fLayer;
160  float fPollRate;
161  float fInstRate;
162 
163  //calTree
164  bool fActive[32];
165  float fGain[32];
166  float fGainErr[32];
167  float fGainXsqr[32];
168  short fGainNdf[32];
169  float fGainPed[32];
170  float fGainPedErr[32];
171  short fNpeak[32];
172  float fPed[32];
173  float fPedErr[32];
174  float fPedXsqr[32];
175  short fPedNdf[32];
176  float fPedSigma[32];
177  float fPedSigmaErr[32];
178  float fPedNorm[32];
179  float fPedNormErr[32];
180  int fThreshADC[32];
181  float fThreshPE[32];
182  int fNabove[32];
183  float fPeakNorm[32][5];
184  float fPeakNormErr[32][5];
185  float fPeakSigma[32][5];
186  float fPeakSigmaErr[32][5];
187  float fPeakMean[32][5];
188  float fPeakMeanErr[32][5];
189  float fPeakXsqr[32][5];
190  short fPeakNdf[32][5];
191 
192 };
193 
194 //Define the constructor
196  : EDAnalyzer(config),
197  pFile(config().CalFile()),
198  pCalibrate(config().Calibrate()),
199  //pMacs(config().Macs()),
200  pPeThresh(config().PeThresh()),
201  fRegion(config().Region()),
202  fLayer(config().Layer())
203 {
204 
205  if (fRegion==0 && fLayer==1) pMacs = config().MacsNI();
206  else if(fRegion==0 && fLayer==0) pMacs = config().MacsNO();
207  else if(fRegion==1 && fLayer==1) pMacs = config().MacsWI();
208  else if(fRegion==1 && fLayer==0) pMacs = config().MacsWO();
209  else std::cout << "ERROR in AnaProducer::AnaProducer: bad region and/or layer codes!" << std::endl;
210 
211  //this is how you setup/use the TFileService
212  //I do this here in the constructor to setup the histogram just once
213  //but you can call the TFileService and make new objects from anywhere
214  art::ServiceHandle<art::TFileService> tfs; //pointer to a file named tfs
215 
216  fCalTree = 0;
217  if(pCalibrate)
218  fCalTree = tfs->make<TTree>("calTree","gain, pedestal, and fit statistics");
219  fRawTree = tfs->make<TTree>("rawTree", "fields from DAQ framqments with metadata");
220  fAnaTree = tfs->make<TTree>("anaTree","calibrated charge, low-level ana");
221 
222  //rawTree
223  fRawTree->Branch("mac5", &fMac5, "mac5/b");
224  fRawTree->Branch("flags", &fFlags, "flags/s");
225  fRawTree->Branch("lostcpu", &fLostcpu, "lostcpu/s");
226  fRawTree->Branch("lostfpga", &fLostfpga, "lostfpga/s");
227  fRawTree->Branch("ts0", &fTs0, "ts0/i");
228  fRawTree->Branch("ts1", &fTs1, "ts1/i");
229  fRawTree->Branch("adc", &fAdc, "adc[32]/s");
230  fRawTree->Branch("coinc", &fCoinc, "coinc/i");
231  fRawTree->Branch("run_start_time", &fRun_start_time, "run_start_time/l");
232  fRawTree->Branch("this_poll_start", &fThis_poll_start, "this_poll_start/l");
233  fRawTree->Branch("this_poll_end", &fThis_poll_end, "this_poll_end/l");
234  fRawTree->Branch("last_poll_start", &fLast_poll_start, "last_poll_start/l");
235  fRawTree->Branch("last_poll_end", &fLast_poll_end, "last_poll_end/l");
236  fRawTree->Branch("system_clock_deviation", &fSystem_clock_deviation, "system_clock_deviation/I");
237  fRawTree->Branch("feb_in_poll", &fFeb_in_poll, "feb_in_poll/i");
238  fRawTree->Branch("feb_event_number", &fFeb_event_number, "feb_event_number/i");
239  fRawTree->Branch("sequence_id", &fSequence_id, "sequence_id/i");
240  fRawTree->Branch("fragment_timestamp", &fFragment_timestamp, "fragment_timestamp/l");
241 
242  //anaTree
243  fAnaTree->Branch("mac5", &fMac5, "mac5/b");
244  fAnaTree->Branch("pe", fPE, "pe[32]/F");
245  fAnaTree->Branch("active", fActive, "active[32]/O");
246  fAnaTree->Branch("maxChan", &fMaxChan, "maxChan/b");
247  fAnaTree->Branch("maxPE", &fMaxPE, "maxPE/F");
248  fAnaTree->Branch("totPE", &fTotPE, "totPE/F");
249  fAnaTree->Branch("nAbove", &fNChanAbove, "nAbove/b");
250  fAnaTree->Branch("above", fAbove, "above[32]/O");
251  fAnaTree->Branch("isNoise", &fIsNoise, "isNoise/O");
252  fAnaTree->Branch("region", &fRegion, "region/I");
253  fAnaTree->Branch("layer", &fLayer, "layer/I");
254  fAnaTree->Branch("t0", &fT0, "t0/l");
255  fAnaTree->Branch("pollRate", &fPollRate, "pollRate/F");
256  fAnaTree->Branch("instRate", &fInstRate, "instRate/F");
257 
258  //calTree
259  if(pCalibrate){
260  fCalTree->Branch("mac5", &fMac5, "mac5/b");
261  fCalTree->Branch("active", fActive, "active[32]/O");
262  fCalTree->Branch("gain", fGain, "gain[32]/F");
263  fCalTree->Branch("gainErr", fGainErr, "gainErr[32]/F");
264  fCalTree->Branch("gainXsqr", fGainXsqr, "gainXsqr[32]/F");
265  fCalTree->Branch("gainNdf", fGainNdf, "gainNdf[32]/s");
266  fCalTree->Branch("gainPed", fGainPed, "gainPed[32]/F");
267  fCalTree->Branch("gainPedErr", fGainPedErr, "gainPedErr[32]/F");
268  fCalTree->Branch("nPeak", fNpeak, "nPeak[32]/s");
269  fCalTree->Branch("peakXsqr", fPeakXsqr, "peakXsqr[32][5]/F");
270  fCalTree->Branch("peakNdf", fPeakNdf, "peakNdf[32][5]/s");
271  fCalTree->Branch("peakMean", fPeakMean, "peakMean[32][5]/F");
272  fCalTree->Branch("peakMeanErr", fPeakMeanErr, "peakMeanErr[32][5]/F");
273  fCalTree->Branch("peakNorm", fPeakNorm, "peakNorm[32][5]/F");
274  fCalTree->Branch("peakNormErr", fPeakNormErr, "peakNormErr[32][5]/F");
275  fCalTree->Branch("peakSigma", fPeakSigma, "peakSigma[32][5]/F");
276  fCalTree->Branch("peakSigmaErr", fPeakSigmaErr, "peakSigmaErr[32][5]/F");
277  fCalTree->Branch("ped", fPed, "ped[32]/F");
278  fCalTree->Branch("pedErr", fPedErr, "pedErr[32]/F");
279  fCalTree->Branch("pedXsqr", fPedXsqr, "pedXsqr[32]/F");
280  fCalTree->Branch("pedNdf", fPedNdf, "pedNdf[32]/s");
281  fCalTree->Branch("pedSigma", fPedSigma, "pedSigma[32]/F");
282  fCalTree->Branch("pedSigmaErr", fPedSigmaErr, "pedSigmaErr[32]/F");
283  fCalTree->Branch("pedNorm", fPedNorm, "pedNorm[32]/F");
284  fCalTree->Branch("pedNormErr", fPedNormErr, "pedNormErr[32]/F");
285  fCalTree->Branch("threshAdc", fThreshADC, "threshAdc[32]/I");
286  fCalTree->Branch("threshPe", fThreshPE, "threshPe[32]/F");
287  fCalTree->Branch("nAbove", fNabove, "nAbove[32]/I");
288 
289  }//end if pCal
290 
291 
292  //initialize vars
293  fMac5 = 0;
294  fFlags = 0;
295  fLostcpu = 0;
296  fLostfpga = 0;
297  fTs0 = 0;
298  fTs1 = 0;
299  for(int i=0; i<32; ++i) fAdc[i] = 0;
300  fCoinc = 0;
301  fRun_start_time = 0;
302  fThis_poll_start = 0;
303  fThis_poll_end = 0;
304  fLast_poll_start = 0;
305  fLast_poll_end = 0;
307  fFeb_in_poll = 0;
308  fFeb_event_number = 0;
309  fSequence_id = 0;
311 
312  fIsNoise = false;
313  fMaxChan = 33;
314  fMaxPE = -1.;
315  fTotPE = -1.;
316  fNChanAbove = 0;
317  fT0 = 0;
318  fRegion = config().Region();
319  fLayer = config().Layer();
320  fPollRate = 0.;
321  fInstRate = 0.;
322 
323 
324  //generate histograms
325  for(int i=0; i<(int)pMacs.size(); i++){
326  fMacToHistos[pMacs[i]] = new vector<TH1F*>();
327  fMacToPEHistos[pMacs[i]] = new vector<TH1F*>();
328  for(int ch=0; ch<32; ch++){
329  string hname = "hadc_"+to_string(pMacs[i])+"_"+to_string(ch);
330  string htitle = "raw charge: mac5 "+to_string(pMacs[i])+", ch. "+to_string(ch);
331  fMacToHistos[pMacs[i]]->push_back(tfs->make<TH1F>(hname.c_str(),htitle.c_str(),4100,0,4100));
332 
333  string hnamePE = "hpe_"+to_string(pMacs[i])+"_"+to_string(ch);
334  string htitlePE = "calibrated charge: mac5 "+to_string(pMacs[i])+", ch. "+to_string(ch);
335  fMacToPEHistos[pMacs[i]]->push_back(tfs->make<TH1F>(hnamePE.c_str(),htitlePE.c_str(),2000,-5,95));
336  }
337  }
338 
339  for(int i=0; i<32; i++) {
340  fPE[i] = -1.;
341  fAbove[i] = false;
342  fActive[i] = false;
343  fGain[i] = FLT_MAX;
344  fGainErr[i] = FLT_MAX;
345  fGainXsqr[i] = FLT_MAX;
346  fGainNdf[i] = SHRT_MAX;
347  fGainPed[i] = FLT_MAX;
348  fGainPedErr[i] = FLT_MAX;
349  fNpeak[i] = SHRT_MAX;
350  fPed[i] = FLT_MAX;
351  fPedErr[i] = FLT_MAX;
352  fPedXsqr[i] = FLT_MAX;
353  fPedNdf[i] = SHRT_MAX;
354  fPedSigma[i] = FLT_MAX;
355  fPedSigmaErr[i] = FLT_MAX;
356  fPedNorm[i] = FLT_MAX;
357  fPedNormErr[i] = FLT_MAX;
358  fThreshADC[i] = INT_MAX;
359  fThreshPE[i] = FLT_MAX;
360  fNabove[i] = INT_MAX;
361 
362  for(size_t j=0; j<5; j++){
363  fPeakNorm[i][j] = FLT_MAX;
364  fPeakNormErr[i][j] = FLT_MAX;
365  fPeakSigma[i][j] = FLT_MAX;
366  fPeakSigmaErr[i][j] = FLT_MAX;
367  fPeakMean[i][j] = FLT_MAX;
368  fPeakMeanErr[i][j] = FLT_MAX;
369  fPeakXsqr[i][j] = FLT_MAX;
370  fPeakNdf[i][j] = SHRT_MAX;
371  }
372  }
373 
374 }
375 
377 {
378 }
379 
381 
382 }
383 
384 void icarus::crt::AnaProducer::analyze(art::Event const & evt)
385 {
386  //WK 09/02/21. Update to BernCRTTranslator in sbndaq_artdaq_core
387  std::vector<icarus::crt::BernCRTTranslator> hit_vector;
388 
389  auto fragmentHandles = evt.getMany<artdaq::Fragments>();
390  for (auto handle : fragmentHandles) {
391  if (!handle.isValid() || handle->size() == 0)
392  continue;
393 
394  auto this_hit_vector = icarus::crt::BernCRTTranslator::getCRTData(*handle);
395 
396  hit_vector.insert(hit_vector.end(),this_hit_vector.begin(),this_hit_vector.end());
397 
398  }
399 
400  for(auto & hit : hit_vector) {
401 
402  fFragment_timestamp = hit.timestamp;
403  fSequence_id = hit.sequence_id;
404 
405  fMac5 = hit.mac5;
406  fFlags = hit.flags;
407  fLostcpu = hit.lostcpu;
408  fLostfpga = hit.lostfpga;
409  fTs0 = hit.ts0;
410  fTs1 = hit.ts1;
411  fCoinc = hit.coinc;
412 
413  for(int ch=0; ch<32; ch++){
414  fMacToHistos[fMac5]->at(ch)->Fill( hit.adc[ch] );
415  fAdc[ch] = hit.adc[ch];
416  }
417 
418  fRun_start_time = hit.run_start_time;
419  fThis_poll_start = hit.this_poll_start;
420  fThis_poll_end = hit.this_poll_end;
421  fLast_poll_start = hit.last_poll_start;
422  fLast_poll_end = hit.last_poll_end;
423  fSystem_clock_deviation = hit.system_clock_deviation;
424  fFeb_in_poll = hit.hits_in_poll;
425  fFeb_event_number = hit.feb_hit_number;
426 
427  fRawTree->Fill();
428  }
429 } //analyze
430 
431 
433 
434  std::cout << "done filling histograms..." << std::endl;
435  std::cout << "found " << fMacToHistos.size() << " FEBs" << std::endl;
436  if(!fMacToHistos.begin()->second->empty()){
437  std::cout << "first histo size: " << fMacToHistos.begin()->second->at(0)->Integral()
438  << " entries" << std::endl;
439  }
440  else {
441  std::cout << "hist vect is empty!" << std::endl;
442  }
443 
444 
445  if(pCalibrate)
446  for(auto const& macHist : fMacToHistos){
447 
448  uint8_t mac = macHist.first;
449  vector<TH1F*>* hvec = macHist.second;
450 
451  std::cout << "construct instance of CrtCal for mac5 " << (short)mac << std::endl;
452  CrtCal* cal = new CrtCal(hvec);
453  cal->Cal();
454 
455  std::cout << "retreiving cal data..." << std::endl;
456  fMac5 = macHist.first;
457  bool* ptrActive = cal->GetActive();
458  float* ptrGain = cal->GetGain();
459  float* ptrGainErr = cal->GetGainErr();
460  float* ptrGainXsqr = cal->GetGainXsqr();
461  short* ptrGainNdf = cal->GetGainNdf();
462  float* ptrGainPed = cal->GetGainPed();
463  float* ptrGainPedErr = cal->GetGainPedErr();
464  short* ptrNpeak = cal->GetNpeak();
465  float** ptrPeakNorm = cal->GetPeakNorm();
466  float** ptrPeakNormErr = cal->GetPeakNormErr();
467  float** ptrPeakSigma = cal->GetPeakSigma();
468  float** ptrPeakSigmaErr = cal->GetPeakSigmaErr();
469  float** ptrPeakMean = cal->GetPeakMean();
470  float** ptrPeakMeanErr = cal->GetPeakMeanErr();
471  float** ptrPeakXsqr = cal->GetPeakXsqr();
472  short** ptrPeakNdf = cal->GetPeakNdf();
473  float* ptrPed = cal->GetPed();
474  float* ptrPedErr = cal->GetPedErr();
475  float* ptrPedXsqr = cal->GetPedXsqr();
476  short* ptrPedNdf = cal->GetPedNdf();
477  float* ptrPedSigma = cal->GetPedSigma();
478  float* ptrPedSigmaErr = cal->GetPedSigmaErr();
479  float* ptrPedNorm = cal->GetPedNorm();
480  float* ptrPedNormErr = cal->GetPedNormErr();
481  int* ptrThreshADC = cal->GetThreshADC();
482  float* ptrThreshPE = cal->GetThreshPE();
483  int* ptrNabove = cal->GetNabove();
484 
485  //copy values to local arrays
486  for(size_t i=0; i<32; i++){
487  if(ptrActive!=nullptr) fActive[i] = ptrActive[i];
488  if(ptrGain!=nullptr) fGain[i] = ptrGain[i];
489  if(ptrGainErr!=nullptr) fGainErr[i] = ptrGainErr[i];
490  if(ptrGainXsqr!=nullptr) fGainXsqr[i] = ptrGainXsqr[i];
491  if(ptrGainNdf!=nullptr) fGainNdf[i] = ptrGainNdf[i];
492  if(ptrGainPed!=nullptr) fGainPed[i] = ptrGainPed[i];
493  if(ptrGainPedErr!=nullptr) fGainPedErr[i] = ptrGainPedErr[i];
494  if(ptrNpeak!=nullptr) fNpeak[i] = ptrNpeak[i];
495  if(ptrPed!=nullptr) fPed[i] = ptrPed[i];
496  if(ptrPedErr!=nullptr) fPedErr[i] = ptrPedErr[i];
497  if(ptrPedXsqr!=nullptr) fPedXsqr[i] = ptrPedXsqr[i];
498  if(ptrPedNdf!=nullptr) fPedNdf[i] = ptrPedNdf[i];
499  if(ptrPedSigma!=nullptr) fPedSigma[i] = ptrPedSigma[i];
500  if(ptrPedSigmaErr!=nullptr) fPedSigmaErr[i] = ptrPedSigmaErr[i];
501  if(ptrPedNorm!=nullptr) fPedNorm[i] = ptrPedNorm[i];
502  if(ptrPedNormErr!=nullptr) fPedNormErr[i] = ptrPedNormErr[i];
503  if(ptrThreshADC!=nullptr) fThreshADC[i] = ptrThreshADC[i];
504  if(ptrThreshPE!=nullptr) fThreshPE[i] = ptrThreshPE[i];
505  if(ptrNabove!=nullptr) fNabove[i] = ptrNabove[i];
506 
507  for(size_t j=0; j<5; j++){
508  if(ptrPeakNorm!=nullptr) fPeakNorm[i][j] = ptrPeakNorm[i][j];
509  if(ptrPeakNormErr!=nullptr) fPeakNormErr[i][j] = ptrPeakNormErr[i][j];
510  if(ptrPeakSigma!=nullptr) fPeakSigma[i][j] = ptrPeakSigma[i][j];
511  if(ptrPeakSigmaErr!=nullptr) fPeakSigmaErr[i][j] = ptrPeakSigmaErr[i][j];
512  if(ptrPeakMean!=nullptr) fPeakMean[i][j] = ptrPeakMean[i][j];
513  if(ptrPeakMeanErr!=nullptr) fPeakMeanErr[i][j] = ptrPeakMeanErr[i][j];
514  if(ptrPeakXsqr!=nullptr) fPeakXsqr[i][j] = ptrPeakXsqr[i][j];
515  if(ptrPeakNdf!=nullptr) fPeakNdf[i][j] = ptrPeakNdf[i][j];
516  }
517  }
518 
519  std::cout << "fill tree event" << std::endl;
520  fCalTree->Fill();
521 
522  delete cal;
523 
524  }//end for mac5s if(pCalibrate)
525 
527  if(pCalibrate) ccl = new CrtCalTree(fCalTree);
528  else ccl = new CrtCalTree(pFile);
529 
530  //ccl->Dump();
531 
532  const size_t nRaw = fRawTree->GetEntriesFast();
533 
534  std::cout << "initiallizing time utility" << std::endl;
535  icarus::crt::CRTRawTree traw(fRawTree);
536  icarus::crt::CRTTiming time(traw);
537  const map<size_t,size_t>* sortedToRaw = time.GetOrderedToRawMap();
538  std::cout << "done. sorted through " << sortedToRaw->size() << " entries" << std::endl;
539  if(sortedToRaw->size()!=nRaw)
540  std::cout << "WARNING: sort map and rawTree are of different size!" << std::endl;
541 
542  //time.DumpRawTimes(0);
543  //time.DumpSortedTimes(0);
544 
545  std::cout << "filling AnaTree..." << std::endl;
546  for(size_t iraw=0; iraw<nRaw; iraw++) {
547  //if(sortedToRaw->find(iraw)==sortedToRaw->end()) {
548  // std::cout << "raw tree index not found in time order map!" << std::endl;
549  //}
550  if(iraw%10000==0) std::cout << 100.0*iraw/nRaw << " %" << std::endl;
551  fMaxPE = -1.;
552  fTotPE = 0.;
553  fMaxChan = 33;
554  fIsNoise = false;
555  fNChanAbove = 0;
556  fMac5 = traw.GetMac(sortedToRaw->at(iraw));
557  fT0 = traw.GetAbsTime(sortedToRaw->at(iraw));
558  //std::cout << "T0: " << fT0 << std::endl;
559  fPollRate = traw.GetPollRate(sortedToRaw->at(iraw));
560  if(iraw!=0 && iraw != nRaw-1)
561  fInstRate = traw.GetInstRate(sortedToRaw->at(iraw-1),sortedToRaw->at(iraw+1));
562  else
563  fInstRate = fPollRate;
564 
565  for(size_t ch=0; ch<32; ch++) {
566  fAbove[ch] = false;
567  fActive[ch] = ccl->GetActive(fMac5,ch);
568  fPE[ch] = 0.0;
569  if(!fActive[ch]) continue;
570 
571  uint16_t adc = traw.GetADC(sortedToRaw->at(iraw),ch);
572  fPE[ch] = (adc-ccl->GetPed(fMac5,ch))/ccl->GetGain(fMac5,ch);
573  fMacToPEHistos[fMac5]->at(ch)->Fill(fPE[ch]);
574  if(fPE[ch]>fMaxPE){
575  fMaxPE = fPE[ch];
576  fMaxChan = ch;
577  }
578  if(fPE[ch] > pPeThresh) {
579  fTotPE+=fPE[ch];
580  fAbove[ch] = true;
581  fNChanAbove++;
582  }
583  }
584  if(fMaxPE<pPeThresh) fIsNoise = true;
585 
586  fAnaTree->Fill();
587  }//end
588  std::cout << "done" << std::endl;
589 
590 }
591 
592 DEFINE_ART_MODULE(icarus::crt::AnaProducer)
593 //this is where the name is specified
bool GetActive(uint8_t mac, uint8_t channel)
Definition: CrtCalTree.cxx:60
createEngine fT0
float GetPed(uint8_t mac, uint8_t channel)
Definition: CrtCalTree.cxx:56
fhicl::Atom< std::string > CalFile
process_name hit
Definition: cheaterreco.fcl:51
float GetPollRate(size_t ientry) const
Definition: CRTRawTree.cc:80
float GetInstRate(size_t ientry_prev, size_t ientry_next) const
Definition: CRTRawTree.cc:74
virtual void analyze(art::Event const &evt)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
map< uint8_t, vector< TH1F * > * > fMacToHistos
fhicl::Sequence< uint8_t > MacsNO
art::EDAnalyzer::Table< Config > Parameters
BEGIN_PROLOG vertical distance to the surface Name
map< uint8_t, vector< TH1F * > * > fMacToPEHistos
std::string to_string(WindowPattern const &pattern)
uint64_t GetAbsTime(size_t ientry) const
Definition: CRTRawTree.cc:44
float GetGain(uint8_t mac, uint8_t channel)
Definition: CrtCalTree.cxx:52
fhicl::Sequence< uint8_t > MacsWI
art::ServiceHandle< art::TFileService > tfs
uint8_t GetMac(size_t ientry) const
Definition: CRTRawTree.cc:54
TCEvent evt
Definition: DataStructs.cxx:8
process_name crt
AnaProducer(Parameters const &config)
BEGIN_PROLOG could also be cout
fhicl::Sequence< uint8_t > MacsWO
const map< size_t, size_t > * GetOrderedToRawMap()
Definition: CRTTiming.cc:58
fhicl::Sequence< uint8_t > MacsNI
uint16_t GetADC(size_t ientry, uint8_t chan) const
Definition: CRTRawTree.cc:64