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"
13 #include "canvas/Utilities/Exception.h"
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"
20 #include "sbndaq-artdaq-core/Overlays/Common/BernCRTTranslator.hh"
23 #include "art_root_io/TFileService.h"
61 Comment(
"used for determining if a channel is above the discriminator threshold")
67 Comment(
"Full path to calibration file")
72 Comment(
"calibrate the data (true) or read from cal file (false)")
77 Comment(
"CRT region e.g. north (n) or west (w)")
81 Comment(
"CRT layer inner (i) or outer (o)")
86 Comment(
"mac addresses for each FEB in the north, inner daisychain")
90 Comment(
"mac addresses for each FEB in the north, outer daisychain")
94 Comment(
"mac addresses for each FEB in the west, inner daisychain")
98 Comment(
"mac addresses for each FEB in the west, outer daisychain")
196 : EDAnalyzer(config),
197 pFile(config().CalFile()),
198 pCalibrate(config().Calibrate()),
200 pPeThresh(config().PeThresh()),
201 fRegion(config().Region()),
202 fLayer(config().Layer())
209 else std::cout <<
"ERROR in AnaProducer::AnaProducer: bad region and/or layer codes!" << std::endl;
214 art::ServiceHandle<art::TFileService>
tfs;
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");
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");
237 fRawTree->Branch(
"feb_in_poll", &
fFeb_in_poll,
"feb_in_poll/i");
239 fRawTree->Branch(
"sequence_id", &
fSequence_id,
"sequence_id/i");
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");
299 for(
int i=0; i<32; ++i)
fAdc[i] = 0;
319 fLayer = config().Layer();
325 for(
int i=0; i<(int)
pMacs.size(); i++){
328 for(
int ch=0; ch<32; ch++){
331 fMacToHistos[pMacs[i]]->push_back(tfs->make<TH1F>(hname.c_str(),htitle.c_str(),4100,0,4100));
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));
339 for(
int i=0; i<32; i++) {
362 for(
size_t j=0; j<5; j++){
387 std::vector<icarus::crt::BernCRTTranslator> hit_vector;
389 auto fragmentHandles = evt.getMany<artdaq::Fragments>();
390 for (
auto handle : fragmentHandles) {
391 if (!handle.isValid() || handle->size() == 0)
394 auto this_hit_vector = icarus::crt::BernCRTTranslator::getCRTData(*handle);
396 hit_vector.insert(hit_vector.end(),this_hit_vector.begin(),this_hit_vector.end());
400 for(
auto &
hit : hit_vector) {
402 fFragment_timestamp =
hit.timestamp;
403 fSequence_id =
hit.sequence_id;
407 fLostcpu =
hit.lostcpu;
408 fLostfpga =
hit.lostfpga;
413 for(
int ch=0; ch<32; ch++){
414 fMacToHistos[fMac5]->at(ch)->Fill(
hit.adc[ch] );
415 fAdc[ch] =
hit.adc[ch];
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;
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;
441 std::cout <<
"hist vect is empty!" << std::endl;
446 for(
auto const& macHist : fMacToHistos){
448 uint8_t mac = macHist.first;
449 vector<TH1F*>* hvec = macHist.second;
451 std::cout <<
"construct instance of CrtCal for mac5 " << (short)mac << std::endl;
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();
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];
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];
519 std::cout <<
"fill tree event" << std::endl;
527 if(pCalibrate) ccl =
new CrtCalTree(fCalTree);
532 const size_t nRaw = fRawTree->GetEntriesFast();
534 std::cout <<
"initiallizing time utility" << std::endl;
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;
545 std::cout <<
"filling AnaTree..." << std::endl;
546 for(
size_t iraw=0; iraw<nRaw; iraw++) {
550 if(iraw%10000==0)
std::cout << 100.0*iraw/nRaw <<
" %" << std::endl;
556 fMac5 = traw.
GetMac(sortedToRaw->at(iraw));
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));
563 fInstRate = fPollRate;
565 for(
size_t ch=0; ch<32; ch++) {
569 if(!fActive[ch])
continue;
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]);
578 if(fPE[ch] > pPeThresh) {
584 if(fMaxPE<pPeThresh) fIsNoise =
true;
bool GetActive(uint8_t mac, uint8_t channel)
uint64_t fFragment_timestamp
int32_t fSystem_clock_deviation
float GetPed(uint8_t mac, uint8_t channel)
fhicl::Atom< std::string > CalFile
fhicl::Atom< uint8_t > Region
fhicl::Atom< bool > Calibrate
float GetPollRate(size_t ientry) const
float GetInstRate(size_t ientry_prev, size_t ientry_next) const
virtual void analyze(art::Event const &evt)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
map< uint8_t, vector< TH1F * > * > fMacToHistos
fhicl::Sequence< uint8_t > MacsNO
fhicl::Atom< uint8_t > Layer
art::EDAnalyzer::Table< Config > Parameters
BEGIN_PROLOG vertical distance to the surface Name
map< uint8_t, vector< TH1F * > * > fMacToPEHistos
float fPeakNormErr[32][5]
float fPeakSigmaErr[32][5]
uint32_t fFeb_event_number
uint64_t fThis_poll_start
std::string to_string(WindowPattern const &pattern)
uint64_t fLast_poll_start
uint64_t GetAbsTime(size_t ientry) const
float GetGain(uint8_t mac, uint8_t channel)
fhicl::Atom< float > PeThresh
fhicl::Sequence< uint8_t > MacsWI
art::ServiceHandle< art::TFileService > tfs
uint8_t GetMac(size_t ientry) const
float fPeakMeanErr[32][5]
AnaProducer(Parameters const &config)
BEGIN_PROLOG could also be cout
fhicl::Sequence< uint8_t > MacsWO
const map< size_t, size_t > * GetOrderedToRawMap()
fhicl::Sequence< uint8_t > MacsNI
uint16_t GetADC(size_t ientry, uint8_t chan) const