ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimLayerStudyConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
3from AthenaConfiguration.ComponentFactory import CompFactory
4from AthenaCommon.Logging import logging
5
6
7import AthenaCommon.Utils.unixtools as unixtools
8import importlib
9import os
10from FPGATrackSimConfTools.FPGATrackSimSecondStageConfig import getPadding
11
12log = logging.getLogger ('FPGATrackSim')
13
14
15from FPGATrackSimConfTools import FPGATrackSimDataPrepConfig
16from FPGATrackSimConfTools import FPGATrackSimAnalysisConfig
17
19 # This can probably be imported in the future from the analysis config, but for now it's here.
20 result = ComponentAccumulator()
21 log.info("Setting binning parameters")
22
23 # Allow the initial set of cuts to be read in via config flags, instead of the cuts file.
24 # This effectively eliminates the need to make a "step 0" cut file.
25 # If not set then default to loading the cuts file.
26 if flags.Trigger.FPGATrackSim.GenScan.initialLayerStudy:
27 cutset = {"rin": flags.Trigger.FPGATrackSim.GenScan.rin,
28 "rout": flags.Trigger.FPGATrackSim.GenScan.rout,
29 "parBins": flags.Trigger.FPGATrackSim.GenScan.parBins,
30 "parMin": flags.Trigger.FPGATrackSim.GenScan.parMin,
31 "parMax": flags.Trigger.FPGATrackSim.GenScan.parMax,
32 "parSet": flags.Trigger.FPGATrackSim.GenScan.parSet
33 }
34 log.info("Running initial layer study, taking FPGATrackSimBinning cuts from flags")
35 log.info(cutset)
36 elif flags.Trigger.FPGATrackSim.GenScan.layerStudyCutFile:
37 if flags.Trigger.FPGATrackSim.oldRegionDefs:
38 cutset = importlib.import_module(flags.Trigger.FPGATrackSim.GenScan.layerStudyCutFile).cuts[flags.Trigger.FPGATrackSim.region]
39 else:
40 # this allows the cut file defined in python to be loaded from the map directory
41 # Updated to use python path resolver. It seems like we have to manually pass in CALIBPATH.
42 relpath = os.path.join(flags.Trigger.FPGATrackSim.mapsDir, flags.Trigger.FPGATrackSim.GenScan.layerStudyCutFile + ".py")
43 abspath = unixtools.find_datafile(relpath, pathlist=os.getenv("CALIBPATH").split(":"))
44 spec=importlib.util.spec_from_file_location("FPGATrackSimGenScanCuts", abspath)
45 if spec is None:
46 log.fatal("Failed to load cuts file")
47 cutmodule = importlib.util.module_from_spec(spec)
48 spec.loader.exec_module(cutmodule)
49 cutset=cutmodule.cuts[flags.Trigger.FPGATrackSim.region]
50 log.info("Running layer study using configured cuts file")
51 log.info(cutset)
52 else:
53 log.fatal("Must either set initialLayerStudy=True or set layerStudyCutFile to the name of a cut file!")
54
55 # make the binned hits class
56 BinnnedHits = CompFactory.FPGATrackSimBinnedHits("BinnedHits_LayerStudy")
57 BinnnedHits.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
58 BinnnedHits.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
59
60 # make the bintool class
61 BinTool = CompFactory.FPGATrackSimBinTool("BinTool_LayerStudy")
62 BinTool.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
63
64 # Inputs for the BinTool
65 binsteps=[]
66 BinDesc=None
67 if (cutset["parSet"]=="PhiSlicedKeyLyrPars"):
68 BinDesc = CompFactory.FPGATrackSimKeyLayerBinDesc("KeyLayerBinDescLayerStudy")
69 BinDesc.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
70 BinDesc.rin=cutset["rin"]
71 BinDesc.rout=cutset["rout"]
72 phirange = FPGATrackSimDataPrepConfig.getPhiRange(flags)
73 if flags.Trigger.FPGATrackSim.GenScan.useLayerRadiiFile:
74 phicenter = (phirange[0]+phirange[1])/2.0
75 BinDesc.PhiOffset = -1.0*phicenter
76
77 BinDesc.region = flags.Trigger.FPGATrackSim.region
78
79 # parameters for key layer bindesc are :"zR1", "zR2", "phiR1", "phiR2", "xm"
80 step1 = CompFactory.FPGATrackSimBinStep("PhiBinning")
81 step1.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
82 step1.parBins = [1,1,cutset["parBins"][2],cutset["parBins"][3],cutset["parBins"][4]]
83 step2 = CompFactory.FPGATrackSimBinStep("FullBinning")
84 step2.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
85 step2.parBins = cutset["parBins"]
86 binsteps = [step1,step2]
87 else:
88 log.fatal("Unknown Binning Setup: ",cutset["parSet"])
89
90 BinTool.BinDesc = BinDesc
91 BinTool.Steps = binsteps
92
93
94 # configure the padding around the nominal region
95 BinTool.d0FractionalPadding =0.05
96 BinTool.z0FractionalPadding =0.05
97 BinTool.etaFractionalPadding =0.05
98 BinTool.phiFractionalPadding =0.05
99 BinTool.qOverPtFractionalPadding =0.05
100 BinTool.parMin = cutset["parMin"]
101 BinTool.parMax = cutset["parMax"]
102 BinnnedHits.BinTool = BinTool
103
104 result.setPrivateTools(BinnnedHits)
105
106 return result
107
109 result=ComponentAccumulator()
110
111 Monitor = CompFactory.FPGATrackSimLayerStudyTool("BinMonitoring")
112 Monitor.THistSvc = CompFactory.THistSvc()
113 Monitor.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
114 Monitor.phiScale = 10.0
115 Monitor.etaScale = 100.0
116 Monitor.drScale = 20.0
117 Monitor.plotAllBins = False
118
119 Monitor.D0Pad=getPadding(flags.Trigger.FPGATrackSim.region)["d0"]
120 Monitor.EtaPad=getPadding(flags.Trigger.FPGATrackSim.region)["eta"]
121 Monitor.QPtPad=getPadding(flags.Trigger.FPGATrackSim.region)["qpt"]
122 Monitor.PhiPad=getPadding(flags.Trigger.FPGATrackSim.region)["phi"]
123 Monitor.Z0Pad=getPadding(flags.Trigger.FPGATrackSim.region)["z0"]
124
125 result.setPrivateTools(Monitor)
126 return result
127
129 from AthenaConfiguration.ComponentFactory import CompFactory
130 flags = FPGATrackSimAnalysisConfig.prepareFlagsForFPGATrackSimLogicalHitsProcessAlg(flags)
131 result = ComponentAccumulator()
132 if not flags.Trigger.FPGATrackSim.wrapperFileName:
133 from InDetConfig.InDetPrepRawDataFormationConfig import AthenaTrkClusterizationCfg
134 result.merge(AthenaTrkClusterizationCfg(flags))
135
136 reg = flags.Trigger.FPGATrackSim.region
137
138 monitor_tool = CompFactory.FPGATrackSimLayerStudyTool(
139 f"BinMonitoring_reg{reg}",
140 LayerStudyTreeName=FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags, "LayerStudy"),
141 TruthTreeName=FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags, "TruthTree"),
142 )
143
144 theFPGATrackSimLayerStudyAlg = CompFactory.FPGATrackSimLayerStudyAlg(name=f"FPGATrackSimLayerStudyAlg_reg{reg}")
145
146 theFPGATrackSimLayerStudyAlg.BinningTool = result.getPrimaryAndMerge(FPGATrackSimBinnedHitsToolCfg(flags))
147 theFPGATrackSimLayerStudyAlg.BinMonitoringTool = monitor_tool
148 theFPGATrackSimLayerStudyAlg.threshold = flags.Trigger.FPGATrackSim.ActiveConfig.threshold[0]
149 theFPGATrackSimLayerStudyAlg.stage = flags.Trigger.FPGATrackSim.layerStudyStage
150 theFPGATrackSimLayerStudyAlg.eventSelector = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
151 theFPGATrackSimLayerStudyAlg.FPGATrackSimMapping = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
152
153 result.addEventAlgo(theFPGATrackSimLayerStudyAlg)
154 return result
155
156
157if __name__ == "__main__":
158
159 from AthenaConfiguration.AllConfigFlags import initConfigFlags
160 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
161
162
163 flags = initConfigFlags()
164
165
167 FinalProtoTrackChainxAODTracksKey="FPGA"
168 flags.Detector.EnableCalo = False
169
170 # ensure that the xAOD SP and cluster containers are available
171 flags.Tracking.ITkMainPass.doAthenaToActsSpacePoint=True
172 flags.Tracking.ITkMainPass.doAthenaToActsCluster=True
173 from ActsConfig.ActsCIFlags import actsLegacyWorkflowFlags
174 actsLegacyWorkflowFlags(flags)
175 flags.Acts.doRotCorrection = False
176
177
178 flags.Concurrency.NumThreads=1
179 #flags.Concurrency.NumProcs=0
180 flags.Scheduler.ShowDataDeps=True
181 flags.Scheduler.CheckDependencies=True
182 flags.Debug.DumpEvtStore=False
183
184 # flags.Exec.DebugStage="exec" # useful option to debug the execution of the job - we want it commented out for production
185 flags.fillFromArgs()
186
187
188 if isinstance(flags.Trigger.FPGATrackSim.wrapperFileName, str):
189 log.info("wrapperFile is string, converting to list")
190 flags.Trigger.FPGATrackSim.wrapperFileName = [flags.Trigger.FPGATrackSim.wrapperFileName]
191 flags.Input.Files = lambda f: [f.Trigger.FPGATrackSim.wrapperFileName]
192
193 # The region map needs to not be loaded when running layer study; we set this here to
194 # guarantee it propagates consistently to all code that tries to set up the mapping service.
195 flags.Trigger.FPGATrackSim.loadRegionMap = False
196 flags.Trigger.FPGATrackSim.loadRadii = False
197
198 # We also don't want to load any of the ONNX files, so set them to the empty string.
199 # Again, override the user.
200 flags.Trigger.FPGATrackSim.FakeNNonnxFile1st = ""
201 flags.Trigger.FPGATrackSim.FakeNNonnxFile2nd = ""
202 flags.Trigger.FPGATrackSim.ParamNNonnxFile1st = ""
203 flags.Trigger.FPGATrackSim.ParamNNonnxFile2nd = ""
204 flags.Trigger.FPGATrackSim.ExtensionNNVolonnxFile = ""
205 flags.Trigger.FPGATrackSim.ExtensionNNHitonnxFile = ""
206
207 flags.lock()
208 flags.dump()
209 flags = flags.cloneAndReplace("Tracking.ActiveConfig","Tracking.MainPass")
210 acc=MainServicesCfg(flags)
211
212
213 if flags.Trigger.FPGATrackSim.writeAdditionalOutputData:
214 acc.addService(CompFactory.THistSvc(Output = ["EXPERT DATAFILE='monitoring.root', OPT='RECREATE'"]))
215
216
217 # Always produce the "genscan" layer study tree.
218 if (flags.Trigger.FPGATrackSim.Hough.genScan):
219 acc.addService(CompFactory.THistSvc(Output = ["GENSCAN DATAFILE='genscan.root', OPT='RECREATE'"]))
220
221 if not flags.Trigger.FPGATrackSim.wrapperFileName:
222 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
223 acc.merge(PoolReadCfg(flags))
224
225 if flags.Input.isMC:
226 from xAODTruthCnv.xAODTruthCnvConfig import GEN_AOD2xAODCfg
227 acc.merge(GEN_AOD2xAODCfg(flags))
228
229 from JetRecConfig.JetRecoSteering import addTruthPileupJetsToOutputCfg # TO DO: check if this is indeed necessary for pileup samples
230 acc.merge(addTruthPileupJetsToOutputCfg(flags))
231
232 if flags.Detector.EnableCalo:
233 from CaloRec.CaloRecoConfig import CaloRecoCfg
234 acc.merge(CaloRecoCfg(flags))
235
236 if flags.Tracking.recoChain:
237 from InDetConfig.TrackRecoConfig import InDetTrackRecoCfg
238 acc.merge(InDetTrackRecoCfg(flags))
239
240 #Configure Multiregion config algo for layerstudyalg
241 from FPGATrackSimConfTools.FPGATrackSimMultiRegionConfig import FPGATrackSimRunLayerStudyOnManyRegions
242 acc.merge(FPGATrackSimRunLayerStudyOnManyRegions(flags))
243
244 # Configure dataprep as well; layerstudy is already configured above
245 acc.merge(FPGATrackSimDataPrepConfig.FPGATrackSimDataPrepAlgCfg(flags))
246
247 acc.store(open('AnalysisConfig.pkl','wb'))
248 acc.foreach_component("*FPGATrackSim*").OutputLevel=flags.Trigger.FPGATrackSim.loglevel
249 if flags.Trigger.FPGATrackSim.msgLimit!=-1:
250 acc.getService("MessageSvc").debugLimit = flags.Trigger.FPGATrackSim.msgLimit
251 acc.getService("MessageSvc").infoLimit = flags.Trigger.FPGATrackSim.msgLimit
252
253 statusCode = acc.run(flags.Exec.MaxEvents)
254 assert statusCode.isSuccess() is True, "Application execution did not succeed"
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177