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