22#include "TApplication.h"
30#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
31#include "Cintex/Cintex.h"
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);
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;
123 printf (
"Listing Thresholds:\n");
124 printf (
"\tMin number of appearences in LCE ntuple: %u\n",
m_minNSeen);
126 printf (
"Flagging Thresholds:\n");
139 printf(
"Appending to already-existing list of bad lumi-blocks of size %zu\n",
m_badLBs.size());
142 std::ifstream infile(LBfile);
146 std::getline(infile,line,
'\n');
148 printf(
"No bad LBs found in file %s\n" ,(
const char*)LBfile);
152 for (
size_t pos=0;pos!=std::string::npos;pos=line.find(
',',pos)) {
155 unsigned LB=std::atoi(line.c_str()+pos);
159 printf(
"Number of bad lumi-blocks: %d\n",(
int)
m_badLBs.size());
165std::vector< LCE_CellList::thrCounter_t>
LCE_CellList::buildList(
const char* inputfile,
const float nSigma,
const float Ethr,
const float Qthr,
unsigned& nLBsSeen)
const {
167 std::vector<thrCounter_t> retvec;
169 std::set<unsigned> nLBsSeenSet;
172 const unsigned nchannels = tuple->
nChannels();
174 retvec.reserve(nchannels);
176 for (
unsigned ichan=0;ichan<nchannels;++ichan) {
180 const int nEvents=hist->nData();
184 cnt.slot=cellInfo->
slot();
185 cnt.channel=cellInfo->
channel();
186 cnt.caloid=cellInfo->
calo();
187 cnt.layer=cellInfo->
layer();
189 for (
int iEvent=0;iEvent<
nEvents;++iEvent) {
192 if(!Evdata)
continue;
193 unsigned lumiBlock = Evdata->
lumiBlock();
197 const double energy=
data->energy();
198 const double noise =
data->noise();
199 const double quality =
data->quality();
202 if (energy > nSigma * noise) cnt.nAboveSigNoise++;
203 if (energy > Ethr) cnt.nAboveAbsE++;
204 if (quality > Qthr) cnt.nAboveQ++;
205 if (!cnt.bc_status) cnt.bc_status=
data->status();
207 cnt.LBs.insert(lumiBlock);
208 nLBsSeenSet.insert(lumiBlock);
211 if (cnt.nSeen>0) retvec.emplace_back(cnt);
214 nLBsSeen=nLBsSeenSet.size();
215 std::cout <<
"Evaluated a total of " << nLBsSeen <<
"LBs" << std::endl;
240 FILE* pFile = fopen (textfilename ,
"w");
242 std::cerr <<
"Cannot open output file " << textfilename <<
"\n";
246 fprintf(pFile,
"onlid // partition // FT // Slot // channel // nAboveSigNoise // nAboveAbsE // MeanE [GeV] // fracQ4k // nLBs // Algoflag\n");
248 for (
const auto& cnt : cellList) {
251 if (cnt.EventEnergyCut) {
253 if (cnt.MeanCellHitCut) flag=2;
258 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",
260 cnt.FT, cnt.slot, cnt.channel, cnt.nAboveSigNoise, cnt.nAboveAbsE,
261 cnt.Esum/(1000.0*cnt.nSeen), (
float)cnt.nAboveQ/cnt.nSeen,
262 (
unsigned)cnt.LBs.size(), flag );
276 std::string slayer=std::to_string(layer);
283 if (layer==0) slayer=
"P";
288 if (layer==0) slayer=
"P";
295 if (layer==0) slayer=
"P";
302 if (layer==0) slayer=
"P";
330 return name+slayer+side;
341 if (argc<3 || (argc>1 && (!strcmp(argv[1],
"-h") || !strcmp(argv[1],
"--help")))) {
342 std::cout <<
"Syntax:" << std::endl;
343 std::cout <<
"RunLCE.exe inFile outFile <defectLBfile>" << std::endl;
347 const char* inputFile=argv[1];
348 const char* outputFile=argv[2];
350 char* defectsLBFileName=
nullptr;
352 defectsLBFileName=argv[3];
354 TROOT root (
"root",
"root");
355#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
356 ROOT::Cintex::Cintex::Enable();
359 gSystem->Load(
"libLArCafJobsDict.so");
360 gSystem->Load(
"libLArSamplesMonDict.so");
363 if (gSystem->AccessPathName(inputFile)) {
364 printf(
"Cannot access file %s.\n",inputFile);
371 if (defectsLBFileName) {
375 const float Ethr=1000.0;
376 const float nSigma=10.0;
377 const float Qthr=4000;
380 printf(
"Thresholds:\n");
381 printf(
"\tAbsolute Energy: %.2f MeV\n",Ethr);
382 printf(
"\tSigma Noise: %.2f\n",nSigma);
383 printf(
"\tQuality Factor: %.2f\n\n",Qthr);
387 std::vector<LCE_CellList::thrCounter_t> celllist=lceList.
buildList(inputFile, nSigma, Ethr, Qthr, nLBsSeen);
388 printf(
"Total number of cells read from LCE ntuple: %zu\n",celllist.size());
389 lceList.
addFlags(celllist, nLBsSeen);
int main(int, char **)
Main class for all the CppUnit test classes.
char data[hepevt_bytes_allocation_ATLAS]
int main ATLAS_NOT_THREAD_SAFE(int argc, char **argv)
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
virtual unsigned int nChannels() const
short feedThrough() const
unsigned int lumiBlock() const
static Interface * open(const TString &fileName)
const History * cellHistory(unsigned int i) const
double m_UpperCellEnergyThreshold
std::vector< LCE_CellList::thrCounter_t > buildList(const char *inputfile, const float nSigma, const float Ethr, const float QThr, unsigned &nLBsSeen) const
std::string partitionName(const short caloId, const short slot) const
unsigned m_minAboveSigNoise
void addFlags(std::vector< LCE_CellList::thrCounter_t > &celllist, const unsigned nLBsSeen) const
void setListingThresholds(const unsigned minNSeen, const unsigned minAboveSigNoise)
void writeList(const char *filename, const std::vector< LCE_CellList::thrCounter_t > &celllist) const
double m_LowerCellEnergyThreshold
std::set< unsigned > m_badLBs
void setFlaggingThresholds(const float hitsPerLB, const unsigned upperCountThr, const double lowerEThr, const unsigned lowerCountThr, const double upperEThr)
bool checkBadLBList(const unsigned lumiBlock) const
void printThresholds() const
unsigned m_LowerCountThreshold
unsigned m_UpperCountThreshold
void readDefectLBList(const char *LBfile)
bool applySelection(const LCE_CellList::thrCounter_t &counter) const
float m_hitCountPerLBThreshold
thrCounter_t(const unsigned id)