ATLAS Offline Software
JetRecAlgTestCfg.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
7 
8 # Config flags steer the job at various levels
9 from AthenaConfiguration.AllConfigFlags import initConfigFlags
10 flags = initConfigFlags()
11 flags.Input.isMC = True
12 # Grab standard test file (annoyingly, set incorrectly in master?)
13 flags.Input.Files = ["/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/CommonInputs/mc16_13TeV.410501.PowhegPythia8EvtGen_A14_ttbar_hdamp258p75_nonallhad.merge.AOD.e5458_s3126_r9364_r9315/AOD.11182705._000001.pool.root.1"]
14 
15 # Flags relating to multithreaded execution
16 flags.Concurrency.NumThreads = 1
17 # Dump some information about the job scheduling
18 flags.Scheduler.ShowDataDeps = True
19 flags.Scheduler.ShowDataFlow = True
20 flags.Scheduler.ShowControlFlow = True
21 flags.Concurrency.NumConcurrentEvents = 1
22 
23 # Prevent the flags from being modified
24 flags.lock()
25 
26 
29 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
30 
31 # Get a ComponentAccumulator setting up the fundamental Athena job
32 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
33 cfg=MainServicesCfg(flags)
34 
35 # Add the components for reading in pool files
36 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
37 cfg.merge(PoolReadCfg(flags))
38 
39 # This import is needed to get components (tools, algs)
40 # See https://indico.cern.ch/event/871612/contributions/3677824/attachments/1963726/3264714/UseCompFactory.pdf
41 from AthenaConfiguration.ComponentFactory import CompFactory
42 
43 # Return a ComponentAccumulator holding the jet input sequence
44 def JetInputCfg(flags):
45  # Create a sequence that holds a set of algorithms
46  # -- mainly for understanding how chunks of the job
47  # relate to each other
48  sequencename = "JetInputSeq"
49  inputcfg = ComponentAccumulator()
50  inputcfg.addSequence( CompFactory.AthSequencer(sequencename, ModeOR=True) )
51 
52 
53  from xAODBase.xAODType import xAODType
54 
55  # Apply some corrections to the topoclusters
56  # Example with property assignments
57  jetmodseq = CompFactory.JetConstituentModSequence("JetMod_LCOrigin")
58  jetmodseq.InputType=xAODType.CaloCluster
59  jetmodseq.InputContainer = "CaloCalTopoClusters"
60  jetmodseq.OutputContainer = "LCOriginTopoClusters"
61 
62  # Build the list of modifiers to run
63  # Configuration with constructor keywords
64  modlist = [
65  CompFactory.CaloClusterConstituentsOrigin("ClusterOrigin",InputType=xAODType.CaloCluster)
66  ]
67  jetmodseq.Modifiers = modlist
68 
69  # We need a JetAlgorithm to run the modseq, which is a tool
70  jetmodalg = CompFactory.JetAlgorithm(
71  "JetModAlg_LCOrigin",
72  Tools = [jetmodseq])
73 
74  # Add the alg to the sequence in the ComponentAccumulator
75  inputcfg.addEventAlgo(jetmodalg,sequencename)
76 
77  # Create a PseudoJetAlgorithm
78 
79  constitpjgalg = CompFactory.PseudoJetAlgorithm(
80  "pjgalg_LCTopo",
81  InputContainer = "LCOriginTopoClusters",
82  OutputContainer = "PseudoJetLCTopo",
83  Label = "LCTopo",
84  SkipNegativeEnergy=True)
85 
86  ghostpjgalg = CompFactory.PseudoJetAlgorithm(
87  "pjgalg_GhostTruth",
88  InputContainer = "TruthParticles",
89  OutputContainer = "PseudoJetGhostTruth",
90  Label = "GhostTruth",
91  SkipNegativeEnergy=True)
92 
93  pjcs = [constitpjgalg.OutputContainer,ghostpjgalg.OutputContainer]
94 
95  # Add the algs to the sequence in the ComponentAccumulator
96  inputcfg.addEventAlgo(constitpjgalg,sequencename)
97  inputcfg.addEventAlgo(ghostpjgalg,sequencename)
98 
99  return inputcfg, pjcs
100 
101 # Return a ComponentAccumulator holding the jet building sequence
102 def JetBuildAlgCfg(flags,buildjetsname):
103  buildcfg = ComponentAccumulator()
104 
105  # Create a sequence that holds a set of algorithms
106  # -- mainly for understanding how chunks of the job
107  # relate to each other
108 
109  sequencename = "JetBuildSeq"
110  buildcfg.addSequence( CompFactory.AthSequencer(sequencename) )
111  # Merge in config to get jet inputs
112  inputcfg, pjcs = JetInputCfg(flags)
113  buildcfg.merge(inputcfg)
114 
115  # Create a merger to build the PseudoJetContainer for this specific jet collection
116  mergepjalg = CompFactory.PseudoJetMerger(
117  "pjmergealg_"+buildjetsname,
118  InputPJContainers = pjcs,
119  OutputContainer = "PseudoJetMerged_"+buildjetsname)
120 
121  buildcfg.addEventAlgo(mergepjalg)
122 
123  # Create the JetClusterer, set some standard options
124  jclust = CompFactory.JetClusterer("builder")
125  jclust.JetAlgorithm = "AntiKt"
126  jclust.JetRadius = 1.0
127  jclust.PtMin = 10e3 # MeV
128  jclust.GhostArea = 0.01
129  jclust.InputPseudoJets = "PseudoJetMerged_"+buildjetsname
130  jclust.JetInputType = 1 # Hardcoded "magic number" for now
131  # See https://gitlab.cern.ch/atlas/athena/blob/master/Event/xAOD/xAODJet/xAODJet/JetContainerInfo.h
132  # This should get its own dictionary.
133 
134  # Add a simple jet modifier to the JetRecAlg
135  jclsmoms = CompFactory.JetClusterMomentsTool("clsmoms",
136  JetContainer = buildjetsname)
137 
138  # Create the JetRecAlg, configure it to use the builder
139  # using constructor syntax instead
140  # (equivalent to setting properties with "=")
141  jra = CompFactory.JetRecAlg(
142  "JRA_build",
143  Provider = jclust, # Single ToolHandle
144  Modifiers = [jclsmoms], # ToolHandleArray
145  OutputContainer = buildjetsname)
146 
147  # Add the alg to the ComponentAccumulator in the named sequence
148  buildcfg.addEventAlgo( jra, sequencename )
149  return buildcfg
150 
151 # Return a ComponentAccumulator holding the jet groom sequence
152 def JetGroomAlgCfg(flags,buildjetsname,groomjetsname):
153  groomcfg = ComponentAccumulator()
154 
155  # Create a sequence that holds a set of algorithms
156  # -- mainly for understanding how chunks of the job
157  # relate to each other
158  sequencename = "JetGroomSeq"
159  groomcfg.addSequence( CompFactory.AthSequencer(sequencename) )
160 
161  # Create the JetGroomer, provide it with a JetTrimmer
162  jtrim = CompFactory.getComp("JetGrooming::JetTrimming")("trimSmallR2Frac5",RClus=0.2,PtFrac=0.05)
163  jtrim.UngroomedJets = buildjetsname
164  jtrim.ParentPseudoJets = "PseudoJetMerged_"+buildjetsname
165 
166  # Create the JetRecAlg, configure it to use the builder
167  # using constructor syntax instead
168  # (equivalent to setting properties with "=")
169  jra = CompFactory.JetRecAlg(
170  "JRA_trim",
171  Provider = jtrim, # Single ToolHandle
172  Modifiers = [], # ToolHandleArray
173  OutputContainer = groomjetsname)
174 
175  # Add the alg to the ComponentAccumulator in the named sequence
176  groomcfg.addEventAlgo( jra, sequencename )
177  return groomcfg
178 
179 # Return a ComponentAccumulator holding the jet copy sequence
180 def JetCopyAlgCfg(flags,buildjetsname,copyjetsname):
181  copycfg = ComponentAccumulator()
182 
183  # Create a sequence that holds a set of algorithms
184  # -- mainly for understanding how chunks of the job
185  # relate to each other
186  sequencename = "JetCopySeq"
187  copycfg.addSequence( CompFactory.AthSequencer(sequencename) )
188 
189  # Create the JetCopier, set some standard options
190  jcopy = CompFactory.JetCopier("copier")
191  jcopy.InputJets = buildjetsname
192 
193  # Add a simple jet modifier to the JetRecAlg
194  jclsmoms = CompFactory.JetClusterMomentsTool("clsmoms",
195  JetContainer = copyjetsname)
196 
197  # Create the JetRecAlg, configure it to use the copier
198  # using constructor syntax instead
199  # (equivalent to setting properties with "=")
200  jra = CompFactory.JetRecAlg(
201  "JRA_copy",
202  Provider = jcopy, # Single ToolHandle
203  Modifiers = [jclsmoms], # ToolHandleArray
204  OutputContainer = copyjetsname)
205 
206  # Add the alg to the ComponentAccumulator in the named sequence
207  copycfg.addEventAlgo( jra, sequencename )
208  return copycfg
209 
210 if __name__=="__main__":
211  # Add the build config to the job
212  # One could add options to make it more customisable
213  buildjetsname = "MyAntiKt10LCTopoJets"
214  groomjetsname = "MyAntiKt10LCTopoTrimmedSmallR5Frac20Jets"
215  copyjetsname = "CopyAntiKt10LCTopoJets"
216  cfg.merge( JetBuildAlgCfg(flags, buildjetsname) )
217  cfg.merge( JetGroomAlgCfg(flags, buildjetsname, groomjetsname) )
218  cfg.merge( JetCopyAlgCfg(flags, buildjetsname, copyjetsname) )
219 
220  # Write what we produced to AOD
221  # First define the output list
222  outputlist = ["EventInfo#*"]
223  jetlist = [buildjetsname,groomjetsname,copyjetsname]
224  for jetcoll in jetlist:
225  if "Copy" in jetcoll:
226  outputlist += ["xAOD::JetContainer#"+copyjetsname,
227  "xAOD::ShallowAuxContainer#"+copyjetsname+"Aux.-PseudoJet"]
228  else:
229  outputlist += ["xAOD::JetContainer#"+jetcoll,
230  "xAOD::JetAuxContainer#"+jetcoll+"Aux.-PseudoJet"]
231 
232  # Now get the output stream components
233  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName
234  cfg.merge(OutputStreamCfg(flags,"xAOD",ItemList=outputlist))
235  from pprint import pprint
236  pprint( cfg.getEventAlgo(outputStreamName("xAOD")).ItemList )
237  cfg.printConfig()
238  # For local tests, not in the CI
239  # Print the contents of the store every event
240  # cfg.getService("StoreGateSvc").Dump = True
241 
242  # Run the job
243  cfg.run(maxEvents=10)
AthenaPoolExample_WriteCond.outputStreamName
string outputStreamName
Definition: AthenaPoolExample_WriteCond.py:21
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
JetRecAlgTestCfg.JetGroomAlgCfg
def JetGroomAlgCfg(flags, buildjetsname, groomjetsname)
Definition: JetRecAlgTestCfg.py:152
JetRecAlgTestCfg.JetCopyAlgCfg
def JetCopyAlgCfg(flags, buildjetsname, copyjetsname)
Definition: JetRecAlgTestCfg.py:180
JetRecAlgTestCfg.JetBuildAlgCfg
def JetBuildAlgCfg(flags, buildjetsname)
Definition: JetRecAlgTestCfg.py:102
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:259
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
JetRecAlgTestCfg.JetInputCfg
def JetInputCfg(flags)
Definition: JetRecAlgTestCfg.py:44
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69