416 TString htitle,
hname,textfilename,rootfilename;
428 printf(
"WARNING: Received instruction to select recurring bad cells only in SetSelectRecurringBadCells(bool flag)\n");
429 printf(
"-------> Only one algorithm selected for cell selection criteria in SetAlgo(int algoindex)\n");
430 printf(
"-------> Recurring cell selection overides algorithm specification\n");
435 printf(
"ERROR: Partition not specified in SetPartition(bool set_part, std::string partname)\n");
442 int selectionFlag = -1;
443 const double GeV = 1/1000.;
453 unsigned int onlid = 0;
465 int nEvents_E_gt_ecut=0;
466 double EventEnergySum=0.;
467 double EventEnergyMean=0.;
470 double MeanHits=0, rmsHits=0;
471 int iMeanCellHitsSelection=0,iEnergyThresholdSelection=0,iOR_selection=0,iAND_selection=0;
477 vector<int, std::allocator<int> > DQLBList;
478 vector<int, std::allocator<int> > BadLBList;
480 printf(
"Reading in DQ Defect LB List...\n");
485 printf(
"Getting bad LB list...\n");
487 printf(
"...Done.\n");
488 nBadLBs = BadLBList.size();
491 BadLBList = std::move(DQLBList);
492 nBadLBs = BadLBList.size();
496 printf(
"Getting histogram limits... ");
507 printf(
"Done.\n LBmin: %d LBmax: %d Emin: %d Emax: %d Qmin: %d Qmax: %d\n",
lbmin,
lbmax,emin,emax,qmin,qmax);
512 textfilename.Form(
"Output/BadCellSelection_run%d.txt",
runNumber);
515 std::cout<<(
"Cannot open output selection summary file " + textfilename)<<
"\n";
521 std::cout<<(
"Cannot open output selection summary file " + textfilename)<<
"\n";
527 FILE * pFile=
nullptr;
530 textfilename.Form(
"Output/BadCellList_run%d.txt",
runNumber);
531 pFile = fopen (textfilename ,
"w");
533 printf(
"Cannot open output text file\n");
538 pFile = fopen (textfilename ,
"w");
540 printf(
"Cannot open output text file\n");
549 printf(
"Determining mean cell hits...\n ");
552 printf(
"Set threshold at %4.3f counts per cell for LB range. \n",(MeanHits+(nsigmaHits*rmsHits))*((
double)nlb_corr-(
double)nBadLBs));
556 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);
559 int EventCount=0., qcount=0.;
566 rootfilename.Form(
"Output/BadCells_run%d.root",
runNumber);
569 TFile*
fout =
new TFile(rootfilename,
"RECREATE");
577 Float_t meanECell = 0;
579 TH1F* h1_lb =
nullptr;
580 TH1F* h1_e =
nullptr;
581 TH1F* h1_q =
nullptr;
582 TH2F* h2_elb =
nullptr;
583 TH2D* h2_pulse =
nullptr;
584 TH2D* h2_t_LB =
nullptr;
586 TH1F* h1_ADCmax =
nullptr;
587 TTree* tree_cells =
nullptr;
589 tree_cells =
new TTree(
"BadTree",
"LAr Tree ordered by OnlID");
590 tree_cells->Branch(
"Energy",&h1_e);
591 tree_cells->Branch(
"Quality",&h1_q);
592 tree_cells->Branch(
"LB",&h1_lb);
593 tree_cells->Branch(
"larid",&larid);
594 tree_cells->Branch(
"onlid",&onlid);
595 tree_cells->Branch(
"Run",&t_run);
596 tree_cells->Branch(
"selectionFlag",&selectionFlag);
597 tree_cells->Branch(
"nhits_ensig",&n_ensig);
598 tree_cells->Branch(
"nhits_e1GeV",&n_ecut);
599 tree_cells->Branch(
"Quality_4k",&fr_q4k);
600 tree_cells->Branch(
"LBfraction",&fr_LB);
601 tree_cells->Branch(
"EnergyVsLB",&h2_elb);
602 tree_cells->Branch(
"PulseShape",&h2_pulse);
603 tree_cells->Branch(
"PulsePeakTimeVsLB",&h2_t_LB);
604 tree_cells->Branch(
"noise",&
noise);
605 tree_cells->Branch(
"MeanCellEnergy",&meanECell);
606 tree_cells->Branch(
"PulseShapeTProf",&TProf_pulse);
607 tree_cells->Branch(
"ADCmax",&h1_ADCmax);
612 TH2D* NormPulse =
new TH2D(
"Normalised_pulse",
"",100,-200,200,400,-10,10); NormPulse->SetXTitle(
"Time [ns]"); NormPulse->SetYTitle(
"Value [ADC counts] / ADCmax");
613 TH2D** Pulsemaps =
new TH2D*[npl];
616 TH2D** t_LBmaps =
new TH2D*[npl];
617 TH1F** CellsFlagged_LB_part =
new TH1F*[npl];
618 TH1F** Emean_NbrEvents_part =
new TH1F*[npl];
619 TH2F* E_LB =
new TH2F(
"E_LB",
"",nlb,
lbmin,
lbmax,ne,emin,emax); E_LB->SetXTitle(
"LB"); E_LB->SetYTitle(
"Energy [GeV]");
620 TH2D* t_LB=
new TH2D(
"t_LB",
"",nlb,
lbmin,
lbmax,400,-200,200); t_LB->GetXaxis()->SetTitle(
"LB"); t_LB->GetYaxis()->SetTitle(
"Time(maxSample) + ofcTime [ns]");
621 TH1F* CF_LB =
new TH1F(
"CF_LB",
"",nlb,
lbmin,
lbmax); CF_LB->GetXaxis()->SetTitle(
"LB"); CF_LB->GetYaxis()->SetTitle(
"Number of cells flagged");
622 TH1F* ME_EV =
new TH1F(
"ME_EV",
"",1000,0,1000); ME_EV->GetXaxis()->SetTitle(
"Nbr events >1 GeV"); ME_EV->GetYaxis()->SetTitle(
"Mean Energy [GeV]");
627 for (
int ii=0;ii<npl;ii++){
629 Cellmaps[ii]->GetXaxis()->SetTitle(
"#eta"); Cellmaps[ii]->GetYaxis()->SetTitle(
"#Phi");
631 Pulsemaps[ii] = (TH2D*)NormPulse->Clone(
hname);
633 E_LBmaps[ii] = (
TH2F*)E_LB->Clone(
hname);
635 t_LBmaps[ii] = (TH2D*)t_LB->Clone(
hname);
637 CellsFlagged_LB_part[ii] = (
TH1F*)CF_LB->Clone(
hname);
640 Emean_NbrEvents_part[ii] = (
TH1F*)ME_EV->Clone(
hname);
645 Eeta->GetXaxis()->SetTitle(
"#eta"); Eeta->GetYaxis()->SetTitle(
"Energy [GeV]");
646 TH1F* CellEnergy =
new TH1F(
"CellEnergy",
"",ne,emin,emax);
647 CellEnergy->GetXaxis()->SetTitle(
"Cell Mean Energy [GeV]"); CellEnergy->GetYaxis()->SetTitle(
"Cells");
648 TH1F* LBfrac =
new TH1F(
"LBfrac",
"",100,0.,1.);
649 LBfrac->GetXaxis()->SetTitle(
"LB fraction"); LBfrac->GetYaxis()->SetTitle(
"Cells");
650 TH1F* Qfrac =
new TH1F(
"Qfrac",
"",100.,0.,1.);
651 Qfrac->GetXaxis()->SetTitle(
"Fraction of Events Q>4000"); Qfrac->GetYaxis()->SetTitle(
"Cells");
653 CellsFlagged_LB->GetXaxis()->SetTitle(
"LB"); CellsFlagged_LB->GetYaxis()->SetTitle(
"Number of cells flagged");
654 TH1F* Emean_NbrEvents =
new TH1F(
"Emean_NEvents_1GeV",
"",1000,0,1000);
655 Emean_NbrEvents->GetXaxis()->SetTitle(
"N events > 1 GeV"); Emean_NbrEvents->GetYaxis()->SetTitle(
"Mean Energy [GeV]");
660 printf(
"Creating histograms (nEbins = %d, nQbins = %d, nLBbins = %d)... ",ne,nq,nlb);
661 TH1F hene =
TH1F(
"hEne",
"",ne,emin,emax); hene.SetXTitle(
"Energy [GeV]"); hene.SetYTitle(
"Events");
662 TH1F hqua =
TH1F(
"hQua",
"",nq/100.,qmin,qmax); hqua.SetXTitle(
"Quality"); hqua.SetYTitle(
"Events");
663 TH1F hlb =
TH1F(
"hLB",
"",nlb,
lbmin,
lbmax); hlb.SetXTitle(
"LB"); hlb.SetYTitle(
"Events");
664 TH2F henelb =
TH2F(
"hEnelb",
"",nlb,
lbmin,
lbmax,ne,emin,emax); henelb.SetXTitle(
"LB"); henelb.SetYTitle(
"Energy [GeV]");
665 TH2D hpulse = TH2D(
"hPulse",
"",100,-200,200,400, -10,10); hpulse.SetXTitle(
"Time [ns]"); hpulse.SetYTitle(
"Value [ADC counts] / ADCmax");
666 TProfile TProfpulse =
TProfile(
"",
"",5, 0, 5,
"s"); TProfpulse.SetXTitle(
"Sample Number"); TProfpulse.SetYTitle(
"Value [ADC counts]");
667 TH2D ht_LB= TH2D(
"ht_LB",
"",nlb,
lbmin,
lbmax,400,-200,200); ht_LB.GetXaxis()->SetTitle(
"LB"); ht_LB.GetYaxis()->SetTitle(
"Time(maxSample) + ofcTime [ns]");
668 TH1F hADCmax =
TH1F(
"",
"",110,-200,2000); hADCmax.SetXTitle(
"ADCmax [ADC counts]"); hADCmax.SetYTitle(
"Events");
675 unsigned int nchannels = tuple->
nChannels();
677 fprintf(
outputFile,
"Onlid \t MeanCellHitBased \t EnergyThresholdBased \t OR \t AND\n");
680 printf(
"Begin looping over cells...\n");
689 double eta = cellInfo->
eta();
690 double phi = cellInfo->
phi();
695 onlid = cellInfo->
onlid();
703 unsigned int ndigits =
hist->nData();
704 if(ndigits<(
unsigned int)
threshold){ nskipped++;
continue; }
710 hname.Form(
"h0x%x_Energy",onlid);
712 hname.Form(
"h0x%x_Quality",onlid);
714 hname.Form(
"h0x%x_LB",onlid);
716 hname.Form(
"h0x%x_Energy_LB",onlid);
718 hname.Form(
"h0x%x_Pulse",onlid);
719 h2_pulse = (TH2D*)hpulse.Clone(
hname);
720 hname.Form(
"TProf0x%x_Pulse",onlid);
722 hname.Form(
"h0x%x_ADCmax",onlid);
724 hname.Form(
"h0x%x_t_LB",onlid);
725 h2_t_LB = (TH2D*)ht_LB.Clone(
hname);
728 bool CellInList =
false;
729 int LBFlaggedIn = -1;
732 for(
unsigned int idigit = 0; idigit < ndigits; idigit++){
736 if(!Evdata){ noEvdata++;
continue; }
745 if (isBadLB)
continue;
752 h1_e->Fill(
data->energy()*
GeV);
753 h1_q->Fill(
data->quality());
756 h1_ADCmax->Fill(
data->adcMax());
759 for(
unsigned int isample=0;isample<
data->nSamples();isample++) {
760 TProf_pulse->Fill(isample,
data->value(isample));
761 h2_pulse->Fill(
data->time(isample)-
time,
data->value(isample)/
data->adcMax());
766 if (
data->quality() > qthreshold){
774 if (
data->energy()*
GeV > ecut) {
776 EventEnergySum+=(
data->energy()*
GeV);
781 selectionFlag=
CheckCellSelectionCriteria(EventCount,nsigmaHits,MeanHits,rmsHits,nEvents_E_gt_ecut,EventEnergySum,nBadLBs,nlb_corr);
782 if(selectionFlag==2){
786 else if(selectionFlag==1){
796 else if(selectionFlag==0){
813 if ( CellCounter%1000 == 0 ) {
814 printf(
"Scanning Cell No. = %d\n",CellCounter);
816 selectionFlag=
CheckCellSelectionCriteria(EventCount,nsigmaHits,MeanHits,rmsHits,nEvents_E_gt_ecut,EventEnergySum,nBadLBs,nlb_corr);
819 if (selectionFlag >= 0){
820 bool ListOutput =
true;
821 int MeanCellHitsSelection = 0;
822 int EnergyThresholdSelection = 0;
823 int OR_selection = 0;
824 int AND_selection = 0;
826 if (selectionFlag == 2){
827 MeanCellHitsSelection = 1;
828 EnergyThresholdSelection = 1;
834 else if (selectionFlag == 1){
835 if (
m_Algo == 1) ListOutput =
false;
836 MeanCellHitsSelection = 1;
837 EnergyThresholdSelection = 0;
842 else if (selectionFlag == 0){
843 if (
m_Algo == 0) ListOutput =
false;
844 MeanCellHitsSelection = 0;
845 EnergyThresholdSelection = 1;
851 iMeanCellHitsSelection += MeanCellHitsSelection;
852 iEnergyThresholdSelection += EnergyThresholdSelection;
853 iOR_selection += OR_selection;
854 iAND_selection += AND_selection;
861 fprintf(
outputFile,
"0x%x \t %d \t \t \t %d \t \t %d \t %d\n",onlid,MeanCellHitsSelection,EnergyThresholdSelection,OR_selection,AND_selection);
869 if (h1_lb->GetBinContent(
ilb) > 0.)
nLB++;
872 fr_LB = (
double)
nLB/(
double)(nlb_corr-nBadLBs);
874 meanECell = h1_e->GetMean();
875 n_ensig = EventCount;
877 fr_q4k = (
double)qcount/(
double)EventCount;
879 n_ecut = nEvents_E_gt_ecut;
885 if (h1_lb->GetBinContent(
ilb) > 0.)
nLB++;
887 fr_LB = (
double)
nLB/(
double)(nlb_corr-nBadLBs);
889 meanECell = h1_e->GetMean();
890 n_ensig = EventCount;
892 fr_q4k = (
double)qcount/(
double)EventCount;
894 n_ecut = nEvents_E_gt_ecut;
896 Eeta->Fill(
eta,meanECell);
897 CellEnergy->Fill(meanECell);
900 Emean_NbrEvents->Fill(n_ecut,EventEnergySum/n_ecut);
901 Emean_NbrEvents_part[
index]->Fill(n_ecut,EventEnergySum/n_ecut);
905 Pulsemaps[
index]->Add(Pulsemaps[
index],h2_pulse);
907 t_LBmaps[
index]->Add(t_LBmaps[
index],h2_t_LB);
908 CellsFlagged_LB_part[
index]->Fill(LBFlaggedIn);
909 CellsFlagged_LB->Fill(LBFlaggedIn);
918 if (nEvents_E_gt_ecut>0) { EventEnergyMean = EventEnergySum/nEvents_E_gt_ecut; }
919 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);
926 if(h1_e)
delete h1_e;
927 if(h1_q)
delete h1_q;
928 if(h1_lb)
delete h1_lb;
929 if(h2_elb)
delete h2_elb;
930 if(h2_pulse)
delete h2_pulse;
931 if(TProf_pulse)
delete TProf_pulse;
932 if(h1_ADCmax)
delete h1_ADCmax;
933 if(h2_t_LB)
delete h2_t_LB;
936 nEvents_E_gt_ecut = 0.;
938 EventEnergyMean = 0.;
940 printf(
"Cells selected: MeanCellHitsCut \t EnergyThreshodCut \t Either List \t Both Lists\n");
941 printf(
"\t \t %d \t \t \t \t %d \t \t %d \t %d\n",iMeanCellHitsSelection,iEnergyThresholdSelection,iOR_selection,iAND_selection);
948 printf(
"Skipped %d cells. Cells scanned = %d\n",nskipped,nbad);
949 printf(
"Cells put in Bad Cell List = %d\n",nBadCells);
950 if (noEvdata>0) printf(
"No Evdata pointer: %d\n",noEvdata);
955 for(
int i=0;
i<npl;
i++){
960 if(CellsFlagged_LB_part[
i]->
GetEntries()>0) CellsFlagged_LB_part[
i]->Write();
961 if( Emean_NbrEvents_part[
i]->
GetEntries()>0) Emean_NbrEvents_part[
i]->Write();
963 CellsFlagged_LB->Write();
967 Emean_NbrEvents->Write();