ATLAS Offline Software
MuonSegmentReaderConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 
6 def MuonSegmentReaderCfg(configFlags, **kwargs):
7  #setup the tools
8  from MuonConfig.MuonGeometryConfig import MuonIdHelperSvcCfg
9  from MuonConfig.MuonRecToolsConfig import MuonEDMHelperSvcCfg
10 
11  result=ComponentAccumulator()
12  result.merge(MuonIdHelperSvcCfg(configFlags))
13  result.merge(MuonEDMHelperSvcCfg(configFlags))
14 
15  if "PullCalculator" not in kwargs:
16  from TrkConfig.TrkResidualPullCalculatorConfig import (
17  ResidualPullCalculatorCfg)
18  kwargs.setdefault("PullCalculator", result.popToolsAndMerge(
19  ResidualPullCalculatorCfg(configFlags)))
20 
21  alg = CompFactory.MuonCalib.MuonSegmentReader(**kwargs)
22 
23  result.addEventAlgo(alg)
24  return result
25 
26 if __name__ == "__main__":
27  """Run a functional test if module is executed"""
28 
29  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
30  from AthenaConfiguration.AllConfigFlags import initConfigFlags
31  from AthenaCommon.Logging import logging
32 
33  log = logging.getLogger('CalibStreamConfig')
34  flags = initConfigFlags()
35 
36  #flags.Exec.SkipEvents = 1000
37  #flags.Exec.MaxEvents = 1000
38  flags.Concurrency.NumThreads = 1
39 
40 
42  inputdir = '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/MuonRecRTT/MdtCalibration/'
43  flags.Input.Files = [f'{inputdir}data23_calib.00456729.calibration_MuonAll.daq.RAW.0000_0004-0051.data'] # BMG2/4/6A12
44  #flags.Input.Files = [f'{d}data23_calib.00456729.calibration_MuonAll.daq.RAW.0000_0004-0200.data'] # Endcap
45  #flags.Input.Files = [f'{d}data23_calib.00456729.calibration_MuonAll.daq.RAW.0000_0004-0120.data'] # BIS7A16
46  #flags.Input.Files = [f'{d}data23_calib.00456729.calibration_MuonAll.daq.RAW.0000_0004-0113.data'] # BIS7A02
47 
48  flags.Input.TypedCollections = 'calibration_MuonAll'
49  flags.GeoModel.AtlasVersion = 'ATLAS-R3S-2021-03-02-00'
50  flags.IOVDb.GlobalTag = 'CONDBR2-ES1PA-2023-03' # last update May 2024
51  flags.Input.isMC = False
52  flags.Input.ProjectName=flags.Input.Files[0].split('/')[-1].split('.')[0]
53  data = flags.Input.Files[0].split('/')[-1].split('.')
54  if data[1][2:].isdigit():
55  flags.Input.RunNumbers = [int(data[1][2:])]
56  else:
57  flags.Input.RunNumbers = [0] #bogus run number in case parsing filename failed
58  ntuplename = flags.Input.Files[0].split('/')[-1][0:-4] + "ntuple.root"
59 
60  flags.Detector.GeometryMDT = True
61  flags.Detector.GeometryTGC = True
62  flags.Detector.GeometryRPC = True
63  flags.Detector.GeometryCSC = False # CSC was removed after LS2
64  flags.Detector.GeometrysTGC = False # no NSW data in calibration stream
65  flags.Detector.GeometryMM = False # no NSW data in calibration stream
66  flags.Detector.GeometryCalo = False # no Calo data in calibration stream
67  flags.Detector.GeometryID = False # no ID data in calibration stream
68  flags.Detector.GeometryPixel = False # no ID data in calibration stream
69  flags.Detector.GeometrySCT = False # no ID data in calibration stream
70 
71  flags.Muon.makePRDs = True
72 
73  flags.Input.LumiBlockNumbers = [200] # patch for avoiding ES_WrongFileFormat error due to autoConfig
74 
75  from AthenaConfiguration.Enums import BeamType, Format
76  flags.Beam.Type = BeamType.Collisions
77  flags.Input.Collections = []
78  flags.Input.Format = Format.BS
79  # setup the ESD output to verify the containers
80  flags.Output.doWriteESD = False
81  if flags.Output.ESDFileName == '':
82  flags.Output.ESDFileName='newESD.pool.root'
83  else:
84  print('ESD = ', flags.Output.ESDFileName )
85 
86  # setup the outputLevel
87  #flags.Exec.OutputLevel = 2 # DEBUG
88  flags.Exec.OutputLevel = 3 # INFO
89 
90  flags.PerfMon.doFullMonMT = True
91  flags.PerfMon.OutputJSON = flags.Input.Files[0].split('/')[-1][0:-4] + "perfmonmt.json"
92 
93  flags.lock()
94 
95  acc = MainServicesCfg(flags)
96  histSvc = CompFactory.THistSvc(Output=["%s DATAFILE='%s', OPT='RECREATE'" % ("CALIBNTUPLESTREAM", ntuplename)], AutoFlush= -10000000, AutoSave= -10000000)
97  acc.addService(histSvc, primary=True)
98 
99  #setup the cpu and memory monitoring
100  from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
101  acc.merge(PerfMonMTSvcCfg(flags))
102 
103  # setup calibrationtool
104  from MuonConfig.MuonCalibrationConfig import MdtCalibrationToolCfg
105 
106  tool_kwargs = {}
107  tool_kwargs["UseTwin"] = True
108  tool_kwargs["CalibrationTool"] = acc.popToolsAndMerge(MdtCalibrationToolCfg(flags, TimeWindowSetting = 3, DoPropagationCorrection = True, DoSlewingCorrection = True, DoMagneticFieldCorrection = True))
109 
110  # configure the muoncalibration stream reading
111  from MuonCalibStreamCnv.MuonCalibStreamCnvConfig import MuonCalibStreamReadCfg, MdtCalibRawDataProviderCfg, RpcCalibRawDataProviderCfg, TgcCalibRawDataProviderCfg
112 
114  acc.merge(read)
115 
116  if flags.Detector.GeometryMDT:
117  mdtCalibRawDataProvider = MdtCalibRawDataProviderCfg(flags)
118  acc.merge(mdtCalibRawDataProvider)
119 
120  # set the RDO to PRD tools for TGC and RPC (MDT doesn't need this step)
121  from MuonConfig.MuonRdoDecodeConfig import RpcRDODecodeCfg,TgcRDODecodeCfg
122  if flags.Detector.GeometryRPC:
123  rpcCalibRawDataProvider = RpcCalibRawDataProviderCfg(flags)
124  acc.merge(rpcCalibRawDataProvider)
125  acc.merge(RpcRDODecodeCfg(flags))
126  if flags.Detector.GeometryTGC:
127  tgcCalibRawDataProvider = TgcCalibRawDataProviderCfg(flags)
128  acc.merge(tgcCalibRawDataProvider)
129  acc.merge(TgcRDODecodeCfg(flags))
130 
131 
132  from MuonConfig.MuonReconstructionConfig import MuonSegmentFindingCfg, MuonTrackBuildingCfg, StandaloneMuonOutputCfg
133  reco = MuonSegmentFindingCfg(flags, setup_bytestream=False)
134  reco.merge(MuonTrackBuildingCfg(flags))
135  if flags.Output.doWriteESD or flags.Output.doWriteAOD:
136  reco.merge(StandaloneMuonOutputCfg(flags))
137  acc.merge(reco)
138 
139  # configure testAlg (switch off)
140  #from MuonCalibStreamCnv.MuonCalibStreamCnvConfig import MuonCalibStreamTestAlgCfg
141  # testAlg = MuonCalibStreamTestAlgCfg(flags)
142  # acc.merge(testAlg)
143 
144  # configure segment creator
145  #from AthenaCommon.Constants import DEBUG,INFO
146  reader = MuonSegmentReaderCfg(flags, CalibrationTool = acc.popToolsAndMerge(MdtCalibrationToolCfg(flags, TimeWindowSetting = 3, DoPropagationCorrection = True, DoSlewingCorrection = True, DoMagneticFieldCorrection = True)))
147  acc.merge(reader)
148 
149  acc.getCondAlgo("MdtCalibDbAlg").ReadKeyDCS=""
150 
151  acc.getService('Athena::DelayedConditionsCleanerSvc').RingSize=2
152  acc.getService('Athena::DelayedConditionsCleanerSvc').CleanDelay=1
153  acc.getService('Athena::DelayedConditionsCleanerSvc').LookAhead=1
154 
155  acc.printConfig(withDetails=True, summariseProps=True)
156 
157  log.info("Config OK")
158 
159  # save the config
160  with open('MuonCalibByteStreamConfig.pkl', 'wb') as pkl:
161  acc.store(pkl)
162 
163  # Print out the storceGate in the end
164  # acc.getService('StoreGateSvc').Dump = True
165 
166  import sys
167  sys.exit(acc.run(200).isFailure())
168 
python.MuonReconstructionConfig.StandaloneMuonOutputCfg
def StandaloneMuonOutputCfg(flags)
Definition: MuonReconstructionConfig.py:12
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.MuonSegmentFindingConfig.MuonSegmentFindingCfg
def MuonSegmentFindingCfg(flags, setup_bytestream=True, cardinality=1)
Definition: MuonSegmentFindingConfig.py:576
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonCalibStreamCnvConfig.MuonCalibStreamReadCfg
def MuonCalibStreamReadCfg(flags)
Definition: MuonCalibStreamCnvConfig.py:7
MuonCalibStreamCnvConfig.RpcCalibRawDataProviderCfg
def RpcCalibRawDataProviderCfg(flags, name="RpcCalibRawDataProviderAlg", **kwargs)
Definition: MuonCalibStreamCnvConfig.py:91
python.PerfMonCompsConfig.PerfMonMTSvcCfg
def PerfMonMTSvcCfg(flags, **kwargs)
A minimal new-style configuration for PerfMonMTSvc.
Definition: PerfMonCompsConfig.py:10
MuonCalibStreamCnvConfig.MdtCalibRawDataProviderCfg
def MdtCalibRawDataProviderCfg(flags, name="MdtCalibRawDataProviderAlg", **kwargs)
Definition: MuonCalibStreamCnvConfig.py:80
python.MuonRdoDecodeConfig.RpcRDODecodeCfg
def RpcRDODecodeCfg(flags, name="RpcRdoToRpcPrepData", RDOContainer=None, **kwargs)
Definition: MuonRdoDecodeConfig.py:126
python.MuonGeometryConfig.MuonIdHelperSvcCfg
def MuonIdHelperSvcCfg(flags)
Definition: MuonGeometryConfig.py:15
python.MuonTrackBuildingConfig.MuonTrackBuildingCfg
def MuonTrackBuildingCfg(flags, name="MuPatTrackBuilder", **kwargs)
Definition: MuonTrackBuildingConfig.py:498
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.MuonCalibrationConfig.MdtCalibrationToolCfg
def MdtCalibrationToolCfg(flags, name="MdtCalibrationTool", **kwargs)
Definition: MuonCalibrationConfig.py:82
python.MuonRecToolsConfig.MuonEDMHelperSvcCfg
def MuonEDMHelperSvcCfg(flags, name="MuonEDMHelperSvc", **kwargs)
Definition: MuonRecToolsConfig.py:31
python.MuonRdoDecodeConfig.TgcRDODecodeCfg
def TgcRDODecodeCfg(flags, name="TgcRdoToTgcPrepData", RDOContainer=None, **kwargs)
Definition: MuonRdoDecodeConfig.py:142
MuonCalibStreamCnvConfig.TgcCalibRawDataProviderCfg
def TgcCalibRawDataProviderCfg(flags, name="TgcCalibRawDataProviderAlg", **kwargs)
Definition: MuonCalibStreamCnvConfig.py:102
Trk::open
@ open
Definition: BinningType.h:40
MuonSegmentReaderConfig.MuonSegmentReaderCfg
def MuonSegmentReaderCfg(configFlags, **kwargs)
Definition: MuonSegmentReaderConfig.py:6
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.TrkResidualPullCalculatorConfig.ResidualPullCalculatorCfg
def ResidualPullCalculatorCfg(flags, name='ResidualPullCalculator', **kwargs)
Definition: TrkResidualPullCalculatorConfig.py:6
Trk::split
@ split
Definition: LayerMaterialProperties.h:38