ATLAS Offline Software
Loading...
Searching...
No Matches
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
11MdtCalibrationTMaxShiftTool::MdtCalibrationTMaxShiftTool(const std::string& type, const std::string& name, const IInterface* parent) :
12 MdtCalibrationShiftMapBase(type, name, parent) {}
13
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())) {
52 ATH_MSG_WARNING(cabling_data);
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
92StatusCode MdtCalibrationTMaxShiftTool::setTUpper(const float tUpper) {
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Gaudi::Property< float > m_centralValue
std::map< Identifier, float > m_shiftValues
Gaudi::Property< bool > m_forceMapRecreate
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_mdtCab
MdtCalibrationShiftMapBase(const std::string &type, const std::string &name, const IInterface *parent)
StatusCode setTUpper(const float tUpper)
MdtCalibrationTMaxShiftTool(const std::string &type, const std::string &name, const IInterface *parent)
StatusCode initializeMap() override final
const OnlToOffMap & getOnlineConvMap() const
Returns the map to convert the online -> offline identifiers.
MdtCablingData CablingData
bool getOfflineId(CablingData &cabling_data, MsgStream &log) const
return the offline id given the online id
bool convert(const CablingData &cabling_data, Identifier &id, bool check_valid=true) const
converts the cabling data into an identifier.