ATLAS Offline Software
Loading...
Searching...
No Matches
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
9from AthenaConfiguration.AllConfigFlags import initConfigFlags
10flags = initConfigFlags()
11flags.Input.isMC = True
12# Grab standard test file (annoyingly, set incorrectly in master?)
13flags.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
16flags.Concurrency.NumThreads = 1
17# Dump some information about the job scheduling
18flags.Scheduler.ShowDataDeps = True
19flags.Scheduler.ShowDataFlow = True
20flags.Scheduler.ShowControlFlow = True
21flags.Concurrency.NumConcurrentEvents = 1
22
23# Prevent the flags from being modified
24flags.lock()
25
26
29from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
30
31# Get a ComponentAccumulator setting up the fundamental Athena job
32from AthenaConfiguration.MainServicesConfig import MainServicesCfg
33cfg=MainServicesCfg(flags)
34
35# Add the components for reading in pool files
36from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
37cfg.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
41from AthenaConfiguration.ComponentFactory import CompFactory
42
43# Return a ComponentAccumulator holding the jet input sequence
44def 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
102def 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
152def 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
180def 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
210if __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)
JetGroomAlgCfg(flags, buildjetsname, groomjetsname)
JetBuildAlgCfg(flags, buildjetsname)
JetCopyAlgCfg(flags, buildjetsname, copyjetsname)