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 RF.noHitFilter = flags.Trigger.FPGATrackSim.GNN.doAllHits # Flag to turn on doing all hits for full-scan running of GNN pipeline
404
405 patternRecoTool = CompFactory.FPGATrackSimGNNPatternRecoTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimGNNPatternRecoTool"))
406 patternRecoTool.GNNGraphHitSelector = result.popToolsAndMerge(FPGATrackSimGNNGraphHitSelectorToolCfg(flags))
407
408
409 patternRecoTool.GNNGraphConstruction = result.popToolsAndMerge(FPGATrackSimGNNGraphConstructionToolCfg(flags))
410 edgeResult, edgeClassifierTools = FPGATrackSimGNNEdgeClassifierToolCfg(flags)
411 result.merge(edgeResult)
412 patternRecoTool.GNNEdgeClassifiers = edgeClassifierTools
413 patternRecoTool.GNNRoadMaker = result.popToolsAndMerge(FPGATrackSimGNNRoadMakerToolCfg(flags))
414 patternRecoTool.GNNRootOutput = result.popToolsAndMerge(FPGATrackSimGNNRootOutputToolCfg(flags))
415 patternRecoTool.doGNNRootOutput = flags.Trigger.FPGATrackSim.GNN.doGNNRootOutput
416 patternRecoTool.regionNum = int(flags.Trigger.FPGATrackSim.region)
417
418 RF.tools = [patternRecoTool]
419 result.addPublicTool(RF, primary=True)
420
421 return result
422
423def FPGATrackSimGNNGraphHitSelectorToolCfg(flags,name="FPGATrackSimGNNGraphHitSelectorTool"):
424 result = ComponentAccumulator()
425
426 GNNGraphHitSelectorTool = CompFactory.FPGATrackSimGNNGraphHitSelectorTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimGNNGraphHitSelectorTool"))
427 GNNGraphHitSelectorTool.doPixelHits = flags.Trigger.FPGATrackSim.GNN.doPixelHits
428 GNNGraphHitSelectorTool.doStripHits = flags.Trigger.FPGATrackSim.GNN.doStripHits
429
430 result.setPrivateTools(GNNGraphHitSelectorTool)
431
432 return result
433
434
435def FPGATrackSimGNNGraphConstructionToolCfg(flags,name="FPGATrackSimGNNGraphConstructionTool"):
436 result = ComponentAccumulator()
437
438 GNNGraphConstructionTool = CompFactory.FPGATrackSimGNNGraphConstructionTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
439 GNNGraphConstructionTool.graphTool = flags.Trigger.FPGATrackSim.GNN.graphTool.value
440 GNNGraphConstructionTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
441
442
443 # Module Map Configuration
444 GNNGraphConstructionTool.moduleMapType=flags.Trigger.FPGATrackSim.GNN.moduleMapType.value
445 GNNGraphConstructionTool.moduleMapFunc=flags.Trigger.FPGATrackSim.GNN.moduleMapFunc.value
446 GNNGraphConstructionTool.moduleMapTol=flags.Trigger.FPGATrackSim.GNN.moduleMapTol
447 GNNGraphConstructionTool.moduleMapRMSThresholdFactor=flags.Trigger.FPGATrackSim.GNN.moduleMapRMSThresholdFactor
448
449 # Metric Learning Configuration
450 GNNGraphConstructionTool.metricLearningR=flags.Trigger.FPGATrackSim.GNN.metricLearningR
451 GNNGraphConstructionTool.metricLearningMaxN=flags.Trigger.FPGATrackSim.GNN.metricLearningMaxN
452
453 from AthOnnxComps.OnnxRuntimeInferenceConfig import OnnxRuntimeInferenceToolCfg
454 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
455
456 GNNGraphConstructionTool.MLInferenceTool = result.popToolsAndMerge(OnnxRuntimeInferenceToolCfg(
457 flags, flags.Trigger.FPGATrackSim.GNN.MLModelPath, OnnxRuntimeType.CPU))
458
459 result.setPrivateTools(GNNGraphConstructionTool)
460
461 return result
462
463def FPGATrackSimGNNEdgeClassifierToolCfg(flags, name="FPGATrackSimGNNEdgeClassifierTool"):
464 result = ComponentAccumulator()
465
466 from AthOnnxComps.OnnxRuntimeInferenceConfig import OnnxRuntimeInferenceToolCfg
467 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
468
469 # For GNN models, we will have one model for each eta-slice, meant to be used for all 20 phi-slices
470 region = int(flags.Trigger.FPGATrackSim.region)
471 phiBinBase = 2 # [2Ï€/16, 3Ï€/16]
472 etaBin = (region >> 6) & 0x1f # extract η bin and side from the real region number
473 #side = (region >> 5) & 0x1
474 side = 1 # For now, only use the positive size models
475 minAbsEta = etaBin * 0.2
476
477 base_region = FPGATrackSimDataPrepConfig.getRegionNumber(phiBinBase, minAbsEta, side, verbosePrint=False)
478 model_path = f"{flags.Trigger.FPGATrackSim.GNN.GNNModelPath}_{base_region}.onnx"
479
480 GNNEdgeClassifierTool = CompFactory.FPGATrackSimGNNEdgeClassifierTool(
481 FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags, name))
482 GNNEdgeClassifierTool.GNNInferenceTool = result.popToolsAndMerge(
483 OnnxRuntimeInferenceToolCfg(flags, model_path, OnnxRuntimeType.CPU, name=f"OnnxInferenceTool_{region}")
484 )
485 GNNEdgeClassifierTool.regionNum = region
486 GNNEdgeClassifierTool.doGNNPixelSeeding = flags.Trigger.FPGATrackSim.GNN.doGNNPixelSeeding # Use new models
487
488 return result, [GNNEdgeClassifierTool]
489
490def FPGATrackSimGNNRoadMakerToolCfg(flags,name="FPGATrackSimGNNRoadMakerTool"):
491 result = ComponentAccumulator()
492
493 GNNRoadMakerTool = CompFactory.FPGATrackSimGNNRoadMakerTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
494 GNNRoadMakerTool.roadMakerTool = flags.Trigger.FPGATrackSim.GNN.roadMakerTool.value
495 GNNRoadMakerTool.edgeScoreCut = flags.Trigger.FPGATrackSim.GNN.edgeScoreCut
496 GNNRoadMakerTool.doGNNPixelSeeding = flags.Trigger.FPGATrackSim.GNN.doGNNPixelSeeding
497 GNNRoadMakerTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
498
499 from TrigFastTrackFinder.TrigFastTrackFinderConfig import ITkTrigL2LayerNumberToolCfg
500 GNNRoadMakerTool.LayerNumberTool = result.getPrimaryAndMerge(ITkTrigL2LayerNumberToolCfg(flags))
501
502 result.setPrivateTools(GNNRoadMakerTool)
503
504 return result
505
506def FPGATrackSimGNNRootOutputToolCfg(flags,name="FPGATrackSimGNNRootOutputTool"):
507 result = ComponentAccumulator()
508
509 GNNRootOutputTool = CompFactory.FPGATrackSimGNNRootOutputTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
510 GNNRootOutputTool.OutputRegion = str(flags.Trigger.FPGATrackSim.region)
511
512 from TrigFastTrackFinder.TrigFastTrackFinderConfig import ITkTrigL2LayerNumberToolCfg
513 GNNRootOutputTool.LayerNumberTool = result.getPrimaryAndMerge(ITkTrigL2LayerNumberToolCfg(flags))
514
515 if(flags.Trigger.FPGATrackSim.GNN.doGNNRootOutput):
516 result.addService(CompFactory.THistSvc(Output = ["TRIGFPGATrackSimGNNOUTPUT DATAFILE='GNNRootOutput.root', OPT='RECREATE'"]))
517 result.setPrivateTools(GNNRootOutputTool)
518
519 return result
520
521def FPGATrackSimDataFlowToolCfg(flags,name="FPGATrackSimDataFlowTool"):
522 result=ComponentAccumulator()
523 DataFlowTool = CompFactory.FPGATrackSimDataFlowTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
524 DataFlowTool.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
525 DataFlowTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
526 DataFlowTool.Chi2ndofCut = flags.Trigger.FPGATrackSim.ActiveConfig.chi2cut
527 DataFlowTool.THistSvc = CompFactory.THistSvc()
528 result.setPrivateTools(DataFlowTool)
529 return result
530
531def FPGATrackSimHoughRootOutputToolCfg(flags,name="FPGATrackSimHoughRootOutputTool"):
532 result=ComponentAccumulator()
533 HoughRootOutputTool = CompFactory.FPGATrackSimHoughRootOutputTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
534 HoughRootOutputTool.FPGATrackSimEventSelectionSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
535 HoughRootOutputTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
536 HoughRootOutputTool.THistSvc = CompFactory.THistSvc()
537 HoughRootOutputTool.OutputRegion = str(flags.Trigger.FPGATrackSim.region)
538 result.setPrivateTools(HoughRootOutputTool)
539 return result
540
541def LRTRoadFinderCfg(flags,name="LRTRoadFinder"):
542
543 result=ComponentAccumulator()
544 LRTRoadFinder =CompFactory.FPGATrackSimHoughTransform_d0phi0_Tool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
545 LRTRoadFinder.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
546 LRTRoadFinder.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
547 LRTRoadFinder.combine_layers = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackCombineLayers
548 LRTRoadFinder.convolution = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackConvolution
549 LRTRoadFinder.hitExtend_x = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackHitExtendX
550 LRTRoadFinder.scale = flags.Trigger.FPGATrackSim.ActiveConfig.scale
551 LRTRoadFinder.threshold = flags.Trigger.FPGATrackSim.ActiveConfig.lrtStraighttrackThreshold
552 result.setPrivateTools(LRTRoadFinder)
553 return result
554
555def NNTrackToolCfg(flags,name="FPGATrackSimNNTrackTool"):
556 result=ComponentAccumulator()
557 NNTrackTool = CompFactory.FPGATrackSimNNTrackTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
558 NNTrackTool.THistSvc = CompFactory.THistSvc()
559 NNTrackTool.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
560 NNTrackTool.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
561 NNTrackTool.IdealGeoRoads = False
562 NNTrackTool.useSpacePoints = flags.Trigger.FPGATrackSim.spacePoints and not flags.Trigger.FPGATrackSim.ActiveConfig.genScan and not flags.Trigger.FPGATrackSim.ActiveConfig.GNN
563 NNTrackTool.SPRoadFilterTool = result.popToolsAndMerge(SPRoadFilterToolCfg(flags))
564 NNTrackTool.MinNumberOfRealHitsInATrack = 5 if flags.Trigger.FPGATrackSim.ActiveConfig.genScan else 7 if flags.Trigger.FPGATrackSim.ActiveConfig.GNN else 9
565 NNTrackTool.useSectors = False
566 NNTrackTool.doGNNTracking = flags.Trigger.FPGATrackSim.GNN.doGNNTracking
567 NNTrackTool.nInputsGNN = flags.Trigger.FPGATrackSim.GNN.nInputsGNN
568 NNTrackTool.useCartesian = flags.Trigger.FPGATrackSim.NNCartesianCoordinates
569 result.setPrivateTools(NNTrackTool)
570 return result
571
572def FPGATrackSimTrackFitterToolCfg(flags,name="FPGATrackSimTrackFitterTool"):
573 result=ComponentAccumulator()
574 TF_1st = CompFactory.FPGATrackSimTrackFitterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
575 TF_1st.GuessHits = flags.Trigger.FPGATrackSim.ActiveConfig.guessHits
576 TF_1st.IdealCoordFitType = flags.Trigger.FPGATrackSim.ActiveConfig.idealCoordFitType
577 TF_1st.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
578 TF_1st.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
579 TF_1st.chi2DofRecoveryMax = flags.Trigger.FPGATrackSim.ActiveConfig.chi2DoFRecoveryMax
580 TF_1st.chi2DofRecoveryMin = flags.Trigger.FPGATrackSim.ActiveConfig.chi2DoFRecoveryMin
581 TF_1st.doMajority = flags.Trigger.FPGATrackSim.ActiveConfig.doMajority
582 TF_1st.nHits_noRecovery = flags.Trigger.FPGATrackSim.ActiveConfig.nHitsNoRecovery
583 TF_1st.DoDeltaGPhis = flags.Trigger.FPGATrackSim.ActiveConfig.doDeltaGPhis
584 TF_1st.DoMissingHitsChecks = flags.Trigger.FPGATrackSim.ActiveConfig.doMissingHitsChecks
585 TF_1st.IdealGeoRoads = (flags.Trigger.FPGATrackSim.ActiveConfig.IdealGeoRoads and flags.Trigger.FPGATrackSim.tracking)
586 TF_1st.useSpacePoints = flags.Trigger.FPGATrackSim.spacePoints and not flags.Trigger.FPGATrackSim.ActiveConfig.genScan
587 TF_1st.SPRoadFilterTool = result.popToolsAndMerge(SPRoadFilterToolCfg(flags))
588 TF_1st.fitFromRoad = flags.Trigger.FPGATrackSim.ActiveConfig.fitFromRoad
589 result.addPublicTool(TF_1st, primary=True)
590 return result
591
592def FPGATrackSimOverlapRemovalToolCfg(flags,name="FPGATrackSimOverlapRemovalTool"):
593 result=ComponentAccumulator()
594 OR_1st = CompFactory.FPGATrackSimOverlapRemovalTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
595 OR_1st.ORAlgo = "Normal"
596 OR_1st.doFastOR = flags.Trigger.FPGATrackSim.ActiveConfig.doFastOR
597 OR_1st.NumOfHitPerGrouping = 3
598 if flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and not flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
599 OR_1st.MinChi2 = getChi2Cut(flags.Trigger.FPGATrackSim.region)
600 elif flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
601 OR_1st.MinChi2 = getChi2CutNN(flags.Trigger.FPGATrackSim.region)
602 else:
603 OR_1st.MinChi2 = flags.Trigger.FPGATrackSim.ActiveConfig.chi2cut
604 if flags.Trigger.FPGATrackSim.ActiveConfig.hough or flags.Trigger.FPGATrackSim.ActiveConfig.hough1D:
605 OR_1st.nBins_x = flags.Trigger.FPGATrackSim.ActiveConfig.xBins + 2 * flags.Trigger.FPGATrackSim.ActiveConfig.xBufferBins
606 OR_1st.nBins_y = flags.Trigger.FPGATrackSim.ActiveConfig.yBins + 2 * flags.Trigger.FPGATrackSim.ActiveConfig.yBufferBins
607 OR_1st.localMaxWindowSize = flags.Trigger.FPGATrackSim.ActiveConfig.localMaxWindowSize
608 OR_1st.roadSliceOR = flags.Trigger.FPGATrackSim.ActiveConfig.roadSliceOR
609
610 from FPGATrackSimAlgorithms.FPGATrackSimAlgorithmConfig import FPGATrackSimOverlapRemovalToolMonitoringCfg
611 OR_1st.MonTool = result.getPrimaryAndMerge(FPGATrackSimOverlapRemovalToolMonitoringCfg(flags))
612
613 result.addPublicTool(OR_1st, primary=True)
614 return result
615
617 newFlags = flags.cloneAndReplace("Trigger.FPGATrackSim.ActiveConfig", "Trigger.FPGATrackSim." + flags.Trigger.FPGATrackSim.algoTag,keepOriginal=True)
618 return newFlags
619
620def SPRoadFilterToolCfg(flags,secondStage=False,name="FPGATrackSimSpacepointRoadFilterTool"):
621 result=ComponentAccumulator()
622 name="FPGATrackSimSpacepointRoadFilterTool_1st"
623 if secondStage:
624 name="FPGATrackSimSpacepointRoadFilterTool_2st"
625 SPRoadFilter = CompFactory.FPGATrackSimSpacepointRoadFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
626 SPRoadFilter.FPGATrackSimMappingSvc = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
627 SPRoadFilter.FPGATrackSimBankSvc = result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
628 SPRoadFilter.filtering = flags.Trigger.FPGATrackSim.ActiveConfig.spacePointFiltering
629 SPRoadFilter.minSpacePlusPixel = flags.Trigger.FPGATrackSim.minSpacePlusPixel
630 SPRoadFilter.isSecondStage = secondStage
631 SPRoadFilter.dropUnpairedIfSP = flags.Trigger.FPGATrackSim.dropUnpairedIfSP
632
633 # This threshold is the number of *missing* hits allowed. For now, assume that if 1st stage this is always 1.
634 # We don't actually run this tool in the first stage anymore, so this is more to preserve backwards compatibility
635 if secondStage:
636 SPRoadFilter.threshold = flags.Trigger.FPGATrackSim.hitThreshold
637 else:
638 SPRoadFilter.threshold = 1
639
640 SPRoadFilter.setSectors = (flags.Trigger.FPGATrackSim.ActiveConfig.IdealGeoRoads and flags.Trigger.FPGATrackSim.tracking)
641 result.setPrivateTools(SPRoadFilter)
642 return result
643
644
645
646
647def FPGATrackSimLogicalHitsProcessAlgCfg(inputFlags,name="FPGATrackSimLogicalHitsProcessAlg",**kwargs):
648
650
651 result=ComponentAccumulator()
652 kwargs.setdefault("name", FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,name))
653
654 theFPGATrackSimLogicalHitsProcessAlg=CompFactory.FPGATrackSimLogicalHitsProcessAlg(**kwargs)
655 theFPGATrackSimLogicalHitsProcessAlg.writeOutputData = flags.Trigger.FPGATrackSim.writeAdditionalOutputData
656 theFPGATrackSimLogicalHitsProcessAlg.tracking = flags.Trigger.FPGATrackSim.tracking
657 theFPGATrackSimLogicalHitsProcessAlg.SetTruthParametersForTracks = flags.Trigger.FPGATrackSim.SetTruthParametersForTracks
658 theFPGATrackSimLogicalHitsProcessAlg.doOverlapRemoval = flags.Trigger.FPGATrackSim.doOverlapRemoval
659 theFPGATrackSimLogicalHitsProcessAlg.DoMissingHitsChecks = flags.Trigger.FPGATrackSim.ActiveConfig.doMissingHitsChecks
660 theFPGATrackSimLogicalHitsProcessAlg.DoHoughRootOutput1st = flags.Trigger.FPGATrackSim.ActiveConfig.houghRootoutput1st
661 theFPGATrackSimLogicalHitsProcessAlg.NumOfHitPerGrouping = flags.Trigger.FPGATrackSim.ActiveConfig.NumOfHitPerGrouping
662 theFPGATrackSimLogicalHitsProcessAlg.DoNNTrack_1st = flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis
663 theFPGATrackSimLogicalHitsProcessAlg.DoGNNTrack = flags.Trigger.FPGATrackSim.GNN.doGNNTracking
664 theFPGATrackSimLogicalHitsProcessAlg.DoGNNPixelSeeding = flags.Trigger.FPGATrackSim.GNN.doGNNPixelSeeding
665 theFPGATrackSimLogicalHitsProcessAlg.noHitFilter = flags.Trigger.FPGATrackSim.GNN.doAllHits # Flag to turn on doing all hits for full-scan running of GNN pipeline
666 theFPGATrackSimLogicalHitsProcessAlg.eventSelector = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimEventSelectionSvcCfg(flags))
667 if flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and not flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
668 theFPGATrackSimLogicalHitsProcessAlg.TrackScoreCut = getChi2Cut(flags.Trigger.FPGATrackSim.region)
669 elif flags.Trigger.FPGATrackSim.ActiveConfig.useVaryingChi2Cut and flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis2nd:
670 theFPGATrackSimLogicalHitsProcessAlg.TrackScoreCut = getChi2CutNN(flags.Trigger.FPGATrackSim.region)
671 else:
672 theFPGATrackSimLogicalHitsProcessAlg.TrackScoreCut = flags.Trigger.FPGATrackSim.ActiveConfig.chi2cut
673
674 if flags.Trigger.FPGATrackSim.applyEtaPhiChi2Cuts:
675 cutset = getCutSetFromPath(flags)
676 theFPGATrackSimLogicalHitsProcessAlg.TrackScoreCut = 1e10
677 scale = 1.0
678 if flags.Trigger.FPGATrackSim.applyEtaPhiChi2Cuts4HitOnly:
679 theFPGATrackSimLogicalHitsProcessAlg.Chi2PhiCut = [1e10,scale*cutset["pairSetChi2PhiCut_best_lowPt_4"]]
680 theFPGATrackSimLogicalHitsProcessAlg.Chi2EtaCut = [1e10,scale*cutset["pairSetChi2EtaCut_best_lowPt_4"]]
681 else:
682 theFPGATrackSimLogicalHitsProcessAlg.Chi2PhiCut = [cutset["pairSetChi2PhiCut_best_lowPt_5"],cutset["pairSetChi2PhiCut_best_lowPt_4"]]
683 theFPGATrackSimLogicalHitsProcessAlg.Chi2EtaCut = [cutset["pairSetChi2EtaCut_best_lowPt_5"],cutset["pairSetChi2EtaCut_best_lowPt_4"]]
684
685 theFPGATrackSimLogicalHitsProcessAlg.keepHitsStrategy = flags.Trigger.FPGATrackSim.GenScan.keepHitsStrategy
686
687 theFPGATrackSimLogicalHitsProcessAlg.passLowestChi2TrackOnly = flags.Trigger.FPGATrackSim.ActiveConfig.passLowestChi2TrackOnly
688 theFPGATrackSimLogicalHitsProcessAlg.secondStageStrips = (not flags.Trigger.FPGATrackSim.ActiveConfig.GNN)
689 FPGATrackSimMaping = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimMappingCfg(flags))
690 theFPGATrackSimLogicalHitsProcessAlg.FPGATrackSimMapping = FPGATrackSimMaping
691 # Adding region so we can set it for tracks, then get the bfield
692 theFPGATrackSimLogicalHitsProcessAlg.Region = flags.Trigger.FPGATrackSim.region
693 # If tracking is set to False or if we do the NN analysis, don't configure the bank service
694 if flags.Trigger.FPGATrackSim.tracking and not flags.Trigger.FPGATrackSim.ActiveConfig.trackNNAnalysis:
695 result.getPrimaryAndMerge(FPGATrackSimBankSvcCfg(flags))
696
697 if (flags.Trigger.FPGATrackSim.ActiveConfig.hough1D):
698 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionTool1DCfg(flags))
699 elif (flags.Trigger.FPGATrackSim.ActiveConfig.genScan):
700 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionToolGenScanCfg(flags))
701 elif (flags.Trigger.FPGATrackSim.ActiveConfig.GNN):
702 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionToolGNNCfg(flags))
703 else:
704 theFPGATrackSimLogicalHitsProcessAlg.RoadFinder = result.getPrimaryAndMerge(FPGATrackSimRoadUnionToolCfg(flags))
705
706 if (flags.Trigger.FPGATrackSim.ActiveConfig.etaPatternFilter):
707 EtaPatternFilter = CompFactory.FPGATrackSimEtaPatternFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimEtaPatternFilterTool"))
708 EtaPatternFilter.FPGATrackSimMappingSvc = FPGATrackSimMaping
709 EtaPatternFilter.threshold = flags.Trigger.FPGATrackSim.Hough1D.threshold[0]
710 EtaPatternFilter.EtaPatterns = flags.Trigger.FPGATrackSim.mapsDir+"/"+FPGATrackSimDataPrepConfig.getBaseName(flags)+".patt"
711 theFPGATrackSimLogicalHitsProcessAlg.RoadFilter = EtaPatternFilter
712 theFPGATrackSimLogicalHitsProcessAlg.FilterRoads = True
713
714 if (flags.Trigger.FPGATrackSim.ActiveConfig.phiRoadFilter):
715 RoadFilter2 = CompFactory.FPGATrackSimPhiRoadFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimPhiRoadFilterTool"))
716 RoadFilter2.FPGATrackSimMappingSvc = FPGATrackSimMaping
717 RoadFilter2.threshold = flags.Trigger.FPGATrackSim.Hough1D.threshold[0]
718 RoadFilter2.fieldCorrection = flags.Trigger.FPGATrackSim.ActiveConfig.fieldCorrection
719
720 windows = [flags.Trigger.FPGATrackSim.Hough1D.phifilterwindow for i in range(len(flags.Trigger.FPGATrackSim.ActiveConfig.hitExtendX))]
721 RoadFilter2.window = windows
722
723 theFPGATrackSimLogicalHitsProcessAlg.RoadFilter2 = RoadFilter2
724 theFPGATrackSimLogicalHitsProcessAlg.FilterRoads2 = True
725
726 theFPGATrackSimLogicalHitsProcessAlg.SlicingEngineTool = result.getPrimaryAndMerge(FPGATrackSimSlicingEngineCfg(flags))
727
728 theFPGATrackSimLogicalHitsProcessAlg.HoughRootOutputTool = result.getPrimaryAndMerge(FPGATrackSimHoughRootOutputToolCfg(flags))
729 theFPGATrackSimLogicalHitsProcessAlg.writeRegion=flags.Trigger.FPGATrackSim.writeRegion
730
731 LRTRoadFilter = CompFactory.FPGATrackSimLLPRoadFilterTool(FPGATrackSimDataPrepConfig.nameWithRegionSuffix(flags,"FPGATrackSimLLPRoadFilterTool"))
732 result.addPublicTool(LRTRoadFilter)
733 theFPGATrackSimLogicalHitsProcessAlg.LRTRoadFilter = LRTRoadFilter
734
735 theFPGATrackSimLogicalHitsProcessAlg.LRTRoadFinder = result.getPrimaryAndMerge(LRTRoadFinderCfg(flags))
736 theFPGATrackSimLogicalHitsProcessAlg.NNTrackTool = result.getPrimaryAndMerge(NNTrackToolCfg(flags))
737
738 theFPGATrackSimLogicalHitsProcessAlg.writeInputBranches=flags.Trigger.FPGATrackSim.writeAdditionalOutputData and (flags.Trigger.FPGATrackSim.regionToWriteDPTree < 0)
739 theFPGATrackSimLogicalHitsProcessAlg.OutputTool = result.popToolsAndMerge(FPGATrackSimWriteOutputCfg(flags))
740 theFPGATrackSimLogicalHitsProcessAlg.TrackFitter_1st = result.getPrimaryAndMerge(FPGATrackSimTrackFitterToolCfg(flags))
741 theFPGATrackSimLogicalHitsProcessAlg.OverlapRemoval_1st = result.getPrimaryAndMerge(FPGATrackSimOverlapRemovalToolCfg(flags))
742
743 theFPGATrackSimLogicalHitsProcessAlg.SpacePointTool = result.getPrimaryAndMerge(FPGATrackSimDataPrepConfig.FPGATrackSimSpacePointsToolCfg(flags))
744 theFPGATrackSimLogicalHitsProcessAlg.Spacepoints = flags.Trigger.FPGATrackSim.spacePoints
745
746 if flags.Trigger.FPGATrackSim.ActiveConfig.lrt:
747 assert flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseBasicHitFilter != flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseMlHitFilter, 'Inconsistent LRT hit filtering setup, need either ML of Basic filtering enabled'
748 assert flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseStraightTrackHT != flags.Trigger.FPGATrackSim.ActiveConfig.lrtUseDoubletHT, 'Inconsistent LRT HT setup, need either double or strightTrack enabled'
749 theFPGATrackSimLogicalHitsProcessAlg.doLRT = True
750 theFPGATrackSimLogicalHitsProcessAlg.LRTHitFiltering = (not flags.Trigger.FPGATrackSim.ActiveConfig.lrtSkipHitFiltering)
751
752
753
754 from FPGATrackSimAlgorithms.FPGATrackSimAlgorithmConfig import FPGATrackSimTrackMonCfg
755
756
757 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage', flags, variety='road'))
758
759 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadPostFilter1Monitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_filter_1', flags, variety='road'))
760
761 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadPostOverlapRemovalMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_overlap_removal', flags, variety='road'))
762
763 theFPGATrackSimLogicalHitsProcessAlg.FirstStageRoadPostFilter2Monitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_filter_2', flags, variety='road'))
764
765
766 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage', flags, variety='track'))
767
768 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackPostSetTruthMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_set_truth', flags, variety='track'))
769
770 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackPostChi2Monitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_chi2', flags, variety='track'))
771
772 theFPGATrackSimLogicalHitsProcessAlg.FirstStageTrackPostOverlapRemovalTrackMonitor = result.getPrimaryAndMerge(FPGATrackSimTrackMonCfg ('first_stage_post_overlap_removal', flags, variety='track'))
773
774 result.addEventAlgo(theFPGATrackSimLogicalHitsProcessAlg)
775
776 return result
777
778
779
780
781def getChi2Cut(region):
782 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
783 binSize = 0.2
784 side = (region >> 5) & 0x1
785 etaBin = (region >> 6) & 0x1F
786 etaRange = [round(binSize * etaBin, 1), round(binSize * (etaBin + 1), 1)] if side else [round(-binSize * (etaBin + 1), 1), round(-binSize * etaBin, 1)]
787
788 abs_etaRange = tuple(round(abs(val), 1) for val in etaRange)
789
790 eta_to_chi2 = {
791 (0.0, 0.2): chi2cut_l[0], (0.2, 0.4): chi2cut_l[1], (0.4, 0.6): chi2cut_l[2],
792 (0.6, 0.8): chi2cut_l[3], (0.8, 1.0): chi2cut_l[4], (1.0, 1.2): chi2cut_l[5],
793 (1.2, 1.4): chi2cut_l[6], (1.4, 1.6): chi2cut_l[7], (1.6, 1.8): chi2cut_l[8],
794 (1.8, 2.0): chi2cut_l[9], (2.0, 2.2): chi2cut_l[10], (2.2, 2.4): chi2cut_l[11],
795 (2.4, 2.6): chi2cut_l[12], (2.6, 2.8): chi2cut_l[13], (2.8, 3.0): chi2cut_l[14],
796 (3.0, 3.2): chi2cut_l[15], (3.2, 3.4): chi2cut_l[16], (3.4, 3.6): chi2cut_l[17],
797 (3.6, 3.8): chi2cut_l[18], (3.8, 4.0): chi2cut_l[19]
798 }
799
800 return eta_to_chi2.get(abs_etaRange, 20)
801
802def getChi2CutNN(region):
803 chi2cut_l = [0.97,0.97,0.99,
804 0.7,0.86,0.99,
805 0.98,0.92,0.98,
806 0.95,0.93,0.4,
807 0.4,0.4,0.7,
808 0.6,0.5,0.4,
809 0.4,0.4]
810 binSize = 0.2
811 side = (region >> 5) & 0x1
812 etaBin = (region >> 6) & 0x1F
813 etaRange = [round(binSize * etaBin, 1), round(binSize * (etaBin + 1), 1)] if side else [round(-binSize * (etaBin + 1), 1), round(-binSize * etaBin, 1)]
814
815 abs_etaRange = tuple(round(abs(val), 1) for val in etaRange)
816
817 eta_to_chi2 = {
818 (0.0, 0.2): chi2cut_l[0], (0.2, 0.4): chi2cut_l[1], (0.4, 0.6): chi2cut_l[2],
819 (0.6, 0.8): chi2cut_l[3], (0.8, 1.0): chi2cut_l[4], (1.0, 1.2): chi2cut_l[5],
820 (1.2, 1.4): chi2cut_l[6], (1.4, 1.6): chi2cut_l[7], (1.6, 1.8): chi2cut_l[8],
821 (1.8, 2.0): chi2cut_l[9], (2.0, 2.2): chi2cut_l[10], (2.2, 2.4): chi2cut_l[11],
822 (2.4, 2.6): chi2cut_l[12], (2.6, 2.8): chi2cut_l[13], (2.8, 3.0): chi2cut_l[14],
823 (3.0, 3.2): chi2cut_l[15], (3.2, 3.4): chi2cut_l[16], (3.4, 3.6): chi2cut_l[17],
824 (3.6, 3.8): chi2cut_l[18], (3.8, 4.0): chi2cut_l[19]
825 }
826 return eta_to_chi2.get(abs_etaRange, 0.99)
827
828
830 print(f"Input Region: {flags.Trigger.FPGATrackSim.regionList} and RegionList: {flags.Trigger.FPGATrackSim.regionList}")
831 # convert regex to array of regions
832 if flags.Trigger.FPGATrackSim.regionList == "": # in case of empty list just use the region set to flags.Trigger.FPGATrackSim.region
833 flags.Trigger.FPGATrackSim.regionList = [flags.Trigger.FPGATrackSim.region]
834 else: # otherwise use the regionList (this overrides the region flag)
835 from FPGATrackSimConfTools.FPGATrackSimHelperFunctions import convertRegionsExpressionToArray
836 flags.Trigger.FPGATrackSim.regionList = convertRegionsExpressionToArray(flags.Trigger.FPGATrackSim.regionList)
837 print(f"Running for regions: {flags.Trigger.FPGATrackSim.regionList}")
838
839
840
842 FPGATrackSimDataPrepConfig.FPGATrackSimDataPrepFlagCfg(flags)
843
844 flags.Scheduler.ShowDataDeps=True
845 flags.Scheduler.CheckDependencies=True
846 flags.Debug.DumpEvtStore=False
847
848 flags.Trigger.FPGATrackSim.readOfflineObjects=False
849 flags.Trigger.FPGATrackSim.doMultiTruth=False
850
851 flags.Trigger.FPGATrackSim.tracking = False
852 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)
853 flags.Tracking.ITkActsValidateF150Pass.doActsSpacePoint = not flags.Trigger.FPGATrackSim.convertSPs
854 flags.Trigger.FPGATrackSim.Hough.secondStage = False
855 flags.Trigger.FPGATrackSim.loadRadii=False
856 flags.Trigger.FPGATrackSim.FakeNNonnxFile1st=''
857 flags.Trigger.FPGATrackSim.ParamNNonnxFile1st=''
858 flags.Trigger.FPGATrackSim.FakeNNonnxFile2nd=''
859 flags.Trigger.FPGATrackSim.ParamNNonnxFile2nd=''
860 flags.Trigger.FPGATrackSim.ExtensionNNVolonnxFile=''
861 flags.Trigger.FPGATrackSim.ExtensionNNHitonnxFile=''
862
864
865 return flags
866
867
868# # this is meant to be called in the preExec
869# def FPGATrackSimDoF150FlagCfg():
870# flags=AthConfigFlags()
871# print("Calling the F150 preExec flag configuration")
872# FPGATrackSimF150FlagCfg(flags)
873
874# this is meant to be called in the preExec
876 print("HELLO!!!!")
877
878# this is meant to be called in the preExec
880 print("Loading FPGATrackSim Config")
881
882
884 acc=ComponentAccumulator()
885 if not flags.Trigger.FPGATrackSim.runOnPreProducedHeaderFiles:
886 acc.merge(FPGATrackSimDataPrepConfig.FPGATrackSimClusteringCfg(flags))
887
888 from FPGATrackSimConfTools.FPGATrackSimMultiRegionConfig import FPGATrackSimMultiRegionTrackingCfg
889 acc.merge(FPGATrackSimMultiRegionTrackingCfg(flags))
890 else:
891 from FPGATrackSimConfTools.FPGATrackSimMergeOutputsConfig import FPGATrackSimMergeOutputsAlgCfg
892 acc.merge(FPGATrackSimMergeOutputsAlgCfg(flags))
893
894 from FPGATrackSimSeeding.FPGATrackSimSeedingConfig import FPGATrackSimSeedingCfg
895 acc.merge(FPGATrackSimSeedingCfg(flags))
896
897
898 if flags.Tracking.ActiveConfig.storeTrackSeeds:
899 from ActsConfig.ActsSeedingConfig import ActsStoreTrackSeedsCfg
900 from InDetConfig.ITkActsHelpers import isFastPrimaryPass
901
902 acc.merge(ActsStoreTrackSeedsCfg(flags,
903 processPixels = True,
904 processStrips = not isFastPrimaryPass(flags)))
905
906
908
909 # for testing hardware run in F150
910 if(flags.Trigger.FPGATrackSim.runF150hw):
911 from EFTrackingFPGAPipeline.F100IntegrationConfig import F100DataEncodingCfg
912 acc.merge(F100DataEncodingCfg(flags))
913
914 from EFTrackingFPGAPipeline.F150KernelTesterConfig import KernelTesterCfg, F150EDMConversionAlgCfg
915 acc.merge(KernelTesterCfg(flags))
916 acc.merge(F150EDMConversionAlgCfg(flags))
917
918
919
920
921 acc.printConfig(withDetails=True, summariseProps=True)
922
923 return acc
924
926 acc=ComponentAccumulator()
927 if flags.Trigger.FPGATrackSim.writeAdditionalOutputData:
928 acc.addService(CompFactory.THistSvc(Output = ["EXPERT DATAFILE='monitoring.root', OPT='RECREATE'"]))
929
930 if (flags.Trigger.FPGATrackSim.Hough.houghRootoutput1st | flags.Trigger.FPGATrackSim.Hough.houghRootoutput2nd):
931 acc.addService(CompFactory.THistSvc(Output = ["TRIGFPGATrackSimHOUGHOUTPUT DATAFILE='HoughRootOutput.root', OPT='RECREATE'"]))
932
933 if flags.Trigger.FPGATrackSim.Hough.writeTestOutput:
934 acc.addService(CompFactory.THistSvc(Output = ["FPGATRACKSIMOUTPUT DATAFILE='test.root', OPT='RECREATE'"]))
935
936 if (flags.Trigger.FPGATrackSim.Hough.genScan):
937 acc.addService(CompFactory.THistSvc(Output = ["GENSCAN DATAFILE='genscan.root', OPT='RECREATE'"]))
938 return acc
939
940if __name__ == "__main__":
941 from AthenaConfiguration.AllConfigFlags import initConfigFlags
942 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
943
944
945 flags = initConfigFlags()
946
947
949 FinalProtoTrackChainxAODTracksKey="FPGA"
950 flags.Detector.EnableCalo = False
951
952 from ActsConfig.ActsCIFlags import actsWorkflowFlags
953 actsWorkflowFlags(flags)
954
955 if not flags.Trigger.FPGATrackSim.runBaselineActs:
956 flags.Tracking.ITkActsPass.doActsSpacePoint = False
957
958 flags.Concurrency.NumThreads=1
959 flags.Concurrency.NumConcurrentEvents=1
960 flags.Concurrency.NumProcs=0
961 flags.Scheduler.ShowDataDeps=True
962 flags.Scheduler.CheckDependencies=True
963 flags.Debug.DumpEvtStore=False
964
965 # flags.Exec.DebugStage="exec" # useful option to debug the execution of the job - we want it commented out for production
966 flags.fillFromArgs()
967
968
969 if flags.Trigger.FPGATrackSim.Hough.useVaryingChi2Cut and not flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis:
970 flags.Trigger.FPGATrackSim.Hough.chi2cut = getChi2Cut(flags.Trigger.FPGATrackSim.region)
971 assert not flags.Trigger.FPGATrackSim.pipeline.startswith('F-5'),"ERROR You are trying to run an F-5* pipeline! This is not yet supported!"
972
973 if (flags.Trigger.FPGATrackSim.pipeline.startswith('F-1')):
974 print("You are trying to run an F-100 pipeline! I am going to run the Data Prep chain for you and nothing else!")
975 FPGATrackSimDataPrepConfig.runDataPrepChain()
976 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-2')):
977 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")
978 flags.Trigger.FPGATrackSim.Hough.etaPatternFilter = True
979 flags.Trigger.FPGATrackSim.Hough.phiRoadFilter = True
980 flags.Trigger.FPGATrackSim.Hough.hough1D = True
981 flags.Trigger.FPGATrackSim.Hough.hough = False
982 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-3')):
983 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")
984 flags.Trigger.FPGATrackSim.Hough.etaPatternFilter = False
985 flags.Trigger.FPGATrackSim.Hough.phiRoadFilter = False
986 flags.Trigger.FPGATrackSim.Hough.hough1D = False
987 flags.Trigger.FPGATrackSim.Hough.hough = True
988 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-4')):
989 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")
990 flags.Trigger.FPGATrackSim.Hough.GNN = True
991 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
992 elif (flags.Trigger.FPGATrackSim.pipeline.startswith('F-6')):
993 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")
994 flags.Trigger.FPGATrackSim.Hough.genScan=True
995 flags.Trigger.FPGATrackSim.spacePoints = flags.Trigger.FPGATrackSim.Hough.secondStage
996 elif (flags.Trigger.FPGATrackSim.pipeline != ""):
997 raise AssertionError("ERROR You are trying to run the pipeline " + flags.Trigger.FPGATrackSim.pipeline + " which is not yet supported!")
998
999 if (not flags.Trigger.FPGATrackSim.pipeline.startswith('F-1')):
1000
1001 flags.Tracking.writeExtendedSi_PRDInfo = not flags.Trigger.FPGATrackSim.writeOfflPRDInfo
1002 splitPipeline=flags.Trigger.FPGATrackSim.pipeline.split('-')
1003 trackingOption=9999999
1004 if (len(splitPipeline) > 1): trackingOption=int(splitPipeline[1])
1005 if (trackingOption < 9999999):
1006 trackingOptionMod = (trackingOption % 100)
1007 if (trackingOptionMod == 0):
1008 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")
1009 flags.Trigger.FPGATrackSim.tracking = True
1010 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis = False
1011 elif (trackingOptionMod == 10):
1012 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")
1013 flags.Trigger.FPGATrackSim.tracking = True
1014 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis = True
1015 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis2nd = flags.Trigger.FPGATrackSim.Hough.secondStage
1016 if (flags.Trigger.FPGATrackSim.pipeline.startswith('F-6')):
1017 flags.Trigger.FPGATrackSim.doNNPathFinder = True
1018 flags.Trigger.FPGATrackSim.doOverlapRemoval = False
1019 flags.Trigger.FPGATrackSim.tracking = False
1020 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis = False
1021 flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis2nd = flags.Trigger.FPGATrackSim.Hough.secondStage
1022 else:
1023 raise AssertionError("ERROR Your tracking option for the pipeline = " + str(trackingOption) + " is not yet supported!")
1024
1025 if isinstance(flags.Trigger.FPGATrackSim.wrapperFileName, str):
1026 log.info("wrapperFile is string, converting to list")
1027 flags.Trigger.FPGATrackSim.wrapperFileName = [flags.Trigger.FPGATrackSim.wrapperFileName]
1028 flags.Input.Files = lambda f: [f.Trigger.FPGATrackSim.wrapperFileName]
1029
1030 if flags.Trigger.FPGATrackSim.Hough.useVaryingChi2Cut and flags.Trigger.FPGATrackSim.Hough.trackNNAnalysis:
1031 flags.Trigger.FPGATrackSim.Hough.chi2cut = getChi2CutNN(flags.Trigger.FPGATrackSim.region)
1032
1033 flags.Detector.GeometryMuon = False
1034
1035 flags.lock()
1036 flags.dump()
1037 flags = flags.cloneAndReplace("Tracking.ActiveConfig","Tracking.ITkActsPass",keepOriginal=True)
1038 acc=MainServicesCfg(flags)
1039
1040 acc.merge(WriteAdditionalFPGATrackSimOutputCfg(flags))
1041
1042 if not flags.Trigger.FPGATrackSim.wrapperFileName:
1043 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
1044 acc.merge(PoolReadCfg(flags))
1045
1046 if flags.Input.isMC:
1047 from xAODTruthCnv.xAODTruthCnvConfig import GEN_AOD2xAODCfg
1048 acc.merge(GEN_AOD2xAODCfg(flags))
1049
1050 from JetRecConfig.JetRecoSteering import addTruthPileupJetsToOutputCfg
1051 acc.merge(addTruthPileupJetsToOutputCfg(flags)) # needed by IDTPM
1052
1053 if flags.Tracking.recoChain:
1054 if flags.Trigger.FPGATrackSim.runBaselineActs:
1055 # Full ITk reconstruction
1056 from InDetConfig.ITkTrackRecoConfig import ITkTrackRecoCfg
1057 acc.merge(ITkTrackRecoCfg(flags))
1058 else:
1059 # Only schedule data preparation (clustering) for technical efficiency
1060 from InDetConfig.SiliconPreProcessing import ITkRecPreProcessingSiliconCfg
1061 acc.merge(ITkRecPreProcessingSiliconCfg(flags))
1062
1063 from BeamSpotConditions.BeamSpotConditionsConfig import BeamSpotCondAlgCfg
1064 acc.merge(BeamSpotCondAlgCfg(flags))
1065
1066 if flags.Trigger.FPGATrackSim.writeOfflPRDInfo:
1067 from InDetConfig.InDetPrepRawDataToxAODConfig import ITkActsPrepDataToxAODCfg
1068 acc.merge( ITkActsPrepDataToxAODCfg( flags,
1069 PixelMeasurementContainer = "ITkPixelMeasurements_offl",
1070 StripMeasurementContainer = "ITkStripMeasurements_offl" ) )
1071
1072 # Configure both the dataprep and logical hits algorithms.
1073 acc.merge(FPGATrackSimDataPrepConfig.FPGATrackSimDataPrepAlgCfg(flags))
1074 from FPGATrackSimConfTools.FPGATrackSimMultiRegionConfig import FPGATrackSimMultiRegionTrackingCfg
1075 acc.merge(FPGATrackSimMultiRegionTrackingCfg(flags))
1076
1077 if flags.Trigger.FPGATrackSim.doEDMConversion:
1078 stage = "_2nd" if flags.Trigger.FPGATrackSim.Hough.secondStage else "_1st"
1079 acc.merge(FPGATrackSimDataPrepConfig.FPGAConversionAlgCfg(flags, name = f"FPGAConversionAlg{stage}",
1080 stage = f"{stage}",
1081 doActsTrk=True,
1082 doSP=flags.Trigger.FPGATrackSim.convertSPs))
1083
1084 from FPGATrackSimPrototrackFitter.FPGATrackSimPrototrackFitterConfig import FPGATruthDecorationCfg, FPGAProtoTrackFitCfg
1085 acc.merge(FPGAProtoTrackFitCfg(flags,stage=f"{stage}")) # Run ACTS KF
1086 acc.merge(FPGATruthDecorationCfg(flags,FinalProtoTrackChainxAODTracksKey=FinalProtoTrackChainxAODTracksKey)) # Run Truth Matching/Decoration chain
1087 if flags.Trigger.FPGATrackSim.runCKF:
1088 from FPGATrackSimConfTools.FPGATrackExtensionConfig import FPGATrackExtensionAlgCfg
1089 acc.merge(FPGATrackExtensionAlgCfg(flags, enableTrackStatePrinter=False, name="FPGATrackExtension",
1090 ProtoTracksLocation=f"ActsProtoTracks{stage}FromFPGATrack")) # run CKF track extension on FPGA tracks
1091
1092 if flags.Trigger.FPGATrackSim.writeToAOD:
1093 acc.merge(FPGATrackSimDataPrepConfig.WriteToAOD(flags,
1094 stage = f"{stage}",
1095 finalTrackParticles=f"{FinalProtoTrackChainxAODTracksKey}TrackParticles"))
1096
1097 # Reporting algorithm (used for debugging - can be disabled)
1098 from FPGATrackSimReporting.FPGATrackSimReportingConfig import FPGATrackSimReportingCfg
1099 acc.merge(FPGATrackSimReportingCfg(flags, stage=f"{stage}",
1100 perEventReports = ((flags.Trigger.FPGATrackSim.sampleType != 'skipTruth') and flags.Exec.MaxEvents<=10 ) )) # disable perEventReports for pileup samples or many events
1101
1102 acc.store(open('AnalysisConfig.pkl','wb'))
1103
1104 acc.foreach_component("*FPGATrackSim*").OutputLevel=flags.Trigger.FPGATrackSim.loglevel
1105 if flags.Trigger.FPGATrackSim.msgLimit!=-1:
1106 acc.getService("MessageSvc").debugLimit = flags.Trigger.FPGATrackSim.msgLimit
1107 acc.getService("MessageSvc").infoLimit = flags.Trigger.FPGATrackSim.msgLimit
1108 acc.getService("MessageSvc").verboseLimit = flags.Trigger.FPGATrackSim.msgLimit
1109
1110 statusCode = acc.run(flags.Exec.MaxEvents)
1111 assert statusCode.isSuccess() is True, "Application execution did not succeed"
if(pathvar)
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:179
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")
FPGATrackSimGNNGraphHitSelectorToolCfg(flags, name="FPGATrackSimGNNGraphHitSelectorTool")
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")