ATLAS Offline Software
SiChargedDiodeCollection.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // SiChargedDiodeCollection.h
7 // Header file for class SiChargedDiodeCollection
9 // (c) ATLAS Detector software
11 // Class used to store the list of SiChargedDiode objects for one
12 // module (Pixel) or half module (SCT) and one event.
14 // Version 3.0 09/07/2001 David Calvet
15 // Davide Costanzo. Revisited version. 04-03-03
16 // - added a Identifier wafer_id to the private members
17 // - added a IdHelper to the private members
18 // - constructor modified to initialize wafer_id and IdHelper
19 // - replaced <list> with <map> and use the compact id of the
20 // SiChargedDiode to map them.
21 // - Inherit from Identifiable to enforce the identify() method
23 #ifndef SIDIGITIZATION_SICHARGEDDIODECOLLECTION_H
24 #define SIDIGITIZATION_SICHARGEDDIODECOLLECTION_H
25 
26 // Base class
28 
29 // Data member classes
30 #include <unordered_map>
32 #include "Identifier/Identifier.h"
34 
35 // Input/output classes
36 #include "InDetSimEvent/SiHit.h"
37 
38 // STL includes
39 #include <atomic>
40 #include <set>
41 #include <memory>
42 
43 class AtlasDetectorID;
44 namespace InDetDD{
45  class DetectorDesign;
46  class SiCellId;
47 }
48 
51 
53 {
54  size_t operator() (const InDetDD::SiCellId & id) const
55  {
56  return id.word();
57  }
58 };
59 
60 typedef std::unordered_map<InDetDD::SiCellId,
63  std::equal_to<InDetDD::SiCellId>,
65  std::pair<const InDetDD::SiCellId, SiChargedDiode> > >
67 
68 
69 // Iterator typedef to make it easier
71 
72 
73 
74 //
75 // A normal iteration over a SiChargedDiodeCollection will use
76 // the unordered_map, so the ordering is not defined. The observed
77 // ordering can (and does) change depending on the compiler and library
78 // version used. In some cases, though, we are sensitive to the
79 // order of iteration, for example in cases where we generate a random
80 // number for each element of the collection. To get results which
81 // are identical across compilers, we need to instead do the iteration
82 // in a well-defined order.
83 //
84 // This can be done using the methods sortedBegin and sortedEnd instead
85 // of begin and end. These work by maintaining a std::set of pointers
86 // to the diodes, sorted by the diode number. In order to avoid paying
87 // the penalty for maintaining the sorted set when we don't need to, we only
88 // start maintaining it the first time that it's requested.
90 {
91  size_t operator() (const SiChargedDiode* a,
92  const SiChargedDiode* b) const
93  {
94  return a->diode().word() < b->diode().word();
95  }
96 };
97 
98 
99 
100 typedef std::set<SiChargedDiode*,
104 
105 
106 // Iterator typedef to make it easier
108 
111  // Public methods:
113  public:
114 
115 
116  // Constructor with parameters:
117  // ref. to the detector element for this collection
119 
121 
122 
123  // Destructor:
125 
127  // Const methods:
129 
130  // detector element:
132 
133  // wafer identifier for this collection
134  virtual Identifier identify() const override final;
135  virtual IdentifierHash identifyHash() const override final;
136 
137  // id helper for this collection
139 
140  // detector design:
141  const InDetDD::DetectorDesign &design() const;
142 
143  // translation from SiReadoutCellId to Identifier
144  Identifier getId(const InDetDD::SiCellId& id) const
145  {
146  return (element()->identifierFromCellId(id));
147  }
148 
150  // Non-const methods:
152 
153  // clean up:
154  void clear();
155 
156  // read/write access to the collection:
158 
159  // Set the SiDetectorElement
161 
162  // Add a new SiCharge to the collection
163  // (add or merge in an existing SiChargedDiode):
164  // Diode which contains the new charge
165  // SiCharge to be added.
166  template <class T>
167  void add(const InDetDD::SiCellId & diode, const T &charge);
168 
169  template <class T>
170  void emplace_charge(const InDetDD::SiCellId & diode, const T &charge);
171 
172  bool AlreadyHit(const InDetDD::SiCellId & siId);
173  bool AlreadyHit(const Identifier & id);
178  bool empty() const; // Test if there is anything in the collection.
179 
180  // return a Charged diode given its CellId, NULL if doesn't exist
181  SiChargedDiode * find(const InDetDD::SiCellId & siId);
182  // return a Charged diode given its identifier, NULL if doesn't exist
184 
186  // Private methods:
188  private:
191  void order();
192 
194  // Private data:
196  private:
197  SiChargedDiodeMap m_chargedDiodes; // list of SiChargedDiodes
200 };
201 
203 // Inline methods:
205 
206 // Set the DetectorElement
208 {
209  m_sielement=SiElement;
210 }
211 
213 {
214  return m_chargedDiodes;
215 }
216 
217 // access to the element
219 {
220  return m_sielement;
221 }
222 
223 // access to the design
225 {
226  return m_sielement->design();
227 }
228 
229 // Get the Identifier of the collection
231 {
232  return m_sielement->identify();
233 }
234 
235 // Get the Identifier of the collection
237 {
238  return m_sielement->identifyHash();
239 }
240 
241 // Get the Id Helper
243 {
244  return m_sielement->getIdHelper();
245 }
246 
247 
249 {
250  return m_chargedDiodes.begin();
251 }
252 
254 {
255  return m_chargedDiodes.end();
256 }
257 
259 {
260  if (m_orderedChargedDiodes.empty() && !m_chargedDiodes.empty()) {
261  order();
262  }
263  return m_orderedChargedDiodes.begin();
264 }
265 
267 {
268  if (m_orderedChargedDiodes.empty() && !m_chargedDiodes.empty()) {
269  order();
270  }
271  return m_orderedChargedDiodes.end();
272 }
273 
274 inline bool SiChargedDiodeCollection::empty() const {
275  return m_chargedDiodes.empty();
276 }
277 
278 template<class T>
280 {
282  if (!roCell.isValid()) { // I don't think this can occur at this stage but cant hurt.
283  MsgStream log(Athena::getMessageSvc(),"SiChargedDiodeCollection");
284  log << MSG::FATAL << "Could not create SiReadoutCellId object !"<< endmsg;
285  }
286  // create a new charged diode
287  SiChargedDiode chargedDiode(diode,roCell);
288  // add the new charge to it
289  chargedDiode.add(charge);
290  if (charge.processType() == SiCharge::extraNoise) SiHelper::noise(chargedDiode,true);
291  // add the new charged diode to the charged diode collection
292  auto p = m_chargedDiodes.emplace(diode,chargedDiode);
293  if (!m_orderedChargedDiodes.empty()) {
294  m_orderedChargedDiodes.insert (&p.first->second);
295  }
296 }
297 
298 template <class T>
300  const T & charge)
301 {
302  // check the pointer is correct
303  if (!diode.isValid()) return;
304  SiChargedDiodeIterator the_diode = m_chargedDiodes.find(diode);
305  if(the_diode != m_chargedDiodes.end()) the_diode->second.add(charge);
306  else emplace_charge(diode, charge);
307 }
308 
309 #endif // SIDIGITIZATION_SICHARGEDDIODECOLLECTION_H
310 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
SolidStateDetectorElementBase.h
SiHelper.h
SiChargedDiode
Definition: SiChargedDiode.h:30
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SiChargedDiodeCollection::element
const InDetDD::SolidStateDetectorElementBase * element() const
Definition: SiChargedDiodeCollection.h:218
InDetDD::SolidStateDetectorElementBase
Definition: SolidStateDetectorElementBase.h:132
SiChargedDiodeOrderedSetCompare
Definition: SiChargedDiodeCollection.h:90
SiHit.h
SiHelper::noise
static void noise(SiChargedDiode &chDiode, bool flag, bool mask=false)
Definition: SiHelper.h:75
SiChargedDiodeCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
Definition: SiChargedDiodeCollection.h:236
SiChargedDiodeCollection::SiChargedDiodeCollection
SiChargedDiodeCollection()
Definition: SiChargedDiodeCollection.cxx:28
SiChargedDiodeHash::operator()
size_t operator()(const InDetDD::SiCellId &id) const
Definition: SiChargedDiodeCollection.h:54
InDetDD::SiCellId::isValid
bool isValid() const
Test if its in a valid state.
Definition: SiCellId.h:136
SiChargedDiodeCollection::end
SiChargedDiodeIterator end()
Definition: SiChargedDiodeCollection.h:253
SiChargedDiodeCollection::orderedEnd
SiChargedDiodeOrderedIterator orderedEnd()
Definition: SiChargedDiodeCollection.h:266
SiChargedDiodeCollection::SiChargedDiodeCollection
SiChargedDiodeCollection(const SiChargedDiodeCollection &)
SiChargedDiodeCollection::empty
bool empty() const
Definition: SiChargedDiodeCollection.h:274
Identifiable.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
SiCharge::extraNoise
@ extraNoise
Definition: SiCharge.h:28
SiChargedDiodeMap
std::unordered_map< InDetDD::SiCellId, SiChargedDiode, SiChargedDiodeHash, std::equal_to< InDetDD::SiCellId >, SG::ArenaPoolSTLAllocator< std::pair< const InDetDD::SiCellId, SiChargedDiode > > > SiChargedDiodeMap
Definition: SiChargedDiodeCollection.h:66
SiChargedDiodeCollection::begin
SiChargedDiodeIterator begin()
Definition: SiChargedDiodeCollection.h:248
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
InDetDD::SolidStateDetectorElementBase::identifyHash
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
InDetDD::SolidStateDetectorElementBase::getIdHelper
const AtlasDetectorID * getIdHelper() const
Returns the id helper (inline)
SiChargedDiode.h
SiChargedDiodeIterator
SiChargedDiodeMap::iterator SiChargedDiodeIterator
Definition: SiChargedDiodeCollection.h:70
SiChargedDiode::add
void add(const SiCharge &charge)
Definition: SiChargedDiode.cxx:29
SiChargedDiodeCollection::find
SiChargedDiode * find(const InDetDD::SiCellId &siId)
Definition: SiChargedDiodeCollection.cxx:63
InDetDD::DetectorDesign::readoutIdOfCell
virtual SiReadoutCellId readoutIdOfCell(const SiCellId &cellId) const =0
diode id -> readout id NB assignment of a SiReadoutCellId to a SiCellId is allowed so you are can pas...
ArenaPoolSTLAllocator.h
STL-style allocator wrapper for ArenaPoolAllocator.
SiChargedDiodeCollection::getId
Identifier getId(const InDetDD::SiCellId &id) const
Definition: SiChargedDiodeCollection.h:144
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SiChargedDiodeCollection::~SiChargedDiodeCollection
~SiChargedDiodeCollection()
SiChargedDiodeCollection
Definition: SiChargedDiodeCollection.h:109
SiChargedDiodeCollection::setDetectorElement
void setDetectorElement(const InDetDD::SolidStateDetectorElementBase *SiElement)
Definition: SiChargedDiodeCollection.h:207
SiChargedDiodeCollection::operator=
SiChargedDiodeCollection & operator=(const SiChargedDiodeCollection &)
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
InDetDD::SolidStateDetectorElementBase::design
virtual const DetectorDesign & design() const
access to the local description (inline):
InDetDD::DetectorDesign
Definition: DetectorDesign.h:57
SiChargedDiodeCollection::clear
void clear()
Definition: SiChargedDiodeCollection.cxx:45
SiChargedDiodeOrderedSet
std::set< SiChargedDiode *, SiChargedDiodeOrderedSetCompare, SG::ArenaPoolSTLAllocator< SiChargedDiode * > > SiChargedDiodeOrderedSet
Definition: SiChargedDiodeCollection.h:103
SiChargedDiodeCollection::m_chargedDiodes
SiChargedDiodeMap m_chargedDiodes
Definition: SiChargedDiodeCollection.h:197
SiChargedDiodeCollection::m_sielement
const InDetDD::SolidStateDetectorElementBase * m_sielement
Definition: SiChargedDiodeCollection.h:199
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
SiChargedDiodeCollection::id_helper
const AtlasDetectorID * id_helper()
Definition: SiChargedDiodeCollection.h:242
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
charge
double charge(const T &p)
Definition: AtlasPID.h:538
SiChargedDiodeHash
Definition: SiChargedDiodeCollection.h:53
SiChargedDiodeCollection::add
void add(const InDetDD::SiCellId &diode, const T &charge)
Definition: SiChargedDiodeCollection.h:299
InDetDD::SiCellId
Definition: SiCellId.h:29
SiChargedDiodeCollection::chargedDiodes
SiChargedDiodeMap & chargedDiodes()
Definition: SiChargedDiodeCollection.h:212
a
TList * a
Definition: liststreamerinfos.cxx:10
Identifiable
This class provides an abstract interface to an Identifiable object.
Definition: Identifiable.h:27
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
SG::ArenaPoolSTLAllocator
STL-style allocator wrapper for ArenaPoolAllocator.
Definition: ArenaPoolSTLAllocator.h:106
SiChargedDiodeOrderedSetCompare::operator()
size_t operator()(const SiChargedDiode *a, const SiChargedDiode *b) const
Definition: SiChargedDiodeCollection.h:91
SiChargedDiodeCollection::m_orderedChargedDiodes
SiChargedDiodeOrderedSet m_orderedChargedDiodes
Definition: SiChargedDiodeCollection.h:198
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
SiChargedDiodeOrderedIterator
SiChargedDiodeOrderedSet::iterator SiChargedDiodeOrderedIterator
Definition: SiChargedDiodeCollection.h:107
SiChargedDiodeCollection::emplace_charge
void emplace_charge(const InDetDD::SiCellId &diode, const T &charge)
Definition: SiChargedDiodeCollection.h:279
SiChargedDiodeCollection::orderedBegin
SiChargedDiodeOrderedIterator orderedBegin()
Definition: SiChargedDiodeCollection.h:258
InDetDD::SiReadoutCellId
Definition: SiReadoutCellId.h:42
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
SiChargedDiodeCollection::AlreadyHit
bool AlreadyHit(const InDetDD::SiCellId &siId)
Definition: SiChargedDiodeCollection.cxx:53
InDetDD::SolidStateDetectorElementBase::identify
virtual Identifier identify() const override final
identifier of this detector element (inline)
AtlasDetectorID
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Definition: AtlasDetectorID.h:57
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
SiChargedDiodeCollection::design
const InDetDD::DetectorDesign & design() const
Definition: SiChargedDiodeCollection.h:224
SiChargedDiodeCollection::identify
virtual Identifier identify() const override final
Definition: SiChargedDiodeCollection.h:230
SiChargedDiodeCollection::order
void order()
Definition: SiChargedDiodeCollection.cxx:78
Identifier
Definition: IdentifierFieldParser.cxx:14