ATLAS Offline Software
Loading...
Searching...
No Matches
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
43class AtlasDetectorID;
44namespace 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
60typedef 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
70typedef SiChargedDiodeMap::iterator SiChargedDiodeIterator;
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{
92 const SiChargedDiode* b) const
93 {
94 return a->diode().word() < b->diode().word();
95 }
96};
97
98
99
100typedef std::set<SiChargedDiode*,
104
105
106// Iterator typedef to make it easier
107typedef SiChargedDiodeOrderedSet::iterator SiChargedDiodeOrderedIterator;
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
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
211
216
217// access to the element
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
252
257
265
273
275 return m_chargedDiodes.empty();
276}
277
278template<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
298template <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
#define endmsg
STL-style allocator wrapper for ArenaPoolAllocator.
double charge(const T &p)
Definition AtlasPID.h:997
static Double_t a
std::set< SiChargedDiode *, SiChargedDiodeOrderedSetCompare, SG::ArenaPoolSTLAllocator< SiChargedDiode * > > SiChargedDiodeOrderedSet
SiChargedDiodeMap::iterator SiChargedDiodeIterator
std::unordered_map< InDetDD::SiCellId, SiChargedDiode, SiChargedDiodeHash, std::equal_to< InDetDD::SiCellId >, SG::ArenaPoolSTLAllocator< std::pair< const InDetDD::SiCellId, SiChargedDiode > > > SiChargedDiodeMap
SiChargedDiodeOrderedSet::iterator SiChargedDiodeOrderedIterator
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
This class provides an abstract interface to an Identifiable object.
This is a "hash" representation of an Identifier.
Base class for the detector design classes for ITk and HGTD.
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...
Identifier for the strip or pixel cell.
Definition SiCellId.h:29
bool isValid() const
Test if its in a valid state.
Definition SiCellId.h:136
Identifier for the strip or pixel readout cell.
Class to hold geometrical description of a solid state detector element.
STL-style allocator wrapper for ArenaPoolAllocator.
Identifier for the strip or pixel cell.
Definition SiCellId.h:29
@ extraNoise
Definition SiCharge.h:28
bool AlreadyHit(const InDetDD::SiCellId &siId)
virtual Identifier identify() const override final
SiChargedDiodeMap & chargedDiodes()
void setDetectorElement(const InDetDD::SolidStateDetectorElementBase *SiElement)
SiChargedDiodeOrderedIterator orderedEnd()
SiChargedDiodeOrderedIterator orderedBegin()
void emplace_charge(const InDetDD::SiCellId &diode, const T &charge)
SiChargedDiodeCollection & operator=(const SiChargedDiodeCollection &)
SiChargedDiodeIterator begin()
SiChargedDiodeCollection(const SiChargedDiodeCollection &)
const InDetDD::DetectorDesign & design() const
const InDetDD::SolidStateDetectorElementBase * m_sielement
SiChargedDiode * find(const InDetDD::SiCellId &siId)
virtual IdentifierHash identifyHash() const override final
const AtlasDetectorID * id_helper()
Identifier getId(const InDetDD::SiCellId &id) const
const InDetDD::SolidStateDetectorElementBase * element() const
void add(const InDetDD::SiCellId &diode, const T &charge)
SiChargedDiodeOrderedSet m_orderedChargedDiodes
void add(const SiCharge &charge)
static void noise(SiChargedDiode &chDiode, bool flag, bool mask=false)
Definition SiHelper.h:75
IMessageSvc * getMessageSvc(bool quiet=false)
Message Stream Member.
size_t operator()(const InDetDD::SiCellId &id) const
size_t operator()(const SiChargedDiode *a, const SiChargedDiode *b) const