ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArSamplesMon
src
LCE_CellList.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
//Dear emacs, this is -*-c++-*-
6
7
8
9
#include "
LArSamplesMon/Data.h
"
10
#include "
LArSamplesMon/Interface.h
"
11
#include "
LArSamplesMon/HistoryIterator.h
"
12
#include "
LArSamplesMon/History.h
"
13
#include "
LArSamplesMon/LArCellsEmptyMonitoring.h
"
14
#include "
LArCafJobs/CellInfo.h
"
15
#include "
LArCafJobs/ShapeInfo.h
"
16
#include "
LArCafJobs/EventData.h
"
17
#include "
LArCafJobs/CaloId.h
"
18
19
#include "
CxxUtils/checker_macros.h
"
20
21
#include "TROOT.h"
22
#include "TApplication.h"
23
#include "TSystem.h"
24
#include <fstream>
25
#include <vector>
26
#include <string>
27
#include <set>
28
#include <iostream>
29
30
#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
31
#include "Cintex/Cintex.h"
32
#endif
33
34
using namespace
LArSamples
;
35
using namespace
std
;
36
37
class
ATLAS_NOT_THREAD_SAFE
LCE_CellList
{
38
39
public
:
40
41
struct
thrCounter_t
{
42
public
:
43
unsigned
onlId
;
44
unsigned
nSeen
=0;
45
unsigned
nAboveSigNoise
=0;
46
unsigned
nAboveAbsE
=0;
47
unsigned
nAboveQ
=0;
48
unsigned
bc_status
=0;
49
double
Esum
=0.0;
50
51
short
caloid
=0;
52
short
FT
=0;
53
short
slot
=0;
54
short
channel
=0;
55
short
layer
=0;
56
57
//Flags:
58
bool
EventEnergyCut
=
false
;
59
bool
MeanCellHitCut
=
false
;
60
std::set<unsigned>
LBs
;
61
62
thrCounter_t
(
const
unsigned
id
) :
63
onlId
(id) {};
64
65
};
66
67
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);
70
71
72
void
readDefectLBList(
const
char
* LBfile);
73
74
inline
bool
checkBadLBList
(
const
unsigned
lumiBlock)
const
{
75
return
(
m_badLBs
.find(lumiBlock)!=
m_badLBs
.end());
76
}
77
78
std::vector<LCE_CellList::thrCounter_t> buildList(
const
char
* inputfile,
const
float
nSigma,
const
float
Ethr,
const
float
QThr,
unsigned
& nLBsSeen)
const
;
79
80
void
writeList(
const
char
* filename,
const
std::vector<LCE_CellList::thrCounter_t>& celllist)
const
;
81
82
void
addFlags(std::vector<LCE_CellList::thrCounter_t>& celllist,
const
unsigned
nLBsSeen)
const
;
83
84
bool
applySelection(
const
LCE_CellList::thrCounter_t
& counter)
const
;
85
86
std::string partitionName(
const
short
caloId,
const
short
slot)
const
;
87
88
void
printThresholds()
const
;
89
90
private
:
91
std::set<unsigned>
m_badLBs
;
92
93
//Flagging thresholds
94
float
m_hitCountPerLBThreshold
=0.01;
95
unsigned
m_UpperCountThreshold
=50;
96
unsigned
m_LowerCountThreshold
=20;
97
double
m_LowerCellEnergyThreshold
=1000.0;
//1 GeV
98
double
m_UpperCellEnergyThreshold
=50000.0;
//50GeV
99
100
//Listing thresholds
101
unsigned
m_minNSeen
=10;
102
unsigned
m_minAboveSigNoise
=1;
103
104
};
105
106
107
void
LCE_CellList::setFlaggingThresholds
(
const
float
hitsPerLB,
const
unsigned
upperCountThr,
const
double
lowerEThr,
const
unsigned
lowerCountThr,
const
double
upperEThr){
108
m_hitCountPerLBThreshold
=hitsPerLB;
109
m_UpperCountThreshold
= upperCountThr;
110
m_LowerCountThreshold
= lowerCountThr;
111
m_LowerCellEnergyThreshold
= lowerEThr;
112
m_UpperCellEnergyThreshold
= upperEThr;
113
}
114
115
116
void
LCE_CellList::setListingThresholds
(
const
unsigned
minNSeen,
const
unsigned
minAboveSigNoise) {
117
m_minNSeen
=minNSeen;
118
m_minAboveSigNoise
=minAboveSigNoise;
119
}
120
121
122
void
LCE_CellList:: printThresholds
()
const
{
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
);
132
}
133
134
135
136
void
LCE_CellList::readDefectLBList
(
const
char
* LBfile) {
137
138
if
(!
m_badLBs
.empty())
139
printf(
"Appending to already-existing list of bad lumi-blocks of size %zu\n"
,
m_badLBs
.size());
140
141
142
std::ifstream infile(LBfile);
143
std::string line;
144
145
// assume single-line format with coma-separated LBs (from python)
146
std::getline(infile,line,
'\n'
);
147
if
(line.empty()) {
148
printf(
"No bad LBs found in file %s\n"
,(
const
char
*)LBfile);
149
return
;
150
}
151
152
for
(
size_t
pos=0;pos!=std::string::npos;pos=line.find(
','
,pos)) {
153
if
(pos) pos++;
//Jump over comma if not the first iteration
154
//std::cout << "Parsing " << line.c_str()+pos << std::endl;
155
unsigned
LB=std::atoi(line.c_str()+pos);
156
m_badLBs
.insert(LB);
157
}
158
159
printf(
"Number of bad lumi-blocks: %d\n"
,(
int
)
m_badLBs
.size());
160
161
return
;
162
}
163
164
165
std::vector< LCE_CellList::thrCounter_t>
LCE_CellList::buildList
(
const
char
* inputfile,
const
float
nSigma,
const
float
Ethr,
const
float
Qthr,
unsigned
& nLBsSeen)
const
{
166
167
std::vector<thrCounter_t> retvec;
168
169
std::set<unsigned> nLBsSeenSet;
170
171
std::unique_ptr<LArSamples::Interface> tuple =
Interface::open
(inputfile);
172
const
unsigned
nchannels = tuple->nChannels();
173
174
retvec.reserve(nchannels);
175
176
for
(
unsigned
ichan=0;ichan<nchannels;++ichan) {
177
const
LArSamples::History
* hist = tuple->cellHistory(ichan);
178
if
(!hist)
continue
;
179
const
LArSamples::CellInfo
* cellInfo = hist->cellInfo();
180
const
int
nEvents
=hist->nData();
181
182
thrCounter_t
cnt(cellInfo->
onlid
());
183
cnt.FT=cellInfo->
feedThrough
();
184
cnt.slot=cellInfo->
slot
();
185
cnt.channel=cellInfo->
channel
();
186
cnt.caloid=cellInfo->
calo
();
187
cnt.layer=cellInfo->
layer
();
188
189
for
(
int
iEvent=0;iEvent<
nEvents
;++iEvent) {
190
const
LArSamples::Data
* data = hist->data(iEvent);
191
const
LArSamples::EventData
& Evdata = data->eventData();
192
unsigned
lumiBlock = Evdata.
lumiBlock
();
193
if
(
checkBadLBList
(lumiBlock))
continue
;
//skip bad LBs
194
195
196
const
double
energy= data->energy();
197
const
double
noise = data->noise();
198
const
double
quality = data->quality();
199
200
cnt.nSeen++;
201
if
(energy > nSigma * noise) cnt.nAboveSigNoise++;
202
if
(energy > Ethr) cnt.nAboveAbsE++;
203
if
(quality > Qthr) cnt.nAboveQ++;
204
if
(!cnt.bc_status) cnt.bc_status=data->status();
205
cnt.Esum+=energy;
206
cnt.LBs.insert(lumiBlock);
207
nLBsSeenSet.insert(lumiBlock);
208
}
//End loop over events
209
210
if
(cnt.nSeen>0) retvec.emplace_back(cnt);
211
}
//end loop over channels
212
213
nLBsSeen=nLBsSeenSet.size();
214
std::cout <<
"Evaluated a total of "
<< nLBsSeen <<
"LBs"
<< std::endl;
215
216
return
retvec;
217
218
}
219
220
void
LCE_CellList::addFlags
(std::vector<LCE_CellList::thrCounter_t>& celllist,
const
unsigned
nLBsSeen)
const
{
221
for
(
thrCounter_t
& counter : celllist) {
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
)));
225
226
}
227
228
}
229
230
231
232
bool
LCE_CellList::applySelection
(
const
LCE_CellList::thrCounter_t
& counter)
const
{
233
return
counter.nSeen >
m_minNSeen
&& counter.nAboveSigNoise >
m_minAboveSigNoise
;
234
}
235
236
237
void
LCE_CellList::writeList
(
const
char
* textfilename,
const
std::vector<LCE_CellList::thrCounter_t>& cellList)
const
{
238
FILE* pFile = fopen (textfilename ,
"w"
);
239
if
(!pFile) {
240
std::cerr <<
"Cannot open output file "
<< textfilename <<
"\n"
;
241
exit(1);
242
}
243
// 0 1 2 3 4 5 6 7 8 9 10
244
fprintf(pFile,
"onlid // partition // FT // Slot // channel // nAboveSigNoise // nAboveAbsE // MeanE [GeV] // fracQ4k // nLBs // Algoflag\n"
);
245
246
for
(
const
auto
& cnt : cellList) {
247
if
(
applySelection
(cnt)) {
248
unsigned
flag=0;
249
if
(cnt.EventEnergyCut) {
250
flag=1;
251
if
(cnt.MeanCellHitCut) flag=2;
252
}
253
//Expected format (by WDE):
254
//online id Partition FT Slot Chan nEvt>10Sig nEvt>1GeV, MeanE, fracQ4k, nLBs,
255
// 0 1 2 3 4 5 6 7 8 9 10
256
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.onlId,
partitionName
(cnt.caloid,cnt.layer).c_str(),
258
cnt.FT, cnt.slot, cnt.channel, cnt.nAboveSigNoise, cnt.nAboveAbsE,
259
cnt.Esum/(1000.0*cnt.nSeen), (
float
)cnt.nAboveQ/cnt.nSeen,
260
(
unsigned
)cnt.LBs.size(), flag );
261
262
263
fprintf(pFile,
"\n"
);
264
}
265
}
266
fclose(pFile);
267
return
;
268
}
269
270
271
std::string
LCE_CellList::partitionName
(
const
short
caloId,
const
short
layer)
const
{
272
273
std::string name;
274
std::string slayer=std::to_string(layer);
275
std::string side;
276
277
switch
(caloId) {
278
case
EMB_C
:
279
name=
"EMB"
;
280
side=
"C"
;
281
if
(layer==0) slayer=
"P"
;
282
break
;
283
case
EMB_A
:
284
name=
"EMB"
;
285
side=
"A"
;
286
if
(layer==0) slayer=
"P"
;
287
break
;
288
289
case
EMEC_INNER_C
:
290
case
EMEC_OUTER_C
:
291
name=
"EMEC"
;
292
side=
"C"
;
293
if
(layer==0) slayer=
"P"
;
294
break
;
295
296
case
EMEC_INNER_A
:
297
case
EMEC_OUTER_A
:
298
name=
"EMEC"
;
299
side=
"A"
;
300
if
(layer==0) slayer=
"P"
;
301
break
;
302
303
case
HEC_A
:
304
name=
"HEC"
;
305
side=
"A"
;
306
break
;
307
308
case
HEC_C
:
309
name=
"HEC"
;
310
side=
"C"
;
311
break
;
312
313
case
FCAL_A
:
314
name=
"FCAL"
;
315
side=
"A"
;
316
break
;
317
318
case
FCAL_C
:
319
name=
"FCAL"
;
320
side=
"C"
;
321
break
;
322
323
default
:
324
name=
"UNKNOWN"
;
325
slayer=
""
;
326
}
327
328
return
name+slayer+side;
329
}
330
331
/* FCAL_C = -5, HEC_C = -4, EMEC_INNER_C = -3, EMEC_OUTER_C = -2, EMB_C = -1,
332
UNKNOWN_CALO = 0,
333
EMB_A = 1, EMEC_OUTER_A = 2, EMEC_INNER_A = 3, HEC_A = 4, FCAL_A = 5,*/
334
335
336
337
int
main
ATLAS_NOT_THREAD_SAFE
(
int
argc,
char
** argv) {
338
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;
342
return
-1;
343
}
344
345
const
char
* inputFile=argv[1];
346
const
char
* outputFile=argv[2];
347
348
char
* defectsLBFileName=
nullptr
;
349
if
(argc>3)
350
defectsLBFileName=argv[3];
351
352
TROOT root (
"root"
,
"root"
);
353
#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
354
ROOT::Cintex::Cintex::Enable();
355
#endif
356
357
gSystem->Load(
"libLArCafJobsDict.so"
);
358
gSystem->Load(
"libLArSamplesMonDict.so"
);
359
360
361
if
(gSystem->AccessPathName(inputFile)) {
362
printf(
"Cannot access file %s.\n"
,inputFile);
363
return
-1;
364
}
365
366
367
LCE_CellList
lceList;
368
369
if
(defectsLBFileName) {
370
lceList.
readDefectLBList
(defectsLBFileName);
371
}
372
373
const
float
Ethr=1000.0;
//1GeV
374
const
float
nSigma=10.0;
375
const
float
Qthr=4000;
376
unsigned
nLBsSeen=0;
377
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);
382
383
lceList.
printThresholds
();
384
385
std::vector<LCE_CellList::thrCounter_t> celllist=lceList.
buildList
(inputFile, nSigma, Ethr, Qthr, nLBsSeen);
386
printf(
"Total number of cells read from LCE ntuple: %zu\n"
,celllist.size());
387
lceList.
addFlags
(celllist, nLBsSeen);
388
lceList.
writeList
(outputFile,celllist);
389
390
return
0;
391
}
CaloId.h
CellInfo.h
main
int main(int, char **)
Main class for all the CppUnit test classes.
Definition
CppUnit_SGtestdriver.cxx:141
Data.h
EventData.h
HistoryIterator.h
History.h
Interface.h
LArCellsEmptyMonitoring.h
ATLAS_NOT_THREAD_SAFE
int main ATLAS_NOT_THREAD_SAFE(int argc, char **argv)
Definition
LCE_CellList.cxx:337
ShapeInfo.h
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition
checker_macros.h:212
LArSamples::CellInfo
Definition
CellInfo.h:31
LArSamples::CellInfo::slot
short slot() const
Definition
CellInfo.h:68
LArSamples::CellInfo::layer
short layer() const
Definition
CellInfo.h:53
LArSamples::CellInfo::feedThrough
short feedThrough() const
Definition
CellInfo.h:65
LArSamples::CellInfo::onlid
ULong64_t onlid() const
Definition
CellInfo.h:90
LArSamples::CellInfo::calo
CaloId calo() const
Definition
CellInfo.h:50
LArSamples::CellInfo::channel
short channel() const
Definition
CellInfo.h:76
LArSamples::Data
Definition
Data.h:73
LArSamples::EventData
Definition
EventData.h:29
LArSamples::EventData::lumiBlock
unsigned int lumiBlock() const
Definition
EventData.h:47
LArSamples::History
Definition
History.h:36
LArSamples::Interface::open
static std::unique_ptr< Interface > open(const TString &fileName)
Definition
Interface.cxx:35
LCE_CellList
Definition
LCE_CellList.cxx:37
LCE_CellList::m_UpperCellEnergyThreshold
double m_UpperCellEnergyThreshold
Definition
LCE_CellList.cxx:98
LCE_CellList::buildList
std::vector< LCE_CellList::thrCounter_t > buildList(const char *inputfile, const float nSigma, const float Ethr, const float QThr, unsigned &nLBsSeen) const
Definition
LCE_CellList.cxx:165
LCE_CellList::partitionName
std::string partitionName(const short caloId, const short slot) const
Definition
LCE_CellList.cxx:271
LCE_CellList::m_minAboveSigNoise
unsigned m_minAboveSigNoise
Definition
LCE_CellList.cxx:102
LCE_CellList::addFlags
void addFlags(std::vector< LCE_CellList::thrCounter_t > &celllist, const unsigned nLBsSeen) const
Definition
LCE_CellList.cxx:220
LCE_CellList::setListingThresholds
void setListingThresholds(const unsigned minNSeen, const unsigned minAboveSigNoise)
Definition
LCE_CellList.cxx:116
LCE_CellList::m_minNSeen
unsigned m_minNSeen
Definition
LCE_CellList.cxx:101
LCE_CellList::writeList
void writeList(const char *filename, const std::vector< LCE_CellList::thrCounter_t > &celllist) const
Definition
LCE_CellList.cxx:237
LCE_CellList::m_LowerCellEnergyThreshold
double m_LowerCellEnergyThreshold
Definition
LCE_CellList.cxx:97
LCE_CellList::m_badLBs
std::set< unsigned > m_badLBs
Definition
LCE_CellList.cxx:91
LCE_CellList::setFlaggingThresholds
void setFlaggingThresholds(const float hitsPerLB, const unsigned upperCountThr, const double lowerEThr, const unsigned lowerCountThr, const double upperEThr)
Definition
LCE_CellList.cxx:107
LCE_CellList::checkBadLBList
bool checkBadLBList(const unsigned lumiBlock) const
Definition
LCE_CellList.cxx:74
LCE_CellList::printThresholds
void printThresholds() const
Definition
LCE_CellList.cxx:122
LCE_CellList::m_LowerCountThreshold
unsigned m_LowerCountThreshold
Definition
LCE_CellList.cxx:96
LCE_CellList::m_UpperCountThreshold
unsigned m_UpperCountThreshold
Definition
LCE_CellList.cxx:95
LCE_CellList::readDefectLBList
void readDefectLBList(const char *LBfile)
Definition
LCE_CellList.cxx:136
LCE_CellList::applySelection
bool applySelection(const LCE_CellList::thrCounter_t &counter) const
Definition
LCE_CellList.cxx:232
LCE_CellList::m_hitCountPerLBThreshold
float m_hitCountPerLBThreshold
Definition
LCE_CellList.cxx:94
nEvents
const int nEvents
Definition
fbtTestBasics.cxx:78
LArSamples
Definition
AbsShape.h:24
LArSamples::EMB_C
@ EMB_C
Definition
CaloId.h:22
LArSamples::HEC_C
@ HEC_C
Definition
CaloId.h:22
LArSamples::FCAL_A
@ FCAL_A
Definition
CaloId.h:24
LArSamples::EMEC_INNER_C
@ EMEC_INNER_C
Definition
CaloId.h:22
LArSamples::HEC_A
@ HEC_A
Definition
CaloId.h:24
LArSamples::EMEC_INNER_A
@ EMEC_INNER_A
Definition
CaloId.h:24
LArSamples::EMB_A
@ EMB_A
Definition
CaloId.h:24
LArSamples::FCAL_C
@ FCAL_C
Definition
CaloId.h:22
LArSamples::EMEC_OUTER_C
@ EMEC_OUTER_C
Definition
CaloId.h:22
LArSamples::EMEC_OUTER_A
@ EMEC_OUTER_A
Definition
CaloId.h:24
std
STL namespace.
LCE_CellList::thrCounter_t
Definition
LCE_CellList.cxx:41
LCE_CellList::thrCounter_t::onlId
unsigned onlId
Definition
LCE_CellList.cxx:43
LCE_CellList::thrCounter_t::nAboveQ
unsigned nAboveQ
Definition
LCE_CellList.cxx:47
LCE_CellList::thrCounter_t::nSeen
unsigned nSeen
Definition
LCE_CellList.cxx:44
LCE_CellList::thrCounter_t::channel
short channel
Definition
LCE_CellList.cxx:54
LCE_CellList::thrCounter_t::thrCounter_t
thrCounter_t(const unsigned id)
Definition
LCE_CellList.cxx:62
LCE_CellList::thrCounter_t::nAboveAbsE
unsigned nAboveAbsE
Definition
LCE_CellList.cxx:46
LCE_CellList::thrCounter_t::layer
short layer
Definition
LCE_CellList.cxx:55
LCE_CellList::thrCounter_t::slot
short slot
Definition
LCE_CellList.cxx:53
LCE_CellList::thrCounter_t::Esum
double Esum
Definition
LCE_CellList.cxx:49
LCE_CellList::thrCounter_t::bc_status
unsigned bc_status
Definition
LCE_CellList.cxx:48
LCE_CellList::thrCounter_t::caloid
short caloid
Definition
LCE_CellList.cxx:51
LCE_CellList::thrCounter_t::MeanCellHitCut
bool MeanCellHitCut
Definition
LCE_CellList.cxx:59
LCE_CellList::thrCounter_t::EventEnergyCut
bool EventEnergyCut
Definition
LCE_CellList.cxx:58
LCE_CellList::thrCounter_t::nAboveSigNoise
unsigned nAboveSigNoise
Definition
LCE_CellList.cxx:45
LCE_CellList::thrCounter_t::FT
short FT
Definition
LCE_CellList.cxx:52
LCE_CellList::thrCounter_t::LBs
std::set< unsigned > LBs
Definition
LCE_CellList.cxx:60
Generated on
for ATLAS Offline Software by
1.17.0