25 #include "TApplication.h"
28 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
29 #include "Cintex/Cintex.h"
43 unsigned nAboveSigNoise=0;
44 unsigned nAboveAbsE=0;
56 bool EventEnergyCut=
false;
57 bool MeanCellHitCut=
false;
58 std::set<unsigned>
LBs;
66 void setFlaggingThresholds(
const float hitsPerLB,
const unsigned upperCountThr,
const double lowerEThr,
const unsigned lowerCountThr,
const double upperEThr);
67 void setListingThresholds(
const unsigned minNSeen,
const unsigned minAboveSigNoise);
70 void readDefectLBList(
const char* LBfile);
73 return (m_badLBs.find(
lumiBlock)!=m_badLBs.end());
76 std::vector<LCE_CellList::thrCounter_t> buildList(
const char*
inputfile,
const float nSigma,
const float Ethr,
const float QThr,
unsigned& nLBsSeen)
const;
78 void writeList(
const char*
filename,
const std::vector<LCE_CellList::thrCounter_t>& celllist)
const;
80 void addFlags(std::vector<LCE_CellList::thrCounter_t>& celllist,
const unsigned nLBsSeen)
const;
84 std::string
partitionName(
const short caloId,
const short slot)
const;
86 void printThresholds()
const;
92 float m_hitCountPerLBThreshold=0.01;
93 unsigned m_UpperCountThreshold=50;
94 unsigned m_LowerCountThreshold=20;
95 double m_LowerCellEnergyThreshold=1000.0;
96 double m_UpperCellEnergyThreshold=50000.0;
99 unsigned m_minNSeen=10;
100 unsigned m_minAboveSigNoise=1;
106 m_hitCountPerLBThreshold=hitsPerLB;
107 m_UpperCountThreshold = upperCountThr;
108 m_LowerCountThreshold = lowerCountThr;
109 m_LowerCellEnergyThreshold = lowerEThr;
110 m_UpperCellEnergyThreshold = upperEThr;
116 m_minAboveSigNoise=minAboveSigNoise;
121 printf (
"Listing Thresholds:\n");
122 printf (
"\tMin number of appearences in LCE ntuple: %u\n",m_minNSeen);
123 printf (
"\tMin mumber of events with E> n Sigma Noise: %u\n", m_minAboveSigNoise);
124 printf (
"Flagging Thresholds:\n");
125 printf (
"\tMin number of events > sigNoise: %.3f * nLumiBlocks\n",m_hitCountPerLBThreshold);
126 printf (
"\tUpper count threshold for event energy cut %u\n", m_UpperCountThreshold);
127 printf (
"\tLower count threshold for event energy cut %u\n", m_LowerCountThreshold);
128 printf (
"\tUpper mean energy threshold for event energy cut %.2f MeV\n", m_UpperCellEnergyThreshold);
129 printf (
"\tLower mean energy threshold for event energy cut %.2f MeV\n",m_LowerCellEnergyThreshold);
136 if (!m_badLBs.empty())
137 printf(
"Appending to already-existing list of bad lumi-blocks of size %zu\n",m_badLBs.size());
140 std::ifstream
infile(LBfile);
146 printf(
"No bad LBs found in file %s\n" ,(
const char*)LBfile);
157 printf(
"Number of bad lumi-blocks: %d\n",(
int)m_badLBs.size());
165 std::vector<thrCounter_t> retvec;
167 std::set<unsigned> nLBsSeenSet;
170 const unsigned nchannels = tuple->
nChannels();
172 retvec.reserve(nchannels);
187 for (
int iEvent=0;iEvent<
nEvents;++iEvent) {
190 if(!Evdata)
continue;
197 const double quality =
data->quality();
202 if (quality > Qthr)
cnt.nAboveQ++;
203 if (!
cnt.bc_status)
cnt.bc_status=
data->status();
209 if (
cnt.nSeen>0) retvec.emplace_back(
cnt);
212 nLBsSeen=nLBsSeenSet.size();
213 std::cout <<
"Evaluated a total of " << nLBsSeen <<
"LBs" << std::endl;
222 counter.MeanCellHitCut=(
counter.nAboveAbsE> m_hitCountPerLBThreshold*nLBsSeen);
223 counter.EventEnergyCut= ((
counter.nAboveSigNoise > m_UpperCountThreshold && (
counter.Esum/
counter.nAboveSigNoise) > m_LowerCellEnergyThreshold) ||
224 (
counter.nAboveSigNoise > m_LowerCountThreshold && (
counter.Esum/
counter.nAboveSigNoise > m_UpperCellEnergyThreshold)));
233 return counter.nSeen > m_minNSeen &&
counter.nAboveSigNoise > m_minAboveSigNoise;
238 FILE* pFile = fopen (textfilename ,
"w");
240 fprintf(pFile,
"onlid // partition // FT // Slot // channel // nAboveSigNoise // nAboveAbsE // MeanE [GeV] // fracQ4k // nLBs // Algoflag\n");
242 for (
const auto&
cnt : cellList) {
245 if (
cnt.EventEnergyCut) {
247 if (
cnt.MeanCellHitCut)
flag=2;
252 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",
255 cnt.Esum/(1000.0*
cnt.nSeen), (
float)
cnt.nAboveQ/
cnt.nSeen,
256 (
unsigned)
cnt.LBs.size(),
flag );
279 if (
layer==0) slayer=
"P";
284 if (
layer==0) slayer=
"P";
291 if (
layer==0) slayer=
"P";
298 if (
layer==0) slayer=
"P";
337 if (
argc<3 || (
argc>1 && (!strcmp(
argv[1],
"-h") || !strcmp(
argv[1],
"--help")))) {
338 std::cout <<
"Syntax:" << std::endl;
339 std::cout <<
"RunLCE.exe inFile outFile <defectLBfile>" << std::endl;
346 char* defectsLBFileName=
nullptr;
348 defectsLBFileName=
argv[3];
350 TROOT
root (
"root",
"root");
351 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
352 ROOT::Cintex::Cintex::Enable();
355 gSystem->Load(
"libLArCafJobsDict.so");
356 gSystem->Load(
"libLArSamplesMonDict.so");
359 if (gSystem->AccessPathName(
inputFile)) {
360 printf(
"Cannot access file %s.\n",
inputFile);
367 if (defectsLBFileName) {
371 const float Ethr=1000.0;
373 const float Qthr=4000;
376 printf(
"Thresholds:\n");
377 printf(
"\tAbsolute Energy: %.2f MeV\n",Ethr);
378 printf(
"\tSigma Noise: %.2f\n",
nSigma);
379 printf(
"\tQuality Factor: %.2f\n\n",Qthr);
384 printf(
"Total number of cells read from LCE ntuple: %zu\n",celllist.size());
385 lceList.
addFlags(celllist, nLBsSeen);