ATLAS Offline Software
MdtCalibrationTMaxShiftTool.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 // TRandom2 for random smearing
8 // should later be replaced with std
9 #include "TRandom2.h"
10 
11 MdtCalibrationTMaxShiftTool::MdtCalibrationTMaxShiftTool(const std::string& type, const std::string& name, const IInterface* parent) :
13 
15  if (m_mapIsInitialized) {
17  "Map already initalized. Multiple calls of initalizeMap "
18  "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 */
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  TRandom2 rng(/*seed*/ 20160211);
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  if (m_shiftValues.find(channelIdentifier) != m_shiftValues.end()) {
71  ATH_MSG_FATAL("Double counting in initilization of map");
72  return StatusCode::FAILURE;
73  }
74  float rn = rng.Gaus(m_centralValue, m_sigma);
75  float shift =
76  rn / m_tUpper; // store relative variation: Delta_t / t
77  m_shiftValues[channelIdentifier] = shift;
78  }
79  }
80  }
81 
82 
83  /* initalization was successful */
84  m_mapIsInitialized = true;
85 
86  /* write map to the default location */
88 
89  return StatusCode::SUCCESS;
90 }
91 
93  if (m_mapIsInitialized) {
94  ATH_MSG_FATAL("You cannot change m_tUpper once the map is initialized.");
95  return StatusCode::FAILURE;
96  }
97 
98  m_tUpper = tUpper;
99  return StatusCode::SUCCESS;
100 }
MdtCalibrationShiftMapBase::dumpMapAsFile
StatusCode dumpMapAsFile()
Definition: MdtCalibrationShiftMapBase.cxx:22
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
MdtCalibrationTMaxShiftTool.h
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MdtCalibrationTMaxShiftTool::MdtCalibrationTMaxShiftTool
MdtCalibrationTMaxShiftTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MdtCalibrationTMaxShiftTool.cxx:11
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
MdtCalibrationTMaxShiftTool::m_tUpper
float m_tUpper
Definition: MdtCalibrationTMaxShiftTool.h:33
MdtCalibrationShiftMapBase::m_mdtCab
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_mdtCab
Definition: MdtCalibrationShiftMapBase.h:61
MdtCalibrationShiftMapBase::m_mapIsInitialized
bool m_mapIsInitialized
Definition: MdtCalibrationShiftMapBase.h:58
MdtCalibrationTMaxShiftTool::initializeMap
StatusCode initializeMap() override final
Definition: MdtCalibrationTMaxShiftTool.cxx:14
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
MdtCalibrationTMaxShiftTool::setTUpper
StatusCode setTUpper(const float tUpper)
Definition: MdtCalibrationTMaxShiftTool.cxx:92