26def toCSV(fileName, metadata, HLTTriggers, readL1=False):
29 with open(fileName, mode=
'w')
as outputCSV_file:
30 rates_csv_writer = csv.writer(outputCSV_file, delimiter=
',', quotechar=
'"', quoting=csv.QUOTE_MINIMAL)
32 rates_csv_writer.writerow([
'Name',
'Active Time [s]',
'Group',
'Weighted PS Rate [Hz]',
'Weighted PS Rate Err [Hz]', \
33 'Unique Rate [Hz]',
'Unique Rate Err [Hz]',
'Express Rate [Hz]',
'Express Rate Err [Hz]',
'Prescale',
'Express Prescale',
'ID', \
34 'Raw Active Events',
'Raw Pass Events',
'Active Events',
'Input Rate [Hz]',
'Pass Fraction after PS [%]',
'Pass Weighted PS'])
35 rates_csv_writer.writerow([
'Trigger name',
'Integrated length of all lumi blocks which contributed events to this rates prediction.',
'The group this chain belongs to.',
'Rate after applying all prescale(s) as weights.',
'Error on rate after applying all prescale(s) as weights',
'Total rate without this chain rate',
'Error on unique rate',
'Express stream rate',
'Error on express rate',
'The prescale of this chain. Only displayed for simple combinations.',
'The prescale of the chain including express prescale',
'The CPTID or HLT Chain ID',
'Raw underlying statistics on the number events processed for this chain.',
'Raw underlying statistics on the number events passed by this chain.',
'Number of events in which the chain - or at least one chain in the combination - was executed.',
'Input rate to this chain or combination of chains. At L1 this will be the collision frequency for the bunch pattern.',
'Fraction of events which pass this trigger after prescale.',
'Number of events this chain or combination passed after applying prescales as weighting factors.'])
37 for trig
in HLTTriggers:
39 group_name = chain_id =
""
40 if "ChainL1" in fileName:
42 chain_id = metadata[
"itemID"].
get(trig.name)
43 elif "ChainHLT" in fileName:
44 group_name = metadata[
"chainGroup"].
get(trig.name)
45 chain_id = metadata[
"chainID"].
get(trig.name)
46 elif "Group" in fileName:
48 group_name =
"All" if "GLOBAL" in trig.name
else group_name
50 if float(trig.rateDenominator)==0:
51 print(
"float(trig.rateDenominator) is ZERO! This shouldn't happen")
52 if float(trig.activeWeighted)==0:
55 passFrac_afterPS=100*float(trig.passWeighted)/float(trig.activeWeighted)
57 isL1 = trig.name.startswith(
"L1_")
58 rates_csv_writer.writerow([trig.name,
"%.4f" % trig.rateDenominator,group_name,
"%.4f" % trig.rate,
"%.4f" % trig.rateErr, \
59 "%.4f" % trig.rateUnique,
"%.4f" % trig.rateUniqueErr, (
"%.4f" % trig.rateExpress
if not isL1
else "-"), (
"%.4f" % trig.rateExpressErr
if not isL1
else "-"), \
60 trig.prescale, (trig.expressPrescale
if not isL1
else "-"), chain_id,
"%.0f" % trig.activeRaw,
"%.0f" % trig.passRaw,
"%.4f" % trig.activeWeighted, \
61 "%.4f" % (float(trig.activeWeighted)/float(trig.rateDenominator)),
"%.4f" % passFrac_afterPS,
"%.4f" % trig.passWeighted])
65def toJson(fileName, metadata, L1Triggers, HLTTriggers):
68 for trig
in L1Triggers:
71 for trig
in HLTTriggers:
79 jsonDict[
'PredictionLumi'] = metadata[
'targetLumi']
80 for k,v
in metadata.items():
81 if k.startswith(
"n_evts"):
83 jsonDict[
'AtlasProject'] = metadata[
'AtlasProject']
84 jsonDict[
'AtlasVersion'] = metadata[
'AtlasVersion']
85 jsonDict[
'triggerMenuSetup'] = metadata[
'masterKey']
86 jsonDict[
'L1PrescaleSet'] = metadata[
'lvl1PrescaleKey']
87 jsonDict[
'HLTPrescaleSet'] = metadata[
'hltPrescaleKey']
88 jsonDict[
'bunchgroup'] = metadata[
'bunchGroups']
89 jsonDict[
'level'] = level
91 with open(fileName,
'w')
as outFile:
92 json.dump(obj=jsonDict, fp=outFile, indent=2, sort_keys=
True)
96 {
'PredictionLumi' : metadata[
'targetLumi']},
97 {
'TargetMu' : metadata[
'targetMu']},
98 {
'RunNumber' : metadata[
'runNumber']},
99 {
'Details' : metadata[
'details']},
100 {
'JIRA' : metadata[
'JIRA']},
101 {
'AMITag' : metadata[
'amiTag']},
102 {
'SMK' : metadata[
'masterKey']},
103 {
'DB' :
readDBFromAMI(metadata[
'amiTag'])
if metadata[
'amiTag']
else None},
104 {
'LVL1PSK' : metadata[
'lvl1PrescaleKey']},
105 {
'HLTPSK' : metadata[
'hltPrescaleKey']},
106 {
'AtlasProject' : metadata[
'AtlasProject']},
107 {
'AtlasVersion' : metadata[
'AtlasVersion']}
109 for k,v
in metadata.items():
110 if k.startswith(
"n_evts"):
111 metajsonData.append({k: v})
114 metajsonDict[
'text'] =
'metadata'
115 metajsonDict[
'children'] = metajsonData
117 with open(
'metadata.json',
'w')
as outMetaFile:
118 json.dump(obj=metajsonDict, fp=outMetaFile, indent=2, sort_keys=
True)
132 '''Get metadata for rates.json file'''
133 metatree = inputFile.Get(
"metadata")
140 metadata[
'runNumber'] = metatree.runNumber
142 metadata[
'targetMu'] = metatree.targetMu
143 metadata[
'targetBunches'] = metatree.targetBunches
144 metadata[
'targetLumi'] = metatree.targetLumi
146 metadata[
'masterKey'] = metatree.masterKey
147 metadata[
'lvl1PrescaleKey'] = metatree.lvl1PrescaleKey
148 metadata[
'hltPrescaleKey'] = metatree.hltPrescaleKey
150 metadata[
'AtlasProject'] =
str(metatree.AtlasProject)
151 metadata[
'AtlasVersion'] =
str(metatree.AtlasVersion)
153 metadata[
'bunchCrossingRate'] = metatree.bunchCrossingRate
155 metadata[
'multiSliceDiJet'] = metatree.multiSliceDiJet
160 for i
in range(0, metatree.triggers.size()):
161 prescale = metatree.prescales.at(i)
162 expressPrescale = metatree.express.at(i)
164 prescales[metatree.triggers.at(i)] = prescale
if prescale >= -1
else "Multiple"
165 lowers[metatree.triggers.at(i)] =
str(metatree.lowers.at(i))
166 express[metatree.triggers.at(i)] = expressPrescale
if expressPrescale >= -1
else "Multiple"
168 metadata[
'prescales'] = prescales
169 metadata[
'lowers'] = lowers
170 metadata[
'express'] = express
174 for i
in range(0, metatree.hltChainIDGroup.size()):
175 chainid[metatree.hltChainIDGroup.at(i).at(0)] = metatree.hltChainIDGroup.at(i).at(1)
176 chaingroup[metatree.hltChainIDGroup.at(i).at(0)] = metatree.hltChainIDGroup.at(i).at(2)
178 metadata[
'chainID'] = chainid
179 metadata[
'chainGroup'] = chaingroup
182 for i
in range(0, metatree.l1ItemID.size()):
183 itemid[metatree.l1ItemID.at(i).at(0)] = metatree.l1ItemID.at(i).at(1)
185 metadata[
'itemID'] = itemid
188 for bg
in metatree.bunchGroups:
189 bunchGroups.append(bg)
190 metadata[
'bunchGroups'] = bunchGroups
197 def getTriggerName(name, filter):
198 if "Group" in filter
and "GLOBAL" not in name:
199 return name.replace(
'_',
':', 1)
203 from .RatesTrigger
import RatesTrigger
205 for key
in inputFile.GetListOfKeys():
206 if key.GetName() ==
'All':
207 for subdirKey
in key.ReadObj().GetListOfKeys():
208 if filter
not in subdirKey.GetName():
continue
209 for triggerKey
in subdirKey.ReadObj().GetListOfKeys():
211 for suffix, data
in numeratorDict.items():
213 triggerList.append(
RatesTrigger(getTriggerName(triggerKey.GetName(), filter)+suffix, metadata, data, globalGroupDict[suffix], suffix))
215 log.error(
"Cannot create a new trigger for {0}".format(triggerKey.GetName()))