ATLAS Offline Software
MuonCalibrationConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 # Based on : https://gitlab.cern.ch/atlas/athena/blob/master/MuonSpectrometer/MuonCnv/MuonCnvExample/python/MuonCalibConfig.py
4 
5 from MuonConfig.MuonCondAlgConfig import CscCondDbAlgCfg, NswCalibDbAlgCfg
6 from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
7 from AthenaConfiguration.AccumulatorCache import AccumulatorCache
8 from AthenaConfiguration.ComponentFactory import CompFactory
9 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
10 from AthenaConfiguration.Enums import BeamType, LHCPeriod
11 from IOVDbSvc.IOVDbSvcConfig import addFoldersSplitOnline
12 from MagFieldServices.MagFieldServicesConfig import AtlasFieldCacheCondAlgCfg
13 
14 from AthenaCommon.Logging import logging
15 log = logging.getLogger('MuonCalibConfig')
16 
17 
20 
21 def CscCalibToolCfg(flags, name="CscCalibTool", **kwargs):
22  """Return ComponentAccumulator configured for CSC calibration with CscCalibTool as PrivateTools"""
23 
24  acc = CscCondDbAlgCfg(flags)
25 
26  kwargs.setdefault("Slope", 0.19)
27  kwargs.setdefault("Noise", 3.5)
28  kwargs.setdefault("Pedestal", 2048.0)
29  kwargs.setdefault("ReadFromDatabase", True)
30  kwargs.setdefault("SlopeFromDatabase", False)
31  kwargs.setdefault("integrationNumber", 12.0)
32  kwargs.setdefault("integrationNumber2", 11.66)
33  kwargs.setdefault("samplingTime", 50.0)
34  kwargs.setdefault("signalWidth", 14.40922)
35  kwargs.setdefault("timeOffset", 71.825)
36  kwargs.setdefault("IsOnline", flags.Common.isOnline)
37  kwargs.setdefault("Latency", 119)
38 
39  acc.setPrivateTools(CompFactory.CscCalibTool(name, **kwargs))
40 
41  return acc
42 
43 
44 
45 
48 
49 def _setupMdtCondDB(flags):
50  result=ComponentAccumulator()
51 
52  if flags.Muon.Calib.readMDTCalibFromBlob:
53  mdt_folder_name_appendix = "BLOB"
54  else:
55  mdt_folder_name_appendix=""
56 
57  online_folders = ['/MDT/Onl/RT'+ mdt_folder_name_appendix,'/MDT/Onl/T0' + mdt_folder_name_appendix]
58  offline_folders = ['/MDT/RT' + mdt_folder_name_appendix, '/MDT/T0' + mdt_folder_name_appendix]
59 
60  if flags.Muon.Calib.mdtCalibrationSource=="MDT":
61  if flags.GeoModel.Run is LHCPeriod.Run4:
62  # TODO: temporary conditions override until we get a global tag
63  from IOVDbSvc.IOVDbSvcConfig import addFolders
64  # Ugly, but hopefully temporary hack
65  if flags.GeoModel.AtlasVersion.startswith('ATLAS-P2-RUN4-01-00'):
66  result.merge(addFolders(flags, '/MDT/RT' + mdt_folder_name_appendix, 'MDT_OFL', className='CondAttrListCollection', tag='MDTRT_Sim-Run4-01', db="OFLP200"))
67  result.merge(addFolders(flags, '/MDT/T0' + mdt_folder_name_appendix, 'MDT_OFL', className='CondAttrListCollection', tag='MDTT0_Sim-Run4-01', db="OFLP200"))
68  else:
69  result.merge(addFolders(flags, '/MDT/RT' + mdt_folder_name_appendix, 'MDT_OFL', className='CondAttrListCollection', tag='MDTRT_Sim-R3SYM-04', db="OFLP200"))
70  result.merge(addFolders(flags, '/MDT/T0' + mdt_folder_name_appendix, 'MDT_OFL', className='CondAttrListCollection', tag='MDTT0_Sim-R3SYM-03', db="OFLP200"))
71  else:
72  result.merge(addFoldersSplitOnline(flags, 'MDT', online_folders , offline_folders,
73  className = 'CondAttrListCollection' ) )
74  else:
75  result.merge(addFoldersSplitOnline(flags, flags.Muon.Calib.mdtCalibrationSource, online_folders, offline_folders,
76  className = 'CondAttrListCollection' ) )
77 
78  return result, mdt_folder_name_appendix
79 # end of function setupMdtCondDB()
80 
81 @AccumulatorCache
82 def MdtCalibrationToolCfg(flags, name= "MdtCalibrationTool", **kwargs):
83  result=ComponentAccumulator()
84  result.merge(MdtCalibDbAlgCfg(flags))
85 
86  kwargs.setdefault("DoSlewingCorrection", flags.Muon.Calib.correctMdtRtForTimeSlewing)
87  kwargs.setdefault("DoTemperatureCorrection", flags.Muon.Calib.applyRtScaling)
88  kwargs.setdefault("DoTofCorrection", flags.Beam.Type is BeamType.Collisions) # No TOF correction if not collisions
89 
90  if flags.Beam.Type is BeamType.Collisions:
91  from MuonConfig.MuonRIO_OnTrackCreatorToolConfig import MdtCalibWindowNumber
92  kwargs.setdefault("TimeWindowSetting", MdtCalibWindowNumber('Collision_G4'))
93 
94  result.merge(AtlasFieldCacheCondAlgCfg(flags))
95 
96  mdt_calibration_tool = CompFactory.MdtCalibrationTool(name= name, **kwargs)
97  result.setPrivateTools(mdt_calibration_tool)
98  return result
99 
100 def MdtCalibDbAlgCfg(flags,name="MdtCalibDbAlg",**kwargs):
101  result = ComponentAccumulator()
102  result.merge(MuonGeoModelCfg(flags))
103  if flags.GeoModel.Run is LHCPeriod.Run4 and flags.Muon.usePhaseIIGeoSetup:
104  alg = CompFactory.MuonCalibR4.MdtCalibDbAlg(name)
105  result.addCondAlgo (alg, primary = True)
106  return result
107  from MuonConfig.MuonCondAlgConfig import MdtCondDbAlgCfg
108  result.merge(MdtCondDbAlgCfg(flags))
109 
110  # setup COOL folders
111  acc, mdt_folder_name_appendix = _setupMdtCondDB(flags)
112  result.merge(acc)
113 
114  # set some default proper ties
115  if flags.Common.isOnline and not flags.Input.isMC:
116  kwargs.setdefault("ReadKeyTube", "/MDT/T0")
117  kwargs.setdefault("ReadKeyRt", "/MDT/RT")
118  else:
119  kwargs.setdefault("ReadKeyTube", "/MDT/T0"+ mdt_folder_name_appendix)
120  kwargs.setdefault("ReadKeyRt", "/MDT/RT"+ mdt_folder_name_appendix)
121  if flags.Input.isMC is False: # Should be " if flags.Input.isMC=='data' " ?
122  kwargs.setdefault("defaultT0", 40)
123  else:
124  kwargs.setdefault("defaultT0", 799)
125  if flags.Common.isOnline:
126  kwargs.setdefault("ReadKeyDCS", "" )
127  kwargs.setdefault("UseMLRt", flags.Muon.Calib.useMLRt )
128  kwargs.setdefault("TimeSlewingCorrection", flags.Muon.Calib.correctMdtRtForTimeSlewing)
129  kwargs.setdefault("MeanCorrectionVsR", [ -5.45973, -4.57559, -3.71995, -3.45051, -3.4505, -3.4834, -3.59509, -3.74869, -3.92066, -4.10799, -4.35237, -4.61329, -4.84111, -5.14524 ])
130  kwargs.setdefault("PropagationSpeedBeta", flags.Muon.Calib.mdtPropagationSpeedBeta)
131  # the same as MdtCalibrationDbTool
132  kwargs.setdefault("CreateBFieldFunctions", flags.Muon.Calib.correctMdtRtForBField)
133  kwargs.setdefault("CreateSlewingFunctions", flags.Muon.Calib.correctMdtRtForTimeSlewing)
134  from RngComps.RngCompsConfig import AthRNGSvcCfg
135  kwargs.setdefault("AthRNGSvc", result.getPrimaryAndMerge(AthRNGSvcCfg(flags)))
136 
137  kwargs.setdefault("UseR4DetMgr", flags.Muon.usePhaseIIGeoSetup)
138  alg = CompFactory.MdtCalibDbAlg (name, **kwargs)
139  result.addCondAlgo (alg, primary = True)
140  return result
141 
142 def NSWCalibToolCfg(flags, name="NSWCalibTool", **kwargs):
143  """Return ComponentAccumulator configured for NSW calibration with NSWCalibTool as PrivateTools"""
144  result = ComponentAccumulator()
145  result.merge(NswCalibDbAlgCfg(flags))
146  from MagFieldServices.MagFieldServicesConfig import AtlasFieldCacheCondAlgCfg
147  result.merge(AtlasFieldCacheCondAlgCfg(flags))
148  kwargs.setdefault("isData", not flags.Input.isMC)
149  kwargs.setdefault("mmPeakTime",200)
150  kwargs.setdefault("sTgcPeakTime",0)
151  kwargs.setdefault("applyMmT0Calib", flags.Muon.Calib.applyMmT0Correction)
152  kwargs.setdefault("applysTgcT0Calib", flags.Muon.Calib.applysTgcT0Correction)
153  kwargs.setdefault("applyMmBFieldCalib",flags.Muon.Calib.applyMmBFieldCalib)
154  the_tool = CompFactory.Muon.NSWCalibTool(name,**kwargs)
155  result.setPrivateTools(the_tool)
156  return result
157 
158 def MMCalibSmearingToolCfg(flags, name="MMCalibSmearingTool", **kwargs):
159  """Return ComponentAccumulator configured for MM smearing with NSWCalibSmearing as PrivateTools"""
160  result = ComponentAccumulator()
161  kwargs.setdefault("EtaSectors", [True, True, True, True])
162  the_tool = CompFactory.Muon.NSWCalibSmearingTool(name,**kwargs)
163  result.setPrivateTools(the_tool)
164  return result
165 
166 def STgcCalibSmearingToolCfg(flags, name="STgcCalibSmearingTool", **kwargs):
167  """Return ComponentAccumulator configured for sTGC smearing with NSWCalibSmearing as PrivateTools"""
168  result = ComponentAccumulator()
169  kwargs.setdefault("EtaSectors", [True, True, True, True, True, True])
170  the_tool = CompFactory.Muon.NSWCalibSmearingTool(name,**kwargs)
171  result.setPrivateTools(the_tool)
172  return result
173 
174 def NswErrorCalibDbAlgCfg(flags, name = "NswErrorCalibDbAlg", **kwargs):
175  result = ComponentAccumulator()
176  folderNames = []
177  if "readFromJSON" in kwargs:
178  folderNames=[]
179 
180  elif flags.Common.isOnline:
181  from IOVDbSvc.IOVDbSvcConfig import addFolders
182  folderNames+=["/MDT/Onl/MM/ClusterUncertainties/SIDEA",
183  "/MDT/Onl/MM/ClusterUncertainties/SIDEC",
184  "/TGC/Onl/NSW/ClusterUncertainties/SIDEA",
185  "/TGC/Onl/NSW/ClusterUncertainties/SIDEC",
186  ]
187  result.merge(addFolders(flags,folderNames[:2], className='CondAttrListCollection', detDb="MDT_ONL"))
188  result.merge(addFolders(flags,folderNames[2:], className='CondAttrListCollection', detDb="TGC_ONL"))
189 
190  else:
191  from IOVDbSvc.IOVDbSvcConfig import addFolders
192  folderNames+=["/MDT/MM/ClusterUncertainties/SIDEA",
193  "/MDT/MM/ClusterUncertainties/SIDEC",
194  "/TGC/NSW/ClusterUncertainties/SIDEA",
195  "/TGC/NSW/ClusterUncertainties/SIDEC"]
196  result.merge(addFolders(flags,folderNames[:2], className='CondAttrListCollection', detDb="MDT_OFL"))
197  result.merge(addFolders(flags,folderNames[2:], className='CondAttrListCollection', detDb="TGC_OFL"))
198 
199  kwargs.setdefault("ReadKeys", folderNames)
200  the_alg = CompFactory.NswUncertDbAlg(name = name, **kwargs)
201  result.addCondAlgo(the_alg, primary = True)
202  return result
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.MuonRIO_OnTrackCreatorToolConfig.MdtCalibWindowNumber
def MdtCalibWindowNumber(name)
Definition: MuonRIO_OnTrackCreatorToolConfig.py:19
python.MuonCalibrationConfig.NswErrorCalibDbAlgCfg
def NswErrorCalibDbAlgCfg(flags, name="NswErrorCalibDbAlg", **kwargs)
Definition: MuonCalibrationConfig.py:174
python.MuonCalibrationConfig.CscCalibToolCfg
def CscCalibToolCfg(flags, name="CscCalibTool", **kwargs)
CSC calibration.
Definition: MuonCalibrationConfig.py:21
python.MuonCondAlgConfig.CscCondDbAlgCfg
def CscCondDbAlgCfg(flags, **kwargs)
Definition: MuonCondAlgConfig.py:90
python.MuonCalibrationConfig._setupMdtCondDB
def _setupMdtCondDB(flags)
MDT calibration.
Definition: MuonCalibrationConfig.py:49
python.MuonCondAlgConfig.MdtCondDbAlgCfg
def MdtCondDbAlgCfg(flags, **kwargs)
Definition: MuonCondAlgConfig.py:13
python.MuonCalibrationConfig.NSWCalibToolCfg
def NSWCalibToolCfg(flags, name="NSWCalibTool", **kwargs)
Definition: MuonCalibrationConfig.py:142
python.MuonCalibrationConfig.MdtCalibrationToolCfg
def MdtCalibrationToolCfg(flags, name="MdtCalibrationTool", **kwargs)
Definition: MuonCalibrationConfig.py:82
python.IOVDbSvcConfig.addFolders
def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers='')
Definition: IOVDbSvcConfig.py:72
python.MuonCondAlgConfig.NswCalibDbAlgCfg
def NswCalibDbAlgCfg(flags, **kwargs)
Definition: MuonCondAlgConfig.py:181
python.IOVDbSvcConfig.addFoldersSplitOnline
def addFoldersSplitOnline(flags, detDb, onlineFolders, offlineFolders, className=None, extensible=False, addMCString='_OFL', splitMC=False, tag=None, forceDb=None, modifiers='')
Definition: IOVDbSvcConfig.py:153
python.MuonCalibrationConfig.MMCalibSmearingToolCfg
def MMCalibSmearingToolCfg(flags, name="MMCalibSmearingTool", **kwargs)
Definition: MuonCalibrationConfig.py:158
python.MuonGeometryConfig.MuonGeoModelCfg
def MuonGeoModelCfg(flags)
Definition: MuonGeometryConfig.py:28
python.MuonCalibrationConfig.MdtCalibDbAlgCfg
def MdtCalibDbAlgCfg(flags, name="MdtCalibDbAlg", **kwargs)
Definition: MuonCalibrationConfig.py:100
python.MagFieldServicesConfig.AtlasFieldCacheCondAlgCfg
def AtlasFieldCacheCondAlgCfg(flags, **kwargs)
Definition: MagFieldServicesConfig.py:8
python.MuonCalibrationConfig.STgcCalibSmearingToolCfg
def STgcCalibSmearingToolCfg(flags, name="STgcCalibSmearingTool", **kwargs)
Definition: MuonCalibrationConfig.py:166
RngCompsConfig.AthRNGSvcCfg
def AthRNGSvcCfg(flags, name="AthRNGSvc")
Definition: RngCompsConfig.py:51