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  from MuonConfig.MuonCondAlgConfig import MdtCondDbAlgCfg
104  result.merge(MdtCondDbAlgCfg(flags))
105 
106  # setup COOL folders
107  acc, mdt_folder_name_appendix = _setupMdtCondDB(flags)
108  result.merge(acc)
109 
110  if flags.GeoModel.Run is LHCPeriod.Run4 and flags.Muon.usePhaseIIGeoSetup:
111  alg = CompFactory.MuonCalibR4.MdtCalibDbAlg(name, **kwargs)
112  result.addCondAlgo (alg, primary = True)
113  return result
114 
115  # set some default proper ties
116  if flags.Common.isOnline and not flags.Input.isMC:
117  kwargs.setdefault("ReadKeyTube", "/MDT/T0")
118  kwargs.setdefault("ReadKeyRt", "/MDT/RT")
119  else:
120  kwargs.setdefault("ReadKeyTube", "/MDT/T0"+ mdt_folder_name_appendix)
121  kwargs.setdefault("ReadKeyRt", "/MDT/RT"+ mdt_folder_name_appendix)
122  if flags.Input.isMC is False: # Should be " if flags.Input.isMC=='data' " ?
123  kwargs.setdefault("defaultT0", 40)
124  else:
125  kwargs.setdefault("defaultT0", 799)
126  if not flags.Muon.useMdtDcsData:
127  kwargs.setdefault("ReadKeyDCS", "" )
128  kwargs.setdefault("UseMLRt", flags.Muon.Calib.useMLRt )
129  kwargs.setdefault("TimeSlewingCorrection", flags.Muon.Calib.correctMdtRtForTimeSlewing)
130  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 ])
131  kwargs.setdefault("PropagationSpeedBeta", flags.Muon.Calib.mdtPropagationSpeedBeta)
132  # the same as MdtCalibrationDbTool
133  kwargs.setdefault("CreateBFieldFunctions", flags.Muon.Calib.correctMdtRtForBField)
134  kwargs.setdefault("CreateSlewingFunctions", flags.Muon.Calib.correctMdtRtForTimeSlewing)
135  from RngComps.RngCompsConfig import AthRNGSvcCfg
136  kwargs.setdefault("AthRNGSvc", result.getPrimaryAndMerge(AthRNGSvcCfg(flags)))
137 
138  kwargs.setdefault("UseR4DetMgr", flags.Muon.usePhaseIIGeoSetup)
139  alg = CompFactory.MdtCalibDbAlg (name, **kwargs)
140  result.addCondAlgo (alg, primary = True)
141  return result
142 
143 def NSWCalibToolCfg(flags, name="NSWCalibTool", **kwargs):
144  """Return ComponentAccumulator configured for NSW calibration with NSWCalibTool as PrivateTools"""
145  result = ComponentAccumulator()
146  result.merge(NswCalibDbAlgCfg(flags))
147  from MagFieldServices.MagFieldServicesConfig import AtlasFieldCacheCondAlgCfg
148  result.merge(AtlasFieldCacheCondAlgCfg(flags))
149  kwargs.setdefault("isData", not flags.Input.isMC)
150  kwargs.setdefault("mmPeakTime",200)
151  kwargs.setdefault("sTgcPeakTime",0)
152  kwargs.setdefault("applyMmT0Calib", flags.Muon.Calib.applyMmT0Correction)
153  kwargs.setdefault("applysTgcT0Calib", flags.Muon.Calib.applysTgcT0Correction)
154  kwargs.setdefault("applyMmBFieldCalib",flags.Muon.Calib.applyMmBFieldCalib)
155  the_tool = CompFactory.Muon.NSWCalibTool(name,**kwargs)
156  result.setPrivateTools(the_tool)
157  return result
158 
159 def MMCalibSmearingToolCfg(flags, name="MMCalibSmearingTool", **kwargs):
160  """Return ComponentAccumulator configured for MM smearing with NSWCalibSmearing as PrivateTools"""
161  result = ComponentAccumulator()
162  kwargs.setdefault("EtaSectors", [True, True, True, True])
163  the_tool = CompFactory.Muon.NSWCalibSmearingTool(name,**kwargs)
164  result.setPrivateTools(the_tool)
165  return result
166 
167 def STgcCalibSmearingToolCfg(flags, name="STgcCalibSmearingTool", **kwargs):
168  """Return ComponentAccumulator configured for sTGC smearing with NSWCalibSmearing as PrivateTools"""
169  result = ComponentAccumulator()
170  kwargs.setdefault("EtaSectors", [True, True, True, True, True, True])
171  the_tool = CompFactory.Muon.NSWCalibSmearingTool(name,**kwargs)
172  result.setPrivateTools(the_tool)
173  return result
174 
175 def NswErrorCalibDbAlgCfg(flags, name = "NswErrorCalibDbAlg", **kwargs):
176  result = ComponentAccumulator()
177  folderNames = []
178  if "readFromJSON" in kwargs:
179  folderNames=[]
180 
181  elif flags.Common.isOnline:
182  from IOVDbSvc.IOVDbSvcConfig import addFolders
183  folderNames+=["/MDT/Onl/MM/ClusterUncertainties/SIDEA",
184  "/MDT/Onl/MM/ClusterUncertainties/SIDEC",
185  "/TGC/Onl/NSW/ClusterUncertainties/SIDEA",
186  "/TGC/Onl/NSW/ClusterUncertainties/SIDEC",
187  ]
188  result.merge(addFolders(flags,folderNames[:2], className='CondAttrListCollection', detDb="MDT_ONL"))
189  result.merge(addFolders(flags,folderNames[2:], className='CondAttrListCollection', detDb="TGC_ONL"))
190 
191  else:
192  from IOVDbSvc.IOVDbSvcConfig import addFolders
193  folderNames+=["/MDT/MM/ClusterUncertainties/SIDEA",
194  "/MDT/MM/ClusterUncertainties/SIDEC",
195  "/TGC/NSW/ClusterUncertainties/SIDEA",
196  "/TGC/NSW/ClusterUncertainties/SIDEC"]
197  result.merge(addFolders(flags,folderNames[:2], className='CondAttrListCollection', detDb="MDT_OFL"))
198  result.merge(addFolders(flags,folderNames[2:], className='CondAttrListCollection', detDb="TGC_OFL"))
199 
200  kwargs.setdefault("ReadKeys", folderNames)
201  the_alg = CompFactory.NswUncertDbAlg(name = name, **kwargs)
202  result.addCondAlgo(the_alg, primary = True)
203  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:175
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:143
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:159
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:167
RngCompsConfig.AthRNGSvcCfg
def AthRNGSvcCfg(flags, name="AthRNGSvc")
Definition: RngCompsConfig.py:51