4 from AthenaCommon.Utils.unixtools
import find_datafile
5 from AthenaCommon.Logging
import logging
9 utility function to retrieve the flag dictionary
10 for every TrackAnalysis from an input JSON file
15 if input_file ==
"Default":
20 if dataPath
is None and input_file !=
"Default":
21 raise Exception(f
"Input file with analyses definition: {input_file} could not be found, for files given with absolute path use ./ prefix")
27 with open( dataPath,
"r" )
as input_json_file:
28 analysesDictTmp = json.load( input_json_file )
32 for trkAnaName, trkAnaDict
in analysesDictTmp.items():
34 analysesDict.update( { trkAnaName : trkAnaDict } )
36 analysesDict[trkAnaName][
"anaTag"] =
"_" + trkAnaName
38 if (
"SubFolder" not in analysesDict[trkAnaName].
keys()
or
39 analysesDict[trkAnaName][
"SubFolder"] ==
"" ) :
40 analysesDict[trkAnaName][
"SubFolder"] = trkAnaName
41 analysesDict[trkAnaName][
"SubFolder"] +=
"/"
43 if "ChainNames" in analysesDict[trkAnaName]:
44 fullChainList =
getChainList( flags, analysesDict[trkAnaName][
"ChainNames"] )
45 analysesDict[trkAnaName][
"ChainNames"] = fullChainList
52 utility function to define a separate TrackAnalysis
53 for each configured trigger chain
55 if not analysesDictIn :
return analysesDictIn
58 for trkAnaName, trkAnaDict
in analysesDictIn.items():
59 if "ChainNames" in trkAnaDict:
60 chainList = trkAnaDict[
"ChainNames"]
61 for chain
in chainList:
62 trkAnaName_new = trkAnaName +
"_" + chain
63 trkAnaDict_new = dict( trkAnaDict )
64 trkAnaDict_new[
"anaTag"] = trkAnaDict[
"anaTag"] +
"_" + chain
65 trkAnaDict_new[
"ChainNames"] = [ chain ]
66 analysesDictOut.update( { trkAnaName_new : trkAnaDict_new } )
68 analysesDictOut.update( { trkAnaName : trkAnaDict } )
70 return analysesDictOut
76 utility function to retrieve full list of
77 configured trigger chains matching
78 the passed regex list of chains
80 if not regexChainList:
return regexChainList
82 if not flags.locked():
83 flags_tmp = flags.clone()
87 from TrigConfigSvc.TriggerConfigAccess
import getHLTMenuAccess
92 for regexChain
in regexChainList:
93 for item
in chainsMenu:
94 chains = re.findall( regexChain, item )
96 if chain
is not None and chain == item:
97 configChains.append( chain )
104 Open json files and load all merged contents
105 in a dictionary, which is later converted to a
106 list of strings, each to be parsed in a
107 (flattened) json format
109 log = logging.getLogger(
"getPlotsDefList" )
112 log.debug(
"plotsDefFileList : %s", flags.PhysVal.IDTPM.plotsDefFileList )
113 listPath =
find_datafile( flags.PhysVal.IDTPM.plotsDefFileList )
115 log.error(
"plotsDefFileList not found" )
118 plotsDefFileNames = []
119 with open( listPath,
"r" )
as input_flist :
120 plotsDefFileNames = input_flist.read().splitlines()
125 for plotsDefFileName
in plotsDefFileNames :
127 log.debug(
"Reading input plots definitions : %s", dataPath )
129 log.error(
"plotsDefFile %s not found", plotsDefFileName )
132 with open( dataPath,
"r" )
as input_json_file :
133 plotsDefDict.update( json.load( input_json_file ) )
137 plotsDefStrList_v1 = []
138 for plotName, plotDict
in plotsDefDict.items():
139 newPlotDict = plotDict.copy()
140 newPlotDict[
"name" ] = plotName
146 plotDefStr =
str( json.dumps( plotDictFlat ) )
149 plotsDefStrList_v1.append( plotDefStr )
153 commonValuesDict = {}
154 commonValuesPath =
find_datafile( flags.PhysVal.IDTPM.plotsCommonValuesFile )
155 if commonValuesPath
is None :
156 log.error(
"plotsCommonValuesFile not found" )
159 with open( commonValuesPath,
"r" )
as input_commonValues :
160 commonValuesDict.update( json.load( input_commonValues ) )
162 plotsDefStrList_v2 = []
163 for plotDefStr
in plotsDefStrList_v1 :
164 newPlotDefStr = plotDefStr
165 if commonValuesDict :
166 for key, value
in commonValuesDict.items() :
167 plotDefStr_tmp = newPlotDefStr.replace(
"$"+key, value[0] )
168 newPlotDefStr = plotDefStr_tmp
169 plotsDefStrList_v2.append( newPlotDefStr )
173 getLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.TestType ),
174 getLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.RefType )
178 for plotsDefStr
in plotsDefStrList_v2 :
179 if (
"$TRKTAG" not in plotsDefStr )
and (
"$TRKTYPE" not in plotsDefStr ) :
180 plotsDefStrList.append( plotsDefStr )
182 for trkLabel
in trkLabels :
183 newPlotsDefStr = plotsDefStr.replace(
"$TRKTYPE", trkLabel[0] ).
replace(
"$TRKTAG", trkLabel[1] )
184 plotsDefStrList.append( newPlotsDefStr )
186 return plotsDefStrList
190 if key ==
"Offline" and flags.PhysVal.IDTPM.currentTrkAna.SelectOfflineObject:
191 if "Truth" not in flags.PhysVal.IDTPM.currentTrkAna.SelectOfflineObject:
192 key += flags.PhysVal.IDTPM.currentTrkAna.SelectOfflineObject
194 "EFTrigger" : [
"EF Trigger track",
"eftrig" ],
195 "Trigger" : [
"Trigger track",
"trig" ],
196 "Offline" : [
"Offline track",
"offl" ],
197 "OfflineElectron" : [
"Offline e^{#pm} track",
"offEle" ],
198 "OfflineMuon" : [
"Offline #mu^{#pm} track",
"offMu" ],
199 "OfflineTau" : [
"Offline #tau^{#pm} track",
"offTau" ],
200 "Truth" : [
"Truth particle",
"truth" ],
201 "TruthElectron" : [
"Truth e^{#pm}",
"truthEle" ],
202 "TruthMuon" : [
"Truth #mu^{#pm}",
"truthMu" ],
203 "TruthTau" : [
"Truth #tau^{#pm}",
"truthEle" ],
205 return trkLabelsDict[ key ]
215 def flatten(x, name=''):
219 flatten(x[a], name + a +
'_')
221 elif type(x)
is list:
224 flatten(a, name +
str(i) +
'_')