ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimAnalysisConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
3from AthenaConfiguration.ComponentFactory import CompFactory
4from AthenaCommon.Logging import AthenaLogger
5from PathResolver import PathResolver
6import importlib
7import os
8
9log = AthenaLogger(__name__)
10
11
12from FPGATrackSimConfTools import FPGATrackSimDataPrepConfig
13
14
15def getEtaBin(flags):
16 etaBin = (flags.Trigger.FPGATrackSim.region >> 6) & 0x1f
17 return etaBin
18
19def getFitWeights(etaBin):
20 weight4Eta = [563.9382667,493.23055,381.835315,264.7819679,179.555554,116.0867029,96.30409326,96.13504916,163.7278321,270.5480971,270.6937626,180.2164132,129.0011743,91.50412962,72.65953377,49.77568766,32.518927,20.38964651,12.97547848,8.05716611]
21 weight4Phi = [5291.005291,4784.688995,4739.336493,4329.004329,3508.77193,3278.688525,4366.812227,6756.756757,10752.68817,14925.37313,16666.66667,16949.15254,17543.85965,16666.66667,19230.76923,20833.33333,20408.16327,20000,20000,18181.81818]
22 weights5Eta = [217.5331768,184.2304061,148.3134888,98.13939253,66.37534817,42.93312711,33.65526204,34.33247487,47.5202135,77.16881734,110.4844013,100.8706594,83.79061435,58.69032222,44.9857434,30.5678705,18.85832071,12.76889006,8.270441607,5.426907903]
23 weights5Phi = [1302.083333,1138.952164,1068.376068,961.5384615,831.9467554,764.5259939,996.0159363,1481.481481,2857.142857,3875.968992,4504.504505,5076.142132,5681.818182,5747.126437,6493.506494,6578.947368,6622.516556,6802.721088,6849.315068,6578.947368]
24
25 assert(etaBin >= 0 and etaBin < 20)
26 return [weight4Eta[etaBin], weight4Phi[etaBin], weights5Eta[etaBin], weights5Phi[etaBin]]
27
28def getNSubregions(filePath):
29 with open(PathResolver.FindCalibFile(filePath), 'r') as f:
30 fields = f.readline()
31 assert(fields.startswith('towers'))
32 n = fields.split()[1]
33 return int(n)
34
35
36# Need to figure out if we have two output writers or somehow only one.
38 result=ComponentAccumulator()
39 FPGATrackSimWriteOutput = CompFactory.FPGATrackSimOutputHeaderTool("FPGATrackSimWriteOutput")
40 FPGATrackSimWriteOutput.InFileName = ["test.root"]
41 FPGATrackSimWriteOutput.OutputTreeName = FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimLogicalEventTree")
42
43 if not flags.Trigger.FPGATrackSim.writeAdditionalOutputData:
44 FPGATrackSimWriteOutput.EventLimit = 0
45 else:
46 FPGATrackSimWriteOutput.EventLimit = flags.Trigger.FPGATrackSim.writeOutputEventLimit
47 if flags.Trigger.FPGATrackSim.writeRegion>=0: # negative is off
48 FPGATrackSimWriteOutput.RequireActivation=True
49 # RECREATE means that that this tool opens the file.
50 # HEADER would mean that something else (e.g. THistSvc) opens it and we just add the object.
51 FPGATrackSimWriteOutput.RWstatus = "HEADER"
52 FPGATrackSimWriteOutput.THistSvc = CompFactory.THistSvc()
53 result.setPrivateTools(FPGATrackSimWriteOutput)
54 return result
55
56def FPGATrackSimSlicingEngineCfg(flags,name="FPGATrackSimSlicingEngineTool"):
57 result = ComponentAccumulator()
58 FPGATrackSimSlicingEngineTool = CompFactory.FPGATrackSimSlicingEngineTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
59 # this is the same as the layer map used by the genscan/inside out tool below.
60 FPGATrackSimSlicingEngineTool.LayerMap = os.path.join(PathResolver.FindCalibDirectory(flags.Trigger.FPGATrackSim.mapsDir),f"{FPGATrackSimDataPrepConfig.getBaseName(flags)}_lyrmap.json")
61 FPGATrackSimSlicingEngineTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
62 # If the GNN is enabled (i.e. this is F-4xx) then we don't want to separate first vs second stage.
63 FPGATrackSimSlicingEngineTool.doSecondStage = (not flags.Trigger.FPGATrackSim.ActiveConfig.GNN)
64 FPGATrackSimSlicingEngineTool.RootOutput = flags.Trigger.FPGATrackSim.writeAdditionalOutputData
65 result.setPrivateTools(FPGATrackSimSlicingEngineTool)
66 return result
67
68def FPGATrackSimBankSvcCfg(flags,name="FPGATrackSimBankSvc"):
69 result=ComponentAccumulator()
70 FPGATrackSimBankSvc = CompFactory.FPGATrackSimBankSvc(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
71 FPGATrackSimBankSvc.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
72 pathBankSvc = flags.Trigger.FPGATrackSim.bankDir if flags.Trigger.FPGATrackSim.bankDir != '' else f'/eos/atlas/atlascerngroupdisk/det-htt/HTTsim/{flags.GeoModel.AtlasVersion}/21.9.16/'+FPGATrackSimDataPrepConfig.getBaseName(flags)+'/SectorBanks/'
73 pathBankSvc=PathResolver.FindCalibDirectory(pathBankSvc)
74 FPGATrackSimBankSvc.constantsNoGuess_1st = [
75 f'{pathBankSvc}corrgen_raw_8L_skipPlane0.gcon',
76 f'{pathBankSvc}corrgen_raw_8L_skipPlane1.gcon',
77 f'{pathBankSvc}corrgen_raw_8L_skipPlane2.gcon',
78 f'{pathBankSvc}corrgen_raw_8L_skipPlane3.gcon',
79 f'{pathBankSvc}corrgen_raw_8L_skipPlane4.gcon',
80 f'{pathBankSvc}corrgen_raw_8L_skipPlane5.gcon',
81 f'{pathBankSvc}corrgen_raw_8L_skipPlane6.gcon',
82 f'{pathBankSvc}corrgen_raw_8L_skipPlane7.gcon']
83 FPGATrackSimBankSvc.constantsNoGuess_2nd = [
84 f'{pathBankSvc}corrgen_raw_13L_skipPlane0.gcon',
85 f'{pathBankSvc}corrgen_raw_13L_skipPlane1.gcon',
86 f'{pathBankSvc}corrgen_raw_13L_skipPlane2.gcon',
87 f'{pathBankSvc}corrgen_raw_13L_skipPlane3.gcon',
88 f'{pathBankSvc}corrgen_raw_13L_skipPlane4.gcon',
89 f'{pathBankSvc}corrgen_raw_13L_skipPlane5.gcon',
90 f'{pathBankSvc}corrgen_raw_13L_skipPlane6.gcon',
91 f'{pathBankSvc}corrgen_raw_13L_skipPlane7.gcon']
92 layers="5L" if flags.Trigger.FPGATrackSim.ActiveConfig.genScan else "9L"
93 s2_layers = 13
94 pathMapSvc = flags.Trigger.FPGATrackSim.mapsDir if flags.Trigger.FPGATrackSim.mapsDir != '' else f'/eos/atlas/atlascerngroupdisk/det-htt/HTTsim/{flags.GeoModel.AtlasVersion}/21.9.16/'+FPGATrackSimDataPrepConfig.getBaseName(flags)+'/SectorMaps/'
95 pathMapSvc = PathResolver.FindCalibDirectory(pathMapSvc)
96 pmap_file = os.path.join(pathMapSvc, f"region{flags.Trigger.FPGATrackSim.region}.pmap")
97 with open(pmap_file) as f:
98 for line in f:
99 if 'logical_s2' in line:
100 s2_layers = int(line.strip().split()[0])
101 break
102 FPGATrackSimBankSvc.constants_1st = f'{pathBankSvc}corrgen_raw_{layers}_reg{flags.Trigger.FPGATrackSim.region}_checkGood1.gcon'
103 FPGATrackSimBankSvc.constants_2nd = f'{pathBankSvc}corrgen_raw_{s2_layers}L_reg{flags.Trigger.FPGATrackSim.region}_checkGood1.gcon'
104 FPGATrackSimBankSvc.sectorBank_1st = f'{pathBankSvc}sectorsHW_raw_{layers}_reg{flags.Trigger.FPGATrackSim.region}_checkGood1.patt'
105 FPGATrackSimBankSvc.sectorBank_2nd = f'{pathBankSvc}sectorsHW_raw_{s2_layers}L_reg{flags.Trigger.FPGATrackSim.region}_checkGood1.patt'
106 FPGATrackSimBankSvc.sectorSlices = f'{pathBankSvc}slices_{layers}_reg{flags.Trigger.FPGATrackSim.region}.root'
107 FPGATrackSimBankSvc.phiShift = flags.Trigger.FPGATrackSim.phiShift
108
109 # These should be configurable. The tag system needs updating though.
110 FPGATrackSimBankSvc.sectorQPtBins = [-0.001, -0.0005, 0, 0.0005, 0.001]
111 FPGATrackSimBankSvc.qptAbsBinning = False
112
113 result.addService(FPGATrackSimBankSvc, create=True, primary=True)
114 return result
115
116
117def FPGATrackSimRoadUnionToolCfg(flags,name="FPGATrackSimRoadUnionTool"):
118 result=ComponentAccumulator()
119 RF = CompFactory.FPGATrackSimRoadUnionTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
120
121 xBins = flags.Trigger.FPGATrackSim.ActiveConfig.xBins
122 xBufferBins = flags.Trigger.FPGATrackSim.ActiveConfig.xBufferBins
123 yBins = flags.Trigger.FPGATrackSim.ActiveConfig.yBins
124 yBufferBins = flags.Trigger.FPGATrackSim.ActiveConfig.yBufferBins
125 yMin = flags.Trigger.FPGATrackSim.ActiveConfig.qptMin
126 yMax = flags.Trigger.FPGATrackSim.ActiveConfig.qptMax
127 xMin = flags.Trigger.FPGATrackSim.ActiveConfig.phiMin
128 xMax = flags.Trigger.FPGATrackSim.ActiveConfig.phiMax
129 if (not flags.Trigger.FPGATrackSim.oldRegionDefs):
130 phiRange = FPGATrackSimDataPrepConfig.getPhiRange(flags)
131 xMin = phiRange[0]
132 xMax = phiRange[1]
133
134 xBuffer = (xMax - xMin) / xBins * xBufferBins
135 xMin = xMin - xBuffer
136 xMax = xMax + xBuffer
137 yBuffer = (yMax - yMin) / yBins * yBufferBins
138 yMin -= yBuffer
139 yMax += yBuffer
140 tools = []
141 houghType = flags.Trigger.FPGATrackSim.ActiveConfig.houghType
142 roadMerge = flags.Trigger.FPGATrackSim.ActiveConfig.roadMerge
143
144
145 FPGATrackSimMapping = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
146 for number in range(getNSubregions(FPGATrackSimMapping.subrmap)):
147 HoughTransform = CompFactory.FPGATrackSimHoughTransformTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimHoughTransformTool")+"_" + str(number))
148 HoughTransform.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
149 HoughTransform.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
150 HoughTransform.FPGATrackSimMappingSvc = FPGATrackSimMapping
151 HoughTransform.combine_layers = flags.Trigger.FPGATrackSim.ActiveConfig.combineLayers
152 HoughTransform.convSize_x = flags.Trigger.FPGATrackSim.ActiveConfig.convSizeX
153 HoughTransform.convSize_y = flags.Trigger.FPGATrackSim.ActiveConfig.convSizeY
154 HoughTransform.convolution = flags.Trigger.FPGATrackSim.ActiveConfig.convolution
155 HoughTransform.d0_max = 0
156 HoughTransform.d0_min = 0
157 HoughTransform.fieldCorrection = flags.Trigger.FPGATrackSim.ActiveConfig.fieldCorrection
158 HoughTransform.hitExtend_x = flags.Trigger.FPGATrackSim.ActiveConfig.hitExtendX
159 HoughTransform.localMaxWindowSize = flags.Trigger.FPGATrackSim.ActiveConfig.localMaxWindowSize
160 HoughTransform.nBins_x = xBins + 2 * xBufferBins
161 HoughTransform.nBins_y = yBins + 2 * yBufferBins
162 HoughTransform.phi_max = xMax
163 HoughTransform.phi_min = xMin
164 HoughTransform.qpT_max = yMax
165 HoughTransform.qpT_min = yMin
166 HoughTransform.scale = flags.Trigger.FPGATrackSim.ActiveConfig.scale
167 HoughTransform.subRegion = number
168 HoughTransform.threshold = flags.Trigger.FPGATrackSim.ActiveConfig.threshold
169 HoughTransform.traceHits = True
170 HoughTransform.IdealGeoRoads = (flags.Trigger.FPGATrackSim.ActiveConfig.IdealGeoRoads and flags.Trigger.FPGATrackSim.tracking)
171 HoughTransform.useSpacePoints = flags.Trigger.FPGATrackSim.spacePoints
172 HoughTransform.houghType = houghType
173 HoughTransform.roadMerge = roadMerge
174 if houghType=='LowResource':
175 HoughTransform.requirements = flags.Trigger.FPGATrackSim.ActiveConfig.requirements
176 if houghType=='Flexible':
177 HoughTransform.r_max=flags.Trigger.FPGATrackSim.ActiveConfig.r_max
178 HoughTransform.phi_coord_max=flags.Trigger.FPGATrackSim.ActiveConfig.phi_coord_max
179 HoughTransform.phi_range=flags.Trigger.FPGATrackSim.ActiveConfig.phi_range
180 HoughTransform.r_max_mm=flags.Trigger.FPGATrackSim.ActiveConfig.r_max_mm
181 HoughTransform.bitwise_qApt_conv=flags.Trigger.FPGATrackSim.ActiveConfig.bitwise_qApt_conv
182 HoughTransform.bitwise_phi0_conv=flags.Trigger.FPGATrackSim.ActiveConfig.bitwise_phi0_conv
183 HoughTransform.phi0_sectors=flags.Trigger.FPGATrackSim.ActiveConfig.phi0_sectors
184 HoughTransform.qApt_sectors=flags.Trigger.FPGATrackSim.ActiveConfig.qApt_sectors
185 HoughTransform.pipes_qApt=flags.Trigger.FPGATrackSim.ActiveConfig.pipes_qApt
186 HoughTransform.pipes_phi0=flags.Trigger.FPGATrackSim.ActiveConfig.pipes_phi0
187
188 tools.append(HoughTransform)
189
190 RF.tools = tools
191 result.addPublicTool(RF, primary=True)
192 return result
193
194def FPGATrackSimRoadUnionTool1DCfg(flags,name="FPGATrackSimRoadUnionTool1D"):
195 result=ComponentAccumulator()
196 tools = []
197 RF = CompFactory.FPGATrackSimRoadUnionTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
198 splitpt=flags.Trigger.FPGATrackSim.Hough1D.splitpt
199 FPGATrackSimMapping = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
200 for ptstep in range(splitpt):
201 qpt_min = flags.Trigger.FPGATrackSim.Hough1D.qptMin
202 qpt_max = flags.Trigger.FPGATrackSim.Hough1D.qptMax
203 lowpt = qpt_min + (qpt_max-qpt_min)/splitpt*ptstep
204 highpt = qpt_min + (qpt_max-qpt_min)/splitpt*(ptstep+1)
205 nSlice = getNSubregions(FPGATrackSimMapping.subrmap)
206 for iSlice in range(nSlice):
207 tool = CompFactory.FPGATrackSimHough1DShiftTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,
208 "Hough1DShift" + str(iSlice)+(("_pt{}".format(ptstep)) if splitpt>1 else "")))
209 tool.subRegion = iSlice if nSlice > 1 else -1
210 xMin = flags.Trigger.FPGATrackSim.Hough1D.phiMin
211 xMax = flags.Trigger.FPGATrackSim.Hough1D.phiMax
212 if (not flags.Trigger.FPGATrackSim.oldRegionDefs):
213 phiRange = FPGATrackSimDataPrepConfig.getPhiRange(flags)
214 xMin = phiRange[0]
215 xMax = phiRange[1]
216 tool.phiMin = xMin
217 tool.phiMax = xMax
218 tool.qptMin = lowpt
219 tool.qptMax = highpt
220 tool.nBins = flags.Trigger.FPGATrackSim.Hough1D.xBins
221 tool.useDiff = True
222 tool.variableExtend = True
223 tool.drawHitMasks = False
224 tool.phiRangeCut = flags.Trigger.FPGATrackSim.Hough1D.phiRangeCut
225 tool.d0spread=-1.0 # mm
226 tool.iterStep = 0 # auto, TODO put in tag
227 tool.iterLayer = 7 # TODO put in tag
228 tool.threshold = flags.Trigger.FPGATrackSim.Hough1D.threshold[0]
229 tool.hitExtend = flags.Trigger.FPGATrackSim.Hough1D.hitExtendX
230 tool.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
231 tool.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
232 tool.FPGATrackSimMappingSvc = FPGATrackSimMapping
233 tool.IdealGeoRoads = (flags.Trigger.FPGATrackSim.ActiveConfig.IdealGeoRoads and flags.Trigger.FPGATrackSim.tracking)
234 tool.useSpacePoints = flags.Trigger.FPGATrackSim.spacePoints
235
236 tools.append(tool)
237
238 RF.tools = tools
239 result.addPublicTool(RF, primary=True)
240 return result
241
242
243
244def FPGATrackSimRoadUnionToolGenScanCfg(flags,name="FPGATrackSimRoadUnionToolGenScan"):
245 result=ComponentAccumulator()
246
247 print("logLevel",flags.Trigger.FPGATrackSim.loglevel)
248
249 # read the cuts from a seperate python file specified by FPGATrackSim.GenScan.genScanCuts
250 cutset=None
251 if flags.Trigger.FPGATrackSim.oldRegionDefs:
252 toload=flags.Trigger.FPGATrackSim.GenScan.genScanCuts
253 if toload == 'FPGATrackSimGenScanCuts': # its on the newRegion default so it hasn't been set
254 toload = 'FPGATrackSimHough.FPGATrackSimGenScanCuts_incr'
255 cutset = importlib.import_module(toload).cuts[flags.Trigger.FPGATrackSim.region]
256 else:
257 # this allows the cut file defined in python to be loaded from the map directory
258 cutpath = os.path.join(
259 PathResolver.FindCalibDirectory(flags.Trigger.FPGATrackSim.mapsDir),
260 f"{flags.Trigger.FPGATrackSim.GenScan.genScanCuts}.py")
261 print("Cut File = ", cutpath)
262 spec=importlib.util.spec_from_file_location(flags.Trigger.FPGATrackSim.GenScan.genScanCuts,cutpath)
263 if spec is None:
264 print("Failed to find Cut File")
265 cutmodule = importlib.util.module_from_spec(spec)
266 spec.loader.exec_module(cutmodule)
267 cutset=cutmodule.cuts[flags.Trigger.FPGATrackSim.region]
268
269 # make the binned hits class
270 BinnnedHits = CompFactory.FPGATrackSimBinnedHits("BinnedHits_1stStage")
271 BinnnedHits.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
272 BinnnedHits.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
273
274 # set layer map
275 if not flags.Trigger.FPGATrackSim.GenScan.layerStudy:
276 if flags.Trigger.FPGATrackSim.oldRegionDefs:
277 BinnnedHits.layerMapFile = flags.Trigger.FPGATrackSim.GenScan.layerMapFile
278 else:
279 print("Loading Layer Radii from ", PathResolver.FindCalibDirectory(flags.Trigger.FPGATrackSim.mapsDir),
280 f"regioneta{FPGATrackSimDataPrepConfig.getEtaSideBits(flags)}_lyrradii.json")
281 # now assumed to be in the map directory with name = basename for region + _lyrmap.json
282 if flags.Trigger.FPGATrackSim.GenScan.useLayerRadiiFile:
283 BinnnedHits.layerRadiiFile =os.path.join(
284 PathResolver.FindCalibDirectory(flags.Trigger.FPGATrackSim.mapsDir),
285 f"regioneta{FPGATrackSimDataPrepConfig.getEtaSideBits(flags)}_lyrradii.json")
286 else:
287 BinnnedHits.layerMapFile =os.path.join(
288 PathResolver.FindCalibDirectory(flags.Trigger.FPGATrackSim.mapsDir),
289 f"{FPGATrackSimDataPrepConfig.getBaseName(flags)}_lyrmap.json")
290
291
292
293
294 # make the bintool class
295 BinTool = CompFactory.FPGATrackSimBinTool("BinTool_1stStage")
296 BinTool.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
297
298 # Inputs for the BinTool
299 binsteps=[]
300 BinDesc=None
301 if (cutset["parSet"]=="PhiSlicedKeyLyrPars") :
302 BinDesc = CompFactory.FPGATrackSimKeyLayerBinDesc("KeyLayerBinDesc")
303 BinDesc.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
304 BinDesc.rin=cutset["rin"]
305 BinDesc.rout=cutset["rout"]
306 if flags.Trigger.FPGATrackSim.GenScan.useLayerRadiiFile:
307 phirange = FPGATrackSimDataPrepConfig.getPhiRange(flags)
308 phicenter = (phirange[0]+phirange[1])/2.0
309 BinDesc.PhiOffset = -1.0*phicenter
310
311 BinDesc.region = flags.Trigger.FPGATrackSim.region
312
313 # parameters for key layer bindesc are :"zR1", "zR2", "phiR1", "phiR2", "xm"
314 step1 = CompFactory.FPGATrackSimBinStep("PhiBinning")
315 step1.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
316 step1.parBins = [1,1,cutset["parBins"][2],cutset["parBins"][3],cutset["parBins"][4]]
317 step2 = CompFactory.FPGATrackSimBinStep("FullBinning")
318 step2.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
319 step2.parBins = cutset["parBins"]
320 binsteps = [step1,step2]
321 else:
322 log.error("Unknown Binning Setup: ",cutset["parSet"])
323
324 BinTool.BinDesc = BinDesc
325 BinTool.Steps=binsteps
326
327
328 # configure the padding around the nominal region
329 BinTool.d0FractionalPadding =0.05
330 BinTool.z0FractionalPadding =0.05
331 BinTool.etaFractionalPadding =0.05
332 BinTool.phiFractionalPadding =0.05
333 BinTool.qOverPtFractionalPadding =0.05
334 BinTool.parMin = cutset["parMin"]
335 BinTool.parMax = cutset["parMax"]
336 BinnnedHits.BinTool = BinTool
337
338
339 # make the monitoring class
340 Monitor = CompFactory.FPGATrackSimGenScanMonitoring(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"GenScanMonitoring"))
341 Monitor.dir = "/GENSCAN/"+FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"GenScanMonitoring")+"/"
342 Monitor.THistSvc = CompFactory.THistSvc()
343 Monitor.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
344 Monitor.phiScale = 10.0
345 Monitor.etaScale = 100.0
346 Monitor.drScale = 20.0
347
348 # make the main tool
349 tool = CompFactory.FPGATrackSimGenScanTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"GenScanTool"))
350 tool.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
351 tool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
352 tool.OutputLevel=flags.Trigger.FPGATrackSim.loglevel
353 tool.Monitoring = Monitor
354 tool.BinnedHits = BinnnedHits
355 tool.rin=cutset["rin"]
356 tool.rout=cutset["rout"]
357
358 # For the 'track fitter' part of GenScanTool.
359 tool.inBinFiltering = flags.Trigger.FPGATrackSim.GenScan.filterInBin
360 weights = getFitWeights(getEtaBin(flags))
361 tool.etaChi2Weight_4hits = weights[0]
362 tool.phiChi2Weight_4hits = weights[1]
363 tool.etaChi2Weight_5hits = weights[2]
364 tool.phiChi2Weight_5hits = weights[3]
365
366 # configure which filers and thresholds to apply
367 tool.binFilter=flags.Trigger.FPGATrackSim.GenScan.binFilter
368 tool.reversePairDir=flags.Trigger.FPGATrackSim.GenScan.reverse
369 tool.applyPairFilter= not flags.Trigger.FPGATrackSim.GenScan.noCuts
370 tool.applyPairSetFilter= not flags.Trigger.FPGATrackSim.GenScan.noCuts
371 tool.keepHitsStrategy = flags.Trigger.FPGATrackSim.GenScan.keepHitsStrategy
372 tool.threshold = 4
373
374 # set cuts
375 for (cut,val) in cutset.items():
376 if cut in ["parBins","parSet","parMin","parMax"]:
377 continue
378 setattr(tool,cut,val)
379
380 # even though we are not actually doing a Union, we need the
381 # RoadUnionTool because mapping is now there
382 RoadUnion = CompFactory.FPGATrackSimRoadUnionTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
383 RoadUnion.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
384 RoadUnion.tools = [tool,]
385 result.addPublicTool(RoadUnion, primary=True)
386
387 # special configuration for studing layer definitions
388 # pass through all hits, but turn off pairing because
389 # it won't be able to run
390 if flags.Trigger.FPGATrackSim.GenScan.layerStudy:
391 RoadUnion.noHitFilter=True
392 tool.binningOnly=True
393 return result
394
395def FPGATrackSimRoadUnionToolGNNCfg(flags,name="FPGATrackSimRoadUnionToolGNN"):
396 result = ComponentAccumulator()
397 RF = CompFactory.FPGATrackSimRoadUnionTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
398 RF.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
399
400 patternRecoTool = CompFactory.FPGATrackSimGNNPatternRecoTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimGNNPatternRecoTool"))
401 patternRecoTool.GNNGraphHitSelector = CompFactory.FPGATrackSimGNNGraphHitSelectorTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimGNNGraphHitSelectorTool"))
402 patternRecoTool.GNNGraphConstruction = result.popToolsAndMerge(FPGATrackSimGNNGraphConstructionToolCfg(flags))
403 edgeResult, edgeClassifierTools = FPGATrackSimGNNEdgeClassifierToolCfg(flags)
404 result.merge(edgeResult)
405 patternRecoTool.GNNEdgeClassifiers = edgeClassifierTools
406 patternRecoTool.GNNRoadMaker = result.popToolsAndMerge(FPGATrackSimGNNRoadMakerToolCfg(flags))
407 patternRecoTool.GNNRootOutput = result.popToolsAndMerge(FPGATrackSimGNNRootOutputToolCfg(flags))
408 patternRecoTool.doGNNRootOutput = flags.Trigger.FPGATrackSim.GNN.doGNNRootOutput
409 patternRecoTool.regionNum = int(flags.Trigger.FPGATrackSim.region)
410
411 RF.tools = [patternRecoTool]
412 result.addPublicTool(RF, primary=True)
413
414 return result
415
416def FPGATrackSimGNNGraphConstructionToolCfg(flags,name="FPGATrackSimGNNGraphConstructionTool"):
417 result = ComponentAccumulator()
418
419 GNNGraphConstructionTool = CompFactory.FPGATrackSimGNNGraphConstructionTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
420 GNNGraphConstructionTool.graphTool = flags.Trigger.FPGATrackSim.GNN.graphTool.value
421 GNNGraphConstructionTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
422
423
424 # Module Map Configuration
425 GNNGraphConstructionTool.moduleMapType=flags.Trigger.FPGATrackSim.GNN.moduleMapType.value
426 GNNGraphConstructionTool.moduleMapFunc=flags.Trigger.FPGATrackSim.GNN.moduleMapFunc.value
427 GNNGraphConstructionTool.moduleMapTol=flags.Trigger.FPGATrackSim.GNN.moduleMapTol
428
429 # Metric Learning Configuration
430 GNNGraphConstructionTool.metricLearningR=flags.Trigger.FPGATrackSim.GNN.metricLearningR
431 GNNGraphConstructionTool.metricLearningMaxN=flags.Trigger.FPGATrackSim.GNN.metricLearningMaxN
432
433 from AthOnnxComps.OnnxRuntimeInferenceConfig import OnnxRuntimeInferenceToolCfg
434 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
435
436 GNNGraphConstructionTool.MLInferenceTool = result.popToolsAndMerge(OnnxRuntimeInferenceToolCfg(
437 flags, flags.Trigger.FPGATrackSim.GNN.MLModelPath, OnnxRuntimeType.CPU))
438
439 result.setPrivateTools(GNNGraphConstructionTool)
440
441 return result
442
443def FPGATrackSimGNNEdgeClassifierToolCfg(flags, name="FPGATrackSimGNNEdgeClassifierTool"):
444 result = ComponentAccumulator()
445
446 from AthOnnxComps.OnnxRuntimeInferenceConfig import OnnxRuntimeInferenceToolCfg
447 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
448
449 region = int(flags.Trigger.FPGATrackSim.region)
450 model_path = f"{flags.Trigger.FPGATrackSim.GNN.GNNModelPath}_{region}.onnx"
451
452 GNNEdgeClassifierTool = CompFactory.FPGATrackSimGNNEdgeClassifierTool(
453 FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags, name))
454 GNNEdgeClassifierTool.GNNInferenceTool = result.popToolsAndMerge(
455 OnnxRuntimeInferenceToolCfg(flags, model_path, OnnxRuntimeType.CPU, name=f"OnnxInferenceTool_{region}")
456 )
457 GNNEdgeClassifierTool.regionNum = region
458
459 return result, [GNNEdgeClassifierTool]
460
461def FPGATrackSimGNNRoadMakerToolCfg(flags,name="FPGATrackSimGNNRoadMakerTool"):
462 result = ComponentAccumulator()
463
464 GNNRoadMakerTool = CompFactory.FPGATrackSimGNNRoadMakerTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
465 GNNRoadMakerTool.roadMakerTool = flags.Trigger.FPGATrackSim.GNN.roadMakerTool.value
466 GNNRoadMakerTool.edgeScoreCut = flags.Trigger.FPGATrackSim.GNN.edgeScoreCut
467 GNNRoadMakerTool.doGNNPixelSeeding = flags.Trigger.FPGATrackSim.GNN.doGNNPixelSeeding
468 GNNRoadMakerTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
469
470 from TrigFastTrackFinder.TrigFastTrackFinderConfig import ITkTrigL2LayerNumberToolCfg
471 GNNRoadMakerTool.LayerNumberTool = result.getPrimaryAndMerge(ITkTrigL2LayerNumberToolCfg(flags))
472
473 result.setPrivateTools(GNNRoadMakerTool)
474
475 return result
476
477def FPGATrackSimGNNRootOutputToolCfg(flags,name="FPGATrackSimGNNRootOutputTool"):
478 result = ComponentAccumulator()
479
480 GNNRootOutputTool = CompFactory.FPGATrackSimGNNRootOutputTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
481 GNNRootOutputTool.OutputRegion = str(flags.Trigger.FPGATrackSim.region)
482
483 if(flags.Trigger.FPGATrackSim.GNN.doGNNRootOutput):
484 result.addService(CompFactory.THistSvc(Output = ["TRIGFPGATrackSimGNNOUTPUT DATAFILE='GNNRootOutput.root', OPT='RECREATE'"]))
485 result.setPrivateTools(GNNRootOutputTool)
486
487 return result
488
489def FPGATrackSimDataFlowToolCfg(flags,name="FPGATrackSimDataFlowTool"):
490 result=ComponentAccumulator()
491 DataFlowTool = CompFactory.FPGATrackSimDataFlowTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
492 DataFlowTool.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
493 DataFlowTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
494 DataFlowTool.Chi2ndofCut = flags.Trigger.FPGATrackSim.ActiveConfig.chi2cut
495 DataFlowTool.THistSvc = CompFactory.THistSvc()
496 result.setPrivateTools(DataFlowTool)
497 return result
498
499def FPGATrackSimHoughRootOutputToolCfg(flags,name="FPGATrackSimHoughRootOutputTool"):
500 result=ComponentAccumulator()
501 HoughRootOutputTool = CompFactory.FPGATrackSimHoughRootOutputTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
502 HoughRootOutputTool.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
503 HoughRootOutputTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
504 HoughRootOutputTool.THistSvc = CompFactory.THistSvc()
505 HoughRootOutputTool.OutputRegion = str(flags.Trigger.FPGATrackSim.region)
506 result.setPrivateTools(HoughRootOutputTool)
507 return result
508
509def LRTRoadFinderCfg(flags,name="LRTRoadFinder"):
510
511 result=ComponentAccumulator()
512 LRTRoadFinder =CompFactory.FPGATrackSimHoughTransform_d0phi0_Tool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
513 LRTRoadFinder.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
514 LRTRoadFinder.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
515 LRTRoadFinder.combine_layers = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackCombineLayers
516 LRTRoadFinder.convolution = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackConvolution
517 LRTRoadFinder.hitExtend_x = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackHitExtendX
518 LRTRoadFinder.scale = flags.Trigger.FPGATrackSim.ActiveConfig.scale
519 LRTRoadFinder.threshold = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackThreshold
520 result.setPrivateTools(LRTRoadFinder)
521 return result
522
523def NNTrackToolCfg(flags,name="FPGATrackSimNNTrackTool"):
524 result=ComponentAccumulator()
525 NNTrackTool = CompFactory.FPGATrackSimNNTrackTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
526 NNTrackTool.THistSvc = CompFactory.THistSvc()
527 NNTrackTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
528 NNTrackTool.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
529 NNTrackTool.IdealGeoRoads = False
530 NNTrackTool.useSpacePoints = flags.Trigger.FPGATrackSim.spacePoints and not flags.Trigger.FPGATrackSim.ActiveConfig.genScan and not flags.Trigger.FPGATrackSim.ActiveConfig.GNN
531 NNTrackTool.SPRoadFilterTool = result.popToolsAndMerge(SPRoadFilterToolCfg(flags))
532 NNTrackTool.MinNumberOfRealHitsInATrack = 5 if flags.Trigger.FPGATrackSim.ActiveConfig.genScan else 7 if flags.Trigger.FPGATrackSim.ActiveConfig.GNN else 9
533 NNTrackTool.useSectors = False
534 NNTrackTool.doGNNTracking = flags.Trigger.FPGATrackSim.GNN.doGNNTracking
535 NNTrackTool.nInputsGNN = flags.Trigger.FPGATrackSim.GNN.nInputsGNN
536 NNTrackTool.useCartesian = flags.Trigger.FPGATrackSim.NNCartesianCoordinates
537 result.setPrivateTools(NNTrackTool)
538 return result
539
540def FPGATrackSimTrackFitterToolCfg(flags,name="FPGATrackSimTrackFitterTool"):
541 result=ComponentAccumulator()
542 TF_1st = CompFactory.FPGATrackSimTrackFitterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
543 TF_1st.GuessHits = flags.Trigger.FPGATrackSim.ActiveConfig.guessHits
544 TF_1st.IdealCoordFitType = flags.Trigger.FPGATrackSim.ActiveConfig.idealCoordFitType
545 TF_1st.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
546 TF_1st.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
547 TF_1st.chi2DofRecoveryMax = flags.Trigger.FPGATrackSim.ActiveConfig.chi2DoFRecoveryMax
548 TF_1st.chi2DofRecoveryMin = flags.Trigger.FPGATrackSim.ActiveConfig.chi2DoFRecoveryMin
549 TF_1st.doMajority = flags.Trigger.FPGATrackSim.ActiveConfig.doMajority
550 TF_1st.nHits_noRecovery = flags.Trigger.FPGATrackSim.ActiveConfig.nHitsNoRecovery
551 TF_1st.DoDeltaGPhis = flags.Trigger.FPGATrackSim.ActiveConfig.doDeltaGPhis
552 TF_1st.DoMissingHitsChecks = flags.Trigger.FPGATrackSim.ActiveConfig.doMissingHitsChecks
553 TF_1st.IdealGeoRoads = (flags.Trigger.FPGATrackSim.ActiveConfig.IdealGeoRoads and flags.Trigger.FPGATrackSim.tracking)
554 TF_1st.useSpacePoints = flags.Trigger.FPGATrackSim.spacePoints and not flags.Trigger.FPGATrackSim.ActiveConfig.genScan
555 TF_1st.SPRoadFilterTool = result.popToolsAndMerge(SPRoadFilterToolCfg(flags))
556 TF_1st.fitFromRoad = flags.Trigger.FPGATrackSim.ActiveConfig.fitFromRoad
557 result.addPublicTool(TF_1st, primary=True)
558 return result
559
560def FPGATrackSimOverlapRemovalToolCfg(flags,name="FPGATrackSimOverlapRemovalTool"):
561 result=ComponentAccumulator()
562 OR_1st = CompFactory.FPGATrackSimOverlapRemovalTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
563 OR_1st.ORAlgo = "Normal"
564 OR_1st.doFastOR = flags.Trigger.FPGATrackSim.ActiveConfig.doFastOR
565 OR_1st.NumOfHitPerGrouping = 3
566 if flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and not flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
567 OR_1st.MinChi2 = getChi2Cut(flags.Trigger.FPGATrackSim.region)
568 elif flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
569 OR_1st.MinChi2 = getChi2CutNN(flags.Trigger.FPGATrackSim.region)
570 else:
571 OR_1st.MinChi2 = flags.Trigger.FPGATrackSim.ActiveConfig.chi2cut
572 if flags.Trigger.FPGATrackSim.ActiveConfig.hough or flags.Trigger.FPGATrackSim.ActiveConfig.hough1D:
573 OR_1st.nBins_x = flags.Trigger.FPGATrackSim.ActiveConfig.xBins + 2 * flags.Trigger.FPGATrackSim.ActiveConfig.xBufferBins
574 OR_1st.nBins_y = flags.Trigger.FPGATrackSim.ActiveConfig.yBins + 2 * flags.Trigger.FPGATrackSim.ActiveConfig.yBufferBins
575 OR_1st.localMaxWindowSize = flags.Trigger.FPGATrackSim.ActiveConfig.localMaxWindowSize
576 OR_1st.roadSliceOR = flags.Trigger.FPGATrackSim.ActiveConfig.roadSliceOR
577
578 from FPGATrackSimAlgorithms.FPGATrackSimAlgorithmConfig import FPGATrackSimOverlapRemovalToolMonitoringCfg
579 OR_1st.MonTool = result.getPrimaryAndMerge(FPGATrackSimOverlapRemovalToolMonitoringCfg(flags))
580
581 result.addPublicTool(OR_1st, primary=True)
582 return result
583
585 newFlags = flags.cloneAndReplace("Trigger.FPGATrackSim.ActiveConfig", "Trigger.FPGATrackSim." + flags.Trigger.FPGATrackSim.algoTag,keepOriginal=True)
586 return newFlags
587
588def SPRoadFilterToolCfg(flags,secondStage=False,name="FPGATrackSimSpacepointRoadFilterTool"):
589 result=ComponentAccumulator()
590 name="FPGATrackSimSpacepointRoadFilterTool_1st"
591 if secondStage:
592 name="FPGATrackSimSpacepointRoadFilterTool_2st"
593 SPRoadFilter = CompFactory.FPGATrackSimSpacepointRoadFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
594 SPRoadFilter.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
595 SPRoadFilter.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
596 SPRoadFilter.filtering = flags.Trigger.FPGATrackSim.ActiveConfig.spacePointFiltering
597 SPRoadFilter.minSpacePlusPixel = flags.Trigger.FPGATrackSim.minSpacePlusPixel
598 SPRoadFilter.isSecondStage = secondStage
599 SPRoadFilter.dropUnpairedIfSP = flags.Trigger.FPGATrackSim.dropUnpairedIfSP
600
601 # This threshold is the number of *missing* hits allowed. For now, assume that if 1st stage this is always 1.
602 # We don't actually run this tool in the first stage anymore, so this is more to preserve backwards compatibility
603 if secondStage:
604 SPRoadFilter.threshold = flags.Trigger.FPGATrackSim.hitThreshold
605 else:
606 SPRoadFilter.threshold = 1
607
608 SPRoadFilter.setSectors = (flags.Trigger.FPGATrackSim.ActiveConfig.IdealGeoRoads and flags.Trigger.FPGATrackSim.tracking)
609 result.setPrivateTools(SPRoadFilter)
610 return result
611
612
613
614
615def FPGATrackSimLogicalHitsProcessAlgCfg(inputFlags,name="FPGATrackSimLogicalHitsProcessAlg",**kwargs):
616
618
619 result=ComponentAccumulator()
620 kwargs.setdefault("name", FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
621
622 theFPGATrackSimLogicalHitsProcessAlg=CompFactory.FPGATrackSimLogicalHitsProcessAlg(**kwargs)
623 theFPGATrackSimLogicalHitsProcessAlg.writeOutputData = flags.Trigger.FPGATrackSim.writeAdditionalOutputData
624 theFPGATrackSimLogicalHitsProcessAlg.tracking = flags.Trigger.FPGATrackSim.tracking
625 theFPGATrackSimLogicalHitsProcessAlg.SetTruthParametersForTracks = flags.Trigger.FPGATrackSim.SetTruthParametersForTracks
626 theFPGATrackSimLogicalHitsProcessAlg.doOverlapRemoval = flags.Trigger.FPGATrackSim.doOverlapRemoval
627 theFPGATrackSimLogicalHitsProcessAlg.DoMissingHitsChecks = flags.Trigger.FPGATrackSim.ActiveConfig.doMissingHitsChecks
628 theFPGATrackSimLogicalHitsProcessAlg.DoHoughRootOutput1st = flags.Trigger.FPGATrackSim.ActiveConfig.houghRootoutput1st
629 theFPGATrackSimLogicalHitsProcessAlg.NumOfHitPerGrouping = flags.Trigger.FPGATrackSim.ActiveConfig.NumOfHitPerGrouping
630 theFPGATrackSimLogicalHitsProcessAlg.DoNNTrack_1st = flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis
631 theFPGATrackSimLogicalHitsProcessAlg.DoGNNTrack = flags.Trigger.FPGATrackSim.GNN.doGNNTracking
632 theFPGATrackSimLogicalHitsProcessAlg.DoGNNPixelSeeding = flags.Trigger.FPGATrackSim.GNN.doGNNPixelSeeding
633 theFPGATrackSimLogicalHitsProcessAlg.eventSelector = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
634 if flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and not flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
635 theFPGATrackSimLogicalHitsProcessAlg.TrackScoreCut = getChi2Cut(flags.Trigger.FPGATrackSim.region)
636 elif flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
637 theFPGATrackSimLogicalHitsProcessAlg.TrackScoreCut = getChi2CutNN(flags.Trigger.FPGATrackSim.region)
638 else:
639 theFPGATrackSimLogicalHitsProcessAlg.TrackScoreCut = flags.Trigger.FPGATrackSim.ActiveConfig.chi2cut
640 theFPGATrackSimLogicalHitsProcessAlg.passLowestChi2TrackOnly = flags.Trigger.FPGATrackSim.ActiveConfig.passLowestChi2TrackOnly
641 theFPGATrackSimLogicalHitsProcessAlg.secondStageStrips = (not flags.Trigger.FPGATrackSim.ActiveConfig.GNN)
642 FPGATrackSimMaping = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
643 theFPGATrackSimLogicalHitsProcessAlg.FPGATrackSimMapping = FPGATrackSimMaping
644 # Adding region so we can set it for tracks, then get the bfield
645 theFPGATrackSimLogicalHitsProcessAlg.Region = flags.Trigger.FPGATrackSim.region
646 # If tracking is set to False or if we do the NN analysis, don't configure the bank service
647 if flags.Trigger.FPGATrackSim.tracking and not flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis:
648 result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
649
650 if (flags.Trigger.FPGATrackSim.ActiveConfig.hough1D):
651 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionTool1DCfg(flags))
652 elif (flags.Trigger.FPGATrackSim.ActiveConfig.genScan):
653 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionToolGenScanCfg(flags))
654 elif (flags.Trigger.FPGATrackSim.ActiveConfig.GNN):
655 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionToolGNNCfg(flags))
656 else:
657 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionToolCfg(flags))
658
659 if (flags.Trigger.FPGATrackSim.ActiveConfig.etaPatternFilter):
660 EtaPatternFilter = CompFactory.FPGATrackSimEtaPatternFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimEtaPatternFilterTool"))
661 EtaPatternFilter.FPGATrackSimMappingSvc = FPGATrackSimMaping
662 EtaPatternFilter.threshold = flags.Trigger.FPGATrackSim.Hough1D.threshold[0]
663 EtaPatternFilter.EtaPatterns = flags.Trigger.FPGATrackSim.mapsDir+"/"+FPGATrackSimDataPrepConfig.getBaseName(flags)+".patt"
664 theFPGATrackSimLogicalHitsProcessAlg.RoadFilter = EtaPatternFilter
665 theFPGATrackSimLogicalHitsProcessAlg.FilterRoads = True
666
667 if (flags.Trigger.FPGATrackSim.ActiveConfig.phiRoadFilter):
668 RoadFilter2 = CompFactory.FPGATrackSimPhiRoadFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimPhiRoadFilterTool"))
669 RoadFilter2.FPGATrackSimMappingSvc = FPGATrackSimMaping
670 RoadFilter2.threshold = flags.Trigger.FPGATrackSim.Hough1D.threshold[0]
671 RoadFilter2.fieldCorrection = flags.Trigger.FPGATrackSim.ActiveConfig.fieldCorrection
672
673 windows = [flags.Trigger.FPGATrackSim.Hough1D.phifilterwindow for i in range(len(flags.Trigger.FPGATrackSim.ActiveConfig.hitExtendX))]
674 RoadFilter2.window = windows
675
676 theFPGATrackSimLogicalHitsProcessAlg.RoadFilter2 = RoadFilter2
677 theFPGATrackSimLogicalHitsProcessAlg.FilterRoads2 = True
678
679 theFPGATrackSimLogicalHitsProcessAlg.SlicingEngineTool = result.getPrimaryAndMerge(FPGATrackSimSlicingEngineCfg(flags))
680
681 theFPGATrackSimLogicalHitsProcessAlg.HoughRootOutputTool = result.getPrimaryAndMerge(FPGATrackSimHoughRootOutputToolCfg(flags))
682 theFPGATrackSimLogicalHitsProcessAlg.writeRegion=flags.Trigger.FPGATrackSim.writeRegion
683
684 LRTRoadFilter = CompFactory.FPGATrackSimLLPRoadFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimLLPRoadFilterTool"))
685 result.addPublicTool(LRTRoadFilter)
686 theFPGATrackSimLogicalHitsProcessAlg.LRTRoadFilter = LRTRoadFilter
687
688 theFPGATrackSimLogicalHitsProcessAlg.LRTRoadFinder = result.getPrimaryAndMerge(LRTRoadFinderCfg(flags))
689 theFPGATrackSimLogicalHitsProcessAlg.NNTrackTool = result.getPrimaryAndMerge(NNTrackToolCfg(flags))
690
691 theFPGATrackSimLogicalHitsProcessAlg.writeInputBranches=flags.Trigger.FPGATrackSim.writeAdditionalOutputData and (flags.Trigger.FPGATrackSim.regionToWriteDPTree < 0)
692 theFPGATrackSimLogicalHitsProcessAlg.OutputTool = result.popToolsAndMerge(FPGATrackSimWriteOutputCfg(flags))
693 theFPGATrackSimLogicalHitsProcessAlg.TrackFitter_1st = result.getPrimaryAndMerge(FPGATrackSimTrackFitterToolCfg(flags))
694 theFPGATrackSimLogicalHitsProcessAlg.OverlapRemoval_1st = result.getPrimaryAndMerge(FPGATrackSimOverlapRemovalToolCfg(flags))
695
696 theFPGATrackSimLogicalHitsProcessAlg.SpacePointTool = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimSpacePointsToolCfg(flags))
697 theFPGATrackSimLogicalHitsProcessAlg.Spacepoints = flags.Trigger.FPGATrackSim.spacePoints
698
699 if flags.Trigger.FPGATrackSim.ActiveConfig.lrt:
700 assert flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseBasicHitFilter != flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseMlHitFilter, 'Inconsistent LRT hit filtering setup, need either ML of Basic filtering enabled'
701 assert flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseStraightTrackHT != flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseDoubletHT, 'Inconsistent LRT HT setup, need either double or strightTrack enabled'
702 theFPGATrackSimLogicalHitsProcessAlg.doLRT = True
703 theFPGATrackSimLogicalHitsProcessAlg.LRTHitFiltering = (not flags.Trigger.FPGATrackSim.ActiveConfig.lrtSkipHitFiltering)
704
705
706
707 from FPGATrackSimAlgorithms.FPGATrackSimAlgorithmConfig import FPGATrackSimTrackMonCfg
708
709
710 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage', flags, variety='road'))
711
712 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadPostFilter1Monitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_filter_1', flags, variety='road'))
713
714 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadPostOverlapRemovalMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_overlap_removal', flags, variety='road'))
715
716 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadPostFilter2Monitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_filter_2', flags, variety='road'))
717
718
719 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage', flags, variety='track'))
720
721 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackPostSetTruthMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_set_truth', flags, variety='track'))
722
723 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackPostChi2Monitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_chi2', flags, variety='track'))
724
725 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackPostOverlapRemovalTrackMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_overlap_removal', flags, variety='track'))
726
727 result.addEventAlgo(theFPGATrackSimLogicalHitsProcessAlg)
728
729 return result
730
731
732
733
734def getChi2Cut(region):
735 chi2cut_l = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 20] #from most recent run on this branch with new maps/banks, all chi2's are under 1
736 binSize = 0.2
737 side = (region >> 5) & 0x1
738 etaBin = (region >> 6) & 0x1F
739 etaRange = [round(binSize * etaBin, 1), round(binSize * (etaBin + 1), 1)] if side else [round(-binSize * (etaBin + 1), 1), round(-binSize * etaBin, 1)]
740
741 abs_etaRange = tuple(round(abs(val), 1) for val in etaRange)
742
743 eta_to_chi2 = {
744 (0.0, 0.2): chi2cut_l[0], (0.2, 0.4): chi2cut_l[1], (0.4, 0.6): chi2cut_l[2],
745 (0.6, 0.8): chi2cut_l[3], (0.8, 1.0): chi2cut_l[4], (1.0, 1.2): chi2cut_l[5],
746 (1.2, 1.4): chi2cut_l[6], (1.4, 1.6): chi2cut_l[7], (1.6, 1.8): chi2cut_l[8],
747 (1.8, 2.0): chi2cut_l[9], (2.0, 2.2): chi2cut_l[10], (2.2, 2.4): chi2cut_l[11],
748 (2.4, 2.6): chi2cut_l[12], (2.6, 2.8): chi2cut_l[13], (2.8, 3.0): chi2cut_l[14],
749 (3.0, 3.2): chi2cut_l[15], (3.2, 3.4): chi2cut_l[16], (3.4, 3.6): chi2cut_l[17],
750 (3.6, 3.8): chi2cut_l[18], (3.8, 4.0): chi2cut_l[19]
751 }
752
753 return eta_to_chi2.get(abs_etaRange, 20)
754
755def getChi2CutNN(region):
756 chi2cut_l = [0.97,0.97,0.99,
757 0.7,0.86,0.99,
758 0.98,0.92,0.98,
759 0.95,0.93,0.4,
760 0.4,0.4,0.7,
761 0.6,0.5,0.4,
762 0.4,0.4]
763 binSize = 0.2
764 side = (region >> 5) & 0x1
765 etaBin = (region >> 6) & 0x1F
766 etaRange = [round(binSize * etaBin, 1), round(binSize * (etaBin + 1), 1)] if side else [round(-binSize * (etaBin + 1), 1), round(-binSize * etaBin, 1)]
767
768 abs_etaRange = tuple(round(abs(val), 1) for val in etaRange)
769
770 eta_to_chi2 = {
771 (0.0, 0.2): chi2cut_l[0], (0.2, 0.4): chi2cut_l[1], (0.4, 0.6): chi2cut_l[2],
772 (0.6, 0.8): chi2cut_l[3], (0.8, 1.0): chi2cut_l[4], (1.0, 1.2): chi2cut_l[5],
773 (1.2, 1.4): chi2cut_l[6], (1.4, 1.6): chi2cut_l[7], (1.6, 1.8): chi2cut_l[8],
774 (1.8, 2.0): chi2cut_l[9], (2.0, 2.2): chi2cut_l[10], (2.2, 2.4): chi2cut_l[11],
775 (2.4, 2.6): chi2cut_l[12], (2.6, 2.8): chi2cut_l[13], (2.8, 3.0): chi2cut_l[14],
776 (3.0, 3.2): chi2cut_l[15], (3.2, 3.4): chi2cut_l[16], (3.4, 3.6): chi2cut_l[17],
777 (3.6, 3.8): chi2cut_l[18], (3.8, 4.0): chi2cut_l[19]
778 }
779 return eta_to_chi2.get(abs_etaRange, 0.99)
780
781
783 # convert regex to array of regions
784 if flags.Trigger.FPGATrackSim.regionList == "": # in case of empty list just use the region set to flags.Trigger.FPGATrackSim.region
785 flags.Trigger.FPGATrackSim.regionList = [flags.Trigger.FPGATrackSim.region]
786 else: # otherwise use the regionList (this overrides the region flag)
787 from FPGATrackSimConfTools.FPGATrackSimHelperFunctions import convertRegionsExpressionToArray
788 flags.Trigger.FPGATrackSim.regionList = convertRegionsExpressionToArray(flags.Trigger.FPGATrackSim.regionList)
789 print(f"Running for regions: {flags.Trigger.FPGATrackSim.regionList}")
790
791
793 FPGATrackSimDataPrepConfig.FPGATrackSimDataPrepFlagCfg(flags)
794
795 flags.Scheduler.ShowDataDeps=True
796 flags.Scheduler.CheckDependencies=True
797 flags.Debug.DumpEvtStore=False
798
799 flags.Trigger.FPGATrackSim.readOfflineObjects=False
800 flags.Trigger.FPGATrackSim.doMultiTruth=False
801
802 flags.Trigger.FPGATrackSim.tracking = False
803 flags.Trigger.FPGATrackSim.Hough.genScan = True
804 flags.Trigger.FPGATrackSim.convertSPs = False # in case we need the conversion to take place on hw we'll have to convert to SPs after the cluster-sorting (will probably need new algorithm)
805 flags.Tracking.ITkActsValidateF150Pass.doActsSpacePoint = not flags.Trigger.FPGATrackSim.convertSPs
806 flags.Trigger.FPGATrackSim.Hough.secondStage = False
807
808 flags.Trigger.FPGATrackSim.regionList="34,98,162,226,290,354,418,482,546,610,674,738,802,866,930,994,1058,1122,1186,1250"
810
811 return flags
812
814 acc=ComponentAccumulator()
815 if not flags.Trigger.FPGATrackSim.runOnPreProducedHeaderFiles:
816 acc.merge(FPGATrackSimDataPrepConfig.FPGATrackSimClusteringCfg(flags))
817
818 from FPGATrackSimConfTools.FPGATrackSimMultiRegionConfig import FPGATrackSimMultiRegionTrackingCfg
819 acc.merge(FPGATrackSimMultiRegionTrackingCfg(flags))
820 else:
821 from FPGATrackSimConfTools.FPGATrackSimMergeOutputsConfig import FPGATrackSimMergeOutputsAlgCfg
822 acc.merge(FPGATrackSimMergeOutputsAlgCfg(flags))
823
824 from FPGATrackSimSeeding.FPGATrackSimSeedingConfig import FPGATrackSimSeedingCfg
825 acc.merge(FPGATrackSimSeedingCfg(flags))
826
827
828 if flags.Tracking.ActiveConfig.storeTrackSeeds:
829 from ActsConfig.ActsSeedingConfig import ActsStoreTrackSeedsCfg
830 from InDetConfig.ITkActsHelpers import isFastPrimaryPass
831
832 acc.merge(ActsStoreTrackSeedsCfg(flags,
833 processPixels = True,
834 processStrips = not isFastPrimaryPass(flags)))
835
836
838
839 # for testing hardware run in F150
840 if(flags.Trigger.FPGATrackSim.runF150hw):
841 from EFTrackingFPGAPipeline.F100IntegrationConfig import F100DataEncodingCfg
842 acc.merge(F100DataEncodingCfg(flags))
843
844 from EFTrackingFPGAPipeline.F150KernelTesterConfig import KernelTesterCfg, F150EDMConversionAlgCfg
845 acc.merge(KernelTesterCfg(flags))
846 acc.merge(F150EDMConversionAlgCfg(flags))
847
848
849
850
851 acc.printConfig(withDetails=True, summariseProps=True)
852
853 return acc
854
856 acc=ComponentAccumulator()
857 if flags.Trigger.FPGATrackSim.writeAdditionalOutputData:
858 acc.addService(CompFactory.THistSvc(Output = ["EXPERT DATAFILE='monitoring.root', OPT='RECREATE'"]))
859
860 if (flags.Trigger.FPGATrackSim.Hough.houghRootoutput1st | flags.Trigger.FPGATrackSim.Hough.houghRootoutput2nd):
861 acc.addService(CompFactory.THistSvc(Output = ["TRIGFPGATrackSimHOUGHOUTPUT DATAFILE='HoughRootOutput.root', OPT='RECREATE'"]))
862
863 if flags.Trigger.FPGATrackSim.Hough.writeTestOutput:
864 acc.addService(CompFactory.THistSvc(Output = ["FPGATRACKSIMOUTPUT DATAFILE='test.root', OPT='RECREATE'"]))
865
866 if (flags.Trigger.FPGATrackSim.Hough.genScan):
867 acc.addService(CompFactory.THistSvc(Output = ["GENSCAN DATAFILE='genscan.root', OPT='RECREATE'"]))
868 return acc
869
870if __name__ == "__main__":
871 from AthenaConfiguration.AllConfigFlags import initConfigFlags
872 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
873
874
875 flags = initConfigFlags()
876
877
879 FinalProtoTrackChainxAODTracksKey="FPGA"
880 flags.Detector.EnableCalo = False
881
882 # ensure that the xAOD SP and cluster containers are available
883 flags.Tracking.ITkMainPass.doAthenaToActsSpacePoint=True
884 flags.Tracking.ITkMainPass.doAthenaToActsCluster=True
885 from ActsConfig.ActsCIFlags import actsLegacyWorkflowFlags
886 actsLegacyWorkflowFlags(flags)
887 flags.Acts.doRotCorrection = False
888
889
890 flags.Concurrency.NumThreads=1
891 flags.Concurrency.NumConcurrentEvents=1
892 flags.Concurrency.NumProcs=0
893 flags.Scheduler.ShowDataDeps=True
894 flags.Scheduler.CheckDependencies=True
895 flags.Debug.DumpEvtStore=False
896
897 # flags.Exec.DebugStage="exec" # useful option to debug the execution of the job - we want it commented out for production
898 flags.fillFromArgs()
899
901
902
903 if flags.Trigger.FPGATrackSim.Hough.useVaryingChi2Cut and not flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis:
904 flags.Trigger.FPGATrackSim.Hough.chi2cut = getChi2Cut(flags.Trigger.FPGATrackSim.region)
905 assert not flags.Trigger.FPGATrackSim.pipeline.startswith('F-5'),"ERROR You are trying to run an F-5* pipeline! This is not yet supported!"
906
907 if (flags.Trigger.FPGATrackSim.pipeline.startswith('F-1')):
908 print("You are trying to run an F-100 pipeline! I am going to run the Data Prep chain for you and nothing else!")
909 FPGATrackSimDataPrepConfig.runDataPrepChain()
910 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-2')):
911 print("You are trying to run an F-2* pipeline! I am auto-configuring the 1D bitshift for you, including eta pattern filters and phi road filters")
912 flags.Trigger.FPGATrackSim.Hough.etaPatternFilter = True
913 flags.Trigger.FPGATrackSim.Hough.phiRoadFilter = True
914 flags.Trigger.FPGATrackSim.Hough.hough1D = True
915 flags.Trigger.FPGATrackSim.Hough.hough = False
916 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-3')):
917 print("You are trying to run an F-3* pipeline! I am auto-configuring the 2D HT for you, and disabling the eta pattern filter and phi road filter. Whether you wanted to or not")
918 flags.Trigger.FPGATrackSim.Hough.etaPatternFilter = False
919 flags.Trigger.FPGATrackSim.Hough.phiRoadFilter = False
920 flags.Trigger.FPGATrackSim.Hough.hough1D = False
921 flags.Trigger.FPGATrackSim.Hough.hough = True
922 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-4')):
923 print("You are trying to run an F-4* pipeline! I am auto-configuring the GNN pattern recognition for you. Whether you wanted to or not")
924 flags.Trigger.FPGATrackSim.Hough.GNN = True
925 flags.Trigger.FPGATrackSim.Hough.chi2cut = 40 # All of the track candidates have chi2 values around 20 for some reason. Needs further investigation. For now move the default cut value to 40
926 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-6')):
927 print("You are trying to run an F-6* pipeline! I am auto-configuring the Inside-Out for you. Whether you wanted to or not")
928 flags.Trigger.FPGATrackSim.Hough.genScan=True
929 flags.Trigger.FPGATrackSim.spacePoints = flags.Trigger.FPGATrackSim.Hough.secondStage
930 elif (flags.Trigger.FPGATrackSim.pipeline != ""):
931 raise AssertionError("ERROR You are trying to run the pipeline " + flags.Trigger.FPGATrackSim.pipeline + " which is not yet supported!")
932
933 if (not flags.Trigger.FPGATrackSim.pipeline.startswith('F-1')):
934
935 flags.Tracking.writeExtendedSi_PRDInfo = not flags.Trigger.FPGATrackSim.writeOfflPRDInfo
936 splitPipeline=flags.Trigger.FPGATrackSim.pipeline.split('-')
937 trackingOption=9999999
938 if (len(splitPipeline) > 1): trackingOption=int(splitPipeline[1])
939 if (trackingOption < 9999999):
940 trackingOptionMod = (trackingOption % 100)
941 if (trackingOptionMod == 0):
942 print("You are trying to run the linearized chi2 fit as part of a pipeline! I am going to enable this for you whether you want to or not")
943 flags.Trigger.FPGATrackSim.tracking = True
944 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis = False
945 elif (trackingOptionMod == 10):
946 print("You are trying to run the second stage NN fake rejection as part of a pipeline! I am going to enable this for you whether you want to or not")
947 flags.Trigger.FPGATrackSim.tracking = True
948 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis = True
949 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis2nd = flags.Trigger.FPGATrackSim.Hough.secondStage
950 if (flags.Trigger.FPGATrackSim.pipeline.startswith('F-6')):
951 flags.Trigger.FPGATrackSim.doNNPathFinder = True
952 flags.Trigger.FPGATrackSim.doOverlapRemoval = False
953 flags.Trigger.FPGATrackSim.tracking = False
954 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis = False
955 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis2nd = flags.Trigger.FPGATrackSim.Hough.secondStage
956 else:
957 raise AssertionError("ERROR Your tracking option for the pipeline = " + str(trackingOption) + " is not yet supported!")
958
959 if isinstance(flags.Trigger.FPGATrackSim.wrapperFileName, str):
960 log.info("wrapperFile is string, converting to list")
961 flags.Trigger.FPGATrackSim.wrapperFileName = [flags.Trigger.FPGATrackSim.wrapperFileName]
962 flags.Input.Files = lambda f: [f.Trigger.FPGATrackSim.wrapperFileName]
963
964 if flags.Trigger.FPGATrackSim.Hough.useVaryingChi2Cut and flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis:
965 flags.Trigger.FPGATrackSim.Hough.chi2cut = getChi2CutNN(flags.Trigger.FPGATrackSim.region)
966
967 flags.lock()
968 flags.dump()
969 flags = flags.cloneAndReplace("Tracking.ActiveConfig","Tracking.MainPass")
970 acc=MainServicesCfg(flags)
971
973
974 if not flags.Trigger.FPGATrackSim.wrapperFileName:
975 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
976 acc.merge(PoolReadCfg(flags))
977
978 if flags.Input.isMC:
979 from xAODTruthCnv.xAODTruthCnvConfig import GEN_AOD2xAODCfg
980 acc.merge(GEN_AOD2xAODCfg(flags))
981
982 from JetRecConfig.JetRecoSteering import addTruthPileupJetsToOutputCfg # TO DO: check if this is indeed necessary for pileup samples
983 acc.merge(addTruthPileupJetsToOutputCfg(flags))
984
985 if flags.Detector.EnableCalo:
986 from CaloRec.CaloRecoConfig import CaloRecoCfg
987 acc.merge(CaloRecoCfg(flags))
988
989 if flags.Tracking.recoChain:
990 from InDetConfig.TrackRecoConfig import InDetTrackRecoCfg
991 acc.merge(InDetTrackRecoCfg(flags))
992 if flags.Trigger.FPGATrackSim.writeOfflPRDInfo:
993 from InDetConfig.InDetPrepRawDataToxAODConfig import ITkActsPrepDataToxAODCfg
994 acc.merge( ITkActsPrepDataToxAODCfg( flags,
995 PixelMeasurementContainer = "ITkPixelMeasurements_offl",
996 StripMeasurementContainer = "ITkStripMeasurements_offl" ) )
997 from InDetConfig.InDetPrepRawDataToxAODConfig import TruthParticleIndexDecoratorAlgCfg
998 acc.merge( TruthParticleIndexDecoratorAlgCfg(flags) )
999 from InDetConfig.InDetPrepRawDataFormationConfig import ITkXAODToInDetClusterConversionCfg
1000 acc.merge(ITkXAODToInDetClusterConversionCfg(flags))
1001
1002
1003 # Configure both the dataprep and logical hits algorithms.
1004 acc.merge(FPGATrackSimDataPrepConfig.FPGATrackSimDataPrepAlgCfg(flags))
1005 from FPGATrackSimConfTools.FPGATrackSimMultiRegionConfig import FPGATrackSimMultiRegionTrackingCfg
1006 acc.merge(FPGATrackSimMultiRegionTrackingCfg(flags))
1007
1008 if flags.Trigger.FPGATrackSim.doEDMConversion:
1009 stage = "_2nd" if flags.Trigger.FPGATrackSim.Hough.secondStage else "_1st"
1010 acc.merge(FPGATrackSimDataPrepConfig.FPGAConversionAlgCfg(flags, name = f"FPGAConversionAlg{stage}",
1011 stage = f"{stage}",
1012 doActsTrk=True,
1013 doSP=flags.Trigger.FPGATrackSim.convertSPs))
1014
1015 from FPGATrackSimPrototrackFitter.FPGATrackSimPrototrackFitterConfig import FPGATruthDecorationCfg, FPGAProtoTrackFitCfg
1016 acc.merge(FPGAProtoTrackFitCfg(flags,stage=f"{stage}")) # Run ACTS KF
1017 acc.merge(FPGATruthDecorationCfg(flags,FinalProtoTrackChainxAODTracksKey=FinalProtoTrackChainxAODTracksKey)) # Run Truth Matching/Decoration chain
1018 if flags.Trigger.FPGATrackSim.runCKF:
1019 from FPGATrackSimConfTools.FPGATrackExtensionConfig import FPGATrackExtensionAlgCfg
1020 acc.merge(FPGATrackExtensionAlgCfg(flags, enableTrackStatePrinter=False, name="FPGATrackExtension",
1021 ProtoTracksLocation=f"ActsProtoTracks{stage}FromFPGATrack")) # run CKF track extension on FPGA tracks
1022
1023 if flags.Trigger.FPGATrackSim.writeToAOD:
1024 acc.merge(FPGATrackSimDataPrepConfig.WriteToAOD(flags,
1025 stage = f"{stage}",
1026 finalTrackParticles=f"{FinalProtoTrackChainxAODTracksKey}TrackParticles"))
1027
1028 # Reporting algorithm (used for debugging - can be disabled)
1029 from FPGATrackSimReporting.FPGATrackSimReportingConfig import FPGATrackSimReportingCfg
1030 acc.merge(FPGATrackSimReportingCfg(flags, stage=f"{stage}",
1031 perEventReports = ((flags.Trigger.FPGATrackSim.sampleType != 'skipTruth') and flags.Exec.MaxEvents<=10 ) )) # disable perEventReports for pileup samples or many events
1032
1033 acc.store(open('AnalysisConfig.pkl','wb'))
1034
1035 acc.foreach_component("*FPGATrackSim*").OutputLevel=flags.Trigger.FPGATrackSim.loglevel
1036 if flags.Trigger.FPGATrackSim.msgLimit!=-1:
1037 acc.getService("MessageSvc").debugLimit = flags.Trigger.FPGATrackSim.msgLimit
1038 acc.getService("MessageSvc").infoLimit = flags.Trigger.FPGATrackSim.msgLimit
1039 acc.getService("MessageSvc").verboseLimit = flags.Trigger.FPGATrackSim.msgLimit
1040
1041 statusCode = acc.run(flags.Exec.MaxEvents)
1042 assert statusCode.isSuccess() is True, "Application execution did not succeed"
if(febId1==febId2)
void print(char *figname, TCanvas *c1)
static std::string FindCalibFile(const std::string &logical_file_name)
static std::string FindCalibDirectory(const std::string &logical_file_name)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
FPGATrackSimRoadUnionToolGenScanCfg(flags, name="FPGATrackSimRoadUnionToolGenScan")
FPGATrackSimRoadUnionToolCfg(flags, name="FPGATrackSimRoadUnionTool")
FPGATrackSimRoadUnionTool1DCfg(flags, name="FPGATrackSimRoadUnionTool1D")
FPGATrackSimRoadUnionToolGNNCfg(flags, name="FPGATrackSimRoadUnionToolGNN")
FPGATrackSimGNNEdgeClassifierToolCfg(flags, name="FPGATrackSimGNNEdgeClassifierTool")
FPGATrackSimGNNGraphConstructionToolCfg(flags, name="FPGATrackSimGNNGraphConstructionTool")
FPGATrackSimTrackFitterToolCfg(flags, name="FPGATrackSimTrackFitterTool")
FPGATrackSimBankSvcCfg(flags, name="FPGATrackSimBankSvc")
FPGATrackSimOverlapRemovalToolCfg(flags, name="FPGATrackSimOverlapRemovalTool")
SPRoadFilterToolCfg(flags, secondStage=False, name="FPGATrackSimSpacepointRoadFilterTool")
FPGATrackSimHoughRootOutputToolCfg(flags, name="FPGATrackSimHoughRootOutputTool")
FPGATrackSimGNNRoadMakerToolCfg(flags, name="FPGATrackSimGNNRoadMakerTool")
NNTrackToolCfg(flags, name="FPGATrackSimNNTrackTool")
getEtaBin(flags)
return a number 0-19, 0 is most central bin, 19 is most forward (based on absolute value of eta)
FPGATrackSimLogicalHitsProcessAlgCfg(inputFlags, name="FPGATrackSimLogicalHitsProcessAlg", **kwargs)
FPGATrackSimGNNRootOutputToolCfg(flags, name="FPGATrackSimGNNRootOutputTool")
FPGATrackSimSlicingEngineCfg(flags, name="FPGATrackSimSlicingEngineTool")
LRTRoadFinderCfg(flags, name="LRTRoadFinder")
FPGATrackSimDataFlowToolCfg(flags, name="FPGATrackSimDataFlowTool")