ATLAS Offline Software
Loading...
Searching...
No Matches
MdtCalibrationTMaxShiftTool Class Reference

#include <MdtCalibrationTMaxShiftTool.h>

Inheritance diagram for MdtCalibrationTMaxShiftTool:
Collaboration diagram for MdtCalibrationTMaxShiftTool:

Public Member Functions

 MdtCalibrationTMaxShiftTool (const std::string &type, const std::string &name, const IInterface *parent)
 ~MdtCalibrationTMaxShiftTool ()=default
StatusCode initializeMap () override final
StatusCode setTUpper (const float tUpper)
float getTUpper () const
float getValue (const Identifier &id) const override
virtual StatusCode initialize () override
StatusCode dumpMapAsFile ()
StatusCode loadMapFromFile ()

Protected Attributes

Gaudi::Property< std::string > m_mapFileName {this,"MapFile",""}
Gaudi::Property< float > m_centralValue {this,"CentralValue",0}
Gaudi::Property< float > m_sigma {this,"Sigma",10}
Gaudi::Property< bool > m_forceMapRecreate {this,"ForceMapRecreate",false}
std::map< Identifier, float > m_shiftValues
bool m_mapIsInitialized {false}
ServiceHandle< Muon::IMuonIdHelperSvcm_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
SG::ReadCondHandleKey< MuonMDT_CablingMapm_mdtCab {this, "MdtCabling", "MuonMDT_CablingMap"}

Private Attributes

float m_tUpper {688.1818}

Detailed Description

Definition at line 15 of file MdtCalibrationTMaxShiftTool.h.

Constructor & Destructor Documentation

◆ MdtCalibrationTMaxShiftTool()

MdtCalibrationTMaxShiftTool::MdtCalibrationTMaxShiftTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 11 of file MdtCalibrationTMaxShiftTool.cxx.

11 :
12 MdtCalibrationShiftMapBase(type, name, parent) {}
MdtCalibrationShiftMapBase(const std::string &type, const std::string &name, const IInterface *parent)

◆ ~MdtCalibrationTMaxShiftTool()

MdtCalibrationTMaxShiftTool::~MdtCalibrationTMaxShiftTool ( )
default

Member Function Documentation

◆ dumpMapAsFile()

StatusCode MdtCalibrationShiftMapBase::dumpMapAsFile ( )
inherited

Definition at line 22 of file MdtCalibrationShiftMapBase.cxx.

22 {
23 /* initialize map if it's not there */
24 if (!m_mapIsInitialized) {
26 }
27
28 /* write the map to a file */
29 {
30 std::ofstream file(m_mapFileName.value().c_str(), std::ios::out | std::ios::trunc);
31
32 /* see if opening the file was successful */
33 if (!file.is_open()) {
35 "Cannot open map output file for writing. Tried accessing file at \"./"
36 << m_mapFileName << "\"");
37 return StatusCode::FAILURE;
38 }
39
40 /* write header, comments can start with '#' or '//' */
41 file << "# This file contains shift values for MDT tubes\n";
42 file << "# Each Identifier is mapped to a float\n";
43 file << "# Below are comma separated values with formatting\n";
44 file << "# Identifier.get_compact(),float\n";
45 file << "# ------------------------------------------------\n";
46
47 /* dump map contents */
48 for (auto shift : m_shiftValues) {
49 Identifier::value_type identifierCompact = shift.first.get_compact();
50 float shiftValue = shift.second;
51 file << identifierCompact;
52 file << ",";
53 file << shiftValue;
54 file << "\n";
55 }
56 } // '}' flushes file
57 return StatusCode::SUCCESS;
58}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
Gaudi::Property< std::string > m_mapFileName
std::map< Identifier, float > m_shiftValues
virtual StatusCode initializeMap()=0
TFile * file

◆ getTUpper()

float MdtCalibrationTMaxShiftTool::getTUpper ( ) const
inline

Definition at line 30 of file MdtCalibrationTMaxShiftTool.h.

◆ getValue()

float MdtCalibrationShiftMapBase::getValue ( const Identifier & id) const
overrideinherited

Definition at line 130 of file MdtCalibrationShiftMapBase.cxx.

130 {
131 std::map<Identifier, float>::const_iterator itr = m_shiftValues.find(id);
132 if (itr == m_shiftValues.end()){
133 ATH_MSG_FATAL("The identifier "<<m_idHelperSvc->toString(id)<<" is not known for a T0 smearing");
134 throw std::runtime_error("MdtT0Calibration - Invalid identifier");
135 }
136 return itr->second;
137}
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc

◆ initialize()

StatusCode MdtCalibrationShiftMapBase::initialize ( )
overridevirtualinherited

Definition at line 15 of file MdtCalibrationShiftMapBase.cxx.

15 {
16 ATH_CHECK(m_idHelperSvc.retrieve());
17 ATH_CHECK(m_mdtCab.initialize());
19 return StatusCode::SUCCESS;
20}
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_mdtCab

◆ initializeMap()

StatusCode MdtCalibrationTMaxShiftTool::initializeMap ( )
finaloverridevirtual

Loop over all tdc channels

Implements MdtCalibrationShiftMapBase.

Definition at line 14 of file MdtCalibrationTMaxShiftTool.cxx.

14 {
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}
#define ATH_MSG_ERROR(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
Gaudi::Property< bool > m_forceMapRecreate
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.
uint32_t rng()
Definition FillerAlg.cxx:40

◆ loadMapFromFile()

StatusCode MdtCalibrationShiftMapBase::loadMapFromFile ( )
inherited

