ATLAS Offline Software
NswCalibDbTimeChargeData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "GeoModelKernel/throwExcept.h"
8 #include <iostream>
9 #include <iomanip>
10 
11 std::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 ---------------------------------
19  AthMessaging{"NswCalibDbTimeChargeData"},
20  m_idHelperSvc{idHelperSvc} {
21  m_pdo_data.resize(m_nStgcElements + m_nMmElements);
22  m_tdo_data.resize(m_nStgcElements + m_nMmElements);
23 }
24 
27  if (m_idHelperSvc->isMM(chan_id)) {
28  const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
29  return static_cast<unsigned int>(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 int>(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
41 void
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  CalibModule& calib_mod = calibMap.at(array_idx);
52  const unsigned int channel = (m_idHelperSvc->isMM(chnlId) ?
53  m_idHelperSvc->mmIdHelper().channel(chnlId) :
54  m_idHelperSvc->stgcIdHelper().channel(chnlId)) -1;
55  if (calib_mod.channels.empty()) {
56  if (m_idHelperSvc->isMM(chnlId)) {
57  const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
58  calib_mod.layer_id = idHelper.channelID(chnlId, idHelper.multilayer(chnlId), idHelper.gasGap(chnlId), 1);
59  } else if (m_idHelperSvc->issTgc(chnlId)) {
60  const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
61  calib_mod.layer_id = idHelper.channelID(chnlId, idHelper.multilayer(chnlId), idHelper.gasGap(chnlId), idHelper.channelType(chnlId), 1);
62  }
63  }
64  if (calib_mod.channels.size() <= channel) calib_mod.channels.resize(channel +1);
65  if (calib_mod.channels[channel]) {
66  THROW_EXCEPTION("setData() -- Cannot overwrite channel "<<m_idHelperSvc->toString(chnlId)
67  <<"Layer ID: "<<m_idHelperSvc->toString(calib_mod.layer_id)<<
68  " "<<(*calib_mod.channels[channel] ));
69  return;
70  }
71  calib_mod.channels[channel] = std::make_unique<CalibConstants>(std::move(constants));
72 }
73 
74 // setZeroData
75 void
77  ZeroCalibMap& calibMap = m_zero[tech];
78  calibMap.insert(std::make_pair(type, std::move(constants)));
79 }
80 
81 
82 
83 // retrieval functions -------------------------------
84 
85 // getChannelIds
86 std::vector<Identifier>
87 NswCalibDbTimeChargeData::getChannelIds(const CalibDataType type, const std::string& tech, const std::string& side) const {
88  std::vector<Identifier> chnls;
90  chnls.reserve(calibMap.size());
91  for (const CalibModule& module : calibMap) {
93  if (module.channels.empty()) continue;
94  if (side == "A" && m_idHelperSvc->stationEta(module.layer_id) < 0) continue;
95  if (side == "C" && m_idHelperSvc->stationEta(module.layer_id) > 0) continue;
96 
97  if (m_idHelperSvc->isMM(module.layer_id)) {
98  if (tech == "STGC") continue;
99  const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
100  for (unsigned int chn = 1 ; chn <= module.channels.size() ; ++chn) {
101  if (!module.channels[chn -1]) continue;
102 
103  chnls.push_back(idHelper.channelID(module.layer_id,
104  idHelper.multilayer(module.layer_id),
105  idHelper.gasGap(module.layer_id), chn ));
106  }
107  } else if (m_idHelperSvc->issTgc(module.layer_id)) {
108  if (tech == "MM") break;
109  const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
110  for (unsigned int chn = 1 ; chn <= module.channels.size() ; ++chn) {
111  if (!module.channels[chn -1]) continue;
112  chnls.push_back(idHelper.channelID(module.layer_id,
113  idHelper.multilayer(module.layer_id),
114  idHelper.gasGap(module.layer_id),
115  idHelper.channelType(module.layer_id), chn ));
116  }
117  }
118  }
119 
120  return chnls;
121 }
123  const ChannelCalibMap& calibMap = type == CalibDataType::PDO ? m_pdo_data : m_tdo_data;
124  const int array_idx = identToModuleIdx(channelId);
125  const unsigned int channel = (m_idHelperSvc->isMM(channelId) ?
128  if (calibMap.at(array_idx).channels.size() > channel && calibMap[array_idx].channels[channel]) {
129  return calibMap[array_idx].channels[channel].get();
130  }
131  // search for data for channel zero
133  return getZeroCalibChannel(type, tech);
134 
135 }
137  std::map<MuonCond::CalibTechType, ZeroCalibMap>::const_iterator itr = m_zero.find(tech);
138  if(itr != m_zero.end()) {
139  const ZeroCalibMap& zeroMap = itr->second;
140  ZeroCalibMap::const_iterator type_itr = zeroMap.find(type);
141  if(type_itr != zeroMap.end()) return &type_itr->second;
142  }
143  return nullptr;
144 }
145 
146 
NswCalibDbTimeChargeData::setData
void setData(CalibDataType type, const Identifier &chnlId, CalibConstants constants)
Definition: NswCalibDbTimeChargeData.cxx:42
Muon::IMuonIdHelperSvc::stgcIdHelper
virtual const sTgcIdHelper & stgcIdHelper() const =0
access to TgcIdHelper
NswCalibDbTimeChargeData::CalibConstants
Helper struct to cache all calibration constants in a common place of the memory.
Definition: NswCalibDbTimeChargeData.h:34
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
NswCalibDbTimeChargeData.h
NswCalibDbTimeChargeData::CalibDataType::PDO
@ PDO
NswCalibDbTimeChargeData::m_nMmElements
const size_t m_nMmElements
Segmentation of the elements is per NSW gasGap. Each wedge has 4 gasgaps.
Definition: NswCalibDbTimeChargeData.h:64
Muon::IMuonIdHelperSvc::stationEta
virtual int stationEta(const Identifier &id) const =0
Return stationEta for all technologies.
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
NswCalibDbTimeChargeData::CalibDataType
CalibDataType
Definition: NswCalibDbTimeChargeData.h:28
Muon::IMuonIdHelperSvc::mmIdHelper
virtual const MmIdHelper & mmIdHelper() const =0
access to CscIdHelper
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
TRT::Hit::side
@ side
Definition: HitInfo.h:83
NswCalibDbTimeChargeData::setZero
void setZero(CalibDataType type, MuonCond::CalibTechType tech, CalibConstants constants)
Definition: NswCalibDbTimeChargeData.cxx:76
NswCalibDbTimeChargeData::getZeroCalibChannel
const CalibConstants * getZeroCalibChannel(const CalibDataType type, const MuonCond::CalibTechType tech) const
Returns the dummy calibration constant for the given technology type.
Definition: NswCalibDbTimeChargeData.cxx:136
python.PyAthena.module
module
Definition: PyAthena.py:131
NswCalibDbTimeChargeData::m_tdo_data
ChannelCalibMap m_tdo_data
Definition: NswCalibDbTimeChargeData.h:78
sTgcIdHelper::channel
int channel(const Identifier &id) const override
Definition: sTgcIdHelper.cxx:1032
NswCalibDbTimeChargeData::CalibModule::channels
std::vector< std::unique_ptr< CalibConstants > > channels
Definition: NswCalibDbTimeChargeData.h:72
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
NswCalibDbTimeChargeData::NswCalibDbTimeChargeData
NswCalibDbTimeChargeData(const Muon::IMuonIdHelperSvc *idHelperSvc)
Definition: NswCalibDbTimeChargeData.cxx:18
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:121
NswCalibDbTimeChargeData::m_zero
std::map< MuonCond::CalibTechType, ZeroCalibMap > m_zero
Definition: NswCalibDbTimeChargeData.h:81
Muon::IMuonIdHelperSvc::isMM
virtual bool isMM(const Identifier &id) const =0
returns whether this is a MM Identifier or not
NswCalibDbTimeChargeData::ChannelCalibMap
std::vector< CalibModule > ChannelCalibMap
Definition: NswCalibDbTimeChargeData.h:76
IdentifierHash.h
NswCalibDbTimeChargeData::m_idHelperSvc
const Muon::IMuonIdHelperSvc * m_idHelperSvc
Definition: NswCalibDbTimeChargeData.h:62
sTgcIdHelper
Definition: sTgcIdHelper.h:55
THROW_EXCEPTION
#define THROW_EXCEPTION(MESSAGE)
Definition: throwExcept.h:10
MuonCond::CalibTechType::STGC
@ STGC
NswCalibDbTimeChargeData::getChannelIds
std::vector< Identifier > getChannelIds(const CalibDataType type, const std::string &tech, const std::string &side) const
Definition: NswCalibDbTimeChargeData.cxx:87
operator<<
std::ostream & operator<<(std::ostream &ostr, const NswCalibDbTimeChargeData::CalibConstants &obj)
Definition: NswCalibDbTimeChargeData.cxx:11
MmIdHelper::channel
int channel(const Identifier &id) const override
Definition: MmIdHelper.cxx:832
MmIdHelper
Definition: MmIdHelper.h:54
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
Muon::IMuonIdHelperSvc::toString
virtual std::string toString(const Identifier &id) const =0
print all fields to string
constants
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:1
NswCalibDbTimeChargeData::m_pdo_data
ChannelCalibMap m_pdo_data
Definition: NswCalibDbTimeChargeData.h:77
MuonCond::CalibTechType
CalibTechType
Definition: MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/Defs.h:37
NswCalibDbTimeChargeData::ZeroCalibMap
std::map< CalibDataType, CalibConstants > ZeroCalibMap
Definition: NswCalibDbTimeChargeData.h:80
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:27
NswCalibDbTimeChargeData::CalibModule::layer_id
Identifier layer_id
Definition: NswCalibDbTimeChargeData.h:73
NswCalibDbTimeChargeData::CalibModule
Definition: NswCalibDbTimeChargeData.h:71
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
NswCalibDbTimeChargeData::identToModuleIdx
int identToModuleIdx(const Identifier &chan_id) const
Definition: NswCalibDbTimeChargeData.cxx:25
python.PyAthena.obj
obj
Definition: PyAthena.py:132
NswCalibDbTimeChargeData::getCalibForChannel
const CalibConstants * getCalibForChannel(const CalibDataType type, const Identifier &channelId) const
Retrieves the calibration constant for a particular readout channel.
Definition: NswCalibDbTimeChargeData.cxx:122
Muon::IMuonIdHelperSvc::issTgc
virtual bool issTgc(const Identifier &id) const =0
returns whether this is a sTGC Identifier or not
MuonCond::CalibTechType::MM
@ MM
Muon::IMuonIdHelperSvc::detElementHash
virtual IdentifierHash detElementHash(const Identifier &id) const =0
Returns the detector element hash associated to an Identifier.
Identifier
Definition: IdentifierFieldParser.cxx:14