ATLAS Offline Software
MdtCalibrationT0ShiftTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 // TRandom3 for random smearing
8 // should later be replaced with std
9 #include "TRandom3.h"
10 
11 MdtCalibrationT0ShiftTool::MdtCalibrationT0ShiftTool(const std::string& type, const std::string& name, const IInterface* parent) :
13 }
14 
16 {
17  if (m_mapIsInitialized) {
18  ATH_MSG_WARNING("Map already initalized. Multiple calls of initalizeMap should not happen.");
19  return StatusCode::SUCCESS;
20  }
21 
22  /* First try loading the map from its default location */
23  if (!m_forceMapRecreate) {
25  return StatusCode::SUCCESS;
26  }
27 
28  /* map was not found as a file or needs to be recreated */
29  // TODO: What if multiple jobs started in parallel?
30  // (DataRace on MapFile because of parallel jobs)
31 
32  /* initialize random number generator that creates the shift values */
33  TRandom3 rng(/*seed*/ 20120704);
34 
35  SG::ReadCondHandle<MuonMDT_CablingMap> readHandle{m_mdtCab, Gaudi::Hive::currentContext()};
36  const MuonMDT_CablingMap* mdtCabling{*readHandle};
37  if(!mdtCabling){
38  ATH_MSG_ERROR("Null pointer to the MDT cabling conditions object");
39  return StatusCode::FAILURE;
40  }
41 
42  for (const auto& onl_cab : mdtCabling->getOnlineConvMap()) {
44  cabling_data.MdtCablingOnData::operator=(onl_cab.first);
46  for (const auto& tdc : onl_cab.second) {
47  if (!tdc) continue;
48  cabling_data.tdcId = tdc->moduleId();
49  for (cabling_data.channelId = 0; cabling_data.channelId < 24; ++cabling_data.channelId) {
50  /* Get the offline ID, given the current detector element */
51  if (!mdtCabling->getOfflineId(cabling_data, msgStream())) {
53  continue;
54  }
55  Identifier channelIdentifier;
56  bool isValid = mdtCabling->convert(cabling_data,channelIdentifier);
57  // this debug msg can be removed eventually
58  ATH_MSG_DEBUG("Trying to set from online IDs "<<
59  std::endl<<
60  cabling_data<<
61  " .. with channelID"<<
62  std::endl <<
63  " Identifier " <<
64  channelIdentifier <<std::endl<<" Identifier32 " << channelIdentifier.get_identifier32());
65 
66  if (!isValid) {
67  ATH_MSG_FATAL(cabling_data<<" --- Conversion to Identifier is NOT valid.");
68  return StatusCode::FAILURE;
69  }
70 
71  double rn = rng.Gaus(m_centralValue, m_sigma);
72  // Fatal if entry exists
73  if (m_shiftValues.find(channelIdentifier) != m_shiftValues.end()) {
74  ATH_MSG_FATAL("Double counting in initialization of map");
75  return StatusCode::FAILURE;
76  }
77  m_shiftValues[channelIdentifier] = rn;
78 
79  }
80  }
81  }
82  /* initalization was successful */
83  m_mapIsInitialized = true;
84 
85  /* write map to the default location */
87 
88  return StatusCode::SUCCESS;
89 }
MdtCalibrationShiftMapBase::dumpMapAsFile
StatusCode dumpMapAsFile()
Definition: MdtCalibrationShiftMapBase.cxx:22
MdtCalibrationT0ShiftTool::initializeMap
StatusCode initializeMap() override final
Definition: MdtCalibrationT0ShiftTool.cxx:15
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
createCablingJSON.cabling_data
dictionary cabling_data
Definition: createCablingJSON.py:18
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
D3PDTest::rng
uint32_t rng()
Definition: FillerAlg.cxx:40
MdtCalibrationShiftMapBase::m_sigma
Gaudi::Property< float > m_sigma
Definition: MdtCalibrationShiftMapBase.h:54
MdtCalibrationShiftMapBase
Definition: MdtCalibrationShiftMapBase.h:25
MdtCalibrationShiftMapBase::m_forceMapRecreate
Gaudi::Property< bool > m_forceMapRecreate
Definition: MdtCalibrationShiftMapBase.h:55
MuonMDT_CablingMap
Definition: MuonMDT_CablingMap.h:24
MdtCalibrationShiftMapBase::loadMapFromFile
StatusCode loadMapFromFile()
Definition: MdtCalibrationShiftMapBase.cxx:60
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MdtCalibrationShiftMapBase::m_shiftValues
std::map< Identifier, float > m_shiftValues
Definition: MdtCalibrationShiftMapBase.h:57
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
python.BunchSpacingUtils.rn
rn
Definition: BunchSpacingUtils.py:87
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MdtCablingData
Definition: MdtCablingData.h:82
MdtCalibrationT0ShiftTool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MdtCalibrationShiftMapBase::m_centralValue
Gaudi::Property< float > m_centralValue
Definition: MdtCalibrationShiftMapBase.h:53
MdtCalibrationShiftMapBase::m_mdtCab
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_mdtCab
Definition: MdtCalibrationShiftMapBase.h:61
MdtCalibrationShiftMapBase::m_mapIsInitialized
bool m_mapIsInitialized
Definition: MdtCalibrationShiftMapBase.h:58
MdtCalibrationT0ShiftTool::MdtCalibrationT0ShiftTool
MdtCalibrationT0ShiftTool(const std::string &type, const std::string &name, const IInterface *parent)
constructor
Definition: MdtCalibrationT0ShiftTool.cxx:11
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.