ATLAS Offline Software
run_gep.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 if __name__ == '__main__':
6  import sys
7 
8 
11  from AthenaCommon.Logging import logging
12  local_log = logging.getLogger('run_gep')
13  info = local_log.info
14  error = local_log.error
15 
16  import argparse
17  p = argparse.ArgumentParser()
18  p.add_argument('-i', '--input',
19  metavar='KEY',
20  default='ttbar',
21  help='Key of the input from TrigValInputs to be used, default=%(default)s')
22  p.add_argument('-e', '--execute',
23  action='store_true',
24  help='After building the configuration, also process a few events')
25  p.add_argument('-n', '--nevents',
26  metavar='N',
27  type=int,
28  default=25,
29  help='Number of events to process if --execute is used, default=%(default)s')
30  p.add_argument('-g', '--gepInput',
31  metavar='N',
32  type=bool,
33  default=False,
34  help='use input files previously used for GEP jobs')
35  p.add_argument('-f', '--gepInputRun3',
36  action='store_true',
37  help='use Run3 (with jFexJetRoI) input file')
38 
39  p.add_argument('-c', '--clusterAlgs',
40  default='WFS',
41  help='commma separated list of stategies for GepClusterAlg: [WFS, Calo420]')
42 
43  p.add_argument('-j', '--jetAlgs',
44  default='Cone',
45  help='commma separated list of stategies for GepJetAlg:[Cone, ModAntikT]')
46 
47  args = p.parse_args()
48 
49  clusterAlgNames = args.clusterAlgs.split(',')
50  jetAlgNames = args.jetAlgs.split(',')
51  info('GEP clusterAlgs: ' + str(clusterAlgNames))
52  info('GEP jetAlgs: ' + str(jetAlgNames))
53 
54 
57  from AthenaConfiguration.AllConfigFlags import initConfigFlags
58  from TrigValTools.TrigValSteering import Input
59 
60  assert not (args.gepInput and args.gepInputRun3)
61 
62  flags = initConfigFlags()
63 
64  if args.gepInput:
65  ifile = (
66  "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/RecExRecoTest/mc20e_13TeV/"
67  "valid1.410000.PowhegPythiaEvtGen_P2012_ttbar_hdamp172p5_nonallhad.ESD.e4993_s3227_r12689/myESD.pool.root")
68  flags.Input.Files = [ifile]
69  elif args.gepInputRun3:
70  # ifile = (
71  # '/afs/cern.ch/work/m/martyniu/public/forPeter/'
72  # 'mc21.601229.PhPy8EG_A14_ttbar_hdamp258p75_SingleLep.recon.AOD.e8357_e7400_s3775_r13614_r13614/'
73  #'AOD.29004489._000039.pool.root.1')
74 
75  ifile = '/afs/cern.ch/work/m/martyniu/public/forPeter/RDO/tmp.RDO'
76  flags.Input.Files = [ifile]
77  else:
78  flags.Input.Files = Input.get_input(args.input).paths
79 
80  if not flags.Input.isMC:
81  from AthenaConfiguration.TestDefaults import defaultGeometryTags
82  flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
83 
84  info('Command line args: ' + str(args))
85 
86  flags.Output.AODFileName = 'AOD.pool.root'
87  flags.Common.isOnline = not flags.Input.isMC
88  flags.Exec.MaxEvents = args.nevents
89  flags.Concurrency.NumThreads = 1
90  flags.Concurrency.NumConcurrentEvents = 1
91  flags.Scheduler.ShowDataDeps = True
92  flags.Scheduler.CheckDependencies = True
93  flags.Scheduler.ShowDataFlow = True
94  flags.Trigger.EDMVersion = 3
95  flags.Trigger.doLVL1 = True
96  flags.Trigger.enableL1CaloPhase1 = True
97 
98  # Enable only calo for this test
99  from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
100  setupDetectorFlags(flags, ['LAr','Tile','MBTS'], toggle_geometry=True)
101 
102  flags.lock()
103  flags.dump()
104 
105 
108  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
109  acc = MainServicesCfg(flags)
110 
111  from AthenaConfiguration.Enums import Format
112  if flags.Input.Format == Format.POOL:
113  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
114  acc.merge(PoolReadCfg(flags))
115  else:
116  from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
117  acc.merge(ByteStreamReadCfg(flags))
118 
119  from TrigConfigSvc.TrigConfigSvcCfg import L1ConfigSvcCfg, generateL1Menu, createL1PrescalesFileFromMenu
120  acc.merge(L1ConfigSvcCfg(flags))
121  generateL1Menu(flags)
123 
124  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
125  FexEDMList = [
126  'xAOD::eFexEMRoIContainer#L1_eEMRoI','xAOD::eFexEMRoIAuxContainer#L1_eEMRoIAux.',
127  'xAOD::eFexTauRoIContainer#L1_eTauRoI','xAOD::eFexTauRoIAuxContainer#L1_eTauRoIAux.',
128  'xAOD::jFexTauRoIContainer#L1_jFexTauRoI','xAOD::jFexTauRoIAuxContainer#L1_jFexTauRoIAux.',
129  'xAOD::jFexSRJetRoIContainer#L1_jFexSRJetRoI','xAOD::jFexSRJetRoIAuxContainer#L1_jFexSRJetRoIAux.',
130  'xAOD::jFexLRJetRoIContainer#L1_jFexLRJetRoI','xAOD::jFexLRJetRoIAuxContainer#L1_jFexLRJetRoIAux.',
131  'xAOD::jFexMETRoIContainer#L1_jFexMETRoI','xAOD::jFexMETRoIAuxContainer#L1_jFexMETRoIAux.',
132  'xAOD::jFexSumETRoIContainer#L1_jFexSumETRoI','xAOD::jFexSumETRoIAuxContainer#L1_jFexSumETRoIAux.',
133  'xAOD::gFexJetRoIContainer#L1_gFexSRJetRoI','xAOD::gFexJetRoIAuxContainer#L1_gFexSRJetRoIAux.',
134  'xAOD::gFexJetRoIContainer#L1_gFexLRJetRoI','xAOD::gFexJetRoIAuxContainer#L1_gFexLRJetRoIAux.',
135  'xAOD::gFexJetRoIContainer#L1_gFexRhoRoI','xAOD::gFexJetRoIAuxContainer#L1_gFexRhoRoIAux.',
136  'xAOD::gFexGlobalRoIContainer#L1_gScalarEJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gScalarEJwojAux.',
137  'xAOD::gFexGlobalRoIContainer#L1_gMETComponentsJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gMETComponentsJwojAux.',
138  'xAOD::gFexGlobalRoIContainer#L1_gMHTComponentsJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gMHTComponentsJwojAux.',
139  'xAOD::gFexGlobalRoIContainer#L1_gMSTComponentsJwoj','xAOD::gFexGlobalRoIAuxContainer#L1_gMSTComponentsJwojAux.',
140  'xAOD::gFexGlobalRoIContainer#L1_gMETComponentsNoiseCut','xAOD::gFexGlobalRoIAuxContainer#L1_gMETComponentsNoiseCutAux.',
141  'xAOD::gFexGlobalRoIContainer#L1_gMETComponentsRms','xAOD::gFexGlobalRoIAuxContainer#L1_gMETComponentsRmsAux.',
142  'xAOD::gFexGlobalRoIContainer#L1_gScalarENoiseCut','xAOD::gFexGlobalRoIAuxContainer#L1_gScalarENoiseCutAux.',
143  'xAOD::gFexGlobalRoIContainer#L1_gScalarERms','xAOD::gFexGlobalRoIAuxContainer#L1_gScalarERmsAux.',
144  ]
145  acc.merge(OutputStreamCfg(flags, 'AOD', ItemList=FexEDMList))
146 
147 
150 
151  from L1CaloFEXSim.L1CaloFEXSimCfg import L1CaloFEXSimCfg
152  acc.merge(L1CaloFEXSimCfg(flags))
153 
154  # Add in CellMaking, outputs a CaloCellContainer named AllCalo
155  from CaloRec.CaloCellMakerConfig import CaloCellMakerCfg
156  acc.merge(CaloCellMakerCfg(flags))
157 
158 
159 
160  # add the creation of standard 420 Topoclusters
161  from CaloRec.CaloTopoClusterConfig import CaloTopoClusterCfg
162  calo_acc420 = CaloTopoClusterCfg(flags) # default clusters: 420
163  acc.merge(calo_acc420)
164 
165  # Also create 422 topoclusters
166  # PS: cannot find a "civilised" way to set the calorimeter cell energy
167  # cut at 2*sigma cell noise, so do it by force.
168  # Note:
169  # Executing <ComponentAccumator>,printConfig(withDetails=True,
170  # summariseProps=True)
171  # helped to work this out.
172 
173  # 1. set up cluster making with cell energy cut.
174  # 2. avoid container name clashes
175 
176  doLCCalib = flags.Calo.TopoCluster.doTopoClusterLocalCalib
177  clustersname = 'CaloCalTopoClusters422' if doLCCalib else 'CaloTopoClusters422'
178  calo_acc422 = CaloTopoClusterCfg(flags,
179  clustersname=clustersname)
180 
181  def getAlg422(cfg):
182  for comp in cfg.getSequence().Members:
183  if comp.name == 'CaloCalTopoClusters422Maker':
184  return comp
185  return None
186 
187  def fixMakerTool422(alg):
188  if not hasattr(alg, 'ClusterMakerTools'):
189  return False
190 
191  for tool in alg.ClusterMakerTools:
192  if tool.name == 'TopoMaker':
193  assert tool.CellThresholdOnEorAbsEinSigma == 0
194  tool.CellThresholdOnEorAbsEinSigma = 2.0
195  return True
196 
197  return False
198 
200  if not hasattr(alg, 'ClusterCorrectionTools'):
201  return False
202 
203  for tool in alg.ClusterCorrectionTools:
204 
205  if tool.name == 'CaloClusterSnapshot':
206  assert tool.OutputName == 'CaloTopoClusters'
207  if doLCCalib:
208  tool.OutputName = 'CaloCalTopoClusters422Snap'
209  else:
210  tool.OutputName = 'CaloTopoClusters422Snap'
211  return True
212 
213  return False
214 
215 
216  alg = getAlg422(calo_acc422)
217  if alg is None:
218  error('no 422 cluster alg')
219  sys.exit(1)
220 
221  assert fixMakerTool422(alg)
222  assert fixSnapshotTool422(alg)
223 
224  acc.merge(calo_acc422)
225 
226  from AthenaCommon.Constants import DEBUG
227  gepAlgs_output_level = DEBUG
228 
229  from TrigGepPerf.GepClusterTimingAlgConfig import GepClusterTimingAlgCfg
230  acc.merge(GepClusterTimingAlgCfg(flags,
231  OutputLevel=gepAlgs_output_level))
232 
233 
239 
240  from TrigGepPerf.GepPi0AlgConfig import GepPi0AlgCfg
241  # currently caloCellsProducer can be caloCellsFromCaloCells or
242  # caloCellsFromCaloClusters
243  acc.merge(GepPi0AlgCfg(flags,
244  name='GepPi0Alg',
245  caloCellsProducer="caloCellsFromCaloCells",
246  OutputLevel=gepAlgs_output_level))
247 
248  # PS not yet tested: topoclAlgs = ['Calo422']
249  known_cluster_algs = ['WFS', 'Calo420', 'Calo422']
250  for a in clusterAlgNames:
251  assert a in known_cluster_algs
252 
253  known_jet_algs = ['Cone', 'ModAntikT']
254  for a in jetAlgNames:
255  assert a in known_jet_algs
256 
257  # Create a number of Algorithms equal to the size of the product
258  # len(ClusterAlgs) x len(JetAlgs). Will eventually add in
259  # > 1 MET alg, and pileup suppression Algs.
260 
261  caloclustercolls = {('Calo420', False) : 'CaloTopoClusters',
262  ('Calo420', True) : 'CaloCalTopoClusters',
263  ('Calo422', False) : 'CaloTopoClusters422',
264  ('Calo422', True) : 'CaloCalTopoClusters422'}
265 
266 
267  for cluster_alg in clusterAlgNames:
268  caloClustersKey = caloclustercolls.get((cluster_alg, doLCCalib), None)
269  if caloClustersKey is None:
270  from TrigGepPerf.GepClusteringAlgConfig import GepClusteringAlgCfg
271 
272  # Defining the Energy encoding scheme used in GEP
273  NumberOfEnergyBits = 6 # Two bits for energy range, rest to encode energy
274  ValueOfLeastSignificantBit = 10 # in MeV
275  ValueG = 4 # Multiplier for high energy ranges
276 
277  gepEnergyEncodingScheme = str(NumberOfEnergyBits)+"-"+str(ValueOfLeastSignificantBit)+"-"+str(ValueG)
278 
279  caloClustersKey='GEP'+cluster_alg+'Clusters'
280  gepclustering_cfg = GepClusteringAlgCfg(
281  flags,
282  TopoClAlg=cluster_alg,
283  outputCaloClustersKey=caloClustersKey,
284  GEPEnergyEncodingScheme = gepEnergyEncodingScheme,
285  HardwareStyleEnergyEncoding = True,
286  TruncationOfOverflowingFEBs = True,
287  OutputLevel=gepAlgs_output_level)
288 
289 
290  info('gepclustering_cfg dump:')
291  gepclustering_cfg.printConfig(withDetails=True,
292  summariseProps=True)
293 
294  acc.merge(gepclustering_cfg)
295 
296 
297 
298 
299  puSuppressionAlgs = ['']
300 
301  for puSuppressionAlg in puSuppressionAlgs:
302 
303  tcLabel = cluster_alg + puSuppressionAlg
304 
305  for jetAlg in jetAlgNames:
306 
307  from TrigGepPerf.GepJetAlgConfig import GepJetAlgCfg
308  alg_name='Gep'+cluster_alg + jetAlg + 'JetAlg'
309  acc.merge(GepJetAlgCfg(
310  flags,
311  name=alg_name,
312  jetAlgName=jetAlg,
313  caloClustersKey=caloClustersKey,
314  outputJetsKey='GEP' + cluster_alg + jetAlg +'Jets',
315  OutputLevel=gepAlgs_output_level))
316 
317  info('\nGepJetAlg properties dump\n')
318  info(str(acc.getEventAlgo(alg_name)._properties))
319 
320  from TrigGepPerf.GepMETAlgConfig import GepMETAlgCfg
321  alg_name='GepMET'+ cluster_alg +'Alg'
322  acc.merge(GepMETAlgCfg(
323  flags,
324  name=alg_name,
325  caloClustersKey=caloClustersKey,
326  outputMETKey='GEP'+ cluster_alg +'MET',
327  OutputLevel=gepAlgs_output_level))
328 
329 
330  from TrigGepPerf.GepMETPufitAlgConfig import GepMETPufitAlgCfg
331  alg_name='GepMET' + cluster_alg + 'PufitAlg'
332  acc.merge(GepMETPufitAlgCfg(
333  flags,
334  name=alg_name,
335  caloClustersKey=caloClustersKey,
336  outputMETPufitKey='GEP'+ cluster_alg + 'METPufit',
337  OutputLevel=gepAlgs_output_level))
338 
341  with open("L1Sim.pkl", "wb") as f:
342  acc.store(f)
343  f.close()
344 
345  if args.execute:
346  sc = acc.run()
347  if sc.isFailure():
348  exit(1)
GepMETPufitAlgConfig.GepMETPufitAlgCfg
def GepMETPufitAlgCfg(flags, name, caloClustersKey, outputMETPufitKey, OutputLevel=None)
Definition: GepMETPufitAlgConfig.py:6
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
GepClusterTimingAlgConfig.GepClusterTimingAlgCfg
def GepClusterTimingAlgCfg(flags, name='GepClusterTimingAlg', inCaloClustersKey='CaloTopoClusters', outCaloClustersKey='Clusters420Timing', lambdaCalDivide=317, qualityCut=0.02, timeCutLargeQ=5, timeCutSmallQ=15, maxEtaForCut=5.0, OutputLevel=None)
Definition: GepClusterTimingAlgConfig.py:13
python.TrigConfigSvcCfg.createL1PrescalesFileFromMenu
def createL1PrescalesFileFromMenu(flags)
Definition: TrigConfigSvcCfg.py:165
python.TrigConfigSvcCfg.generateL1Menu
def generateL1Menu(flags)
Definition: TrigConfigSvcCfg.py:184
run_gep.info
info
Definition: run_gep.py:13
python.ByteStreamConfig.ByteStreamReadCfg
def ByteStreamReadCfg(flags, type_names=None)
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:25
python.CaloCellMakerConfig.CaloCellMakerCfg
def CaloCellMakerCfg(flags)
Definition: CaloCellMakerConfig.py:12
run_gep.fixMakerTool422
def fixMakerTool422(alg)
Definition: run_gep.py:187
run_gep.fixSnapshotTool422
def fixSnapshotTool422(alg)
Definition: run_gep.py:199
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
GepJetAlgConfig.GepJetAlgCfg
def GepJetAlgCfg(flags, name, jetAlgName, caloClustersKey, outputJetsKey, OutputLevel=None)
Definition: GepJetAlgConfig.py:6
calibdata.exit
exit
Definition: calibdata.py:236
GepClusteringAlgConfig.GepClusteringAlgCfg
def GepClusteringAlgCfg(flags, name='GepClusteringAlg', TopoClAlg='CaloWFS', outputCaloClustersKey='GEPWFSClusters', GEPEnergyEncodingScheme="6-10-4", HardwareStyleEnergyEncoding=True, TruncationOfOverflowingFEBs=True, OutputLevel=None)
Definition: GepClusteringAlgConfig.py:18
python.CaloTopoClusterConfig.CaloTopoClusterCfg
def CaloTopoClusterCfg(flags, cellsname="AllCalo", clustersname=None, clustersnapname="CaloTopoClusters")
Definition: CaloTopoClusterConfig.py:318
python.DetectorConfigFlags.setupDetectorFlags
def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False)
Definition: DetectorConfigFlags.py:289
GepMETAlgConfig.GepMETAlgCfg
def GepMETAlgCfg(flags, name, caloClustersKey, outputMETKey, OutputLevel=None)
Definition: GepMETAlgConfig.py:6
python.TrigConfigSvcCfg.L1ConfigSvcCfg
def L1ConfigSvcCfg(flags)
Definition: TrigConfigSvcCfg.py:198
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
GepPi0AlgConfig.GepPi0AlgCfg
def GepPi0AlgCfg(flags, name, caloCellsProducer="EMB1CellsFromCaloClusters", dump=False, OutputLevel=None)
Definition: GepPi0AlgConfig.py:6
str
Definition: BTagTrackIpAccessor.cxx:11
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
error
Definition: IImpactPoint3dEstimator.h:70
run_gep.getAlg422
def getAlg422(cfg)
Definition: run_gep.py:181
L1CaloFEXSimCfg
Definition: L1CaloFEXSimCfg.py:1