28 #include "TObjString.h"
35 #include "TProfile2D.h"
37 #include "TDirectory.h"
53 using THVec=std::vector<std::unique_ptr<T>>;
55 template <
class T, std::
size_t n>
56 using THArray = std::array<std::unique_ptr<T>,
n >;
58 using TH1Fp = std::unique_ptr<TH1F>;
59 using TH2Fp = std::unique_ptr<TH2F>;
62 LArCellsEmptyMonitoring::LArCellsEmptyMonitoring()
97 TString htitle,
hname,textfilename,rootfilename;
99 double Ecum_cut_PS = 20.;
100 double Ecum_cut_calo = 10.;
103 const double GeV = 1/1000.;
105 double nsigmaHits = 10.;
111 unsigned int onlid = 0;
122 double MeanEventEnergy_max = -999;
123 double MeanEventEnergy_min = 999;
130 vector<int, std::allocator<int> > DQLBList;
132 vector<int, std::allocator<int> > BadLBList;
135 printf(
"Getting histogram limits... ");
144 printf(
"Done.\n LBmin: %d LBmax: %d Emin: %d Emax: %d Qmin: %d Qmax: %d\n",
lbmin,
lbmax,emin,emax,qmin,qmax);
148 FILE * pFile=
nullptr;
151 textfilename.Form(
"Output/BadCellList_run%d.txt",
runNumber);
152 pFile = fopen (textfilename ,
"w");
154 printf(
"Cannot open output text file\n");
160 pFile = fopen (textfilename ,
"w");
162 printf(
"Cannot open output text file\n");
169 fprintf(pFile,
"onlid // part // FT // SL // CH // # Events E>%d sigma // Mean Event Energy [GeV] (min // max) // # LBs // # LBs affected // fraction events Q>%d \n",(
int)nsigmaHits,qthreshold);
172 int EventCount=0., qcount=0.;
178 rootfilename.Form(
"Output/BadCells_run%d.root",
runNumber);
181 auto fout = std::make_unique<TFile>(rootfilename,
"RECREATE");
195 printf(
"Creating histograms (nEbins = %d, nQbins = %d, nLBbins = %d)... ",ne,nq,nlb);
196 TH1F hene =
TH1F(
"hEne",
"",ne,emin,emax); hene.SetXTitle(
"Energy [GeV]"); hene.SetYTitle(
"Events");
197 TH1F hqua =
TH1F(
"hQua",
"",nq/100.,qmin,qmax); hqua.SetXTitle(
"Quality"); hqua.SetYTitle(
"Events");
198 TH1F hlb =
TH1F(
"hLB",
"",nlb,
lbmin,
lbmax); hlb.SetXTitle(
"LB"); hlb.SetYTitle(
"Events");
199 TH2F henelb =
TH2F(
"hEnelb",
"",nlb,
lbmin,
lbmax,ne,emin,emax); henelb.SetXTitle(
"LB"); henelb.SetYTitle(
"Energy [GeV]");
206 printf(
"Creating cut test histograms...");
207 static constexpr
int npl=4;
208 TH2F tempHist =
TH2F(
"tempNEvLB",
"",1000,0,1000.,1000,0.,1000.);
216 for (
int i=0;
i<npl;
i++){
217 hname.Form(
"hNEvVsEMean_Layer%i",
i);
218 hNEvVsEMean[
i].reset((
TH2F*)tempHist.Clone(
hname));
219 hNEvVsEMean[
i]->GetXaxis()->SetTitle(
"Number of Events (E > 10 #sigma) / LB");
220 hNEvVsEMean[
i]->GetYaxis()->SetTitle(
"E_{mean} per Event / LB [GeV]");
222 hname.Form(
"hNEvVsECum_Layer%i",
i);
223 hNEvVsECum[
i].reset((
TH2F*)tempHist.Clone(
hname));
224 hNEvVsECum[
i]->GetXaxis()->SetTitle(
"Number of Events (E > 10 #sigma) / LB");
225 hNEvVsECum[
i]->GetYaxis()->SetTitle(
"E_{cumulative} per Cell / LB [GeV]");
227 hname.Form(
"hECumVsEMean_Layer%i",
i);
228 hECumVsEMean[
i].reset((
TH2F*)tempHist.Clone(
hname));
229 hECumVsEMean[
i]->GetXaxis()->SetTitle(
"E_{cumulative} per Cell / LB [GeV]");
230 hECumVsEMean[
i]->GetYaxis()->SetTitle(
"E_{mean} per Event / LB [GeV]");
232 hname.Form(
"hNoise_Layer%i",
i);
233 hNoise[
i].reset(
new TH1F(
hname,
"",60,0.,30.));
234 hNoise[
i]->GetXaxis()->SetTitle(
"Noise [GeV]");
235 hNoise[
i]->GetYaxis()->SetTitle(
"Number Of Cells");
237 hname.Form(
"hCellsPerLB_Layer%i",
i);
238 hCellsPerLB[
i].reset((
TH1F*)hlb.Clone(
hname));
239 hCellsPerLB[
i]->GetXaxis()->SetTitle(
"LB");
240 hNoise[
i]->GetYaxis()->SetTitle(
"Number Of Cells");
249 unsigned int nchannels = tuple->
nChannels();
251 printf(
"Begin looping over cells...\n");
263 onlid = cellInfo->
onlid();
266 unsigned int ndigits =
hist->nData();
267 if(ndigits<(
unsigned int)
threshold){ nskipped++;
continue; }
271 hname.Form(
"h0x%x_Energy",onlid);
273 hname.Form(
"h0x%x_Quality",onlid);
275 hname.Form(
"h0x%x_LB",onlid);
277 hname.Form(
"h0x%x_hNEvVsEMean",onlid);
279 hname.Form(
"h0x%x_Energy_LB",onlid);
280 h2_elb.reset((
TH2F*)henelb.Clone(
hname));
281 hname.Form(
"h0x%x_Quality_LB",onlid);
286 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
290 if(!Evdata){ noEvdata++;
continue; }
299 h1_q->Fill(
data->quality());
307 if (
data->quality() > qthreshold){
321 if ( CellCounter%1000 == 0 ) {
322 printf(
"Scanning Cell No. = %d\n",CellCounter);
324 MeanEventEnergy_max = -999;
325 MeanEventEnergy_min = 999;
332 if (h1_lb->GetBinContent(
ilb) > 0.){
333 double EtotInLB = h1_elb->GetBinContent(
ilb);
334 double NEventsInLB = h1_lb->GetBinContent(
ilb);
336 int LB_number = h1_lb->GetBinLowEdge(
ilb);
338 double MeanEventEnergy = EtotInLB / NEventsInLB;
341 if (cellInfo->
layer()==0){
342 if (EtotInLB>Ecum_cut_PS){
343 hNEvVsEMean[cellInfo->
layer()]->Fill(NEventsInLB,MeanEventEnergy);
344 hNEvVsECum[cellInfo->
layer()]->Fill(NEventsInLB,EtotInLB);
345 hECumVsEMean[cellInfo->
layer()]->Fill(EtotInLB,MeanEventEnergy);
346 hCellsPerLB[cellInfo->
layer()]->Fill(LB_number);
349 else if (EtotInLB>Ecum_cut_calo){
350 hNEvVsEMean[cellInfo->
layer()]->Fill(NEventsInLB,MeanEventEnergy);
351 hNEvVsECum[cellInfo->
layer()]->Fill(NEventsInLB,EtotInLB);
352 hECumVsEMean[cellInfo->
layer()]->Fill(EtotInLB,MeanEventEnergy);
353 hCellsPerLB[cellInfo->
layer()]->Fill(LB_number);
356 if (EtotInLB>Ecum_cut_PS && cellInfo->
layer()==0){
357 FlagCell=
true; FlagCount++;
358 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
359 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
361 else if (EtotInLB>Ecum_cut_calo && cellInfo->
layer()==1){
362 FlagCell=
true; FlagCount++;
363 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
364 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
366 else if (EtotInLB>Ecum_cut_calo && cellInfo->
layer()==2){
367 FlagCell=
true; FlagCount++;
368 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
369 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
371 else if (EtotInLB>Ecum_cut_calo && cellInfo->
layer()==3){
372 FlagCell=
true; FlagCount++;
373 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
374 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
379 fr_q4k = (
double)qcount/(
double)EventCount;
386 fprintf(pFile,
"0x%x \t %7s \t %d \t %d \t %d \t %d \t %4.3f \t %4.3f \t %d \t %d \t %4.3f \n",onlid,
m_LarIdTranslator->GetPartitonLayerName(
index),cellInfo->
feedThrough(),cellInfo->
slot(),cellInfo->
channel(),EventCount,MeanEventEnergy_min,MeanEventEnergy_max,NFullLB,FlagCount,fr_q4k);
396 printf(
"Skipped %d cells. Cells scanned = %d\n",nskipped,nbad);
397 printf(
"Cells put in Bad Cell List = %d\n",nBadCells);
398 if (noEvdata>0) printf(
"No Evdata pointer: %d\n",noEvdata);
403 for(
int i=0;
i<npl;
i++){
404 hNEvVsEMean[
i]->Write();
405 hNEvVsECum[
i]->Write();
406 hECumVsEMean[
i]->Write();
408 hCellsPerLB[
i]->Write();
424 TString htitle,
hname,textfilename,rootfilename;
436 printf(
"WARNING: Received instruction to select recurring bad cells only in SetSelectRecurringBadCells(bool flag)\n");
437 printf(
"-------> Only one algorithm selected for cell selection criteria in SetAlgo(int algoindex)\n");
438 printf(
"-------> Recurring cell selection overides algorithm specification\n");
443 printf(
"ERROR: Partition not specified in SetPartition(bool set_part, std::string partname)\n");
450 int selectionFlag = -1;
451 const double GeV = 1/1000.;
461 unsigned int onlid = 0;
473 int nEvents_E_gt_ecut=0;
474 double EventEnergySum=0.;
475 double EventEnergyMean=0.;
478 double MeanHits=0, rmsHits=0;
479 int iMeanCellHitsSelection=0,iEnergyThresholdSelection=0,iOR_selection=0,iAND_selection=0;
485 vector<int, std::allocator<int> > DQLBList;
486 vector<int, std::allocator<int> > BadLBList;
488 printf(
"Reading in DQ Defect LB List...\n");
493 printf(
"Getting bad LB list...\n");
495 printf(
"...Done.\n");
496 nBadLBs = BadLBList.size();
499 BadLBList = std::move(DQLBList);
500 nBadLBs = BadLBList.size();
504 printf(
"Getting histogram limits... ");
515 printf(
"Done.\n LBmin: %d LBmax: %d Emin: %d Emax: %d Qmin: %d Qmax: %d\n",
lbmin,
lbmax,emin,emax,qmin,qmax);
520 textfilename.Form(
"Output/BadCellSelection_run%d.txt",
runNumber);
523 std::cout<<(
"Cannot open output selection summary file " + textfilename)<<
"\n";
529 std::cout<<(
"Cannot open output selection summary file " + textfilename)<<
"\n";
535 FILE * pFile=
nullptr;
538 textfilename.Form(
"Output/BadCellList_run%d.txt",
runNumber);
539 pFile = fopen (textfilename ,
"w");
541 printf(
"Cannot open output text file\n");
546 pFile = fopen (textfilename ,
"w");
548 printf(
"Cannot open output text file\n");
557 printf(
"Determining mean cell hits...\n ");
560 printf(
"Set threshold at %4.3f counts per cell for LB range. \n",(MeanHits+(nsigmaHits*rmsHits))*((
double)nlb_corr-(
double)nBadLBs));
564 fprintf(pFile,
"onlid // part // FT // SL // CH // Events (E>%d sigma) // Events E>1GeV // Mean Energy [GeV] // # LBs // fraction events Q>%d // Flagged in LB // selectionFlag\n",(
int)nsigmaHits,qthreshold);
567 int EventCount=0., qcount=0.;
574 rootfilename.Form(
"Output/BadCells_run%d.root",
runNumber);
577 auto fout = std::make_unique<TFile>(rootfilename,
"RECREATE");
585 Float_t meanECell = 0;
587 TH1F* h1_lb =
nullptr;
588 TH1F* h1_e =
nullptr;
589 TH1F* h1_q =
nullptr;
590 TH2F* h2_elb =
nullptr;
591 TH2D* h2_pulse =
nullptr;
592 TH2D* h2_t_LB =
nullptr;
594 TH1F* h1_ADCmax =
nullptr;
595 std::unique_ptr<TTree> tree_cells;
597 tree_cells.reset(
new TTree(
"BadTree",
"LAr Tree ordered by OnlID"));
598 tree_cells->Branch(
"Energy",&h1_e);
599 tree_cells->Branch(
"Quality",&h1_q);
600 tree_cells->Branch(
"LB",&h1_lb);
601 tree_cells->Branch(
"larid",&larid);
602 tree_cells->Branch(
"onlid",&onlid);
603 tree_cells->Branch(
"Run",&t_run);
604 tree_cells->Branch(
"selectionFlag",&selectionFlag);
605 tree_cells->Branch(
"nhits_ensig",&n_ensig);
606 tree_cells->Branch(
"nhits_e1GeV",&n_ecut);
607 tree_cells->Branch(
"Quality_4k",&fr_q4k);
608 tree_cells->Branch(
"LBfraction",&fr_LB);
609 tree_cells->Branch(
"EnergyVsLB",&h2_elb);
610 tree_cells->Branch(
"PulseShape",&h2_pulse);
611 tree_cells->Branch(
"PulsePeakTimeVsLB",&h2_t_LB);
612 tree_cells->Branch(
"noise",&
noise);
613 tree_cells->Branch(
"MeanCellEnergy",&meanECell);
614 tree_cells->Branch(
"PulseShapeTProf",&TProf_pulse);
615 tree_cells->Branch(
"ADCmax",&h1_ADCmax);
620 TH2D NormPulse(
"Normalised_pulse",
"",100,-200,200,400,-10,10);
621 NormPulse.SetXTitle(
"Time [ns]");
622 NormPulse.SetYTitle(
"Value [ADC counts] / ADCmax");
633 E_LB.SetXTitle(
"LB");
634 E_LB.SetYTitle(
"Energy [GeV]");
636 TH2D t_LB(
"t_LB",
"",nlb,
lbmin,
lbmax,400,-200,200);
637 t_LB.GetXaxis()->SetTitle(
"LB");
638 t_LB.GetYaxis()->SetTitle(
"Time(maxSample) + ofcTime [ns]");
641 CF_LB.GetXaxis()->SetTitle(
"LB");
642 CF_LB.GetYaxis()->SetTitle(
"Number of cells flagged");
644 TH1F ME_EV(
"ME_EV",
"",1000,0,1000);
645 ME_EV.GetXaxis()->SetTitle(
"Nbr events >1 GeV");
646 ME_EV.GetYaxis()->SetTitle(
"Mean Energy [GeV]");
651 for (
int ii=0;ii<npl;ii++){
653 Cellmaps[ii]->GetXaxis()->SetTitle(
"#eta"); Cellmaps[ii]->GetYaxis()->SetTitle(
"#Phi");
655 Pulsemaps[ii].reset((TH2D*)NormPulse.Clone(
hname));
657 E_LBmaps[ii].reset((
TH2F*)E_LB.Clone(
hname));
659 t_LBmaps[ii].reset((TH2D*)t_LB.Clone(
hname));
661 CellsFlagged_LB_part[ii].reset((
TH1F*)CF_LB.Clone(
hname));
664 Emean_NbrEvents_part[ii].reset((
TH1F*)ME_EV.Clone(
hname));
669 Eeta.GetXaxis()->SetTitle(
"#eta");
670 Eeta.GetYaxis()->SetTitle(
"Energy [GeV]");
672 TH1F CellEnergy(
"CellEnergy",
"",ne,emin,emax);
673 CellEnergy.GetXaxis()->SetTitle(
"Cell Mean Energy [GeV]");
674 CellEnergy.GetYaxis()->SetTitle(
"Cells");
676 TH1F LBfrac(
"LBfrac",
"",100,0.,1.);
677 LBfrac.GetXaxis()->SetTitle(
"LB fraction");
678 LBfrac.GetYaxis()->SetTitle(
"Cells");
680 TH1F Qfrac(
"Qfrac",
"",100.,0.,1.);
681 Qfrac.GetXaxis()->SetTitle(
"Fraction of Events Q>4000");
682 Qfrac.GetYaxis()->SetTitle(
"Cells");
685 CellsFlagged_LB.GetXaxis()->SetTitle(
"LB");
686 CellsFlagged_LB.GetYaxis()->SetTitle(
"Number of cells flagged");
688 TH1F Emean_NbrEvents(
"Emean_NEvents_1GeV",
"",1000,0,1000);
689 Emean_NbrEvents.GetXaxis()->SetTitle(
"N events > 1 GeV");
690 Emean_NbrEvents.GetYaxis()->SetTitle(
"Mean Energy [GeV]");
695 printf(
"Creating histograms (nEbins = %d, nQbins = %d, nLBbins = %d)... ",ne,nq,nlb);
696 TH1F hene =
TH1F(
"hEne",
"",ne,emin,emax); hene.SetXTitle(
"Energy [GeV]");
697 hene.SetYTitle(
"Events");
698 TH1F hqua =
TH1F(
"hQua",
"",nq/100.,qmin,qmax); hqua.SetXTitle(
"Quality");
699 hqua.SetYTitle(
"Events");
701 hlb.SetYTitle(
"Events");
703 henelb.SetYTitle(
"Energy [GeV]");
704 TH2D hpulse = TH2D(
"hPulse",
"",100,-200,200,400, -10,10); hpulse.SetXTitle(
"Time [ns]");
705 hpulse.SetYTitle(
"Value [ADC counts] / ADCmax");
706 TProfile TProfpulse =
TProfile(
"",
"",5, 0, 5,
"s"); TProfpulse.SetXTitle(
"Sample Number");
707 TProfpulse.SetYTitle(
"Value [ADC counts]");
708 TH2D ht_LB= TH2D(
"ht_LB",
"",nlb,
lbmin,
lbmax,400,-200,200); ht_LB.GetXaxis()->SetTitle(
"LB");
709 ht_LB.GetYaxis()->SetTitle(
"Time(maxSample) + ofcTime [ns]");
710 TH1F hADCmax =
TH1F(
"",
"",110,-200,2000); hADCmax.SetXTitle(
"ADCmax [ADC counts]"); hADCmax.SetYTitle(
"Events");
717 unsigned int nchannels = tuple->
nChannels();
719 fprintf(
outputFile,
"Onlid \t MeanCellHitBased \t EnergyThresholdBased \t OR \t AND\n");
722 printf(
"Begin looping over cells...\n");
731 double eta = cellInfo->
eta();
732 double phi = cellInfo->
phi();
737 onlid = cellInfo->
onlid();
745 unsigned int ndigits =
hist->nData();
746 if(ndigits<(
unsigned int)
threshold){ nskipped++;
continue; }
752 hname.Form(
"h0x%x_Energy",onlid);
754 hname.Form(
"h0x%x_Quality",onlid);
756 hname.Form(
"h0x%x_LB",onlid);
758 hname.Form(
"h0x%x_Energy_LB",onlid);
760 hname.Form(
"h0x%x_Pulse",onlid);
761 h2_pulse = (TH2D*)hpulse.Clone(
hname);
762 hname.Form(
"TProf0x%x_Pulse",onlid);
764 hname.Form(
"h0x%x_ADCmax",onlid);
766 hname.Form(
"h0x%x_t_LB",onlid);
767 h2_t_LB = (TH2D*)ht_LB.Clone(
hname);
770 bool CellInList =
false;
771 int LBFlaggedIn = -1;
774 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
778 if(!Evdata){ noEvdata++;
continue; }
787 if (isBadLB)
continue;
794 h1_e->Fill(
data->energy()*
GeV);
795 h1_q->Fill(
data->quality());
798 h1_ADCmax->Fill(
data->adcMax());
799 double time =
data->maxPosition()*25.0+
data->ofcTime();
801 for(
unsigned int isample=0;isample<
data->nSamples();isample++) {
802 TProf_pulse->Fill(isample,
data->value(isample));
803 h2_pulse->Fill(
data->time(isample)-time,
data->value(isample)/
data->adcMax());
808 if (
data->quality() > qthreshold){
816 if (
data->energy()*
GeV > ecut) {
818 EventEnergySum+=(
data->energy()*
GeV);
823 selectionFlag=
CheckCellSelectionCriteria(EventCount,nsigmaHits,MeanHits,rmsHits,nEvents_E_gt_ecut,EventEnergySum,nBadLBs,nlb_corr);
824 if(selectionFlag==2){
828 else if(selectionFlag==1){
838 else if(selectionFlag==0){
855 if ( CellCounter%1000 == 0 ) {
856 printf(
"Scanning Cell No. = %d\n",CellCounter);
858 selectionFlag=
CheckCellSelectionCriteria(EventCount,nsigmaHits,MeanHits,rmsHits,nEvents_E_gt_ecut,EventEnergySum,nBadLBs,nlb_corr);
861 if (selectionFlag >= 0){
862 bool ListOutput =
true;
863 int MeanCellHitsSelection = 0;
864 int EnergyThresholdSelection = 0;
865 int OR_selection = 0;
866 int AND_selection = 0;
868 if (selectionFlag == 2){
869 MeanCellHitsSelection = 1;
870 EnergyThresholdSelection = 1;
876 else if (selectionFlag == 1){
877 if (
m_Algo == 1) ListOutput =
false;
878 MeanCellHitsSelection = 1;
879 EnergyThresholdSelection = 0;
884 else if (selectionFlag == 0){
885 if (
m_Algo == 0) ListOutput =
false;
886 MeanCellHitsSelection = 0;
887 EnergyThresholdSelection = 1;
893 iMeanCellHitsSelection += MeanCellHitsSelection;
894 iEnergyThresholdSelection += EnergyThresholdSelection;
895 iOR_selection += OR_selection;
896 iAND_selection += AND_selection;
903 fprintf(
outputFile,
"0x%x \t %d \t \t \t %d \t \t %d \t %d\n",onlid,MeanCellHitsSelection,EnergyThresholdSelection,OR_selection,AND_selection);
911 if (h1_lb->GetBinContent(
ilb) > 0.)
nLB++;
914 fr_LB = (
double)
nLB/(
double)(nlb_corr-nBadLBs);
916 meanECell = h1_e->GetMean();
917 n_ensig = EventCount;
919 fr_q4k = (
double)qcount/(
double)EventCount;
921 n_ecut = nEvents_E_gt_ecut;
927 if (h1_lb->GetBinContent(
ilb) > 0.)
nLB++;
929 fr_LB = (
double)
nLB/(
double)(nlb_corr-nBadLBs);
931 meanECell = h1_e->GetMean();
932 n_ensig = EventCount;
934 fr_q4k = (
double)qcount/(
double)EventCount;
936 n_ecut = nEvents_E_gt_ecut;
937 Cellmaps[
index]->Fill(eta,phi,meanECell);
938 Eeta.Fill(eta,meanECell);
939 CellEnergy.Fill(meanECell);
942 Emean_NbrEvents.Fill(n_ecut,EventEnergySum/n_ecut);
943 Emean_NbrEvents_part[
index]->Fill(n_ecut,EventEnergySum/n_ecut);
950 CellsFlagged_LB_part[
index]->Fill(LBFlaggedIn);
951 CellsFlagged_LB.Fill(LBFlaggedIn);
959 if (nEvents_E_gt_ecut>0) { EventEnergyMean = EventEnergySum/nEvents_E_gt_ecut; }
960 fprintf(pFile,
"0x%x \t %7s \t %d \t %d \t %d \t %d \t %d \t %f \t %4.0f \t %4.3f \t %d \t %d\n",onlid,
m_LarIdTranslator->GetPartitonLayerName(
index),cellInfo->
feedThrough(),cellInfo->
slot(),cellInfo->
channel(),EventCount,nEvents_E_gt_ecut,EventEnergyMean,nbrLB,fr_q4k,LBFlaggedIn,selectionFlag);
969 nEvents_E_gt_ecut = 0.;
971 EventEnergyMean = 0.;
973 printf(
"Cells selected: MeanCellHitsCut \t EnergyThreshodCut \t Either List \t Both Lists\n");
974 printf(
"\t \t %d \t \t \t \t %d \t \t %d \t %d\n",iMeanCellHitsSelection,iEnergyThresholdSelection,iOR_selection,iAND_selection);
981 printf(
"Skipped %d cells. Cells scanned = %d\n",nskipped,nbad);
982 printf(
"Cells put in Bad Cell List = %d\n",nBadCells);
983 if (noEvdata>0) printf(
"No Evdata pointer: %d\n",noEvdata);
987 for(
int i=0;
i<npl;
i++){
992 if(CellsFlagged_LB_part[
i]->
GetEntries()>0) CellsFlagged_LB_part[
i]->Write();
993 if( Emean_NbrEvents_part[
i]->
GetEntries()>0) Emean_NbrEvents_part[
i]->Write();
995 CellsFlagged_LB.Write();
999 Emean_NbrEvents.Write();
1022 unsigned int nchannels = tuple->
nChannels();
1025 qmin = emin =
lbmin = 99999;
1026 qmax = emax =
lbmax = -1;
1036 unsigned int ndigits =
hist->nData();
1037 if(ndigits==0){
continue; }
1040 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1043 if(!Evdata)
continue;
1047 if (
data->energy() != 0. &&
data->noise() != 0.){
1050 if (isBadLB)
continue;
1056 double energyGeV =
data->energy()/1000.;
1057 if(energyGeV > emax) emax = energyGeV;
1058 if(energyGeV < emin) emin = energyGeV;
1059 if(
data->quality() > qmax) qmax =
data->quality();
1060 if(
data->quality() < qmin) qmin =
data->quality();
1070 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells_tot;
1071 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy_tot;
1072 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventLumiBlock;
1073 std::map< std::pair<std::string, unsigned int>,
unsigned int > eventCells;
1075 double NSIG = nsigma;
1079 unsigned int nchannels = tuple->
nChannels();
1090 int calo = cellInfo->
calo();
1099 unsigned int ndigits =
hist->nData();
1100 if(ndigits==0){
continue; }
1103 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1107 if(!Evdata)
continue;
1112 double energyGeV =
data->energy()/1000.;
1115 if (lumiBlock <= lbmax && lumiBlock >=
lbmin ) {
1116 if (
data->energy() > sqrt((NSIG*
data->noise())*(NSIG*
data->noise())) &&
data->energy() != 0. &&
data->noise() != 0.){
1118 std::pair<unsigned int, unsigned int>
ev(
data->run(),
data->event());
1119 std::pair<std::string, unsigned int> ev_cryo(
GetCryostat(calo),
data->event());
1120 eventCells_tot[
ev]++;
1121 eventEnergy_tot[
ev] += energyGeV;
1122 eventLumiBlock[
ev] =
lb;
1123 eventCells[ev_cryo]++;
1131 auto hCells_Ev_LB = std::make_unique<TProfile>(
"",
"",nlb,
lbmin,
lbmax,-100,100000);
1132 std::map< std::string, TProfilep> hCellsEvLB;
1133 std::map< std::string, TH1Fp> hp_cryo;
1138 std::string Cryo[8] = {
"EMBA",
"EMBC",
"EMECA",
"EMECC",
"HECA",
"HECC",
"FCALA",
"FCALC"};
1139 for(
int k = 0;
k< nCryo;
k++){
1140 hCellsEvLB[Cryo[
k]].reset((
TProfile*)hCells_Ev_LB->Clone());
1142 for(
unsigned int ievent = 0; ievent < tuple->
nEvents(); ievent++) {
1144 std::pair<unsigned int, unsigned int>
id(evtData->
run(), evtData->
event());
1145 if(eventCells_tot[
id]==0)
continue;
1147 for(
int j=0; j<nCryo ;j++){
1148 std::pair<std::string, unsigned int> id_cryo(Cryo[j], evtData->
event());
1149 hCellsEvLB[Cryo[j]]->Fill(eventLumiBlock[
id], eventCells[id_cryo]);
1152 hCells_Ev_LB->Fill(eventLumiBlock[
id], eventCells_tot[
id]);
1155 auto hp = std::make_unique<TH1F>(
"",
"",(hCells_Ev_LB->GetBinContent(hCells_Ev_LB->GetMaximumBin())),0,hCells_Ev_LB->GetBinContent(hCells_Ev_LB->GetMaximumBin()));
1156 for(
int k = 0;
k< nCryo;
k++){
1157 auto hp_temp = std::make_unique< TH1F>(
"",
"",(hCellsEvLB[Cryo[
k]]->GetBinContent(hCellsEvLB[Cryo[
k]]->GetMaximumBin())*10),0,hCellsEvLB[Cryo[
k]]->GetBinContent(hCellsEvLB[Cryo[
k]]->GetMaximumBin()));
1158 std::string
name1 =
"hp_" + Cryo[
k];
1159 hp_cryo[Cryo[
k]].reset((
TH1F*)hp_temp->Clone(
name1.c_str()));
1162 for (
int p=1;
p<=nlb;
p++){
1163 for(
int j=0; j<nCryo; j++){
1164 double bincont = hCellsEvLB[Cryo[j]]->GetBinContent(
p);
1165 hp_cryo[Cryo[j]]->Fill(bincont);
1167 double bincont1 = hCells_Ev_LB->GetBinContent(
p);
1171 std::map< std::string, double>
Mean;
1172 std::map< std::string, double>
RMS;
1173 std::map< int, vector<std::string> > BadLB_cryo;
1175 for(
int k=0;
k<nCryo;
k++)
1177 Mean[Cryo[
k]] = hp_cryo[Cryo[
k]]->GetMean();
1178 RMS[Cryo[
k]] = hp_cryo[Cryo[
k]]->GetRMS();
1181 double MEAN2 = hp->GetMean();
1182 double RMS2 = hp->GetRMS();
1187 vector<int> BadLB_tot=DQLBList;
1189 double value1 = (MEAN2+(RMS2*3.));
1190 int numberFlagged=0;
1191 for (
int l=1;
l<=nlb;
l++){
1192 for(
int j=0; j<nCryo; j++){
1193 double value = MEAN2 + (
RMS[Cryo[j]]*3);
1194 if(hCellsEvLB[Cryo[j]]->GetBinContent(
l) >
value){
1195 int badLB = hCellsEvLB[Cryo[j]]->GetBinLowEdge(
l);
1196 BadLB_cryo[badLB].push_back(Cryo[j]);
1198 for(
unsigned int p=0;
p< BadLB_tot.size();
p++) {
1199 if(badLB == BadLB_tot[
p]) isadd =
false;
1202 BadLB_tot.push_back(badLB);
1204 printf(
"Removing bad LB %d in %s\n",badLB,Cryo[j].c_str());
1209 if (hCells_Ev_LB->GetBinContent(
l) > value1){
1210 BadLB.push_back(hCells_Ev_LB->GetBinLowEdge(
l));
1214 printf(
"Number of Bad LBs found: %d\n",numberFlagged);
1215 printf(
"Number of LBs to be removed: %zu", BadLB_tot.size());
1224 for (
unsigned int yy=0;
yy<BadLBList.size();
yy++){
1240 unsigned int nchannels = tuple->
nChannels();
1243 double TotalRecordedHits=0;
1244 std::vector<int, std::allocator<int> > HitsPerLB;
1258 unsigned int ndigits =
hist->nData();
1261 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1264 if(!Evdata)
continue;
1270 if (isBadLB)
continue;
1281 if (nHits > 0.)
nCells++;
1294 TH1Fp tp_ev = std::make_unique<TH1F>(
"",
"",th1_Hits->GetBinContent(th1_Hits->GetMaximumBin())*100,0,th1_Hits->GetBinContent(th1_Hits->GetMaximumBin()));
1296 for (
int i=1;
i<=nlb;
i++){
1297 if(hNLB->GetBinContent(
i)>0){
1299 tp_ev->Fill(th1_Hits->GetBinContent(
i));
1300 TotalRecordedHits+=th1_Hits->GetBinContent(
i);
1301 HitsPerLB.push_back(th1_Hits->GetBinContent(
i));
1305 MeanHits = ((
double)TotalRecordedHits/(
double)nlb_corr)/(
double)
nCells;
1309 for (
unsigned int j=0;j<HitsPerLB.size();j++){
1313 rmsHits =
var/nlb_corr;
1315 printf(
"Mean number of hits/cell for 1 LB = %4.3f, RMS = %4.3f\n",MeanHits,rmsHits);
1316 printf(
"Number of cells firing at E > %d sigma = %d\n",nsigma,
nCells);
1317 printf(
"Total number of LBs included = %d\n",nlb_corr);
1328 }
else if (lumiBlock <= lbmax && lumiBlock >=
lbmin &&
energy > sqrt((nsigma*
noise)*(nsigma*
noise)) ) {
1351 if ((EventCount > (MeanHits+(nsigmaHits*rmsHits))*((
double)nlb-(
double)nBadLBs)))
a=
true;
1366 if ((
a &&
b) || (
a &&
c)){
1368 }
else if (
a && !
b && !
c){
1370 }
else if ((!
a &&
b) || (!
a &&
c)){
1402 bool isFoundPartition =
false;
1403 for(
int i=0;
i< npl;
i++){
1407 isFoundPartition =
true;
1410 if(!isFoundPartition){
1411 printf(
"ERROR: Partition %s does not exist! Invalid input name.\n",
partname.c_str());
1412 printf(
"Possible candidates are:\n");
1413 for (
int j=0;j<npl;j++){ printf(
"%s\n",
m_LarIdTranslator->GetPartitonLayerName(j)); }
1421 std::string cryostat =
"NotGiven";
1422 if(calo == 1) cryostat =
"EMBA";
1423 else if(calo == -1) cryostat =
"EMBC";
1424 else if(calo == 5) cryostat =
"FCALA";
1425 else if(calo == -5) cryostat =
"FCALC";
1426 else if(calo == 4) cryostat =
"HECA";
1427 else if(calo == -4) cryostat =
"HECC";
1428 else if(calo == 2 || calo == 3) cryostat =
"EMECA";
1429 else if(calo == -2 || calo == -3) cryostat =
"EMECC";
1452 std::vector<int> LBList;
1454 std::ifstream
infile(LBfile.Data());
1460 std::unique_ptr<TObjArray>
list(
filter.Tokenize(
", "));
1461 if(
list->GetEntries() == 0){
1462 printf(
"No LB filtering specified, or bad format. Exiting.\n");
1463 LBList.push_back(0);
1467 for(
int k = 0;
k <
list->GetEntries();
k++){
1468 TObjString* tobs = (TObjString*)(
list->At(
k));
1469 LBList.push_back((
int)(tobs->String()).Atoi());
1471 printf(
"LB List: %d\n",(
int)LBList.size());
1509 ULong64_t onlid = 0;
1510 std::map<ULong64_t,unsigned int> idmap;
1512 int nskipped=0,nrepeated=0;
1517 unsigned int nchannels = tuple->
nChannels();
1530 onlid = cellInfo->
onlid();
1536 if(onlid<=0) printf(
"%u: Bad Cell Onlid = 0x%x (%+.2f,%+.2f)\n",
ichan,(
unsigned int)onlid,cellInfo->
eta(),cellInfo->
phi());
1538 idmap_itr = idmap.find(onlid);
1541 if(idmap_itr == idmap.end()){
1542 idmap[onlid] =
ichan;
1550 printf(
"Skipped %d cells.\n",nskipped);
1551 printf(
"Number of onlids: Unique=%d, Repeated=%d\n",(
int)idmap.size(),nrepeated);
1570 printf(
"LArCellsEmptyMonitoring::DoEtaPhiMonitoring: Reading options: %s %s.\n",optionplot,optionsave);
1572 bool knormplot =
false;
1573 if(strstr(optionplot,
"Precentage")) knormplot =
true;
1576 double nsigmacut = 0.;
1577 double qualitycut = 0.;
1578 if(strstr(optionplot,
"Sigma")){
1580 if(strstr(optionplot,
"4Sigma")) nsigmacut = 4.;
1581 if(strstr(optionplot,
"5Sigma")) nsigmacut = 5.;
1582 }
else if(strstr(optionplot,
"Quality")){
1590 ULong64_t onlid = 0;
1595 unsigned int nchannels = tuple->
nChannels();
1602 for(
int j=0;j<
nhists;j++){
1605 hmap_counts_all[j]->SetName(
hname);
1609 hmap_energy_cut[j]->SetName(
hname);
1613 hmap_quality_cut[j]->SetName(
hname);
1624 unsigned int ndigits =
hist->nData();
1625 if(ndigits==0){ nskipped++;
continue; }
1630 onlid = cellInfo->
onlid();
1631 if(onlid<=0) printf(
"%u: Bad Cell Onlid = 0x%x (%+.2f,%+.2f)\n",
ichan,(
unsigned int)onlid,cellInfo->
eta(),cellInfo->
phi());
1634 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1642 if(kcuttype==1 &&
data->noise()>0.){
1652 printf(
"Skipped %d cells. Bad Cells = %d\n",nskipped,nbad);
1656 for(
int j=0;j<
nhists;j++){
1657 hmap_energy_cut[j]->Divide(hmap_counts_all[j]);
1658 hmap_quality_cut[j]->Divide(hmap_counts_all[j]);
1662 std::unique_ptr<TFile> tout;
1663 TCanvas*
c0 =
nullptr, *
c1 =
nullptr;
1665 if(!strcmp(optionsave,
"root")){
1666 tout.reset(
new TFile(
"EtaPhiMonitoring.root",
"recreate"));
1668 c0->SetName(
"Normalization");
1670 for(
int j=0;j<
nhists;j++) hmap_counts_all[j]->Write();
1673 c0->SetName(
"EnergyCut");
1675 for(
int j=0;j<
nhists;j++) hmap_energy_cut[j]->Write();
1678 c0 =
m_LarIdTranslator->CaloPartitionLayerDisplay((TH1**)hmap_quality_cut,
"QualityCut",1);
1679 c0->SetName(
"QualityCut");
1681 for(
int j=0;j<
nhists;j++) hmap_quality_cut[j]->Write();
1686 c0->SaveAs(
"Normalization.png");
1687 c1 =
new TCanvas(
"c1",
"");
1688 for(
int j=0;j<
nhists;j++){ hmap_counts_all[j]->Draw(
"colz"); sprintf(
hname,
"%s.png",hmap_counts_all[j]->GetName());
c1->SaveAs(
hname); }
1691 c0->SaveAs(
"EnergyCut.png");
1693 for(
int j=0;j<
nhists;j++){ hmap_energy_cut[j]->Draw(
"colz"); sprintf(
hname,
"%s.png",hmap_energy_cut[j]->GetName());
c1->SaveAs(
hname); }
1696 c0 =
m_LarIdTranslator->CaloPartitionLayerDisplay((TH1**)hmap_quality_cut,
"QualityCut",1);
1697 c0->SaveAs(
"QualityCut.png");
1699 for(
int j=0;j<
nhists;j++){ hmap_quality_cut[j]->Draw(
"colz"); sprintf(
hname,
"%s.png",hmap_quality_cut[j]->GetName());
c1->SaveAs(
hname); }
1702 delete[] hmap_counts_all;
1703 delete[] hmap_energy_cut;
1704 delete[] hmap_quality_cut;
1722 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells;
1723 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy_PS;
1724 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy_LAr;
1725 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells_PS;
1726 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventLayer;
1730 unsigned int nchannels = tuple->
nChannels();
1742 unsigned int ndigits =
hist->nData();
1743 if(ndigits==0){
continue; }
1746 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1751 double energyGeV =
data->energy()/1000.;
1754 std::pair<unsigned int, unsigned int>
ev(
data->run(),
data->event());
1756 eventEnergy_LAr[
ev] += energyGeV;
1759 eventEnergy_PS[
ev] += energyGeV;
1760 eventCells_PS[
ev]++;
1768 constexpr
int nbins = 42;
1769 double binE[
nbins+1]{};
1772 double de = 0.,ene = 0.;
1798 TH1F E_LAr_pass(
"E_LAr_pass",
"",
nbins,binE);
1799 TH1F E_LAr_tot(
"E_LAr_tot",
"",
nbins,binE);
1800 TH1F E_LAr_EM5_pass(
"E_LAr_EM5_pass",
"",
nbins,binE);
1801 TH1F E_LAr_EM5_tot(
"E_LAr_EM5_tot",
"",
nbins,binE);
1802 TH1F E_LAr_TAU8_pass(
"E_LAr_TAU8_pass",
"",
nbins,binE);
1803 TH1F E_LAr_TAU8_tot(
"E_LAr_TAU8_tot",
"",
nbins,binE);
1804 TH1F E_LAr_J10_pass(
"E_LAr_J10_pass",
"",
nbins,binE);
1805 TH1F E_LAr_J10_tot(
"E_LAr_J10_tot",
"",
nbins,binE);
1806 TH1F nCellsPS_pass(
"nCellsPS_pass",
"",100, 0, 100);
1807 TH1F nCellsPS_tot(
"nCellsPS_tot",
"",100, 0, 100);
1808 TH1F nCellsPS_EM5_pass(
"nCellsPS_EM5_pass",
"",100, 0, 100);
1809 TH1F nCellsPS_EM5_tot(
"nCellsPS_EM5_tot",
"",100, 0, 100);
1810 TH1F nCellsPS_TAU8_pass(
"nCellsPS_TAU8_pass",
"",100, 0, 100);
1811 TH1F nCellsPS_TAU8_tot(
"nCellsPS_TAU8_tot",
"",100, 0, 100);
1812 TH1F nCellsPS_J10_tot(
"nCellsPS_J10_tot",
"",100, 0, 100);
1813 TH1F nCellsPS_J10_pass(
"nCellsPS_J10_pass",
"",100, 0, 100);
1818 for(
unsigned int ievent = 0; ievent < tuple->
nEvents(); ievent++) {
1820 std::pair<unsigned int, unsigned int>
id(evtData->
run(), evtData->
event());
1821 if(eventCells[
id]==0)
continue;
1822 if(eventEnergy_LAr[
id]<=0)
continue;
1823 bool isEM5 = evtData->
isPassed(
"L1_EM5_EMPTY");
1824 bool isTAU8 = evtData->
isPassed(
"L1_TAU8_EMPTY");
1825 bool isJ10 = evtData->
isPassed(
"L1_J10_EMPTY");
1827 E_LAr_tot.Fill(eventEnergy_LAr[
id]);
1828 nCellsPS_tot.Fill(eventCells_PS[
id]);
1830 E_LAr_EM5_tot.Fill(eventEnergy_LAr[
id]);
1831 nCellsPS_EM5_tot.Fill(eventCells_PS[
id]);
1834 E_LAr_TAU8_tot.Fill(eventEnergy_LAr[
id]);
1835 nCellsPS_TAU8_tot.Fill(eventCells_PS[
id]);
1838 E_LAr_J10_tot.Fill(eventEnergy_LAr[
id]);
1839 nCellsPS_J10_tot.Fill(eventCells_PS[
id]);
1843 if((eventEnergy_LAr[
id])!=0)
1844 ratio = eventEnergy_PS[
id]/(eventEnergy_LAr[
id]);
1845 bool isL2_PreS =
false;
1846 if(
ratio > fractionInPS) isL2_PreS =
true;
1849 E_LAr_pass.Fill(eventEnergy_LAr[
id]);
1850 nCellsPS_pass.Fill(eventCells_PS[
id]);
1852 E_LAr_EM5_pass.Fill(eventEnergy_LAr[
id]);
1853 nCellsPS_EM5_pass.Fill(eventCells_PS[
id]);
1856 E_LAr_TAU8_pass.Fill(eventEnergy_LAr[
id]);
1857 nCellsPS_TAU8_pass.Fill(eventCells_PS[
id]);
1860 E_LAr_J10_pass.Fill(eventEnergy_LAr[
id]);
1861 nCellsPS_J10_pass.Fill(eventCells_PS[
id]);
1867 sprintf(
fname,
"TriggerEfficiency_%d.root",
run);
1868 auto mfile = std::make_unique<TFile>(
fname,
"recreate");
1871 E_LAr_EM5_pass.Write();
1872 E_LAr_EM5_tot.Write();
1873 E_LAr_TAU8_pass.Write();
1874 E_LAr_TAU8_tot.Write();
1875 E_LAr_J10_pass.Write();
1876 E_LAr_J10_tot.Write();
1877 nCellsPS_pass.Write();
1878 nCellsPS_tot.Write();
1879 nCellsPS_EM5_pass.Write();
1880 nCellsPS_EM5_tot.Write();
1881 nCellsPS_TAU8_pass.Write();
1882 nCellsPS_TAU8_tot.Write();
1883 nCellsPS_J10_pass.Write();
1884 nCellsPS_J10_tot.Write();