ATLAS Offline Software
NswCalibDbTimeChargeData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "Identifier/Identifier.h"
8 #include "GeoModelHelpers/throwExcept.h"
9 
10 std::ostream& operator<<(std::ostream& ostr, const NswCalibDbTimeChargeData::CalibConstants& obj) {
11  ostr<<"slope: "<<std::setprecision(15)<<obj.slope;//<<" pm "<<std::setprecision(15)<<obj.slopeError;
12  ostr<<" intercept: "<<std::setprecision(15)<<obj.intercept;//<<" pm "<<std::setprecision(15)<<obj.interceptError;
13  return ostr;
14 }
15 
16 // general functions ---------------------------------
18  AthMessaging{"NswCalibDbTimeChargeData"},
19  m_idHelperSvc{idHelperSvc} {
20  m_pdo_data.resize(m_nStgcElements + m_nMmElements);
21  m_tdo_data.resize(m_nStgcElements + m_nMmElements);
22 }
23 
26  if (m_idHelperSvc->isMM(chan_id)) {
27  const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
28  return 4 * static_cast<int>(hash) + idHelper.gasGap(chan_id) -1;
29  }
30  const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
31  return m_nMmElements + static_cast<int>(hash)*12 +
32  3* (idHelper.gasGap(chan_id) - 1) + idHelper.channelType(chan_id);
33  }
34 
35 // setting functions ---------------------------------
36 
37 // setData
38 void
40  const Identifier& chnlId,
43 
44 
45  const int array_idx = identToModuleIdx(chnlId);
46  ATH_MSG_VERBOSE("Set "<<(type == CalibDataType::PDO ? "PDO" : "TDO")<<" calibration constants for channel "
47  <<m_idHelperSvc->toString(chnlId)<<", slot: "<< array_idx<<", "<<constants);
48  CalibModule& calib_mod = calibMap.at(array_idx);
49  const unsigned int channel = (m_idHelperSvc->isMM(chnlId) ?
50  m_idHelperSvc->mmIdHelper().channel(chnlId) :
51  m_idHelperSvc->stgcIdHelper().channel(chnlId)) -1;
52  if (calib_mod.channels.empty()) {
53  calib_mod.layer_id = m_idHelperSvc->layerId(chnlId);
54  }
55  if (calib_mod.channels.size() <= channel) calib_mod.channels.resize(channel +1);
56  if (calib_mod.channels[channel]) {
57  THROW_EXCEPTION("setData() -- Cannot overwrite channel "<<m_idHelperSvc->toString(chnlId)
58  <<"Layer ID: "<<m_idHelperSvc->toString(calib_mod.layer_id)<<
59  " "<<(*calib_mod.channels[channel] ));
60  return;
61  }
62  calib_mod.channels[channel] = std::make_unique<CalibConstants>(std::move(constants));
63 }
64 
65 // setZeroData
66 void
68  ZeroCalibMap& calibMap = m_zero[tech];
69  calibMap.insert(std::make_pair(type, std::move(constants)));
70 }
71 
72 
73 
74 // retrieval functions -------------------------------
75 
76 // getChannelIds
77 std::vector<Identifier>
78 NswCalibDbTimeChargeData::getChannelIds(const CalibDataType type, const std::string& tech, const std::string& side) const {
79  std::vector<Identifier> chnls;
81  chnls.reserve(calibMap.size());
82  for (const CalibModule& module : calibMap) {
84  if (module.channels.empty()) continue;
85  if (side == "A" && m_idHelperSvc->stationEta(module.layer_id) < 0) continue;
86  if (side == "C" && m_idHelperSvc->stationEta(module.layer_id) > 0) continue;
87 
88  if (m_idHelperSvc->isMM(module.layer_id)) {
89  if (tech == "STGC") continue;
90  const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
91  for (unsigned int chn = 1 ; chn <= module.channels.size() ; ++chn) {
92  if (!module.channels[chn -1]) continue;
93 
94  chnls.push_back(idHelper.channelID(module.layer_id,
95  idHelper.multilayer(module.layer_id),
96  idHelper.gasGap(module.layer_id), chn ));
97  }
98  } else if (m_idHelperSvc->issTgc(module.layer_id)) {
99  if (tech == "MM") break;
100  const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
101  for (unsigned int chn = 1 ; chn <= module.channels.size() ; ++chn) {
102  if (!module.channels[chn -1]) continue;
103  chnls.push_back(idHelper.channelID(module.layer_id,
104  idHelper.multilayer(module.layer_id),
105  idHelper.gasGap(module.layer_id),
106  idHelper.channelType(module.layer_id), chn ));
107  }
108  }
109  }
110 
111  return chnls;
112 }
114  const ChannelCalibMap& calibMap = type == CalibDataType::PDO ? m_pdo_data : m_tdo_data;
115  const int array_idx = identToModuleIdx(channelId);
116  const unsigned int channel = (m_idHelperSvc->isMM(channelId) ?
119  if (calibMap.at(array_idx).channels.size() > channel && calibMap[array_idx].channels[channel]) {
120  return calibMap[array_idx].channels[channel].get();
121  }
122  // search for data for channel zero
124  return getZeroCalibChannel(type, tech);
125 
126 }
128  std::map<MuonCond::CalibTechType, ZeroCalibMap>::const_iterator itr = m_zero.find(tech);
129  if(itr != m_zero.end()) {
130  const ZeroCalibMap& zeroMap = itr->second;
131  ZeroCalibMap::const_iterator type_itr = zeroMap.find(type);
132  if(type_itr != zeroMap.end()) return &type_itr->second;
133  }
134  return nullptr;
135 }
136 
137 
NswCalibDbTimeChargeData::setData
void setData(CalibDataType type, const Identifier &chnlId, CalibConstants constants)
Definition: NswCalibDbTimeChargeData.cxx:39
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:28
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
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:58
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
THROW_EXCEPTION
#define THROW_EXCEPTION(MSG)
Definition: MMReadoutElement.cxx:48
NswCalibDbTimeChargeData::CalibDataType
CalibDataType
Definition: NswCalibDbTimeChargeData.h:22
Muon::IMuonIdHelperSvc::mmIdHelper
virtual const MmIdHelper & mmIdHelper() const =0
access to CscIdHelper
TRT::Hit::side
@ side
Definition: HitInfo.h:83
NswCalibDbTimeChargeData::setZero
void setZero(CalibDataType type, MuonCond::CalibTechType tech, CalibConstants constants)
Definition: NswCalibDbTimeChargeData.cxx:67
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:127
python.PyAthena.module
module
Definition: PyAthena.py:134
NswCalibDbTimeChargeData::m_tdo_data
ChannelCalibMap m_tdo_data
Definition: NswCalibDbTimeChargeData.h:72
sTgcIdHelper::channel
int channel(const Identifier &id) const override
Definition: sTgcIdHelper.cxx:1027
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
Muon::IMuonIdHelperSvc::layerId
virtual Identifier layerId(const Identifier &id) const =0
create a layer ID, returns tube id for the MDTs
NswCalibDbTimeChargeData::CalibModule::channels
std::vector< std::unique_ptr< CalibConstants > > channels
Definition: NswCalibDbTimeChargeData.h:66
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
NswCalibDbTimeChargeData::NswCalibDbTimeChargeData
NswCalibDbTimeChargeData(const Muon::IMuonIdHelperSvc *idHelperSvc)
Definition: NswCalibDbTimeChargeData.cxx:17
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
NswCalibDbTimeChargeData::m_zero
std::map< MuonCond::CalibTechType, ZeroCalibMap > m_zero
Definition: NswCalibDbTimeChargeData.h:75
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:70
NswCalibDbTimeChargeData::m_idHelperSvc
const Muon::IMuonIdHelperSvc * m_idHelperSvc
Definition: NswCalibDbTimeChargeData.h:56
sTgcIdHelper
Definition: sTgcIdHelper.h:55
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:78
operator<<
std::ostream & operator<<(std::ostream &ostr, const NswCalibDbTimeChargeData::CalibConstants &obj)
Definition: NswCalibDbTimeChargeData.cxx:10
MmIdHelper::channel
int channel(const Identifier &id) const override
Definition: MmIdHelper.cxx:800
MmIdHelper
Definition: MmIdHelper.h:54
MmIdHelper::gasGap
int gasGap(const Identifier &id) const override
get the hashes
Definition: MmIdHelper.cxx:798
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
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:71
MuonCond::CalibTechType
CalibTechType
Definition: MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/Defs.h:37
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
NswCalibDbTimeChargeData::ZeroCalibMap
std::map< CalibDataType, CalibConstants > ZeroCalibMap
Definition: NswCalibDbTimeChargeData.h:74
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:26
NswCalibDbTimeChargeData::CalibModule::layer_id
Identifier layer_id
Definition: NswCalibDbTimeChargeData.h:67
NswCalibDbTimeChargeData::CalibModule
Definition: NswCalibDbTimeChargeData.h:65
IdentifierHash
Definition: IdentifierHash.h:38
NswCalibDbTimeChargeData::identToModuleIdx
int identToModuleIdx(const Identifier &chan_id) const
Definition: NswCalibDbTimeChargeData.cxx:24
python.PyAthena.obj
obj
Definition: PyAthena.py:135
NswCalibDbTimeChargeData::getCalibForChannel
const CalibConstants * getCalibForChannel(const CalibDataType type, const Identifier &channelId) const
Retrieves the calibration constant for a particular readout channel.
Definition: NswCalibDbTimeChargeData.cxx:113
Muon::IMuonIdHelperSvc::issTgc
virtual bool issTgc(const Identifier &id) const =0
returns whether this is a sTGC Identifier or not
IMuonIdHelperSvc.h
MuonCond::CalibTechType::MM
@ MM
Muon::IMuonIdHelperSvc::detElementHash
virtual IdentifierHash detElementHash(const Identifier &id) const =0
Returns the detector element hash associated to an Identifier.