ATLAS Offline Software
Loading...
Searching...
No Matches
NswCalibDbTimeChargeData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "GeoModelKernel/throwExcept.h"
8#include <iostream>
9#include <iomanip>
10
11std::ostream& operator<<(std::ostream& ostr, const NswCalibDbTimeChargeData::CalibConstants& obj) {
12 ostr<<"slope: "<<std::setprecision(15)<<obj.slope;//<<" pm "<<std::setprecision(15)<<obj.slopeError;
13 ostr<<" intercept: "<<std::setprecision(15)<<obj.intercept;//<<" pm "<<std::setprecision(15)<<obj.interceptError;
14 return ostr;
15}
16
17// general functions ---------------------------------
24
26 const IdentifierHash hash = m_idHelperSvc->detElementHash(chan_id);
27 if (m_idHelperSvc->isMM(chan_id)) {
28 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
29 return static_cast<unsigned>(hash)*(idHelper.gasGapMax()) + (idHelper.gasGap(chan_id) -1);
30 } else if (m_idHelperSvc->issTgc(chan_id)) {
31 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
32 return static_cast<unsigned>(hash)*(idHelper.gasGapMax() * 3 /*3 channel types*/) +
33 (idHelper.gasGap(chan_id) -1 + idHelper.gasGapMax() * idHelper.channelType(chan_id)) + m_nMmElements;
34 }
35 return -1;
36}
37
38// setting functions ---------------------------------
39
40// setData
41void
43 const Identifier& chnlId,
46
47
48 const int array_idx = identToModuleIdx(chnlId);
49 ATH_MSG_VERBOSE("Set "<<(type == CalibDataType::PDO ? "PDO" : "TDO")<<" calibration constants for channel "
50 <<m_idHelperSvc->toString(chnlId)<<", slot: "<< array_idx<<", "<<constants);
51 if (array_idx < 0){
52 ATH_MSG_ERROR("Array index is negative in setData.");
53 return;
54 }
55 CalibModule& calib_mod = calibMap.at(array_idx);
56 const unsigned channel = (m_idHelperSvc->isMM(chnlId) ?
57 m_idHelperSvc->mmIdHelper().channel(chnlId) :
58 m_idHelperSvc->stgcIdHelper().channel(chnlId)) -1;
59 if (calib_mod.channels.empty()) {
60 if (m_idHelperSvc->isMM(chnlId)) {
61 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
62 calib_mod.layer_id = idHelper.channelID(chnlId, idHelper.multilayer(chnlId), idHelper.gasGap(chnlId), 1);
63 } else if (m_idHelperSvc->issTgc(chnlId)) {
64 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
65 calib_mod.layer_id = idHelper.channelID(chnlId, idHelper.multilayer(chnlId), idHelper.gasGap(chnlId), idHelper.channelType(chnlId), 1);
66 }
67 }
68 if (calib_mod.channels.size() <= channel) calib_mod.channels.resize(channel +1);
69 if (calib_mod.channels[channel]) {
70 THROW_EXCEPTION("setData() -- Cannot overwrite channel "<<m_idHelperSvc->toString(chnlId)
71 <<"Layer ID: "<<m_idHelperSvc->toString(calib_mod.layer_id)<<
72 " "<<(*calib_mod.channels[channel] ));
73 return;
74 }
75 calib_mod.channels[channel] = std::make_unique<CalibConstants>(std::move(constants));
76}
77
78// setZeroData
79void
84
85
86
87// retrieval functions -------------------------------
88
89// getChannelIds
90std::vector<Identifier>
91NswCalibDbTimeChargeData::getChannelIds(const CalibDataType type, const std::string& tech, const std::string& side) const {
92 std::vector<Identifier> chnls;
94 chnls.reserve(calibMap.size());
95 for (const CalibModule& module : calibMap) {
97 if (module.channels.empty()) continue;
98 if (side == "A" && m_idHelperSvc->stationEta(module.layer_id) < 0) continue;
99 if (side == "C" && m_idHelperSvc->stationEta(module.layer_id) > 0) continue;
100
101 if (m_idHelperSvc->isMM(module.layer_id)) {
102 if (tech == "STGC") continue;
103 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
104 for (unsigned chn = 1 ; chn <= module.channels.size() ; ++chn) {
105 if (!module.channels[chn -1]) continue;
106
107 chnls.push_back(idHelper.channelID(module.layer_id,
108 idHelper.multilayer(module.layer_id),
109 idHelper.gasGap(module.layer_id), chn ));
110 }
111 } else if (m_idHelperSvc->issTgc(module.layer_id)) {
112 if (tech == "MM") break;
113 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
114 for (unsigned chn = 1 ; chn <= module.channels.size() ; ++chn) {
115 if (!module.channels[chn -1]) continue;
116 chnls.push_back(idHelper.channelID(module.layer_id,
117 idHelper.multilayer(module.layer_id),
118 idHelper.gasGap(module.layer_id),
119 idHelper.channelType(module.layer_id), chn ));
120 }
121 }
122 }
123
124 return chnls;
125}
129 const int array_idx = identToModuleIdx(channelId);
130 if (array_idx < 0){
131 ATH_MSG_ERROR("NswCalibDbTimeChargeData::getCalibForChannel: array index is negative.");
132 return nullptr;
133 }
134 const unsigned channel = (m_idHelperSvc->isMM(channelId) ?
135 m_idHelperSvc->mmIdHelper().channel(channelId) :
136 m_idHelperSvc->stgcIdHelper().channel(channelId)) -1;
137 if (calibMap.at(array_idx).channels.size() > channel && calibMap[array_idx].channels[channel]) {
138 return calibMap[array_idx].channels[channel].get();
139 }
140 // search for data for channel zero
142 return getZeroCalibChannel(type, tech);
143
144}
150
151
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
std::ostream & operator<<(std::ostream &ostr, const NswCalibDbTimeChargeData::CalibConstants &obj)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
This is a "hash" representation of an Identifier.
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channel) const
static int gasGapMax()
int gasGap(const Identifier &id) const override
get the hashes
int multilayer(const Identifier &id) const
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
const CalibConstants * getCalibForChannel(const CalibDataType type, const Identifier &channelId) const
Retrieves the calibration constant for a particular readout channel.
const Muon::IMuonIdHelperSvc * m_idHelperSvc
int identToModuleIdx(const Identifier &chan_id) const
void setZero(CalibDataType type, MuonCond::CalibTechType tech, CalibConstants constants)
void setData(CalibDataType type, const Identifier &chnlId, CalibConstants constants)
NswCalibDbTimeChargeData(const Muon::IMuonIdHelperSvc *idHelperSvc)
const size_t m_nMmElements
Segmentation of the elements is per NSW gasGap. Each wedge has 4 gasgaps.
const CalibConstants * getZeroCalibChannel(const CalibDataType type, const MuonCond::CalibTechType tech) const
Returns the dummy calibration constant for the given technology type.
std::vector< Identifier > getChannelIds(const CalibDataType type, const std::string &tech, const std::string &side) const
std::vector< CalibModule > ChannelCalibMap
std::array< ZeroCalibMap, Muon::MuonStationIndex::toInt(MuonCond::CalibTechType::nTypes)> m_zero
const size_t m_nStgcElements
Additionally reserve space for the 3 channel types.
int multilayer(const Identifier &id) const
int channelType(const Identifier &id) const
static int gasGapMax()
int gasGap(const Identifier &id) const override
get the hashes
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int channel) const
constexpr int toInt(const EnumType enumVal)
Helper struct to cache all calibration constants in a common place of the memory.
std::vector< std::unique_ptr< CalibConstants > > channels
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10