ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCalibrationMgrConfig.py
Go to the documentation of this file.
1"""Define methods to construct a configured TRT R-t calibration algorithm
2
3Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4"""
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6from AthenaConfiguration.ComponentFactory import CompFactory
7
8# Steering algorithm. Either it fills track and hit ntuples, or it calls TRTCalibrator
9def TRT_CalibrationMgrCfg(flags,name='TRT_CalibrationMgr',calibconstants='', Hittuple='', caltag='' ,**kwargs) :
10 acc = ComponentAccumulator()
11
12 kwargs.setdefault("DoCalibrate",False)
13 kwargs.setdefault("DoRefit",False)
14
15 if "AlignTrkTools" not in kwargs:
16 from TRT_CalibTools.TRTCalibToolsConfig import (
17 FillAlignTrkInfoCfg, FillAlignTRTHitsCfg)
18 kwargs.setdefault("AlignTrkTools", [
19 acc.addPublicTool(acc.popToolsAndMerge(FillAlignTrkInfoCfg(flags))),
20 acc.addPublicTool(acc.popToolsAndMerge(FillAlignTRTHitsCfg(flags))) ] )
21
22 if "FitTools" not in kwargs:
23 from TRT_CalibTools.TRTCalibToolsConfig import FitToolCfg
24 kwargs.setdefault("FitTools", [acc.popToolsAndMerge(FitToolCfg(flags))])
25
26 if "TrackFitter" not in kwargs:
27 from TrkConfig.CommonTrackFitterConfig import InDetStandaloneTrackFitterCfg
28 kwargs.setdefault("TrackFitter", acc.popToolsAndMerge(
29 InDetStandaloneTrackFitterCfg(flags)))
30
31 if "TrackSelectorTool" not in kwargs:
32 from InDetConfig.InDetTrackSelectorToolConfig import TRT_InDetDetailedTrackSelectorToolCfg
33 kwargs.setdefault("TrackSelectorTool", acc.popToolsAndMerge(TRT_InDetDetailedTrackSelectorToolCfg(flags)))
34
35 if "TRTCalibrator" not in kwargs:
36 from TRT_CalibTools.TRTCalibratorConfig import TRTCalibratorCfg
37
38 if not Hittuple:
39 kwargs.setdefault("TRTCalibrator",[acc.addPublicTool(acc.popToolsAndMerge(TRTCalibratorCfg(flags)))])
40 else:
41 # This changes the name of the input file used for the calibrator tool
42 kwargs.setdefault("TRTCalibrator",[acc.addPublicTool(acc.popToolsAndMerge(TRTCalibratorCfg(flags, Hittuple=Hittuple, calTag=caltag)))])
43
44 # if a text file is in the arguments, use the constants in that instead of the DB
45 if calibconstants:
46
47 # Renaming the keys stored by the CondInputLoader, since we will write the new constants using TRTCondWrite Alg.
48 from IOVDbSvc.IOVDbSvcConfig import addOverride
49 acc.merge(addOverride( flags, "/TRT/Calib/T0", "unused_condDBT0", "key" ))
50 acc.merge(addOverride( flags, "/TRT/Calib/RT", "unused_condDBRT", "key" ))
51
52 from TRT_ConditionsAlgs.TRT_ConditionsAlgsConfig import TRTCondWriteCfg
53 acc.merge(TRTCondWriteCfg(flags,CalibInputFile=calibconstants))
54
55 # add this algorithm to the configuration accumulator
56 acc.addEventAlgo(CompFactory.TRTCalibrationMgr(name, **kwargs))
57
58 return acc
59
60
61def TRT_StrawStatusCfg(flags,name='InDet_TRT_StrawStatus',**kwargs) :
62
63 acc = ComponentAccumulator()
64
65 from TRT_ConditionsServices.TRT_ConditionsServicesConfig import TRT_StrawStatusSummaryToolCfg
66 kwargs.setdefault("TRT_StrawStatusSummaryTool", acc.popToolsAndMerge(TRT_StrawStatusSummaryToolCfg(flags)))
67
68 from InDetConfig.TRT_TrackHoleSearchConfig import TRTTrackHoleSearchToolCfg
69 kwargs.setdefault("trt_hole_finder", acc.popToolsAndMerge(TRTTrackHoleSearchToolCfg(flags)))
70
71 from IOVDbSvc.IOVDbSvcConfig import addOverride
72 acc.merge(addOverride(flags,'/TRT/Cond/Status','TRTCondStatus-empty-00-00'))
73
74 acc.addEventAlgo(CompFactory.InDet.TRT_StrawStatus(name,**kwargs))
75 return acc
76
77
78def CalibConfig(flags):
79
80 from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
81 setupDetectorFlags(flags, ['ID'], toggle_geometry=True)
82
83 # Reco
84 flags.Reco.EnableTau=False
85 flags.Reco.EnableCombinedMuon=False
86 flags.Reco.EnableMet=False
87 flags.Reco.EnableTrigger = False
88 flags.Reco.EnableEgamma=False
89 flags.Reco.EnableCaloRinger=False
90 flags.Reco.EnableCaloExtension=False
91
92 # Detector
93 flags.Detector.EnableMuon=False
94 flags.Detector.EnableCalo=False
95
96 # DQ
97 flags.DQ.doMonitoring=False
98 flags.DQ.Steering.InDet.doPerfMon=False
99 flags.DQ.Steering.InDet.doGlobalMon=False
100 flags.DQ.Steering.doPixelMon=False
101 flags.DQ.Steering.doSCTMon=False
102
103 # Tracking
104 flags.Tracking.doCaloSeededBrem=False
105 flags.Tracking.doCaloSeededAmbi=False
106 flags.Tracking.doTRTSegments=False
107 flags.Tracking.doTRTStandalone=False
108 flags.Tracking.doBackTracking=False
109
110
111if __name__ == '__main__':
112
113 import glob, argparse
114 parser = argparse.ArgumentParser(prog='python -m TRT_CalibAlgs.TRTCalibrationMgrConfig',
115 description="""Run R-t TRT calibration.\n\n
116 Example: python -m TRT_CalibAlgs.TRTCalibrationMgrConfig --filesInput "/path/to/files/data22*" --evtMax 10""")
117
118 parser.add_argument('--evtMax' ,type=int,default=1,help="Number of events.")
119 parser.add_argument('--filesInput' , nargs='+', default=[],help="Input files. RAW data")
120 parser.add_argument('--fileOutput' , default="basic.root" ,help="Output file name. Flat Ntuple")
121 parser.add_argument('--doCalibrator',action='store_true' ,help="Run the calibrator to obtain the constants")
122 parser.add_argument('--calibconstants', default="" ,help="Input file constants for writer")
123 args = parser.parse_args()
124
125 from AthenaConfiguration.AllConfigFlags import initConfigFlags
126 flags = initConfigFlags()
127
128 from AthenaConfiguration.TestDefaults import defaultGeometryTags, defaultTestFiles, defaultConditionsTags
129 if not args.filesInput:
130 flags.Input.Files = defaultTestFiles.RAW_RUN3
131 else:
132 flags.Input.Files = [file for x in args.filesInput for file in glob.glob(x)]
133
134 flags.Output.HISTFileName = args.fileOutput
135 flags.Exec.MaxEvents = args.evtMax
136
137 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
138 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_DATA
139
140 CalibConfig(flags)
141
142 # For debug output INFO=3
143 flags.Exec.OutputLevel = 3
144
145 # Reason why we need to clone and replace: https://gitlab.cern.ch/atlas/athena/-/merge_requests/68616#note_7614858
146 flags = flags.cloneAndReplace(
147 "Tracking.ActiveConfig",
148 f"Tracking.{flags.Tracking.PrimaryPassConfig.value}Pass",
149 # Keep original flags as some of the subsequent passes use
150 # lambda functions relying on them
151 keepOriginal=True)
152
153 flags.lock()
154 flags.dump()
155
156 # Set up the main service "acc"
157 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
158 acc = MainServicesCfg(flags)
159
160 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
161 acc.merge(ByteStreamReadCfg(flags))
162
163 from InDetConfig.TrackRecoConfig import InDetTrackRecoCfg
164 acc.merge(InDetTrackRecoCfg(flags))
165
166 # Algorithm to generate the straw masking file
167 acc.merge(TRT_StrawStatusCfg(flags))
168
169 # Algorithm to create the basic.root ntuple file
170 acc.merge(TRT_CalibrationMgrCfg(flags,calibconstants=args.dbconst ,DoCalibrate=args.doCalibrator))
171
172 with open("TRTCalibConfigCA.pkl", "wb") as f:
173 acc.store(f)
174 f.close()
175
176
177 import sys
178 sys.exit(not acc.run().isSuccess())
179
TRT_CalibrationMgrCfg(flags, name='TRT_CalibrationMgr', calibconstants='', Hittuple='', caltag='', **kwargs)
TRT_StrawStatusCfg(flags, name='InDet_TRT_StrawStatus', **kwargs)