22 #include "TApplication.h"
30 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
31 #include "Cintex/Cintex.h"
45 unsigned nAboveSigNoise=0;
46 unsigned nAboveAbsE=0;
58 bool EventEnergyCut=
false;
59 bool MeanCellHitCut=
false;
60 std::set<unsigned>
LBs;
68 void setFlaggingThresholds(
const float hitsPerLB,
const unsigned upperCountThr,
const double lowerEThr,
const unsigned lowerCountThr,
const double upperEThr);
69 void setListingThresholds(
const unsigned minNSeen,
const unsigned minAboveSigNoise);
72 void readDefectLBList(
const char* LBfile);
75 return (m_badLBs.find(
lumiBlock)!=m_badLBs.end());
78 std::vector<LCE_CellList::thrCounter_t> buildList(
const char*
inputfile,
const float nSigma,
const float Ethr,
const float QThr,
unsigned& nLBsSeen)
const;
80 void writeList(
const char*
filename,
const std::vector<LCE_CellList::thrCounter_t>& celllist)
const;
82 void addFlags(std::vector<LCE_CellList::thrCounter_t>& celllist,
const unsigned nLBsSeen)
const;
86 std::string
partitionName(
const short caloId,
const short slot)
const;
88 void printThresholds()
const;
94 float m_hitCountPerLBThreshold=0.01;
95 unsigned m_UpperCountThreshold=50;
96 unsigned m_LowerCountThreshold=20;
97 double m_LowerCellEnergyThreshold=1000.0;
98 double m_UpperCellEnergyThreshold=50000.0;
101 unsigned m_minNSeen=10;
102 unsigned m_minAboveSigNoise=1;
108 m_hitCountPerLBThreshold=hitsPerLB;
109 m_UpperCountThreshold = upperCountThr;
110 m_LowerCountThreshold = lowerCountThr;
111 m_LowerCellEnergyThreshold = lowerEThr;
112 m_UpperCellEnergyThreshold = upperEThr;
118 m_minAboveSigNoise=minAboveSigNoise;
123 printf (
"Listing Thresholds:\n");
124 printf (
"\tMin number of appearences in LCE ntuple: %u\n",m_minNSeen);
125 printf (
"\tMin mumber of events with E> n Sigma Noise: %u\n", m_minAboveSigNoise);
126 printf (
"Flagging Thresholds:\n");
127 printf (
"\tMin number of events > sigNoise: %.3f * nLumiBlocks\n",m_hitCountPerLBThreshold);
128 printf (
"\tUpper count threshold for event energy cut %u\n", m_UpperCountThreshold);
129 printf (
"\tLower count threshold for event energy cut %u\n", m_LowerCountThreshold);
130 printf (
"\tUpper mean energy threshold for event energy cut %.2f MeV\n", m_UpperCellEnergyThreshold);
131 printf (
"\tLower mean energy threshold for event energy cut %.2f MeV\n",m_LowerCellEnergyThreshold);
138 if (!m_badLBs.empty())
139 printf(
"Appending to already-existing list of bad lumi-blocks of size %zu\n",m_badLBs.size());
142 std::ifstream
infile(LBfile);
148 printf(
"No bad LBs found in file %s\n" ,(
const char*)LBfile);
159 printf(
"Number of bad lumi-blocks: %d\n",(
int)m_badLBs.size());
167 std::vector<thrCounter_t> retvec;
169 std::set<unsigned> nLBsSeenSet;
172 const unsigned nchannels = tuple->
nChannels();
174 retvec.reserve(nchannels);
189 for (
int iEvent=0;iEvent<
nEvents;++iEvent) {
192 if(!Evdata)
continue;
199 const double quality =
data->quality();
204 if (quality > Qthr)
cnt.nAboveQ++;
205 if (!
cnt.bc_status)
cnt.bc_status=
data->status();
211 if (
cnt.nSeen>0) retvec.emplace_back(
cnt);
214 nLBsSeen=nLBsSeenSet.size();
215 std::cout <<
"Evaluated a total of " << nLBsSeen <<
"LBs" << std::endl;
224 counter.MeanCellHitCut=(
counter.nAboveAbsE> m_hitCountPerLBThreshold*nLBsSeen);
225 counter.EventEnergyCut= ((
counter.nAboveSigNoise > m_UpperCountThreshold && (
counter.Esum/
counter.nAboveSigNoise) > m_LowerCellEnergyThreshold) ||
226 (
counter.nAboveSigNoise > m_LowerCountThreshold && (
counter.Esum/
counter.nAboveSigNoise > m_UpperCellEnergyThreshold)));
235 return counter.nSeen > m_minNSeen &&
counter.nAboveSigNoise > m_minAboveSigNoise;
240 FILE* pFile = fopen (textfilename ,
"w");
242 fprintf(pFile,
"onlid // partition // FT // Slot // channel // nAboveSigNoise // nAboveAbsE // MeanE [GeV] // fracQ4k // nLBs // Algoflag\n");
244 for (
const auto&
cnt : cellList) {
247 if (
cnt.EventEnergyCut) {
249 if (
cnt.MeanCellHitCut)
flag=2;
254 fprintf(pFile,
"0x%8.8x \t %7s \t %i \t %i \t %i \t %i \t %i \t %.3f \t %.3f \t %u \t %u",
257 cnt.Esum/(1000.0*
cnt.nSeen), (
float)
cnt.nAboveQ/
cnt.nSeen,
258 (
unsigned)
cnt.LBs.size(),
flag );
281 if (
layer==0) slayer=
"P";
286 if (
layer==0) slayer=
"P";
293 if (
layer==0) slayer=
"P";
300 if (
layer==0) slayer=
"P";
339 if (
argc<3 || (
argc>1 && (!strcmp(
argv[1],
"-h") || !strcmp(
argv[1],
"--help")))) {
340 std::cout <<
"Syntax:" << std::endl;
341 std::cout <<
"RunLCE.exe inFile outFile <defectLBfile>" << std::endl;
348 char* defectsLBFileName=
nullptr;
350 defectsLBFileName=
argv[3];
352 TROOT
root (
"root",
"root");
353 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
354 ROOT::Cintex::Cintex::Enable();
357 gSystem->Load(
"libLArCafJobsDict.so");
358 gSystem->Load(
"libLArSamplesMonDict.so");
361 if (gSystem->AccessPathName(
inputFile)) {
362 printf(
"Cannot access file %s.\n",
inputFile);
369 if (defectsLBFileName) {
373 const float Ethr=1000.0;
375 const float Qthr=4000;
378 printf(
"Thresholds:\n");
379 printf(
"\tAbsolute Energy: %.2f MeV\n",Ethr);
380 printf(
"\tSigma Noise: %.2f\n",
nSigma);
381 printf(
"\tQuality Factor: %.2f\n\n",Qthr);
386 printf(
"Total number of cells read from LCE ntuple: %zu\n",celllist.size());
387 lceList.
addFlags(celllist, nLBsSeen);