28 #include "TObjString.h"
35 #include "TProfile2D.h"
37 #include "TDirectory.h"
54 using THVec=std::vector<std::unique_ptr<T>>;
56 template <
class T, std::
size_t n>
57 using THArray = std::array<std::unique_ptr<T>,
n >;
59 using TH1Fp = std::unique_ptr<TH1F>;
60 using TH2Fp = std::unique_ptr<TH2F>;
63 LArCellsEmptyMonitoring::LArCellsEmptyMonitoring()
98 TString htitle,
hname,textfilename,rootfilename;
100 double Ecum_cut_PS = 20.;
101 double Ecum_cut_calo = 10.;
104 const double GeV = 1/1000.;
106 double nsigmaHits = 10.;
112 unsigned int onlid = 0;
123 double MeanEventEnergy_max = -999;
124 double MeanEventEnergy_min = 999;
131 vector<int, std::allocator<int> > DQLBList;
133 vector<int, std::allocator<int> > BadLBList;
136 printf(
"Getting histogram limits... ");
145 printf(
"Done.\n LBmin: %d LBmax: %d Emin: %d Emax: %d Qmin: %d Qmax: %d\n",
lbmin,
lbmax,emin,emax,qmin,qmax);
149 FILE * pFile=
nullptr;
152 textfilename.Form(
"Output/BadCellList_run%d.txt",
runNumber);
153 pFile = fopen (textfilename ,
"w");
155 printf(
"Cannot open output text file\n");
161 pFile = fopen (textfilename ,
"w");
163 printf(
"Cannot open output text file\n");
170 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);
173 int EventCount=0., qcount=0.;
179 rootfilename.Form(
"Output/BadCells_run%d.root",
runNumber);
182 auto fout = std::make_unique<TFile>(rootfilename,
"RECREATE");
196 printf(
"Creating histograms (nEbins = %d, nQbins = %d, nLBbins = %d)... ",ne,nq,nlb);
197 TH1F hene =
TH1F(
"hEne",
"",ne,emin,emax); hene.SetXTitle(
"Energy [GeV]"); hene.SetYTitle(
"Events");
198 TH1F hqua =
TH1F(
"hQua",
"",nq/100.,qmin,qmax); hqua.SetXTitle(
"Quality"); hqua.SetYTitle(
"Events");
199 TH1F hlb =
TH1F(
"hLB",
"",nlb,
lbmin,
lbmax); hlb.SetXTitle(
"LB"); hlb.SetYTitle(
"Events");
200 TH2F henelb =
TH2F(
"hEnelb",
"",nlb,
lbmin,
lbmax,ne,emin,emax); henelb.SetXTitle(
"LB"); henelb.SetYTitle(
"Energy [GeV]");
207 printf(
"Creating cut test histograms...");
208 static constexpr
int npl=4;
209 TH2F tempHist =
TH2F(
"tempNEvLB",
"",1000,0,1000.,1000,0.,1000.);
217 for (
int i=0;
i<npl;
i++){
218 hname.Form(
"hNEvVsEMean_Layer%i",
i);
219 hNEvVsEMean[
i].reset((
TH2F*)tempHist.Clone(
hname));
220 hNEvVsEMean[
i]->GetXaxis()->SetTitle(
"Number of Events (E > 10 #sigma) / LB");
221 hNEvVsEMean[
i]->GetYaxis()->SetTitle(
"E_{mean} per Event / LB [GeV]");
223 hname.Form(
"hNEvVsECum_Layer%i",
i);
224 hNEvVsECum[
i].reset((
TH2F*)tempHist.Clone(
hname));
225 hNEvVsECum[
i]->GetXaxis()->SetTitle(
"Number of Events (E > 10 #sigma) / LB");
226 hNEvVsECum[
i]->GetYaxis()->SetTitle(
"E_{cumulative} per Cell / LB [GeV]");
228 hname.Form(
"hECumVsEMean_Layer%i",
i);
229 hECumVsEMean[
i].reset((
TH2F*)tempHist.Clone(
hname));
230 hECumVsEMean[
i]->GetXaxis()->SetTitle(
"E_{cumulative} per Cell / LB [GeV]");
231 hECumVsEMean[
i]->GetYaxis()->SetTitle(
"E_{mean} per Event / LB [GeV]");
233 hname.Form(
"hNoise_Layer%i",
i);
234 hNoise[
i].reset(
new TH1F(
hname,
"",60,0.,30.));
235 hNoise[
i]->GetXaxis()->SetTitle(
"Noise [GeV]");
236 hNoise[
i]->GetYaxis()->SetTitle(
"Number Of Cells");
238 hname.Form(
"hCellsPerLB_Layer%i",
i);
239 hCellsPerLB[
i].reset((
TH1F*)hlb.Clone(
hname));
240 hCellsPerLB[
i]->GetXaxis()->SetTitle(
"LB");
241 hNoise[
i]->GetYaxis()->SetTitle(
"Number Of Cells");
250 unsigned int nchannels = tuple->
nChannels();
252 printf(
"Begin looping over cells...\n");
264 onlid = cellInfo->
onlid();
267 unsigned int ndigits =
hist->nData();
268 if(ndigits<(
unsigned int)
threshold){ nskipped++;
continue; }
272 hname.Form(
"h0x%x_Energy",onlid);
274 hname.Form(
"h0x%x_Quality",onlid);
276 hname.Form(
"h0x%x_LB",onlid);
278 hname.Form(
"h0x%x_hNEvVsEMean",onlid);
280 hname.Form(
"h0x%x_Energy_LB",onlid);
281 h2_elb.reset((
TH2F*)henelb.Clone(
hname));
282 hname.Form(
"h0x%x_Quality_LB",onlid);
287 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
291 if(!Evdata){ noEvdata++;
continue; }
300 h1_q->Fill(
data->quality());
308 if (
data->quality() > qthreshold){
322 if ( CellCounter%1000 == 0 ) {
323 printf(
"Scanning Cell No. = %d\n",CellCounter);
325 MeanEventEnergy_max = -999;
326 MeanEventEnergy_min = 999;
333 if (h1_lb->GetBinContent(
ilb) > 0.){
334 double EtotInLB = h1_elb->GetBinContent(
ilb);
335 double NEventsInLB = h1_lb->GetBinContent(
ilb);
337 int LB_number = h1_lb->GetBinLowEdge(
ilb);
339 double MeanEventEnergy = EtotInLB / NEventsInLB;
342 if (cellInfo->
layer()==0){
343 if (EtotInLB>Ecum_cut_PS){
344 hNEvVsEMean[cellInfo->
layer()]->Fill(NEventsInLB,MeanEventEnergy);
345 hNEvVsECum[cellInfo->
layer()]->Fill(NEventsInLB,EtotInLB);
346 hECumVsEMean[cellInfo->
layer()]->Fill(EtotInLB,MeanEventEnergy);
347 hCellsPerLB[cellInfo->
layer()]->Fill(LB_number);
350 else if (EtotInLB>Ecum_cut_calo){
351 hNEvVsEMean[cellInfo->
layer()]->Fill(NEventsInLB,MeanEventEnergy);
352 hNEvVsECum[cellInfo->
layer()]->Fill(NEventsInLB,EtotInLB);
353 hECumVsEMean[cellInfo->
layer()]->Fill(EtotInLB,MeanEventEnergy);
354 hCellsPerLB[cellInfo->
layer()]->Fill(LB_number);
357 if (EtotInLB>Ecum_cut_PS && cellInfo->
layer()==0){
358 FlagCell=
true; FlagCount++;
359 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
360 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
362 else if (EtotInLB>Ecum_cut_calo && cellInfo->
layer()==1){
363 FlagCell=
true; FlagCount++;
364 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
365 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
367 else if (EtotInLB>Ecum_cut_calo && cellInfo->
layer()==2){
368 FlagCell=
true; FlagCount++;
369 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
370 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
372 else if (EtotInLB>Ecum_cut_calo && cellInfo->
layer()==3){
373 FlagCell=
true; FlagCount++;
374 if (MeanEventEnergy_max<MeanEventEnergy){ MeanEventEnergy_max = MeanEventEnergy; }
375 if (MeanEventEnergy_min>MeanEventEnergy){ MeanEventEnergy_min = MeanEventEnergy; }
380 fr_q4k = (
double)qcount/(
double)EventCount;
387 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);
397 printf(
"Skipped %d cells. Cells scanned = %d\n",nskipped,nbad);
398 printf(
"Cells put in Bad Cell List = %d\n",nBadCells);
399 if (noEvdata>0) printf(
"No Evdata pointer: %d\n",noEvdata);
404 for(
int i=0;
i<npl;
i++){
405 hNEvVsEMean[
i]->Write();
406 hNEvVsECum[
i]->Write();
407 hECumVsEMean[
i]->Write();
409 hCellsPerLB[
i]->Write();
425 TString htitle,
hname,textfilename,rootfilename;
437 printf(
"WARNING: Received instruction to select recurring bad cells only in SetSelectRecurringBadCells(bool flag)\n");
438 printf(
"-------> Only one algorithm selected for cell selection criteria in SetAlgo(int algoindex)\n");
439 printf(
"-------> Recurring cell selection overides algorithm specification\n");
444 printf(
"ERROR: Partition not specified in SetPartition(bool set_part, std::string partname)\n");
451 int selectionFlag = -1;
452 const double GeV = 1/1000.;
462 unsigned int onlid = 0;
474 int nEvents_E_gt_ecut=0;
475 double EventEnergySum=0.;
476 double EventEnergyMean=0.;
479 double MeanHits=0, rmsHits=0;
480 int iMeanCellHitsSelection=0,iEnergyThresholdSelection=0,iOR_selection=0,iAND_selection=0;
486 vector<int, std::allocator<int> > DQLBList;
487 vector<int, std::allocator<int> > BadLBList;
489 printf(
"Reading in DQ Defect LB List...\n");
494 printf(
"Getting bad LB list...\n");
496 printf(
"...Done.\n");
497 nBadLBs = BadLBList.size();
500 BadLBList = std::move(DQLBList);
501 nBadLBs = BadLBList.size();
505 printf(
"Getting histogram limits... ");
516 printf(
"Done.\n LBmin: %d LBmax: %d Emin: %d Emax: %d Qmin: %d Qmax: %d\n",
lbmin,
lbmax,emin,emax,qmin,qmax);
521 textfilename.Form(
"Output/BadCellSelection_run%d.txt",
runNumber);
524 std::cout<<(
"Cannot open output selection summary file " + textfilename)<<
"\n";
530 std::cout<<(
"Cannot open output selection summary file " + textfilename)<<
"\n";
536 FILE * pFile=
nullptr;
539 textfilename.Form(
"Output/BadCellList_run%d.txt",
runNumber);
540 pFile = fopen (textfilename ,
"w");
542 printf(
"Cannot open output text file\n");
547 pFile = fopen (textfilename ,
"w");
549 printf(
"Cannot open output text file\n");
558 printf(
"Determining mean cell hits...\n ");
561 printf(
"Set threshold at %4.3f counts per cell for LB range. \n",(MeanHits+(nsigmaHits*rmsHits))*((
double)nlb_corr-(
double)nBadLBs));
565 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);
568 int EventCount=0., qcount=0.;
575 rootfilename.Form(
"Output/BadCells_run%d.root",
runNumber);
578 auto fout = std::make_unique<TFile>(rootfilename,
"RECREATE");
586 Float_t meanECell = 0;
588 TH1F* h1_lb =
nullptr;
589 TH1F* h1_e =
nullptr;
590 TH1F* h1_q =
nullptr;
591 TH2F* h2_elb =
nullptr;
592 TH2D* h2_pulse =
nullptr;
593 TH2D* h2_t_LB =
nullptr;
595 TH1F* h1_ADCmax =
nullptr;
596 std::unique_ptr<TTree> tree_cells;
598 tree_cells.reset(
new TTree(
"BadTree",
"LAr Tree ordered by OnlID"));
599 tree_cells->Branch(
"Energy",&h1_e);
600 tree_cells->Branch(
"Quality",&h1_q);
601 tree_cells->Branch(
"LB",&h1_lb);
602 tree_cells->Branch(
"larid",&larid);
603 tree_cells->Branch(
"onlid",&onlid);
604 tree_cells->Branch(
"Run",&t_run);
605 tree_cells->Branch(
"selectionFlag",&selectionFlag);
606 tree_cells->Branch(
"nhits_ensig",&n_ensig);
607 tree_cells->Branch(
"nhits_e1GeV",&n_ecut);
608 tree_cells->Branch(
"Quality_4k",&fr_q4k);
609 tree_cells->Branch(
"LBfraction",&fr_LB);
610 tree_cells->Branch(
"EnergyVsLB",&h2_elb);
611 tree_cells->Branch(
"PulseShape",&h2_pulse);
612 tree_cells->Branch(
"PulsePeakTimeVsLB",&h2_t_LB);
613 tree_cells->Branch(
"noise",&
noise);
614 tree_cells->Branch(
"MeanCellEnergy",&meanECell);
615 tree_cells->Branch(
"PulseShapeTProf",&TProf_pulse);
616 tree_cells->Branch(
"ADCmax",&h1_ADCmax);
621 TH2D NormPulse(
"Normalised_pulse",
"",100,-200,200,400,-10,10);
622 NormPulse.SetXTitle(
"Time [ns]");
623 NormPulse.SetYTitle(
"Value [ADC counts] / ADCmax");
634 E_LB.SetXTitle(
"LB");
635 E_LB.SetYTitle(
"Energy [GeV]");
637 TH2D t_LB(
"t_LB",
"",nlb,
lbmin,
lbmax,400,-200,200);
638 t_LB.GetXaxis()->SetTitle(
"LB");
639 t_LB.GetYaxis()->SetTitle(
"Time(maxSample) + ofcTime [ns]");
642 CF_LB.GetXaxis()->SetTitle(
"LB");
643 CF_LB.GetYaxis()->SetTitle(
"Number of cells flagged");
645 TH1F ME_EV(
"ME_EV",
"",1000,0,1000);
646 ME_EV.GetXaxis()->SetTitle(
"Nbr events >1 GeV");
647 ME_EV.GetYaxis()->SetTitle(
"Mean Energy [GeV]");
652 for (
int ii=0;ii<npl;ii++){
654 Cellmaps[ii]->GetXaxis()->SetTitle(
"#eta"); Cellmaps[ii]->GetYaxis()->SetTitle(
"#Phi");
656 Pulsemaps[ii].reset((TH2D*)NormPulse.Clone(
hname));
658 E_LBmaps[ii].reset((
TH2F*)E_LB.Clone(
hname));
660 t_LBmaps[ii].reset((TH2D*)t_LB.Clone(
hname));
662 CellsFlagged_LB_part[ii].reset((
TH1F*)CF_LB.Clone(
hname));
665 Emean_NbrEvents_part[ii].reset((
TH1F*)ME_EV.Clone(
hname));
670 Eeta.GetXaxis()->SetTitle(
"#eta");
671 Eeta.GetYaxis()->SetTitle(
"Energy [GeV]");
673 TH1F CellEnergy(
"CellEnergy",
"",ne,emin,emax);
674 CellEnergy.GetXaxis()->SetTitle(
"Cell Mean Energy [GeV]");
675 CellEnergy.GetYaxis()->SetTitle(
"Cells");
677 TH1F LBfrac(
"LBfrac",
"",100,0.,1.);
678 LBfrac.GetXaxis()->SetTitle(
"LB fraction");
679 LBfrac.GetYaxis()->SetTitle(
"Cells");
681 TH1F Qfrac(
"Qfrac",
"",100.,0.,1.);
682 Qfrac.GetXaxis()->SetTitle(
"Fraction of Events Q>4000");
683 Qfrac.GetYaxis()->SetTitle(
"Cells");
686 CellsFlagged_LB.GetXaxis()->SetTitle(
"LB");
687 CellsFlagged_LB.GetYaxis()->SetTitle(
"Number of cells flagged");
689 TH1F Emean_NbrEvents(
"Emean_NEvents_1GeV",
"",1000,0,1000);
690 Emean_NbrEvents.GetXaxis()->SetTitle(
"N events > 1 GeV");
691 Emean_NbrEvents.GetYaxis()->SetTitle(
"Mean Energy [GeV]");
696 printf(
"Creating histograms (nEbins = %d, nQbins = %d, nLBbins = %d)... ",ne,nq,nlb);
697 TH1F hene =
TH1F(
"hEne",
"",ne,emin,emax); hene.SetXTitle(
"Energy [GeV]");
698 hene.SetYTitle(
"Events");
699 TH1F hqua =
TH1F(
"hQua",
"",nq/100.,qmin,qmax); hqua.SetXTitle(
"Quality");
700 hqua.SetYTitle(
"Events");
702 hlb.SetYTitle(
"Events");
704 henelb.SetYTitle(
"Energy [GeV]");
705 TH2D hpulse = TH2D(
"hPulse",
"",100,-200,200,400, -10,10); hpulse.SetXTitle(
"Time [ns]");
706 hpulse.SetYTitle(
"Value [ADC counts] / ADCmax");
707 TProfile TProfpulse =
TProfile(
"",
"",5, 0, 5,
"s"); TProfpulse.SetXTitle(
"Sample Number");
708 TProfpulse.SetYTitle(
"Value [ADC counts]");
709 TH2D ht_LB= TH2D(
"ht_LB",
"",nlb,
lbmin,
lbmax,400,-200,200); ht_LB.GetXaxis()->SetTitle(
"LB");
710 ht_LB.GetYaxis()->SetTitle(
"Time(maxSample) + ofcTime [ns]");
711 TH1F hADCmax =
TH1F(
"",
"",110,-200,2000); hADCmax.SetXTitle(
"ADCmax [ADC counts]"); hADCmax.SetYTitle(
"Events");
718 unsigned int nchannels = tuple->
nChannels();
720 fprintf(
outputFile,
"Onlid \t MeanCellHitBased \t EnergyThresholdBased \t OR \t AND\n");
723 printf(
"Begin looping over cells...\n");
732 double eta = cellInfo->
eta();
733 double phi = cellInfo->
phi();
738 onlid = cellInfo->
onlid();
746 unsigned int ndigits =
hist->nData();
747 if(ndigits<(
unsigned int)
threshold){ nskipped++;
continue; }
753 hname.Form(
"h0x%x_Energy",onlid);
755 hname.Form(
"h0x%x_Quality",onlid);
757 hname.Form(
"h0x%x_LB",onlid);
759 hname.Form(
"h0x%x_Energy_LB",onlid);
761 hname.Form(
"h0x%x_Pulse",onlid);
762 h2_pulse = (TH2D*)hpulse.Clone(
hname);
763 hname.Form(
"TProf0x%x_Pulse",onlid);
765 hname.Form(
"h0x%x_ADCmax",onlid);
767 hname.Form(
"h0x%x_t_LB",onlid);
768 h2_t_LB = (TH2D*)ht_LB.Clone(
hname);
771 bool CellInList =
false;
772 int LBFlaggedIn = -1;
775 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
779 if(!Evdata){ noEvdata++;
continue; }
788 if (isBadLB)
continue;
795 h1_e->Fill(
data->energy()*
GeV);
796 h1_q->Fill(
data->quality());
799 h1_ADCmax->Fill(
data->adcMax());
800 double time =
data->maxPosition()*25.0+
data->ofcTime();
802 for(
unsigned int isample=0;isample<
data->nSamples();isample++) {
803 TProf_pulse->Fill(isample,
data->value(isample));
804 h2_pulse->Fill(
data->time(isample)-time,
data->value(isample)/
data->adcMax());
809 if (
data->quality() > qthreshold){
817 if (
data->energy()*
GeV > ecut) {
819 EventEnergySum+=(
data->energy()*
GeV);
824 selectionFlag=
CheckCellSelectionCriteria(EventCount,nsigmaHits,MeanHits,rmsHits,nEvents_E_gt_ecut,EventEnergySum,nBadLBs,nlb_corr);
825 if(selectionFlag==2){
829 else if(selectionFlag==1){
839 else if(selectionFlag==0){
856 if ( CellCounter%1000 == 0 ) {
857 printf(
"Scanning Cell No. = %d\n",CellCounter);
859 selectionFlag=
CheckCellSelectionCriteria(EventCount,nsigmaHits,MeanHits,rmsHits,nEvents_E_gt_ecut,EventEnergySum,nBadLBs,nlb_corr);
862 if (selectionFlag >= 0){
863 bool ListOutput =
true;
864 int MeanCellHitsSelection = 0;
865 int EnergyThresholdSelection = 0;
866 int OR_selection = 0;
867 int AND_selection = 0;
869 if (selectionFlag == 2){
870 MeanCellHitsSelection = 1;
871 EnergyThresholdSelection = 1;
877 else if (selectionFlag == 1){
878 if (
m_Algo == 1) ListOutput =
false;
879 MeanCellHitsSelection = 1;
880 EnergyThresholdSelection = 0;
885 else if (selectionFlag == 0){
886 if (
m_Algo == 0) ListOutput =
false;
887 MeanCellHitsSelection = 0;
888 EnergyThresholdSelection = 1;
894 iMeanCellHitsSelection += MeanCellHitsSelection;
895 iEnergyThresholdSelection += EnergyThresholdSelection;
896 iOR_selection += OR_selection;
897 iAND_selection += AND_selection;
904 fprintf(
outputFile,
"0x%x \t %d \t \t \t %d \t \t %d \t %d\n",onlid,MeanCellHitsSelection,EnergyThresholdSelection,OR_selection,AND_selection);
912 if (h1_lb->GetBinContent(
ilb) > 0.)
nLB++;
915 fr_LB = (
double)
nLB/(
double)(nlb_corr-nBadLBs);
917 meanECell = h1_e->GetMean();
918 n_ensig = EventCount;
920 fr_q4k = (
double)qcount/(
double)EventCount;
922 n_ecut = nEvents_E_gt_ecut;
928 if (h1_lb->GetBinContent(
ilb) > 0.)
nLB++;
930 fr_LB = (
double)
nLB/(
double)(nlb_corr-nBadLBs);
932 meanECell = h1_e->GetMean();
933 n_ensig = EventCount;
935 fr_q4k = (
double)qcount/(
double)EventCount;
937 n_ecut = nEvents_E_gt_ecut;
938 Cellmaps[
index]->Fill(eta,phi,meanECell);
939 Eeta.Fill(eta,meanECell);
940 CellEnergy.Fill(meanECell);
943 Emean_NbrEvents.Fill(n_ecut,EventEnergySum/n_ecut);
944 Emean_NbrEvents_part[
index]->Fill(n_ecut,EventEnergySum/n_ecut);
951 CellsFlagged_LB_part[
index]->Fill(LBFlaggedIn);
952 CellsFlagged_LB.Fill(LBFlaggedIn);
960 if (nEvents_E_gt_ecut>0) { EventEnergyMean = EventEnergySum/nEvents_E_gt_ecut; }
961 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);
970 nEvents_E_gt_ecut = 0.;
972 EventEnergyMean = 0.;
974 printf(
"Cells selected: MeanCellHitsCut \t EnergyThreshodCut \t Either List \t Both Lists\n");
975 printf(
"\t \t %d \t \t \t \t %d \t \t %d \t %d\n",iMeanCellHitsSelection,iEnergyThresholdSelection,iOR_selection,iAND_selection);
982 printf(
"Skipped %d cells. Cells scanned = %d\n",nskipped,nbad);
983 printf(
"Cells put in Bad Cell List = %d\n",nBadCells);
984 if (noEvdata>0) printf(
"No Evdata pointer: %d\n",noEvdata);
988 for(
int i=0;
i<npl;
i++){
993 if(CellsFlagged_LB_part[
i]->
GetEntries()>0) CellsFlagged_LB_part[
i]->Write();
994 if( Emean_NbrEvents_part[
i]->
GetEntries()>0) Emean_NbrEvents_part[
i]->Write();
996 CellsFlagged_LB.Write();
1000 Emean_NbrEvents.Write();
1023 unsigned int nchannels = tuple->
nChannels();
1026 qmin = emin =
lbmin = 99999;
1027 qmax = emax =
lbmax = -1;
1037 unsigned int ndigits =
hist->nData();
1038 if(ndigits==0){
continue; }
1041 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1044 if(!Evdata)
continue;
1048 if (
data->energy() != 0. &&
data->noise() != 0.){
1051 if (isBadLB)
continue;
1057 double energyGeV =
data->energy()/1000.;
1058 if(energyGeV > emax) emax = energyGeV;
1059 if(energyGeV < emin) emin = energyGeV;
1060 if(
data->quality() > qmax) qmax =
data->quality();
1061 if(
data->quality() < qmin) qmin =
data->quality();
1071 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells_tot;
1072 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy_tot;
1073 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventLumiBlock;
1074 std::map< std::pair<std::string, unsigned int>,
unsigned int > eventCells;
1076 double NSIG = nsigma;
1080 unsigned int nchannels = tuple->
nChannels();
1091 int calo = cellInfo->
calo();
1100 unsigned int ndigits =
hist->nData();
1101 if(ndigits==0){
continue; }
1104 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1108 if(!Evdata)
continue;
1113 double energyGeV =
data->energy()/1000.;
1116 if (lumiBlock <= lbmax && lumiBlock >=
lbmin ) {
1117 if (
data->energy() > sqrt((NSIG*
data->noise())*(NSIG*
data->noise())) &&
data->energy() != 0. &&
data->noise() != 0.){
1119 std::pair<unsigned int, unsigned int>
ev(
data->run(),
data->event());
1120 std::pair<std::string, unsigned int> ev_cryo(
GetCryostat(calo),
data->event());
1121 eventCells_tot[
ev]++;
1122 eventEnergy_tot[
ev] += energyGeV;
1123 eventLumiBlock[
ev] =
lb;
1124 eventCells[ev_cryo]++;
1132 auto hCells_Ev_LB = std::make_unique<TProfile>(
"",
"",nlb,
lbmin,
lbmax,-100,100000);
1133 std::map< std::string, TProfilep> hCellsEvLB;
1134 std::map< std::string, TH1Fp> hp_cryo;
1139 std::string Cryo[8] = {
"EMBA",
"EMBC",
"EMECA",
"EMECC",
"HECA",
"HECC",
"FCALA",
"FCALC"};
1140 for(
int k = 0;
k< nCryo;
k++){
1141 hCellsEvLB[Cryo[
k]].reset((
TProfile*)hCells_Ev_LB->Clone());
1143 for(
unsigned int ievent = 0; ievent < tuple->
nEvents(); ievent++) {
1145 std::pair<unsigned int, unsigned int>
id(evtData->
run(), evtData->
event());
1146 if(eventCells_tot[
id]==0)
continue;
1148 for(
int j=0; j<nCryo ;j++){
1149 std::pair<std::string, unsigned int> id_cryo(Cryo[j], evtData->
event());
1150 hCellsEvLB[Cryo[j]]->Fill(eventLumiBlock[
id], eventCells[id_cryo]);
1153 hCells_Ev_LB->Fill(eventLumiBlock[
id], eventCells_tot[
id]);
1156 auto hp = std::make_unique<TH1F>(
"",
"",(hCells_Ev_LB->GetBinContent(hCells_Ev_LB->GetMaximumBin())),0,hCells_Ev_LB->GetBinContent(hCells_Ev_LB->GetMaximumBin()));
1157 for(
int k = 0;
k< nCryo;
k++){
1158 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()));
1159 std::string
name1 =
"hp_" + Cryo[
k];
1160 hp_cryo[Cryo[
k]].reset((
TH1F*)hp_temp->Clone(
name1.c_str()));
1163 for (
int p=1;
p<=nlb;
p++){
1164 for(
int j=0; j<nCryo; j++){
1165 double bincont = hCellsEvLB[Cryo[j]]->GetBinContent(
p);
1166 hp_cryo[Cryo[j]]->Fill(bincont);
1168 double bincont1 = hCells_Ev_LB->GetBinContent(
p);
1172 std::map< std::string, double>
Mean;
1173 std::map< std::string, double>
RMS;
1174 std::map< int, vector<std::string> > BadLB_cryo;
1176 for(
int k=0;
k<nCryo;
k++)
1178 Mean[Cryo[
k]] = hp_cryo[Cryo[
k]]->GetMean();
1179 RMS[Cryo[
k]] = hp_cryo[Cryo[
k]]->GetRMS();
1182 double MEAN2 = hp->GetMean();
1183 double RMS2 = hp->GetRMS();
1188 vector<int> BadLB_tot=DQLBList;
1190 double value1 = (MEAN2+(RMS2*3.));
1191 int numberFlagged=0;
1192 for (
int l=1;
l<=nlb;
l++){
1193 for(
int j=0; j<nCryo; j++){
1194 double value = MEAN2 + (
RMS[Cryo[j]]*3);
1195 if(hCellsEvLB[Cryo[j]]->GetBinContent(
l) >
value){
1196 int badLB = hCellsEvLB[Cryo[j]]->GetBinLowEdge(
l);
1197 BadLB_cryo[badLB].push_back(Cryo[j]);
1199 for(
unsigned int p=0;
p< BadLB_tot.size();
p++) {
1200 if(badLB == BadLB_tot[
p]) isadd =
false;
1203 BadLB_tot.push_back(badLB);
1205 printf(
"Removing bad LB %d in %s\n",badLB,Cryo[j].c_str());
1210 if (hCells_Ev_LB->GetBinContent(
l) > value1){
1211 BadLB.push_back(hCells_Ev_LB->GetBinLowEdge(
l));
1215 printf(
"Number of Bad LBs found: %d\n",numberFlagged);
1216 printf(
"Number of LBs to be removed: %zu", BadLB_tot.size());
1225 for (
unsigned int yy=0;
yy<BadLBList.size();
yy++){
1241 unsigned int nchannels = tuple->
nChannels();
1244 double TotalRecordedHits=0;
1245 std::vector<int, std::allocator<int> > HitsPerLB;
1259 unsigned int ndigits =
hist->nData();
1262 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1265 if(!Evdata)
continue;
1271 if (isBadLB)
continue;
1282 if (nHits > 0.)
nCells++;
1295 TH1Fp tp_ev = std::make_unique<TH1F>(
"",
"",th1_Hits->GetBinContent(th1_Hits->GetMaximumBin())*100,0,th1_Hits->GetBinContent(th1_Hits->GetMaximumBin()));
1297 for (
int i=1;
i<=nlb;
i++){
1298 if(hNLB->GetBinContent(
i)>0){
1300 tp_ev->Fill(th1_Hits->GetBinContent(
i));
1301 TotalRecordedHits+=th1_Hits->GetBinContent(
i);
1302 HitsPerLB.push_back(th1_Hits->GetBinContent(
i));
1306 MeanHits = ((
double)TotalRecordedHits/(
double)nlb_corr)/(
double)
nCells;
1310 for (
unsigned int j=0;j<HitsPerLB.size();j++){
1314 rmsHits =
var/nlb_corr;
1316 printf(
"Mean number of hits/cell for 1 LB = %4.3f, RMS = %4.3f\n",MeanHits,rmsHits);
1317 printf(
"Number of cells firing at E > %d sigma = %d\n",nsigma,
nCells);
1318 printf(
"Total number of LBs included = %d\n",nlb_corr);
1329 }
else if (lumiBlock <= lbmax && lumiBlock >=
lbmin &&
energy > sqrt((nsigma*
noise)*(nsigma*
noise)) ) {
1352 if ((EventCount > (MeanHits+(nsigmaHits*rmsHits))*((
double)nlb-(
double)nBadLBs)))
a=
true;
1367 if ((
a &&
b) || (
a &&
c)){
1369 }
else if (
a && !
b && !
c){
1371 }
else if ((!
a &&
b) || (!
a &&
c)){
1403 bool isFoundPartition =
false;
1404 for(
int i=0;
i< npl;
i++){
1408 isFoundPartition =
true;
1411 if(!isFoundPartition){
1412 printf(
"ERROR: Partition %s does not exist! Invalid input name.\n",
partname.c_str());
1413 printf(
"Possible candidates are:\n");
1414 for (
int j=0;j<npl;j++){ printf(
"%s\n",
m_LarIdTranslator->GetPartitonLayerName(j)); }
1422 std::string cryostat =
"NotGiven";
1423 if(calo == 1) cryostat =
"EMBA";
1424 else if(calo == -1) cryostat =
"EMBC";
1425 else if(calo == 5) cryostat =
"FCALA";
1426 else if(calo == -5) cryostat =
"FCALC";
1427 else if(calo == 4) cryostat =
"HECA";
1428 else if(calo == -4) cryostat =
"HECC";
1429 else if(calo == 2 || calo == 3) cryostat =
"EMECA";
1430 else if(calo == -2 || calo == -3) cryostat =
"EMECC";
1453 std::vector<int> LBList;
1455 std::ifstream
infile(LBfile.Data());
1461 std::unique_ptr<TObjArray>
list(
filter.Tokenize(
", "));
1462 if(
list->GetEntries() == 0){
1463 printf(
"No LB filtering specified, or bad format. Exiting.\n");
1464 LBList.push_back(0);
1468 for(
int k = 0;
k <
list->GetEntries();
k++){
1469 TObjString* tobs = (TObjString*)(
list->At(
k));
1470 LBList.push_back((
int)(tobs->String()).Atoi());
1472 printf(
"LB List: %d\n",(
int)LBList.size());
1510 ULong64_t onlid = 0;
1511 std::map<ULong64_t,unsigned int> idmap;
1513 int nskipped=0,nrepeated=0;
1518 unsigned int nchannels = tuple->
nChannels();
1531 onlid = cellInfo->
onlid();
1537 if(onlid<=0) printf(
"%u: Bad Cell Onlid = 0x%x (%+.2f,%+.2f)\n",
ichan,(
unsigned int)onlid,cellInfo->
eta(),cellInfo->
phi());
1539 idmap_itr = idmap.find(onlid);
1542 if(idmap_itr == idmap.end()){
1543 idmap[onlid] =
ichan;
1551 printf(
"Skipped %d cells.\n",nskipped);
1552 printf(
"Number of onlids: Unique=%d, Repeated=%d\n",(
int)idmap.size(),nrepeated);
1571 printf(
"LArCellsEmptyMonitoring::DoEtaPhiMonitoring: Reading options: %s %s.\n",optionplot,optionsave);
1573 bool knormplot =
false;
1574 if(strstr(optionplot,
"Precentage")) knormplot =
true;
1577 double nsigmacut = 0.;
1578 double qualitycut = 0.;
1579 if(strstr(optionplot,
"Sigma")){
1581 if(strstr(optionplot,
"4Sigma")) nsigmacut = 4.;
1582 if(strstr(optionplot,
"5Sigma")) nsigmacut = 5.;
1583 }
else if(strstr(optionplot,
"Quality")){
1591 ULong64_t onlid = 0;
1596 unsigned int nchannels = tuple->
nChannels();
1603 for(
int j=0;j<
nhists;j++){
1606 hmap_counts_all[j]->SetName(
hname);
1610 hmap_energy_cut[j]->SetName(
hname);
1614 hmap_quality_cut[j]->SetName(
hname);
1625 unsigned int ndigits =
hist->nData();
1626 if(ndigits==0){ nskipped++;
continue; }
1631 onlid = cellInfo->
onlid();
1632 if(onlid<=0) printf(
"%u: Bad Cell Onlid = 0x%x (%+.2f,%+.2f)\n",
ichan,(
unsigned int)onlid,cellInfo->
eta(),cellInfo->
phi());
1635 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1643 if(kcuttype==1 &&
data->noise()>0.){
1653 printf(
"Skipped %d cells. Bad Cells = %d\n",nskipped,nbad);
1657 for(
int j=0;j<
nhists;j++){
1658 hmap_energy_cut[j]->Divide(hmap_counts_all[j]);
1659 hmap_quality_cut[j]->Divide(hmap_counts_all[j]);
1663 std::unique_ptr<TFile> tout;
1664 TCanvas*
c0 =
nullptr, *
c1 =
nullptr;
1666 if(!strcmp(optionsave,
"root")){
1667 tout.reset(
new TFile(
"EtaPhiMonitoring.root",
"recreate"));
1669 c0->SetName(
"Normalization");
1671 for(
int j=0;j<
nhists;j++) hmap_counts_all[j]->Write();
1674 c0->SetName(
"EnergyCut");
1676 for(
int j=0;j<
nhists;j++) hmap_energy_cut[j]->Write();
1679 c0 =
m_LarIdTranslator->CaloPartitionLayerDisplay((TH1**)hmap_quality_cut,
"QualityCut",1);
1680 c0->SetName(
"QualityCut");
1682 for(
int j=0;j<
nhists;j++) hmap_quality_cut[j]->Write();
1687 c0->SaveAs(
"Normalization.png");
1688 c1 =
new TCanvas(
"c1",
"");
1689 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); }
1692 c0->SaveAs(
"EnergyCut.png");
1694 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); }
1697 c0 =
m_LarIdTranslator->CaloPartitionLayerDisplay((TH1**)hmap_quality_cut,
"QualityCut",1);
1698 c0->SaveAs(
"QualityCut.png");
1700 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); }
1703 delete[] hmap_counts_all;
1704 delete[] hmap_energy_cut;
1705 delete[] hmap_quality_cut;
1723 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells;
1724 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy_PS;
1725 std::map< std::pair<unsigned int, unsigned int>,
double > eventEnergy_LAr;
1726 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventCells_PS;
1727 std::map< std::pair<unsigned int, unsigned int>,
unsigned int > eventLayer;
1731 unsigned int nchannels = tuple->
nChannels();
1743 unsigned int ndigits =
hist->nData();
1744 if(ndigits==0){
continue; }
1747 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
1752 double energyGeV =
data->energy()/1000.;
1755 std::pair<unsigned int, unsigned int>
ev(
data->run(),
data->event());
1757 eventEnergy_LAr[
ev] += energyGeV;
1760 eventEnergy_PS[
ev] += energyGeV;
1761 eventCells_PS[
ev]++;
1769 constexpr
int nbins = 42;
1770 double binE[
nbins+1]{};
1773 double de = 0.,ene = 0.;
1799 TH1F E_LAr_pass(
"E_LAr_pass",
"",
nbins,binE);
1800 TH1F E_LAr_tot(
"E_LAr_tot",
"",
nbins,binE);
1801 TH1F E_LAr_EM5_pass(
"E_LAr_EM5_pass",
"",
nbins,binE);
1802 TH1F E_LAr_EM5_tot(
"E_LAr_EM5_tot",
"",
nbins,binE);
1803 TH1F E_LAr_TAU8_pass(
"E_LAr_TAU8_pass",
"",
nbins,binE);
1804 TH1F E_LAr_TAU8_tot(
"E_LAr_TAU8_tot",
"",
nbins,binE);
1805 TH1F E_LAr_J10_pass(
"E_LAr_J10_pass",
"",
nbins,binE);
1806 TH1F E_LAr_J10_tot(
"E_LAr_J10_tot",
"",
nbins,binE);
1807 TH1F nCellsPS_pass(
"nCellsPS_pass",
"",100, 0, 100);
1808 TH1F nCellsPS_tot(
"nCellsPS_tot",
"",100, 0, 100);
1809 TH1F nCellsPS_EM5_pass(
"nCellsPS_EM5_pass",
"",100, 0, 100);
1810 TH1F nCellsPS_EM5_tot(
"nCellsPS_EM5_tot",
"",100, 0, 100);
1811 TH1F nCellsPS_TAU8_pass(
"nCellsPS_TAU8_pass",
"",100, 0, 100);
1812 TH1F nCellsPS_TAU8_tot(
"nCellsPS_TAU8_tot",
"",100, 0, 100);
1813 TH1F nCellsPS_J10_tot(
"nCellsPS_J10_tot",
"",100, 0, 100);
1814 TH1F nCellsPS_J10_pass(
"nCellsPS_J10_pass",
"",100, 0, 100);
1819 for(
unsigned int ievent = 0; ievent < tuple->
nEvents(); ievent++) {
1821 std::pair<unsigned int, unsigned int>
id(evtData->
run(), evtData->
event());
1822 if(eventCells[
id]==0)
continue;
1823 if(eventEnergy_LAr[
id]<=0)
continue;
1824 bool isEM5 = evtData->
isPassed(
"L1_EM5_EMPTY");
1825 bool isTAU8 = evtData->
isPassed(
"L1_TAU8_EMPTY");
1826 bool isJ10 = evtData->
isPassed(
"L1_J10_EMPTY");
1828 E_LAr_tot.Fill(eventEnergy_LAr[
id]);
1829 nCellsPS_tot.Fill(eventCells_PS[
id]);
1831 E_LAr_EM5_tot.Fill(eventEnergy_LAr[
id]);
1832 nCellsPS_EM5_tot.Fill(eventCells_PS[
id]);
1835 E_LAr_TAU8_tot.Fill(eventEnergy_LAr[
id]);
1836 nCellsPS_TAU8_tot.Fill(eventCells_PS[
id]);
1839 E_LAr_J10_tot.Fill(eventEnergy_LAr[
id]);
1840 nCellsPS_J10_tot.Fill(eventCells_PS[
id]);
1844 if((eventEnergy_LAr[
id])!=0)
1845 ratio = eventEnergy_PS[
id]/(eventEnergy_LAr[
id]);
1846 bool isL2_PreS =
false;
1847 if(
ratio > fractionInPS) isL2_PreS =
true;
1850 E_LAr_pass.Fill(eventEnergy_LAr[
id]);
1851 nCellsPS_pass.Fill(eventCells_PS[
id]);
1853 E_LAr_EM5_pass.Fill(eventEnergy_LAr[
id]);
1854 nCellsPS_EM5_pass.Fill(eventCells_PS[
id]);
1857 E_LAr_TAU8_pass.Fill(eventEnergy_LAr[
id]);
1858 nCellsPS_TAU8_pass.Fill(eventCells_PS[
id]);
1861 E_LAr_J10_pass.Fill(eventEnergy_LAr[
id]);
1862 nCellsPS_J10_pass.Fill(eventCells_PS[
id]);
1868 sprintf(
fname,
"TriggerEfficiency_%d.root",
run);
1869 auto mfile = std::make_unique<TFile>(
fname,
"recreate");
1872 E_LAr_EM5_pass.Write();
1873 E_LAr_EM5_tot.Write();
1874 E_LAr_TAU8_pass.Write();
1875 E_LAr_TAU8_tot.Write();
1876 E_LAr_J10_pass.Write();
1877 E_LAr_J10_tot.Write();
1878 nCellsPS_pass.Write();
1879 nCellsPS_tot.Write();
1880 nCellsPS_EM5_pass.Write();
1881 nCellsPS_EM5_tot.Write();
1882 nCellsPS_TAU8_pass.Write();
1883 nCellsPS_TAU8_tot.Write();
1884 nCellsPS_J10_pass.Write();
1885 nCellsPS_J10_tot.Write();