5 from operator
import itemgetter
10 def readInput(filename, nCellsList=20, bcfile=None, cutoff=0.1):
13 from ROOT
import IdDictParser
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):
23 print (
"ERROR, unable to locate identifier dictionaries")
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
31 stat=larID.initialize_from_dictionary(idd)
33 print (
"ERROR, failed to init LArOnlineID")
38 f=TFile.Open(filename)
40 print(
"ERROR, failed to open input file",filename)
44 for d
in f.GetListOfKeys():
45 mg=re.match(
"run_([0-9]*)",d.GetName())
49 print(
"Found run dir:",rundir)
52 hist=f.Get(rundir+
"/CaloMonitoring/LArClusterCellMon/Summary/cellhashPercent")
55 for idx
in range(hist.GetNbinsX()):
56 freq.append((idx,hist.GetBinContent(idx)))
58 freq.sort(key=itemgetter(1),reverse=
True)
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]))
66 bcfile.write(
"#Bad channel list for run "+runnbr+
"\n")
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)))
77 if __name__==
"__main__":
80 parser= argparse.ArgumentParser()
81 parser.add_argument(
"inputfile",type=argparse.FileType(
'r'),help=
"Input HIST file containig <run>/CaloMonitoring/LArClusterCellMon/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")
86 (args,leftover)=parser.parse_known_args()
88 args.inputfile.close()
90 readInput(args.inputfile.name,args.nPrint,args.BCfile,args.cut)