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());
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();