ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloMonitoring
python
readCCLHist.py
Go to the documentation of this file.
1
#!/bin/env python
2
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
4
from
ROOT
import
TFile
5
from
operator
import
itemgetter
6
import
re
7
import
os,sys
8
9
10
def
readInput
(filename, nCellsList=20, bcfile=None, cutoff=0.1):
11
12
#Set up LArOnlineID helper class in standalone mode (from xml file)
13
from
ROOT
import
IdDictParser
14
parser=
IdDictParser
()
15
#Get xml files:
16
xmlpath=
None
17
for
dd
in
os.getenv(
'XMLPATH'
).
split
(os.pathsep):
18
d=dd+
"/IdDictParser/ATLAS_IDS.xml"
19
if
os.access(d,os.R_OK):
20
xmlpath=dd
21
break
22
if
not
xmlpath:
23
print
(
"ERROR, unable to locate identifier dictionaries"
)
24
sys.exit(-1)
25
26
27
parser.register_external_entity(
"LArCalorimeter"
,xmlpath+
"/IdDictParser/IdDictLArCalorimeter_DC3-05-Comm-01.xml"
)
28
idd = parser.parse(xmlpath+
"/IdDictParser/ATLAS_IDS.xml"
)
29
from
ROOT
import
LArOnlineID
30
larID=
LArOnlineID
()
31
stat=larID.initialize_from_dictionary(idd)
32
if
stat==1:
33
print
(
"ERROR, failed to init LArOnlineID"
)
34
sys.exit(-1)
35
36
37
#Open ROOT HIST file
38
f=TFile.Open(filename)
39
if
not
f.IsOpen():
40
print
(
"ERROR, failed to open input file"
,filename)
41
sys.exit(-1)
42
43
rundir=
None
44
for
d
in
f.GetListOfKeys():
45
mg=re.match(
"run_([0-9]*)"
,d.GetName())
46
rundir=mg.group(0)
47
break
48
49
print
(
"Found run dir:"
,rundir)
50
runnbr=rundir[4:]
51
52
hist=f.Get(rundir+
"/CaloMonitoring/CaloClusterCellMon/Summary/larhashPercent"
)
53
54
freq=[]
55
for
idx
in
range(hist.GetNbinsX()):
56
freq.append((idx,hist.GetBinContent(idx)))
57
58
freq.sort(key=itemgetter(1),reverse=
True
)
59
60
for
f
in
freq[:nCellsList]:
61
c=larID.channel_Id(f[0])
62
print
(
"Channel %s constributes to clusters in %.3f %% of events"
% (larID.channel_name(c),f[1]))
63
64
65
if
bcfile:
66
bcfile.write(
"#Bad channel list for run "
+runnbr+
"\n"
)
67
for
(h,f)
in
freq:
68
if
f<cutoff:
break
69
c=larID.channel_Id(h)
70
bcfile.write(
"%i %i %i %i %i 0 highNoiseHG\n"
% (larID.barrel_ec(c), larID.pos_neg(c), larID.feedthrough(c),
71
larID.slot(c), larID.channel(c)))
72
73
bcfile.close()
74
75
76
77
if
__name__==
"__main__"
:
78
79
import
argparse
80
parser= argparse.ArgumentParser()
81
parser.add_argument(
"inputfile"
,type=argparse.FileType(
'r'
),help=
"Input HIST file containig <run>/CaloMonitoring/CaloClusterCellMon/Summary/cellhashPercent"
)
82
parser.add_argument(
'BCfile'
, type=argparse.FileType(
'w'
),nargs=
'?'
,default=
None
,help=
"Optional output file digestable as bad-channel input"
)
83
parser.add_argument(
"--cut"
,type=float,default=0.1,help=
"Write channels appearing more often that x %% as highNoiseHG"
)
84
parser.add_argument(
"--nPrint"
,type=int,default=20,help=
"Print a list of the N most noisy channels"
)
85
86
(args,leftover)=parser.parse_known_args()
87
88
args.inputfile.close()
#Care only about the name, will be opend by ROOT
89
90
readInput
(args.inputfile.name,args.nPrint,args.BCfile,args.cut)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
IdDictParser
Definition
IdDictParser.h:21
LArOnlineID
Definition
LArOnlineID.h:21
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
readCCLHist.readInput
readInput(filename, nCellsList=20, bcfile=None, cutoff=0.1)
Definition
readCCLHist.py:10
Generated on
for ATLAS Offline Software by
1.17.0