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