ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArExample
LArConditionsCommon
python
LArCellConditionsAlg.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3
10
11
__author__=
"Walter Lampl <walter.lampl@cern.ch>"
12
__doc__ =
" An athena-like algorithm to interactivly convert LAr Identifiers and print the bad channel status"
13
14
#import AthenaCommon.SystemOfUnits as Units
15
from
AthenaPython.PyAthena
import
StatusCode
16
import
AthenaPython.PyAthena
as
PyAthena
17
18
import
ROOT
19
20
from
ROOT
import
HWIdentifier, Identifier, IdentifierHash, LArBadChannel, LArBadChanBitPacking
21
22
from
ctypes
import
c_uint
23
import
time
24
import
os
25
26
class
LArCellConditionsAlg
(
PyAthena.Alg
):
27
"""
28
This class is an Athena algorithm although it doesn't quite behave like one.
29
It's purpose is to interactivly convert LAr Online/Offline identifiers and
30
prints the bad channel status and optionally some calibration constants for
31
the given channel identifier.
32
"""
33
34
def
__init__
(self, name="LArCellConditionsAlg", **kw):
35
36
kw[
'name'
] = name
37
super(LArCellConditionsAlg,self).
__init__
(**kw)
38
39
self.
includeConditions
=kw.get(
'printConditions'
,
False
)
40
self.
includeLocation
=kw.get(
'printLocation'
,
False
)
41
self.
includeDSPTh
=kw.get(
'printDSPTh'
,
False
)
42
self.
nLinesPrinted
=0
43
self.
nEvts
=0
44
45
return
46
47
48
def
initialize
(self):
49
52
53
# Get DetectorStore...
54
55
self.
_detStore
= PyAthena.py_svc(
'StoreGateSvc/DetectorStore'
)
56
if
self.
_detStore
is
None
:
57
self.
msg
.
error
(
"Failed to get DetectorStore"
)
58
return
StatusCode.Failure
59
60
self.
_condStore
= PyAthena.py_svc(
'StoreGateSvc/ConditionStore'
)
61
if
(self.
_condStore
is
None
):
62
self.
msg
.
error
(
"Failed to get ConditionStore"
)
63
return
StatusCode.Failure
64
65
# Get LArOnlineID helper class
66
self.
onlineID
=self.
_detStore
.retrieve(
"LArOnlineID"
,
"LArOnlineID"
)
67
if
self.
onlineID
is
None
:
68
self.
msg
.
error
(
"Failed to get LArOnlineID"
)
69
return
StatusCode.Failure
70
71
# Get CaloCell_ID
72
self.
offlineID
=self.
_detStore
.retrieve(
"CaloCell_ID"
,
"CaloCell_ID"
)
73
if
self.
offlineID
is
None
:
74
self.
msg
.
error
(
"Failed to get CaloCell_ID"
)
75
return
StatusCode.Failure
76
77
self.
bc_packing
=
LArBadChanBitPacking
()
78
79
self.
noisepattern
=0
80
for
n
in
(
"lowNoiseHG"
,
"highNoiseHG"
,
"unstableNoiseHG"
,
"lowNoiseMG"
,
"highNoiseMG"
,
"unstableNoiseMG"
,
"lowNoiseLG"
,
"highNoiseLG"
,
"unstableNoiseLG"
,
"sporadicBurstNoise"
):
81
stat=self.
bc_packing
.enumName(n)
82
if
stat[0]:
83
self.
noisepattern
|= 1<<stat[1]
84
85
self.
deadpattern
=0
86
for
n
in
(
"deadReadout"
,
"deadPhys"
,
"almostDead"
):
87
stat=self.
bc_packing
.enumName(n)
88
if
stat[0]:
89
self.
deadpattern
|= 1<<stat[1]
90
91
self.
noid
=
Identifier
()
92
93
94
95
self.
larPedestal
=
None
96
self.
larMphysOverMcal
=
None
97
self.
larRamp
=
None
98
self.
larDAC2uA
=
None
99
self.
laruA2MeV
=
None
100
self.
larhvScaleCorr
=
None
101
self.
larDSPThr
=
None
102
103
return
StatusCode.Success
104
105
106
def
execute
(self):
107
#self.msg.info('running execute...')
108
109
#for debugging purposes:
110
#sgdump = open("sgdump.txt", 'w')
111
#self._condStore.dump(sgdump)
112
#sgdump.close()
113
114
eid=ROOT.Gaudi.Hive.currentContext().eventID()
115
116
try
:
117
condCont=self.
_condStore
.retrieve(
"CondCont<LArOnOffIdMapping>"
,
"LArOnOffIdMap"
)
118
self.
larCabling
=condCont.find(eid)
119
except
Exception:
120
print
(
"ERROR, failed to get LArCabling"
)
121
return
StatusCode.Failure
122
123
124
try
:
125
condCont=self.
_condStore
.retrieve(
"CondCont<LArBadChannelCont>"
,
"LArBadChannel"
)
126
self.
badChannels
=condCont.find(eid)
127
except
Exception:
128
print
(
"ERROR, failed to get LArBadChannels"
)
129
return
StatusCode.Failure
130
131
if
self.
includeConditions
:
132
try
:
133
condCont=self.
_condStore
.retrieve(
"CondCont<ILArPedestal>"
,
"LArPedestal"
)
134
self.
larPedestal
=condCont.find(eid)
135
except
Exception:
136
print
(
"WARNING: Failed to retrieve Pedestal from DetStore"
)
137
import
traceback
138
traceback.print_exc()
139
self.
larPedestal
=
None
140
141
try
:
142
condCont=self.
_condStore
.retrieve(
"CondCont<ILArMphysOverMcal>"
,
"LArMphysOverMcal"
)
143
self.
larMphysOverMcal
=condCont.find(eid)
144
except
Exception:
145
print
(
"WARNING: Failed to retrieve MphysOverMcal from DetStore"
)
146
import
traceback
147
traceback.print_exc()
148
self.
larMphysOverMcal
=
None
149
150
try
:
151
condCont=self.
_condStore
.retrieve(
"CondCont<ILArRamp>"
,
"LArRamp"
)
152
self.
larRamp
=condCont.find(eid)
153
except
Exception:
154
print
(
"WARNING: Failed to retrieve LArRamp from DetStore"
)
155
import
traceback
156
traceback.print_exc()
157
self.
larRamp
=
None
158
159
try
:
160
condCont=self.
_condStore
.retrieve(
"CondCont<ILArDAC2uA>"
,
"LArDAC2uA"
)
161
self.
larDAC2uA
=condCont.find(eid)
162
except
Exception:
163
print
(
"WARNING: Failed to retrieve LArDAC2uA from DetStore"
)
164
import
traceback
165
traceback.print_exc()
166
self.
larDAC2uA
=
None
167
168
try
:
169
condCont=self.
_condStore
.retrieve(
"CondCont<ILAruA2MeV>"
,
"LAruA2MeV"
)
170
self.
laruA2MeV
=condCont.find(eid)
171
except
Exception:
172
print
(
"WARNING: Failed to retrieve LAruA2MeV from DetStore"
)
173
import
traceback
174
traceback.print_exc()
175
self.
laruA2MeV
=
None
176
177
try
:
178
condCont=self.
_condStore
.retrieve(
"CondCont<ILArHVScaleCorr>"
,
"LArHVScaleCorr"
)
179
self.
larhvScaleCorr
=condCont.find(eid)
180
except
Exception:
181
print
(
"WARNING: Failed to retrieve LArHVScaleCorr from DetStore"
)
182
import
traceback
183
traceback.print_exc()
184
self.
larhvScaleCorr
=
None
185
186
if
self.
includeDSPTh
:
187
try
:
188
self.
larDSPThr
=self.
_detStore
.retrieve(
"LArDSPThresholdsComplete"
,
"LArDSPThresholds"
)
189
except
Exception:
190
print
(
"WARNING: Failed to retrieve LArDPSThresholds from DetStore"
)
191
import
traceback
192
traceback.print_exc()
193
self.
larDSPThr
=
None
194
195
196
if
self.
includeLocation
:
197
try
:
198
condCont=self.
_condStore
.retrieve(
"CondCont<CaloDetDescrManager>"
,
"CaloDetDescrManager"
)
199
self.
caloDDM
= condCont.find(eid)
200
except
Exception:
201
print
(
"Failed to retrieve CaloDDM"
)
202
return
StatusCode.Failure
203
204
if
self.
nEvts
==0:
205
self.
nEvts
+=1
206
#Process one 'dummy' event to make sure all DB connections get closed
207
#print ("Dummy event...")
208
return
StatusCode.Success
209
210
self.
onlineID
.set_do_checks(
True
)
211
self.
offlineID
.set_do_checks(
True
)
212
213
while
(1):
214
id=
None
215
chid=
None
216
rep_in=self.
readInput
()
#"Enter Id >").upper().strip()
217
#rep_in="EMBA 0 0 60 2"
218
rep=rep_in.upper()
219
220
#Quit
221
if
len(rep)==0
or
rep==
"QUIT"
or
rep==
"EXIT"
or
rep==
".Q"
:
break
222
223
224
if
rep.startswith(
"SEARCH"
):
225
inp=rep_in[6:].
strip
()
226
starttime=time.time()
227
self.
search
(inp)
228
print
(
"seach time %.1f sec"
% (time.time()-starttime))
229
continue
230
231
#Help
232
if
rep==
"HELP"
:
233
self.
printHelp
()
234
continue
235
236
237
238
try
:
239
t_int=int(rep,10)
240
t=
Identifier
(c_uint(t_int))
241
if
self.
onlineID
.is_lar(t):
242
print
(t.get_identifier32().get_compact(),
" IsLAr (online)"
)
243
if
self.
offlineID
.is_lar(t):
244
print
(t.get_identifier32().getCompact(),
" isLAr (offline)"
)
245
except
Exception:
246
pass
247
248
249
250
251
252
if
rep.startswith(
"ON"
):
253
s=rep.find(
" "
)
254
if
s==-1:s=0
255
chid=self.
getOnlineIDFromString
(rep[s:])
256
if
chid
is
not
None
and
self.
onlineID
.is_lar(chid):
257
id=self.
larCabling
.cnvToIdentifier(chid)
258
if
id
is
None
: id=self.
noid
259
self.
printChannelInfo
(id,chid)
260
else
:
261
print
(
"ERROR: Could not interpret input."
)
262
print
(
"Interpretation as online ID gave:"
,self.
_onlErrStr
)
263
continue
264
265
if
rep.startswith(
"OF"
):
266
s=rep.find(
" "
)
267
if
s==-1:s=0
268
id=self.
getOfflineIDFromString
(rep[s:])
269
if
id
is
not
None
and
self.
offlineID
.is_lar(id):
270
chid=self.
larCabling
.createSignalChannelID(id)
271
self.
printChannelInfo
(id,chid)
272
else
:
273
print
(
"ERROR: Could not interpret input."
)
274
print
(
"Interpretation as offline ID gave:"
,self.
_oflErrStr
)
275
continue
276
277
#Try to interpet input as identifiers
278
chid=self.
getOnlineIDFromString
(rep)
279
if
chid
is
not
None
and
self.
onlineID
.is_lar(chid):
280
id=self.
larCabling
.cnvToIdentifier(chid)
281
else
:
#try interpret at offline ID
282
id=self.
getOfflineIDFromString
(rep)
283
if
id
is
not
None
and
self.
offlineID
.is_lar(id):
284
chid=self.
larCabling
.createSignalChannelID(id)
285
286
if
chid
is
None
or
id
is
None
:
287
print
(
"ERROR: Could not interpret input."
)
288
print
(
"Interpretation as online ID gave:"
,self.
_onlErrStr
)
289
print
(
"Interpretation as offline ID gave:"
,self.
_oflErrStr
)
290
continue
291
292
self.
printChannelInfo
(id,chid)
293
#break
294
return
StatusCode.Success
295
296
def
printChannelInfo
(self,id,chid):
297
bc=self.
badChannels
.status(chid)
298
print
(self.
IdentifiersToString
(chid,id)+
" "
+ self.
bc_packing
.stringStatus(bc))
299
if
id!=self.
noid
:
#Don't try to show anything more for disconnected channels
300
if
self.
includeLocation
:
301
try
:
302
#idHash=self.offlineID.calo_cell_hash(id)
303
theDDE=self.
caloDDM
.get_element(id)
304
print
(
"raw Eta= %.3f, Phi=%.3f r=%.3f"
% (theDDE.eta_raw(),theDDE.phi_raw(),theDDE.r_raw()))
305
print
(
"raw x=%.3f, y=%.3f, z=%.3f"
% (theDDE.x(),theDDE.y(),theDDE.z_raw()))
306
except
Exception
as
e:
307
print
(e)
308
309
if
self.
includeConditions
:
310
if
self.
larDAC2uA
is
not
None
:
311
print
(
"DAC2uA: %.3f"
% self.
larDAC2uA
.DAC2UA(chid), end=
""
)
312
else
:
313
print
(
"DAC2uA: None"
,end=
""
)
314
315
if
self.
laruA2MeV
is
not
None
:
316
print
(
" uA2MeV: %.3f"
% self.
laruA2MeV
.UA2MEV(chid),end=
""
)
317
else
:
318
print
(
" uA2MeV: None"
,end=
""
)
319
320
if
self.
larhvScaleCorr
is
not
None
:
321
print
(
" HVScaleCorr: %.3f"
% self.
larhvScaleCorr
.HVScaleCorr(chid))
322
else
:
323
print
(
" HVScaleCorr: None"
)
324
325
for
gain,gainname
in
((0,
"HG"
),(1,
"MG"
),(2,
"LG"
)):
326
print
(gainname,end=
""
)
327
if
self.
larPedestal
is
not
None
:
328
ped=self.
larPedestal
.pedestal(chid,gain)
329
pedRMS=self.
larPedestal
.pedestalRMS(chid,gain)
330
else
:
331
ped=-9999
332
pedRMS=-9999
333
334
print
(
" Ped: %.3f "
% ped,end=
""
)
335
print
(
" PedRMS: %.3f"
% pedRMS,end=
""
)
336
337
if
self.
larRamp
is
not
None
:
338
ramp=self.
larRamp
.ADC2DAC(chid,gain)
339
if
len(ramp)>1:
340
print
(
" Ramp: %.3f"
% ramp[1],end=
""
)
341
else
:
342
print
(
" Ramp: Empty"
,end=
""
)
343
else
:
344
print
(
" Ramp: None"
,end=
""
)
345
346
if
self.
larMphysOverMcal
is
not
None
:
347
mpmc=self.
larMphysOverMcal
.MphysOverMcal(chid,gain)
348
print
(
" MphysOverMcal: %.5f"
% mpmc,end=
""
)
349
else
:
350
print
(
" MphysOverMcal: None"
,end=
""
)
351
print
(
""
)
352
if
self.
includeDSPTh
:
353
if
self.
larDSPThr
is
not
None
:
354
tQThr=self.
larDSPThr
.tQThr(chid)
355
samThr=self.
larDSPThr
.samplesThr(chid)
356
trgSumTrh=self.
larDSPThr
.trigSumThr(chid)
357
print
(
"DSP Thresholds: tQ:%f, samples:%f, trigSum:%f"
% (tQThr,samThr,trgSumTrh))
358
else
:
359
print
(
"DSP Thresholds: None"
)
360
361
362
def
finalize
(self):
363
self.
msg
.info(
'finalizing...'
)
364
return
StatusCode.Success
365
366
367
def
output(self,out,file=None):
368
if
file
is
not
None
: file.write(out+
"\n"
)
369
print
(out)
370
self.
nLinesPrinted
=self.
nLinesPrinted
+1
371
if
self.
nLinesPrinted
%40 == 0:
372
c=input(
"Press 'q' to quit, 'a' for all ..."
)
373
if
c.upper().startswith(
"Q"
):
374
return
True
375
if
c.upper().startswith(
"A"
):
376
self.
nLinesPrinted
=0xFFFFFFFF
377
return
False
378
379
380
def
readInput
(self):
381
self.
nLinesPrinted
=0
382
try
:
383
rep=input(
"Enter Id >"
)
384
except
Exception:
385
return
""
386
387
return
rep.strip()
388
389
def
IdentifiersToString
(self,chid,id):
390
onlName=
"None"
391
oflName=
"None"
392
if
chid
is
not
None
:
393
onlName=str(chid.get_identifier32().get_compact())+
" "
#+str(chid.get_compact())+" "
394
#onlName=self.onlineID.channel_name(chid)
395
bec=self.
onlineID
.barrel_ec(chid)
396
side=self.
onlineID
.pos_neg(chid)
397
ft=self.
onlineID
.feedthrough(chid)
398
slot=self.
onlineID
.slot(chid)
399
chan=self.
onlineID
.channel(chid)
400
ftname=self.
onlineID
.feedthrough_name(chid)
401
402
if
bec==0:
403
onlName+=
"[BARREL/"
404
else
:
405
onlName+=
"[ENDCAP/"
406
407
if
side==0:
408
onlName+=
"C/"
409
else
:
410
onlName+=
"A/"
411
412
onlName+=
"FT "
+str(ft)+
"("
+ftname+
")/Slot "
+str(slot)+
"/Chan "
+str(chan)
413
414
try
:
415
calibLines=self.
larCabling
.calibSlotLine(chid)
416
if
(len(calibLines)):
417
onlName+=
"/CL"
418
for
calib_chid
in
calibLines:
419
onlName+=
" "
+str(self.
onlineID
.channel(calib_chid))
420
except
Exception:
421
pass
422
423
onlName+=
']'
424
425
if
id
is
not
None
:
426
427
oflName=str(id.get_identifier32().get_compact()) +
" "
# +str(id.get_compact())+" "
428
429
if
(id==self.
noid
):
#0xFFFFFFFF):
430
oflName +=
"[disconnected]"
431
else
:
432
subcalo=self.
offlineID
.sub_calo(id)
433
side=self.
offlineID
.pos_neg(id)
434
layer=self.
offlineID
.sampling(id)
435
region=self.
offlineID
.region(id)
436
eta=self.
offlineID
.
eta
(id)
437
phi=self.
offlineID
.
phi
(id)
438
439
if
subcalo
is
self.
offlineID
.LAREM:
440
if
abs(side)==1:
441
oflName+=
"[EMB"
442
elif
abs(side)==2:
443
oflName+=
"[EMECOW"
444
elif
abs(side)==3:
445
oflName+=
"[EMECIW"
446
else
:
447
oflName+=
"[UNKNOWN"
448
elif
subcalo
is
self.
offlineID
.LARHEC:
449
oflName+=
"[HEC"
450
elif
subcalo
is
self.
offlineID
.LARFCAL:
451
oflName+=
"[FCAL"
452
else
:
453
oflName+=
"[UNKNOWN"
454
455
oflName+=
"/"
456
if
side>0:
457
oflName+=
"A/"
458
else
:
459
oflName+=
"C/"
460
461
oflName+=
"Lay "
+str(layer)+
"/Reg "
+str(region)+
"/Eta "
+str(eta)+
"/Phi "
+str(phi) +
"]"
462
return
onlName+
" = "
+oflName
463
464
465
def
getOfflineIDFromString
(self,input):
466
self.
_oflErrStr
=
""
467
468
upInput=input.upper().
strip
()
469
if
upInput.startswith(
'0X'
):
470
#hex-input
471
try
:
472
id_int=int(upInput,16)
473
except
Exception:
474
self.
_oflErrStr
=
"Can't interpret hexadecimal identifier, got "
+ upInput
475
return
None
476
id=
Identifier
(id_int << 32)
477
if
not
self.
offlineID
.is_lar(id):
478
self.
_oflErrStr
=
"Not a LAR identifier: "
+ upInput
479
return
None
480
481
elif
upInput.isdigit():
482
try
:
483
id_int=int(upInput,10)
484
except
Exception:
485
self.
_oflErrStr
=
"Can't interpret decimal identifier, got "
+upInput
486
return
None
487
id=
Identifier
(id_int << 32)
488
489
if
not
self.
offlineID
.is_lar(id):
490
self.
_oflErrStr
=
"Not a LAR identifier: "
+ upInput
491
return
None
492
493
else
:
#given as expanded ID
494
tbl=str.maketrans(
r",:;/\#"
,
" "
)
495
fields=[]
496
for
f
in
upInput.translate(tbl).
split
():
497
if
len(f):
498
fields+=[f]
499
if
len(fields)<5:
500
self.
_oflErrStr
=
"Not enough fields to build offline id"
501
return
None
502
503
#Format: Subdet/Side/Layer/Region/Eta/Phi
504
if
fields[0].startswith(
"EMB"
):
505
subcalo=self.
offlineID
.LAREM
506
bepn=1
507
elif
fields[0].startswith(
"EMECOW"
):
508
subcalo=self.
offlineID
.LAREM
509
bepn=2
510
elif
fields[0].startswith(
"EMECIW"
):
511
subcalo=self.
offlineID
.LAREM
512
bepn=3
513
elif
fields[0].startswith(
"HE"
):
514
subcalo=self.
offlineID
.LARHEC
515
bepn=2
516
elif
fields[0].startswith(
"F"
):
517
subcalo=self.
offlineID
.LARFCAL
518
bepn=2
519
else
:
520
self.
_oflErrStr
=
"Can't interpret subcalo field, got "
+fields[0]
521
return
None
522
523
if
len(fields)==6:
524
sidefield=fields[1]
525
elif
len(fields)==5:
526
sidefield=fields[0]
527
else
:
528
self.
_oflErrStr
=
"Can't interpret input: Expected 5 or 6 sub-fields, found "
+str(len(fields))
529
return
None
530
531
if
sidefield.endswith(
"A"
)
or
sidefield.endswith(
"P"
)
or
sidefield.endswith(
"POS"
)
or
sidefield ==
'1'
:
532
side=1
533
elif
sidefield.endswith(
"C"
)
or
sidefield.endswith(
"N"
)
or
sidefield.endswith(
"NEG"
)
or
sidefield ==
'0'
:
534
side=-1
535
else
:
536
self.
_oflErrStr
=
"Can't interpret field for detector side, got "
+ sidefield
537
return
None
538
539
bepn=bepn*side
540
541
542
if
fields[-4].isdigit():
543
layer=int(fields[-4])
544
else
:
545
ls=fields[-4]
546
if
(ls==
"PS"
or
ls.startswith(
"PRES"
)): layer=0
547
elif
(ls==
"FRONT"
or
ls.startswith(
"STRIP"
)): layer=1
548
elif
ls.startswith(
"MID"
): layer=2
549
elif
ls==
"BACK"
: layer=3
550
else
:
551
self.
_oflErrStr
=
"Can't interpet textual value for layer, got "
+ ls
552
return
None
553
try
:
554
region=int(fields[-3])
555
eta=int(fields[-2])
556
phi=int(fields[-1])
557
except
Exception:
558
self.
_oflErrStr
=
"Not-numerical input for region, eta or phi"
559
return
None
560
561
#print ("Got",subcalo,bepn,layer,region,eta,phi)
562
#self.offlineID.set_do_checks(True)
563
try
:
#Build Region ID
564
regid=self.
offlineID
.region_id(subcalo,bepn,layer,region)
565
except
Exception:
566
self.
_oflErrStr
=
"Failed to build offline region identifier. Layer/region values inconsistent?"
567
return
None
568
569
etamin=self.
offlineID
.eta_min(regid)
570
etamax=self.
offlineID
.eta_max(regid)
571
572
if
(eta<etamin
or
eta>etamax):
573
self.
_oflErrStr
=
"Eta must be between %i and %i for this region, got %i"
% (etamin,etamax,eta)
574
return
None
575
576
phimin=self.
offlineID
.phi_min(regid)
577
phimax=self.
offlineID
.phi_max(regid)
578
if
(phi<phimin
or
phi>phimax):
579
self.
_oflErrStr
=
"Phi must be between %i and %i for this region, got %i"
% (phimin,phimax,phi)
580
return
None
581
582
id=
None
583
try
:
584
id=self.
offlineID
.cell_id(regid,eta,phi)
585
#id=self.offlineID.cell_id(subcalo,bepn,layer,region,eta,phi)
586
except
Exception:
587
self.
_oflErrStr
=
"Failed to build offline identifier. One or more values out-of-range?"
588
id=
None
589
590
#self.offlineID.set_do_checks(False)
591
return
id
592
593
594
def
getOnlineIDFromString
(self,input):
595
#print ("onfline id input=[%s]" % input)
596
self.
_onlErrStr
=
""
597
upInput=input.upper().
strip
()
598
if
upInput.startswith(
'0X'
):
599
#hex-input
600
try
:
601
id_int=int(upInput,16)
602
except
Exception:
603
self.
_onlErrStr
=
"Can't interpret hexadecimal online identifier, got "
+input
604
return
None
605
606
if
(id_int < 0x38000000
or
id_int > 0x3bc68000):
607
self.
_onlErrStr
=
"Outside of numerical range of online identifiers"
608
return
None
609
610
611
id=
HWIdentifier
(id_int<<32)
612
if
not
self.
onlineID
.is_lar(id):
613
self.
_onlErrStr
=
"Not a LAR identifier:"
+ input
614
return
None
615
616
elif
upInput.isdigit():
617
try
:
618
id_int=int(upInput,10)
619
except
Exception:
620
self.
_onlErrStr
=
"Can't interpret decimal online identifier, got "
+input
621
return
None
622
623
if
(id_int < 0x38000000
or
id_int > 0x3bc68000):
624
self.
_onlErrStr
=
"Outside of numerical range of online identifiers"
625
return
None
626
627
id=
HWIdentifier
(id_int<<32)
628
if
not
self.
onlineID
.is_lar(id):
629
self.
_onlErrStr
=
"Not a LAR identifier:"
+ input
630
return
None
631
632
else
:
#given as expanded ID
633
tbl=str.maketrans(
r",:;/\#"
,
" "
)
634
fields=[]
635
for
f
in
upInput.translate(tbl).
split
():
636
if
len(f):
637
fields+=[f]
638
639
#fields is now a 'clean array' of input
640
#Format: B/EC Side FT Slot Chan
641
if
len(fields)==4:
642
sideField=fields[0]
643
elif
len(fields)==5:
# and len(fields[1])==1:
644
sideField=fields[1]
645
else
:
646
self.
_onlErrStr
=
"Expected 4 or 5 fields, found "
+str(len(fields))
647
return
None
648
649
if
"BARREL"
.
find
(fields[0][0:6])==0:
650
bec=0
651
elif
"ENDCAP"
.
find
(fields[0][0:6])==0:
652
bec=1
653
elif
"EC"
.
find
(fields[0][0:2])==0:
654
bec=1
655
else
:
656
self.
_onlErrStr
=
"Can't interpret field for Barrel/Endcap, got "
+fields[0]
657
return
None
658
659
if
sideField.endswith(
"A"
)
or
sideField==
"1"
or
sideField.startswith(
"P"
):
660
side=1
661
elif
sideField.endswith(
"C"
)
or
sideField==
"0"
or
sideField.startswith(
"N"
):
662
side=0
663
else
:
664
self.
_onlErrStr
=
"Can't interpret field for detector side, got "
+ sideField
665
return
None
666
try
:
667
chan=int(fields[-1])
668
slot=int(fields[-2])
669
ft=int(fields[-3])
670
except
Exception:
671
self.
_onlErrStr
=
"Not-numerical input for FT slot or channel"
672
return
None
673
674
if
bec==0:
675
if
ft<0
or
ft>31:
676
self.
_onlErrStr
=
"Barrel feedthrough number must be between 0 and 31, got "
+str(slot)
677
return
None
678
else
:
679
if
ft<0
or
ft>24:
680
self.
_onlErrStr
=
"Endcap feedthrough number must be between 0 and 24, got "
+str(slot)
681
return
None
682
683
if
slot<1
or
slot>15:
684
self.
_onlErrStr
=
"Slot number must be between 1 and 15, got "
+str(slot)
685
return
None
686
687
if
chan<0
or
chan>127:
688
self.
_onlErrStr
=
"Channel number must be between 0 and 127, got "
+str(chan)
689
return
None
690
691
692
id=
None
693
#self.onlineID.set_do_checks(True)
694
try
:
695
id=self.
onlineID
.channel_Id(bec,side,ft,slot,chan)
696
except
Exception:
697
self.
_onlErrStr
=
"Failed to build online identifier. One or more values out-of-range?"
698
id=
None
699
#self.onlineID.set_do_checks(False)
700
return
id
701
702
703
def
search
(self,input):
704
705
subcalo=
None
706
eta=
None
707
phi=
None
708
bec=
None
709
side=
None
710
ft=
None
711
slot=
None
712
bctypes=0
713
outname=
None
714
outfile=
None
715
layer=
None
716
cl=
None
717
tbl=str.maketrans(
",:;#="
,
" "
)
718
tokens=[]
719
for
t
in
input.translate(tbl).
split
():
720
if
len(t):
721
if
(len(tokens)>0)
and
not
tokens[-1].isalpha()
and
not
t[0].isalpha():
722
tokens[-1]+=t
723
else
:
724
tokens+=[t]
725
726
def
interpretToken(input):
727
pos=input[1:].
find
(
"+-"
)
728
if
pos==-1:
729
pos=input[1:].
find
(
"-"
)
730
if
pos==-1:
731
uplow=
None
732
pos=len(input)-1
733
else
:
734
uplow=
True
735
else
:
736
uplow=
False
737
738
739
pos=pos+1
740
try
:
741
e1=float(input[:pos])
742
except
Exception:
743
print
(
"Expected numerical value, got"
,input[:pos] )
744
return
None
745
746
if
uplow
is
not
None
:
747
try
:
748
e2=float(input[pos+1:])
749
except
Exception:
750
print
(
"Expected numerical value after '+-', got"
,input[pos+1:])
751
return
None
752
753
754
if
uplow:
755
ret=[e1,e2]
756
else
:
757
ret=[e1-e2,e1+e2]
758
else
:
759
ret=[e1-0.025,e1+0.025]
760
ret.sort()
761
return
ret
762
763
i=0
764
while
(i<len(tokens)):
765
if
tokens[i].
upper
()==
"OUT"
and
i+1<len(tokens):
766
outname=tokens[i+1]
767
i=i+1
768
elif
tokens[i].
upper
()==
"ETA"
and
i+1<len(tokens):
769
eta=interpretToken(tokens[i+1])
770
i=i+1
771
elif
tokens[i].
upper
()==
"LAYER"
and
i+1<len(tokens):
772
layer=interpretToken(tokens[i+1])
773
i=i+1
774
elif
tokens[i].
upper
()==
"PHI"
and
i+1<len(tokens):
775
phi=interpretToken(tokens[i+1])
776
i=i+1
777
elif
tokens[i].
upper
()==
"FT"
and
i+1<len(tokens):
778
ft=interpretToken(tokens[i+1])
779
i=i+1
780
elif
tokens[i].
upper
()==
"SLOT"
and
i+1<len(tokens):
781
slot=interpretToken(tokens[i+1])
782
i=i+1
783
elif
tokens[i].
upper
()==
"BAD"
:
784
bctypes=0xFFFFFFFF
785
elif
tokens[i].
upper
()==
"NOISE"
or
tokens[i].
upper
()==
"NOISY"
:
786
bctypes |= self.
noisepattern
787
elif
tokens[i].
upper
()==
"DEAD"
:
788
bctypes |= self.
deadpattern
789
elif
tokens[i].
upper
().startswith(
"BAR"
):
790
bec=0
791
elif
tokens[i].
upper
().startswith(
"END"
):
792
bec=1
793
elif
tokens[i].
upper
()==
"EM"
:
794
subcalo=self.
offlineID
.LAREM
795
elif
tokens[i].
upper
()==
"HEC"
:
796
subcalo=self.
offlineID
.LARHEC
797
elif
tokens[i].
upper
()==
"FCAL"
:
798
subcalo=self.
offlineID
.LARFCAL
799
elif
tokens[i].
upper
()==
"A"
or
tokens[i]==
"P"
:
800
side=1
801
elif
tokens[i].
upper
()==
"C"
or
tokens[i]==
"N"
:
802
side=0
803
elif
tokens[i].
upper
()==
"CL"
and
tokens[i+1].isdigit():
804
cl=int(tokens[i+1])
805
i=i+1
806
else
:
807
stat=self.
bc_packing
.enumName(tokens[i])
808
if
stat[0]:
809
bctypes |= 1<<stat[1]
810
else
:
811
print
(
"Unknown Keyword"
,tokens[i] )
812
i=i+1
813
814
print
(
"Searching for cells with "
,end=
""
)
815
if
eta
is
not
None
:
print
(
" %.3f <= eta <= %.3f"
% (eta[0],eta[1]),end=
""
)
816
if
phi
is
not
None
:
print
(
" %.3f <= phi <= %.3f"
% (phi[0],phi[1]),end=
""
)
817
if
layer
is
not
None
:
print
(
" %.0f <= layer <= %.0f"
% (layer[0],layer[1]),end=
""
)
818
819
if
bec==0:
print
(
" Barrel"
,end=
""
)
820
if
bec==1:
print
(
" Endcap"
,end=
""
)
821
822
if
side==1:
print
(
" A Side"
,end=
""
)
823
if
side==0:
print
(
" C Side"
,end=
""
)
824
825
if
ft
is
not
None
:
print
(
" %.0f <= FT <= %.0f"
% (ft[0],ft[1]),end=
""
)
826
if
slot
is
not
None
:
print
(
" %.0f <= Slot <= %.0f"
% (slot[0],slot[1]),end=
""
)
827
828
if
bctypes!=0:
829
print
(
" "
+self.
bc_packing
.stringStatus(
LArBadChannel
(bctypes)),end=
""
)
830
831
if
phi
is
None
and
eta
is
None
and
bctypes==0
and
ft
is
None
and
side
is
None
and
bec
is
None
and
slot
is
None
and
layer
and
subcalo
is
None
:
832
print
(
"No search criteria set!"
)
833
return
834
835
836
if
cl
is
not
None
:
print
(
" CL:"
,cl,end=
""
)
837
838
print
(os.linesep)
839
840
if
not
self.
includeLocation
and
(eta
is
not
None
or
phi
is
not
None
):
841
print
(
"ERROR: GeoModel not activated, run with -g option"
)
842
return
843
844
if
outname
is
not
None
:
845
try
:
846
outfile=open(outname,
"w"
)
847
except
IOError:
848
print
(
"ERROR failed to open file"
,outname)
849
import
traceback
850
traceback.print_exc()
851
outfile=
None
852
outname=
None
853
854
855
#for idH in range(self.offlineID.calo_cell_hash_max()): //This one includes also tile cells
856
for
idH
in
range(182468):
857
idHash=
IdentifierHash
(idH)
858
chid=self.
larCabling
.createSignalChannelIDFromHash(idHash)
859
860
#print ("Loop hash=%i , on: %x , off: %x" % (idH, chid.get_identifier32().get_compact(), self.offlineID.cell_id(idHash).get_identifier32().get_compact()))
861
#Check Bad-Channel Status
862
bcstat=self.
badChannels
.status(chid)
863
if
bctypes!=0:
864
bcw=bcstat.packedData()
865
if
bcw & bctypes == 0:
continue
866
867
868
#Check Online Id
869
if
bec
is
not
None
and
bec!=self.
onlineID
.barrel_ec(chid):
continue
870
if
side
is
not
None
and
side!=self.
onlineID
.pos_neg(chid):
continue
871
if
ft
is
not
None
and
(self.
onlineID
.feedthrough(chid)<ft[0]
or
self.
onlineID
.feedthrough(chid)>ft[1]):
continue
872
if
slot
is
not
None
and
(self.
onlineID
.slot(chid)<slot[0]
or
self.
onlineID
.slot(chid)>slot[1]):
continue
873
874
if
cl
is
not
None
:
875
try
:
876
calibLines=self.
larCabling
.calibSlotLine(chid)
877
keep=
False
878
for
foundCLs
in
calibLines:
879
if
self.
onlineID
.channel(foundCLs) == cl:
880
keep=
True
881
break
882
883
if
not
keep:
continue
884
885
except
Exception:
886
print
(
"Failed to get calib line:"
)
887
import
traceback
888
traceback.print_exc()
889
continue
890
891
#Check geometrical location
892
ep=
""
893
if
eta
is
not
None
or
phi
is
not
None
:
894
theDDE=self.
caloDDM
.get_element(idHash)
895
e=theDDE.eta()
896
p=theDDE.phi()
897
if
eta
is
not
None
and
(e<eta[0]
or
e>eta[1]):
continue
898
if
phi
is
not
None
and
(p<phi[0]
or
p>phi[1]):
continue
899
ep=
" eta=%.3f phi=%.3f "
% (e,p)
900
901
id=self.
offlineID
.cell_id(idHash)
902
if
subcalo
is
not
None
and
subcalo!=self.
offlineID
.sub_calo(id):
continue
903
if
layer
is
not
None
and
(self.
offlineID
.sampling(id)<layer[0]
or
self.
offlineID
.sampling(id)>layer[1]):
continue
904
905
br=self.
output
(self.
IdentifiersToString
(chid,id) +
" "
+ep+self.
bc_packing
.stringStatus(bcstat),outfile)
906
if
br:
break
907
908
if
outfile
is
not
None
: outfile.close()
909
return
910
911
def
printHelp
(self):
912
print
(
"First mode of operation:"
)
913
print
(
"Enter a channel identifier (online or offline). Allowed forms are:"
)
914
print
(
" Decimal or hexadecimal compact identifier, eg. 'online 0x39000000'"
)
915
print
(
" Expanded identifer like"
)
916
print
(
" 'online Bar C 1 1 1' (Barrel C FT 1, Slot 1 channel 1)"
)
917
print
(
" 'offline FCAL A 1 0 1 1' (FCAL A, Layer 1, Region 0, Eta 1 Phi 1)"
)
918
print
(
" Offline ids must start with one of the following subdetectors names:"
)
919
print
(
" EMB, EMECIW, EMECOW, HEC, FCAL"
)
920
print
(
" Online ids must start with either 'BAR' or 'END'"
)
921
print
(
" If the prefix 'online' or 'offline' is omitted both are tried."
)
922
print
(
"\nSecond mode of operation:"
)
923
print
(
"Search <keyword> <keyword> .."
)
924
print
(
" Keywords are: 'barrel', 'endcap', A', 'C', or any bad-channel type"
)
925
print
(
" Keywords with arguments are: 'eta', 'phi', 'layer', 'FT', 'Slot' and 'CL'"
)
926
print
(
"\nType 'quit' to terminate'"
)
927
928
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
printHelp
void printHelp()
Definition
AtlCoolCopy.cxx:3353
SiliconTech::strip
@ strip
Definition
FPGATrackSimTypes.h:25
upper
int upper(int c)
Definition
LArBadChannelParser.cxx:49
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
HWIdentifier
Definition
HWIdentifier.h:13
IdentifierHash
This is a "hash" representation of an Identifier.
Definition
IdentifierHash.h:25
Identifier
Definition
DetectorDescription/Identifier/Identifier/Identifier.h:26
LArBadChanBitPacking
Definition
LArBadChanBitPacking.h:13
LArBadChannel
Definition
LArBadChannel.h:10
PyAthena::Alg
Definition
PyAthenaAlg.h:33
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition
PyAthenaAlg.cxx:86
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition
PyAthenaAlg.cxx:60
python.LArCellConditionsAlg.LArCellConditionsAlg
Definition
LArCellConditionsAlg.py:26
python.LArCellConditionsAlg.LArCellConditionsAlg.includeConditions
includeConditions
Definition
LArCellConditionsAlg.py:39
python.LArCellConditionsAlg.LArCellConditionsAlg.output
output(self, out, file=None)
Definition
LArCellConditionsAlg.py:367
python.LArCellConditionsAlg.LArCellConditionsAlg.execute
execute(self)
Definition
LArCellConditionsAlg.py:106
python.LArCellConditionsAlg.LArCellConditionsAlg.nEvts
int nEvts
Definition
LArCellConditionsAlg.py:43
python.LArCellConditionsAlg.LArCellConditionsAlg.printHelp
printHelp(self)
Definition
LArCellConditionsAlg.py:911
python.LArCellConditionsAlg.LArCellConditionsAlg.noid
noid
Definition
LArCellConditionsAlg.py:91
python.LArCellConditionsAlg.LArCellConditionsAlg.larDSPThr
larDSPThr
Definition
LArCellConditionsAlg.py:101
python.LArCellConditionsAlg.LArCellConditionsAlg.laruA2MeV
laruA2MeV
Definition
LArCellConditionsAlg.py:99
python.LArCellConditionsAlg.LArCellConditionsAlg.IdentifiersToString
IdentifiersToString(self, chid, id)
Definition
LArCellConditionsAlg.py:389
python.LArCellConditionsAlg.LArCellConditionsAlg._detStore
_detStore
note that we are using the python logging service and that the PyAthena.Alg base class has already in...
Definition
LArCellConditionsAlg.py:55
python.LArCellConditionsAlg.LArCellConditionsAlg.caloDDM
caloDDM
Definition
LArCellConditionsAlg.py:199
python.LArCellConditionsAlg.LArCellConditionsAlg.includeDSPTh
includeDSPTh
Definition
LArCellConditionsAlg.py:41
python.LArCellConditionsAlg.LArCellConditionsAlg._onlErrStr
str _onlErrStr
Definition
LArCellConditionsAlg.py:262
python.LArCellConditionsAlg.LArCellConditionsAlg.noisepattern
int noisepattern
Definition
LArCellConditionsAlg.py:79
python.LArCellConditionsAlg.LArCellConditionsAlg.larMphysOverMcal
larMphysOverMcal
Definition
LArCellConditionsAlg.py:96
python.LArCellConditionsAlg.LArCellConditionsAlg.badChannels
badChannels
Definition
LArCellConditionsAlg.py:126
python.LArCellConditionsAlg.LArCellConditionsAlg.larCabling
larCabling
Definition
LArCellConditionsAlg.py:118
python.LArCellConditionsAlg.LArCellConditionsAlg.offlineID
offlineID
Definition
LArCellConditionsAlg.py:72
python.LArCellConditionsAlg.LArCellConditionsAlg.search
search(self, input)
Definition
LArCellConditionsAlg.py:703
python.LArCellConditionsAlg.LArCellConditionsAlg.readInput
readInput(self)
Definition
LArCellConditionsAlg.py:380
python.LArCellConditionsAlg.LArCellConditionsAlg.printChannelInfo
printChannelInfo(self, id, chid)
Definition
LArCellConditionsAlg.py:296
python.LArCellConditionsAlg.LArCellConditionsAlg.nLinesPrinted
int nLinesPrinted
Definition
LArCellConditionsAlg.py:42
python.LArCellConditionsAlg.LArCellConditionsAlg._condStore
_condStore
Definition
LArCellConditionsAlg.py:60
python.LArCellConditionsAlg.LArCellConditionsAlg.onlineID
onlineID
Definition
LArCellConditionsAlg.py:66
python.LArCellConditionsAlg.LArCellConditionsAlg.larDAC2uA
larDAC2uA
Definition
LArCellConditionsAlg.py:98
python.LArCellConditionsAlg.LArCellConditionsAlg.includeLocation
includeLocation
Definition
LArCellConditionsAlg.py:40
python.LArCellConditionsAlg.LArCellConditionsAlg._oflErrStr
str _oflErrStr
Definition
LArCellConditionsAlg.py:274
python.LArCellConditionsAlg.LArCellConditionsAlg.deadpattern
int deadpattern
Definition
LArCellConditionsAlg.py:85
python.LArCellConditionsAlg.LArCellConditionsAlg.larRamp
larRamp
Definition
LArCellConditionsAlg.py:97
python.LArCellConditionsAlg.LArCellConditionsAlg.larPedestal
larPedestal
Definition
LArCellConditionsAlg.py:95
python.LArCellConditionsAlg.LArCellConditionsAlg.getOfflineIDFromString
getOfflineIDFromString(self, input)
Definition
LArCellConditionsAlg.py:465
python.LArCellConditionsAlg.LArCellConditionsAlg.bc_packing
bc_packing
Definition
LArCellConditionsAlg.py:77
python.LArCellConditionsAlg.LArCellConditionsAlg.__init__
__init__(self, name="LArCellConditionsAlg", **kw)
Definition
LArCellConditionsAlg.py:34
python.LArCellConditionsAlg.LArCellConditionsAlg.getOnlineIDFromString
getOnlineIDFromString(self, input)
Definition
LArCellConditionsAlg.py:594
python.LArCellConditionsAlg.LArCellConditionsAlg.larhvScaleCorr
larhvScaleCorr
Definition
LArCellConditionsAlg.py:100
find
std::string find(const std::string &s)
return a remapped string
Definition
hcg.cxx:140
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
error
Definition
IImpactPoint3dEstimator.h:72
Generated on
for ATLAS Offline Software by
1.17.0