Definition at line 60 of file MdtCalibrationShiftMapBase.cxx.

60 {
61 /* check if map was already initialized */
63 ATH_MSG_WARNING("Map already initialized, won't overwrite it.");
64 return StatusCode::SUCCESS;
65 }
66
67 /* resolve path */
68 std::string fileWithPath = PathResolver::find_file(m_mapFileName, "DATAPATH");
69 if (fileWithPath.empty()) {
70 ATH_MSG_ERROR("Cannot find file " << m_mapFileName << " in $DATAPATH");
71 return StatusCode::FAILURE;
72 }
73
74 /* check if the file exists */
75 struct stat buffer{};
76 if (stat(fileWithPath.c_str(), &buffer) != 0) {
77 ATH_MSG_ERROR("Cannot stat the file \""
78 << fileWithPath.c_str()
79 << "\" -> map can not be initialized from this file.");
80 return StatusCode::FAILURE;
81 }
82
83 /* check if the map is already stored */
84 std::ifstream fin(fileWithPath.c_str(), std::ios::in);
85 std::string line;
86 bool initializedWithWarnings = false;
87 // get all lines in file
88 while (std::getline(fin, line)) {
89 // check if file is empty, begins with '#', or '//'
90 if (line.empty() || line.compare(0, 1, "#") == 0 ||
91 line.compare(0, 2, "//")) {
92 continue;
93 }
94 // need a stringstream for readline
95 std::stringstream lineStream(line);
96 // get all csv tokens in line
97 std::string token;
98 std::vector<std::string> tokenVector;
99 while (std::getline(lineStream, token, ',')) {
100 tokenVector.push_back(token);
101 }
102 // expect exactly two tokens: identifier and value
103 if (tokenVector.size() == 2) {
104 // we are careful about the type here
105 // watch out for compiler warnings warning about casting ull to value_type
106 // they might occur of Identifier::value_type is changed at some point
107 Identifier::value_type identifierCompact = std::stoull(tokenVector[0]);
108 Identifier id(identifierCompact);
109 float shift = std::stof(tokenVector[1]);
110 m_shiftValues[id] = shift;
111 } else {
112 ATH_MSG_WARNING("Unexpected input format in shift map file "
113 << fileWithPath.c_str());
114 ATH_MSG_WARNING("Expected 2 tokens, got " << tokenVector.size());
115 ATH_MSG_WARNING("Broken line: \"" << line.c_str() << "\"");
116 initializedWithWarnings = true;
117 }
118 }
119 m_mapIsInitialized = true;
120 if (initializedWithWarnings) {
121 ATH_MSG_WARNING("Initialized shift map WITH WARNINGS from file \""
122 << fileWithPath.c_str() << "\"");
123 } else {
124 ATH_MSG_INFO("Successfully initialized shift map from file \""
125 << fileWithPath.c_str() << "\"");
126 }
127 return StatusCode::SUCCESS;
128}
#define ATH_MSG_INFO(x)
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)

◆ setTUpper()

StatusCode MdtCalibrationTMaxShiftTool::setTUpper ( const float tUpper)

Definition at line 92 of file MdtCalibrationTMaxShiftTool.cxx.

92 {
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}

Member Data Documentation

◆ m_centralValue

Gaudi::Property<float> MdtCalibrationShiftMapBase::m_centralValue {this,"CentralValue",0}
protectedinherited

Definition at line 53 of file MdtCalibrationShiftMapBase.h.

53{this,"CentralValue",0};

◆ m_forceMapRecreate

Gaudi::Property<bool> MdtCalibrationShiftMapBase::m_forceMapRecreate {this,"ForceMapRecreate",false}
protectedinherited

Definition at line 55 of file MdtCalibrationShiftMapBase.h.

55{this,"ForceMapRecreate",false};

◆ m_idHelperSvc

ServiceHandle<Muon::IMuonIdHelperSvc> MdtCalibrationShiftMapBase::m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
protectedinherited

Definition at line 60 of file MdtCalibrationShiftMapBase.h.

60{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};

◆ m_mapFileName

Gaudi::Property<std::string> MdtCalibrationShiftMapBase::m_mapFileName {this,"MapFile",""}
protectedinherited

Definition at line 52 of file MdtCalibrationShiftMapBase.h.

52{this,"MapFile",""};

◆ m_mapIsInitialized

bool MdtCalibrationShiftMapBase::m_mapIsInitialized {false}
protectedinherited

Definition at line 58 of file MdtCalibrationShiftMapBase.h.

58{false};

◆ m_mdtCab

SG::ReadCondHandleKey<MuonMDT_CablingMap> MdtCalibrationShiftMapBase::m_mdtCab {this, "MdtCabling", "MuonMDT_CablingMap"}
protectedinherited

Definition at line 61 of file MdtCalibrationShiftMapBase.h.

61{this, "MdtCabling", "MuonMDT_CablingMap"};

◆ m_shiftValues

std::map<Identifier, float> MdtCalibrationShiftMapBase::m_shiftValues
protectedinherited

Definition at line 57 of file MdtCalibrationShiftMapBase.h.

◆ m_sigma

Gaudi::Property<float> MdtCalibrationShiftMapBase::m_sigma {this,"Sigma",10}
protectedinherited

Definition at line 54 of file MdtCalibrationShiftMapBase.h.

54{this,"Sigma",10};

◆ m_tUpper

float MdtCalibrationTMaxShiftTool::m_tUpper {688.1818}
private

Definition at line 33 of file MdtCalibrationTMaxShiftTool.h.

33{688.1818};

The documentation for this class was generated from the following files: