ATLAS Offline Software
EMBPresamplerHVManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "GeoModelKernel/CellBinning.h"
8 #include "GeoModelKernel/CellPartitioning.h"
9 #include <cmath>
10 #include <vector>
11 #include <fstream>
12 #include "EMBPresamplerHVPayload.h"
13 
14 #include "StoreGate/StoreGateSvc.h"
15 #include "GaudiKernel/ISvcLocator.h"
16 #include "GaudiKernel/IToolSvc.h"
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/ServiceHandle.h"
19 
22 
25 
26 #ifndef SIMULATIONBASE
27 #ifndef GENERATIONBASE
29 #endif
30 #endif
31 
33 
34 #include <atomic>
35 
36 
38 public:
40  CellPartitioning etaPartitioning;
41  for (unsigned int i= 0; i<4; i++) etaPartitioning.addValue(i*0.4);
42  etaPartitioning.addValue(1.525);
43  descriptor = std::make_unique<EMBPresamplerHVDescriptor>(etaPartitioning,CellBinning(0.0, 2*M_PI, 32));
44 
45  for(int iSide=0; iSide<2; ++iSide) {
46  for(int iEta=0; iEta<4; ++iEta) {
47  for(int iPhi=0; iPhi<32; ++iPhi) {
48  moduleArray[iSide][iEta][iPhi] = std::make_unique<EMBPresamplerHVModule>(manager, iSide, iEta,iPhi);
49  }
50  }
51  }
52 
53  ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "HECHVManager");
54  if (StatusCode::SUCCESS!=detStore->retrieve(elecId, "LArElectrodeID")) {
55  throw std::runtime_error("EMBPresamplerHVManager failed to retrieve LArElectrodeID");
56  }
57 
58  if (StatusCode::SUCCESS!=detStore->retrieve(hvId,"LArHVLineID")) {
59  throw std::runtime_error("EMBPresamplerHVManager failed to retrieve LArHVLineID");
60  }
61  }
62  ~Clockwork() = default;
63  std::unique_ptr<EMBPresamplerHVDescriptor> descriptor;
64  std::unique_ptr<const EMBPresamplerHVModule> moduleArray[2][4][32];
65  const LArElectrodeID* elecId = nullptr;
66  const LArHVLineID* hvId = nullptr;
67 };
68 
69 
71 {
72 public:
73  std::vector<EMBPresamplerHVPayload> m_payloadArray;
74 };
75 
76 
78 
79 
81  (std::unique_ptr<Payload> payload)
82  : m_payload (std::move (payload))
83 {
84 }
85 
86 
89  if (this != &other) {
90  m_payload = std::move (other.m_payload);
91  }
92  return *this;
93 }
94 
95 
97 = default;
98 
99 
101  (const EMBPresamplerHVModule& module, const int& iGap) const
102 {
103  return voltage (module, iGap) > INVALID;
104 }
105 
106 
108  (const EMBPresamplerHVModule& module, const int& iGap) const
109 {
110  return m_payload->m_payloadArray[index(module)].voltage[iGap];
111 }
112 
113 
115  (const EMBPresamplerHVModule& module, const int& iGap) const
116 {
117  return m_payload->m_payloadArray[index(module)].current[iGap];
118 }
119 
120 
122  (const EMBPresamplerHVModule& module, const int& iGap) const
123 {
124  return m_payload->m_payloadArray[index(module)].hvLineNo[iGap];
125 }
126 
127 
130 {
131  unsigned int sideIndex = module.getSideIndex();
132  unsigned int phiIndex = module.getPhiIndex();
133  unsigned int etaIndex = module.getEtaIndex();
134  unsigned int index = 128*sideIndex+32*etaIndex+phiIndex;
135  return index;
136 }
137 
138 
140  : m_c (std::make_unique<Clockwork> (this))
141 {
142 }
143 
145 = default;
146 
148 {
149  return m_c->descriptor.get();
150 }
151 
153 {
154  return m_c->descriptor->getPhiBinning().getFirstDivisionNumber();
155 }
156 
158 {
159  return m_c->descriptor->getPhiBinning().getFirstDivisionNumber() + m_c->descriptor->getPhiBinning().getNumDivisions();
160 }
161 
163 {
164  return m_c->descriptor->getEtaPartitioning().getFirstDivisionNumber();
165 }
166 
168 {
169  return m_c->descriptor->getEtaPartitioning().getFirstDivisionNumber() + m_c->descriptor->getEtaPartitioning().getNumDivisions();
170 }
171 
172 const EMBPresamplerHVModule& EMBPresamplerHVManager::getHVModule(unsigned int iSide, unsigned int iEta,unsigned int iPhi) const
173 {
174  return *(m_c->moduleArray[iSide][iEta][iPhi]);
175 }
176 
178 {
179  return 0;
180 }
181 
183 {
184  return 2;
185 }
186 
187 
190  const std::vector<const CondAttrListCollection*>& attrLists) const
191 {
192  auto payload = std::make_unique<EMBPresamplerHVData::Payload>();
193  payload->m_payloadArray.reserve(2*4*32);
194 
195  for (int i=0;i<256;i++) {
196  payload->m_payloadArray[i].voltage[0] = EMBPresamplerHVData::INVALID;
197  payload->m_payloadArray[i].voltage[1] = EMBPresamplerHVData::INVALID;
198  }
199 
200  for (const CondAttrListCollection* atrlistcol : attrLists) {
201 
202  for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) {
203 
204  // Construct HWIdentifier
205  // 1. decode COOL Channel ID
206  unsigned int chanID = (*citr).first;
207  int cannode = chanID/1000;
208  int line = chanID%1000;
209 
210  // 2. Construct the identifier
211  HWIdentifier id = m_c->hvId->HVLineId(1,1,cannode,line);
212 
213  std::vector<HWIdentifier> electrodeIdVec = idfunc(id);
214 
215 
216  for(size_t i=0;i<electrodeIdVec.size();i++)
217  {
218  HWIdentifier& elecHWID = electrodeIdVec[i];
219  int detector = m_c->elecId->detector(elecHWID);
220  if (detector==1) {
221 
222 // side in standard offline 0 for z<0 (C) 1 for z>0 (A)
223 // in electrode numbering, this is the opposite (0 for A and 1 for C)
224  unsigned int sideIndex=1-m_c->elecId->zside(elecHWID);
225 // eta index, no trouble
226  unsigned int etaIndex=m_c->elecId->hv_eta(elecHWID)-1;
227 // phi index
228 // offline 0 to 2pi in 2pi/32 bins (2 presampler cells per phi_HV)
229 // module from elecID : 0 to 31
230 // phi 0 pi 2pi
231 // M0 M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12 M13 M14 M15 M0
232 // FT 0 -1 0 -1 0 -1
233 // Module 0 1 2 3 4 5 6 7 9 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 39 30 31
234 // offline phi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
235  unsigned int phiIndex;
236  if (sideIndex==1) {
237  phiIndex=m_c->elecId->module(elecHWID);
238  }
239 // module numbering on the C side 0 around phi=pi, running backwards
240 // phi 0 pi 2pi
241 // P8 P7 P6 P5 P4 P3 P2 P1 P0 P15 P14 P13 P12 P11 P10 P9 P8
242 // FT -1 0 0 -1 0 -1 0
243 // Module 15 14 9 8 7 6 5 4 3 2 1 0 31 30 29 38 27 26 25 24 23 22 21 20 19 18 17 16
244 // offline phi 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
245  else {
246  int imodule=m_c->elecId->module(elecHWID);
247  if (imodule<16) phiIndex = 15 - imodule;
248  else phiIndex = 47 - imodule;
249  }
250 
251  unsigned int index = 128*sideIndex+32*etaIndex+phiIndex;
252 
253  unsigned int gapIndex=m_c->elecId->gap(elecHWID);
254  if (sideIndex==0) gapIndex=1-gapIndex;
255 
256 
257  float voltage = EMBPresamplerHVData::INVALID;
258  if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>();
259  float current = 0.;
260  if (!((*citr).second)["R_IMEAS"].isNull()) current = ((*citr).second)["R_IMEAS"].data<float>();
261 
262  payload->m_payloadArray[index].voltage[gapIndex]=voltage;
263  payload->m_payloadArray[index].current[gapIndex]=current;
264  payload->m_payloadArray[index].hvLineNo[gapIndex]=chanID;
265  }
266  }
267  }
268  }
269 
270  return {std::move (payload)};
271 }
272 
273 #ifndef SIMULATIONBASE
274 #ifndef GENERATIONBASE
277  const std::vector<const CondAttrListCollection*>& attrLists) const
278 {
279  auto idfunc = [&] (HWIdentifier id) { return hvIdMapping.getLArElectrodeIDvec(id); };
280  return getData (idfunc, attrLists);
281 }
282 
283 
285  , int gap
286  , const LArHVIdMapping* hvIdMapping
287  , HWIdentifier *hvlId ) const {
288 
289  int sideIndex = module.getSideIndex();
290  int phiIndex = module.getPhiIndex();
291  int etaIndex = module.getEtaIndex();
292 
293  // ________________________ Construct ElectrodeID ________________________________
294  int id_detector = 1;
295  int id_zside = 1 - sideIndex;
296  int id_module{0};
297  if(sideIndex==1){
298  id_module = phiIndex;
299  }
300  else {
301  if(phiIndex<16) {
302  id_module = 15 - phiIndex;
303  }
304  else {
305  id_module = 47 - phiIndex;
306  }
307  }
308  int id_hv_phi{0};
309  int id_hv_eta = etaIndex + 1;
310  int id_gap = sideIndex==0 ? 1-gap : gap;
311  int id_electrode{0};
312 
313  HWIdentifier elecHWID = m_c->elecId->ElectrodeId(id_detector
314  ,id_zside
315  ,id_module
316  ,id_hv_phi
317  ,id_hv_eta
318  ,id_gap
319  ,id_electrode);
320  // ________________________ ________________________________
321 
322  // Get LArHVLineID corresponding to a given LArElectrodeId
323  HWIdentifier id = hvIdMapping->getLArHVLineID(elecHWID);
324 
325  if(hvlId) *hvlId = id;
326 
327  // Extract HV Line No
328  return m_c->hvId->can_node(id)*1000 + m_c->hvId->hv_line(id);
329 }
330 #endif
331 #endif
EMBPresamplerHVManager::Clockwork::moduleArray
std::unique_ptr< const EMBPresamplerHVModule > moduleArray[2][4][32]
Definition: EMBPresamplerHVManager.cxx:64
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
EMBPresamplerHVDescriptor.h
EMBPresamplerHVManager::EMBPresamplerHVManager
EMBPresamplerHVManager()
Definition: EMBPresamplerHVManager.cxx:139
EMBPresamplerHVManager::endSideIndex
static unsigned int endSideIndex()
Definition: EMBPresamplerHVManager.cxx:182
EMBPresamplerHVManager::Clockwork
Definition: EMBPresamplerHVManager.cxx:37
checkFileSG.line
line
Definition: checkFileSG.py:75
EMBPresamplerHVPayload.h
EMBPresamplerHVManager::EMBPresamplerHVData::operator=
EMBPresamplerHVData & operator=(EMBPresamplerHVData &&other) noexcept
Definition: EMBPresamplerHVManager.cxx:88
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
LArElectrodeID
Helper for the Liquid Argon Calorimeter cell at the electrode level.
Definition: LArElectrodeID.h:101
index
Definition: index.py:1
TRTCalib_cfilter.detector
detector
Definition: TRTCalib_cfilter.py:241
EMBPresamplerHVManager.h
EMBPresamplerHVManager::Clockwork::elecId
const LArElectrodeID * elecId
Definition: EMBPresamplerHVManager.cxx:65
M_PI
#define M_PI
Definition: ActiveFraction.h:11
EMBPresamplerHVManager::m_c
std::unique_ptr< const Clockwork > m_c
Definition: EMBPresamplerHVManager.h:97
EMBPresamplerHVDescriptor
Definition: EMBPresamplerHVDescriptor.h:12
EMBPresamplerHVManager::endPhiIndex
unsigned int endPhiIndex() const
Definition: EMBPresamplerHVManager.cxx:157
LArHVIdMapping::getLArHVLineID
const HWIdentifier getLArHVLineID(HWIdentifier &electrodeId) const
Return the LArHVLineID corresponding to a given LArElectrodeId.
Definition: LArHVIdMapping.cxx:22
EMBPresamplerHVManager::idfunc_t
std::function< std::vector< HWIdentifier >(HWIdentifier)> idfunc_t
Definition: EMBPresamplerHVManager.h:88
EMBPresamplerHVManager::EMBPresamplerHVData::Payload
Definition: EMBPresamplerHVManager.cxx:71
LArHVLineID.h
HWIdentifier
Definition: HWIdentifier.h:13
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
CxxUtils::INVALID
@ INVALID
Definition: CachedValue.h:28
AthenaAttributeList.h
CaloSwCorrections.gap
def gap(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:212
EMBPresamplerHVManager::EMBPresamplerHVData::Payload::m_payloadArray
std::vector< EMBPresamplerHVPayload > m_payloadArray
Definition: EMBPresamplerHVManager.cxx:73
EMBPresamplerHVManager
This class provides direct access to information on the HV electrodes within the barrels....
Definition: EMBPresamplerHVManager.h:37
EMBPresamplerHVManager::beginPhiIndex
unsigned int beginPhiIndex() const
Definition: EMBPresamplerHVManager.cxx:152
python.PyAthena.module
module
Definition: PyAthena.py:131
EMBPresamplerHVManager::EMBPresamplerHVData::EMBPresamplerHVData
EMBPresamplerHVData()
EMBPresamplerHVManager::EMBPresamplerHVData
Definition: EMBPresamplerHVManager.h:40
EMBPresamplerHVManager::EMBPresamplerHVData::current
double current(const EMBPresamplerHVModule &module, const int &iGap) const
Definition: EMBPresamplerHVManager.cxx:115
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArHVIdMapping.h
EMBPresamplerHVManager::Clockwork::~Clockwork
~Clockwork()=default
EMBPresamplerHVManager::EMBPresamplerHVData::hvOn
bool hvOn(const EMBPresamplerHVModule &module, const int &iGap) const
Definition: EMBPresamplerHVManager.cxx:101
EMBPresamplerHVManager::endEtaIndex
unsigned int endEtaIndex() const
Definition: EMBPresamplerHVManager.cxx:167
EMBPresamplerHVManager::getData
EMBPresamplerHVData getData(const LArHVIdMapping &hvIdMapping, const std::vector< const CondAttrListCollection * > &attrLists) const
Definition: EMBPresamplerHVManager.cxx:276
EMBPresamplerHVManager::getDescriptor
const EMBPresamplerHVDescriptor * getDescriptor() const
Definition: EMBPresamplerHVManager.cxx:147
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
HWIdentifier.h
EMBPresamplerHVManager::EMBPresamplerHVData::voltage
double voltage(const EMBPresamplerHVModule &module, const int &iGap) const
Definition: EMBPresamplerHVManager.cxx:108
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
EMBPresamplerHVManager::Clockwork::descriptor
std::unique_ptr< EMBPresamplerHVDescriptor > descriptor
Definition: EMBPresamplerHVManager.cxx:63
EMBPresamplerHVManager::Clockwork::hvId
const LArHVLineID * hvId
Definition: EMBPresamplerHVManager.cxx:66
EMBPresamplerHVManager::EMBPresamplerHVData::hvLineNo
int hvLineNo(const EMBPresamplerHVModule &module, const int &iGap) const
Definition: EMBPresamplerHVManager.cxx:122
EMBPresamplerHVManager::beginEtaIndex
unsigned int beginEtaIndex() const
Definition: EMBPresamplerHVManager.cxx:162
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
EMBPresamplerHVManager::beginSideIndex
static unsigned int beginSideIndex()
Definition: EMBPresamplerHVManager.cxx:177
Trk::iPhi
@ iPhi
Definition: ParamDefs.h:47
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
DeMoScan.index
string index
Definition: DeMoScan.py:364
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
LArHVIdMapping
Definition: LArHVIdMapping.h:21
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
EMBPresamplerHVManager::EMBPresamplerHVData::INVALID
static constexpr double INVALID
Definition: EMBPresamplerHVManager.h:42
EMBPresamplerHVManager::EMBPresamplerHVData::index
static int index(const EMBPresamplerHVModule &module)
Definition: EMBPresamplerHVManager.cxx:129
python.Logging.manager
manager
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/Logging.py:92
LArElectrodeID.h
EMBPresamplerHVManager::~EMBPresamplerHVManager
~EMBPresamplerHVManager()
EMBPresamplerHVManager::EMBPresamplerHVData::~EMBPresamplerHVData
~EMBPresamplerHVData()
EMBPresamplerHVManager::getHVModule
const EMBPresamplerHVModule & getHVModule(unsigned int iSide, unsigned int iEta, unsigned int iPhi) const
Definition: EMBPresamplerHVManager.cxx:172
EMBPresamplerHVManager::hvLineNo
int hvLineNo(const EMBPresamplerHVModule &module, int gap, const LArHVIdMapping *hvIdMapping, HWIdentifier *hvlId=nullptr) const
Definition: EMBPresamplerHVManager.cxx:284
xAOD::iEta
setScale setgFexType iEta
Definition: gFexJetRoI_v1.cxx:77
StoreGateSvc.h
LArHVIdMapping::getLArElectrodeIDvec
const std::vector< HWIdentifier > & getLArElectrodeIDvec(HWIdentifier &hvlineId) const
Return a vector of LArElectrodeID corresponding to a given LArHVLineID.
Definition: LArHVIdMapping.cxx:84
EMBPresamplerHVModule
Describes one HV Module within the EMB Presampler.
Definition: EMBPresamplerHVModule.h:22
ServiceHandle< StoreGateSvc >
EMBPresamplerHVManager::Clockwork::Clockwork
Clockwork(const EMBPresamplerHVManager *manager)
Definition: EMBPresamplerHVManager.cxx:39
LArHVLineID
Helper for the Liquid Argon Calorimeter High-Voltage identifiers.
Definition: LArHVLineID.h:48