ATLAS Offline Software
CaloRings_v1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // standard library includes:
6 #include <iostream>
7 #include <stdexcept>
8 #include <sstream>
9 
10 // EDM include(s):
12 
13 // Local include(s):
16 
17 namespace xAOD {
18 
20  accRingSetLinks( "ringSetLinks" );
22  constAccRingSetLinks( "ringSetLinks" );
23 
26 //==============================================================================
29  ringSetLinks,
30  setRingSetLinks)
31 
32 //==============================================================================
33 unsigned CaloRings_v1::nRingSets() const
34 {
35  return (constAccRingSetLinks.isAvailable( *this ) )?
36  (constAccRingSetLinks( *this ).size()):
37  (0);
38 }
39 
40 
41 //==============================================================================
43 {
44  accRingSetLinks( *this ).push_back(rsEL);
45 }
46 //==============================================================================
48 {
49  accRingSetLinks( *this ).clear();
50 }
51 
52 //==============================================================================
54 {
55  return (accRingSetLinks.isAvailable( *this ) )?
56  (accRingSetLinks( *this ).begin()):
58 }
59 
60 //==============================================================================
62 {
63  return (accRingSetLinks.isAvailable( *this ) )?
64  (accRingSetLinks( *this ).end()):
66 }
67 
68 //==============================================================================
69 RingSetLinks::const_iterator CaloRings_v1::begin() const
70 {
71  return (constAccRingSetLinks.isAvailable( *this ) )?
72  (constAccRingSetLinks( *this ).begin()):
73  (RingSetLinks::const_iterator());
74 }
75 
76 //==============================================================================
77 RingSetLinks::const_iterator CaloRings_v1::end() const
78 {
79  return (constAccRingSetLinks.isAvailable( *this ) )?
80  (constAccRingSetLinks( *this ).end()):
81  (RingSetLinks::const_iterator());
82 }
83 
84 //==============================================================================
85 const RingSet *CaloRings_v1::at(const unsigned int i) const
86 {
87  if ( i > nRingSets() )
88  return nullptr;
90  constAccRingSetLinks( *this ).at(i);
91  if ( !rsEL.isValid() ) {
92  return nullptr;
93  }
94  return *rsEL;
95 }
96 
97 //==============================================================================
98 const RingSet *CaloRings_v1::operator[](const unsigned int i) const
99 {
100  if ( i > nRingSets() )
101  return nullptr;
102  const ElementLink<RingSetContainer_v1> &rsEL =
103  constAccRingSetLinks( *this )[i];
104  if ( !rsEL.isValid() ) {
105  return nullptr;
106  }
107  return *rsEL;
108 }
110 
113 //==============================================================================
114 float CaloRings_v1::ringAt(const unsigned rsIdx, const unsigned ringIdx) const
115 {
116  const RingSet *rs = this->at(rsIdx);
117  if (!rs) {
118  throw std::runtime_error("The element link is invalid.");
119  }
120  return rs->at(ringIdx);
121 }
122 
123 //==============================================================================
124 float CaloRings_v1::ringAt(const unsigned ringIdx) const
125 {
126  unsigned ringStripPartialSize = 0;
127  for (unsigned rsELIdx = 0; rsELIdx < this->nRingSets(); ++rsELIdx){
128  const RingSet *rs = this->at(rsELIdx);
129  if ( !rs ) {
130  throw std::runtime_error("There is an invalid element link.");
131  }
132  unsigned cRsSize = rs->size();
133  if ( ringStripPartialSize + cRsSize > ringIdx ) {
134  // Found the RingSet that contains the nth ring, return it using the
135  // amount that lacks from the previous RingSet to give the nth Ring:
136  return rs->at( ringIdx - ( ringStripPartialSize ) );
137  }
138  ringStripPartialSize += cRsSize;
139  }
140  // If we reached here, then the requested size is greater than the total ring
141  // strip
142  std::stringstream ss;
143  ss << "Requested ring at index: \""
144  << ringIdx << "\", but total rings size is: "
145  << ringStripPartialSize;
146  throw std::overflow_error( ss.str() );
147 }
149 
152 //==============================================================================
154  std::vector<float> &ringStrip,
155  const unsigned rsIdxStart,
156  const unsigned rsIdxEnd) const
157 {
158 
159  // Check if arguments are within range:
160  checkRingSetIndexWithinRange(rsIdxStart);
162 
163  // Prepare RingStrip vector to receive ring strip information:
164  ringStrip.clear();
165 
166  for ( unsigned idx = rsIdxStart; idx <= rsIdxEnd ; ++idx ) {
167  const RingSet *rs = this->at( idx );
168  if ( !rs ) {
169  throw std::runtime_error("Found invalid ElementLink");
170  }
171  rs->copyTo(ringStrip);
172  }
173 }
174 
175 //==============================================================================
177  std::vector<float> &ringStrip,
178  const RingSetConf_v1::RawConfCollection &clRingsRawConfCol,
179  const Ringer::CalJointLayer layerTypeStart,
180  const Ringer::CalJointLayer layerTypeEnd) const
181 {
182 
183  if ( layerTypeEnd < layerTypeStart ) {
184  throw std::invalid_argument( std::string(
185  "Input layerTypeStart greater than layerTypeEnd") );
186  }
187 
188  unsigned nRingSets = this->nRingSets();
189 
190  if ( nRingSets && clRingsRawConfCol.size() != nRingSets ) {
191  throw std::invalid_argument( std::string(
192  "The configuration struct seems not to be valid."));
193  }
194 
195  // Prepare RingStrip vector to receive Rings energy vectorized representation
196  ringStrip.clear();
197 
198  bool foundStartLayer = false;
199 
200  for ( unsigned rsIdx = 0; rsIdx < nRingSets; ++rsIdx ) {
201  const RingSet* rs = this->at(rsIdx);
202  if ( !rs ) {
203  throw std::runtime_error( std::string(
204  "Found invalid ElementLink") );
205  }
206  if ( !foundStartLayer ) {
207  // Check if we found start layer:
208  if ( clRingsRawConfCol[rsIdx].calJointLayer == layerTypeStart )
209  {
210  foundStartLayer = true;
211  rs->copyTo(ringStrip);
212  }
213  } else {
214  rs->copyTo(ringStrip);
215  }
216  // Check if we are at the last requested layer:
217  if ( clRingsRawConfCol[rsIdx].calJointLayer == layerTypeEnd ) {
218  break;
219  }
220  }
221 }
222 
223 //==============================================================================
225  std::vector<float> &ringStrip,
226  const RingSetConf_v1::RawConfCollection &clRingsRawConfCol,
227  const Ringer::CalJointSection sectionType) const
228 {
229 
230  unsigned nRingSets = this->nRingSets();
231 
232  if ( nRingSets && clRingsRawConfCol.size() != nRingSets ) {
233  throw std::invalid_argument( std::string(
234  "The configuration struct seems not to be valid."));
235  }
236 
237  // Prepare RingStrip vector to receive Rings energy vectorized representation
238  ringStrip.clear();
239 
240  bool foundSection = false;
241 
242  for ( unsigned rsIdx = 0; rsIdx < nRingSets; ++rsIdx) {
243  if ( clRingsRawConfCol[rsIdx].calJointSection == sectionType) {
244  foundSection = true;
245  const RingSet* rs = this->at(rsIdx);
246  if ( !rs ) {
247  throw std::runtime_error( std::string(
248  "Found invalid ElementLink") );
249  }
250  rs->copyTo(ringStrip);
251  } else if (foundSection) {
252  break;
253  }
254  }
255 
256 }
258 
261 //==============================================================================
263 {
264  if (this != &cl_rings){ // protect against invalid self-assignment
265  if (!this->container() && !this->hasStore() ) {
267  }
268  this->SG::AuxElement::operator=( cl_rings );
269  }
270  // by convention, always return *this
271  return *this;
272 }
274 
275 
278 
279 //==============================================================================
280 void CaloRings_v1::print( std::ostream &stream ) const
281 {
282  stream << "CaloRings are : " << std::endl;
283  for (unsigned rsIdx = 0; rsIdx < this->nRingSets(); ++rsIdx) {
284  stream << "Ringset #" << rsIdx << " : ";
285  const RingSet* rs = this->at(rsIdx);
286  if ( !rs ) {
287  throw std::runtime_error( std::string(
288  "Found invalid ElementLink") );
289  }
290  rs->print(stream);
291  }
292 }
294 
297 //==============================================================================
299 {
300  if ( index >= this->nRingSets() ) {
301  throw std::overflow_error("Out of RingSet ElementLink vector range.");
302  }
303 }
305 //
306 } // End of namespace xAOD
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
xAOD::CaloRings_v1::checkRingSetIndexWithinRange
void checkRingSetIndexWithinRange(unsigned index) const
Check if index is within range, otherwise throws overflow_error:
Definition: CaloRings_v1.cxx:298
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
xAOD::CaloRings_v1::end
RingSetLinks::iterator end()
returns iterator to the ending of RingSet EL Collection.
Definition: CaloRings_v1.cxx:61
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
AuxStoreAccessorMacros.h
RingSet::at
float & at(unsigned int i)
RingSet ///.
Definition: CaloRings.cxx:11
xAOD::RingSetConf_v1::RawConfCollection
std::vector< RawConf > RawConfCollection
typedef The raw configuration structure data holder
Definition: RingSetConf_v1.h:124
index
Definition: index.py:1
xAOD::RingSetLinks
std::vector< ElementLink< RingSetContainer > > RingSetLinks
Declare element links vector.
Definition: RingSetContainer.h:25
xAOD::RingSet_v1::at
float & at(const unsigned int i)
Get/set ring Et at ith position.
Definition: RingSet_v1.cxx:42
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAOD::RingSet_v1
Class holding a set of rings.
Definition: RingSet_v1.h:31
RingSet
Definition: Reconstruction/egamma/egammaEvent/egammaEvent/CaloRings.h:14
xAOD::CaloRings_v1::nRingSets
unsigned nRingSets() const
Number of RingSets ElementLinks available.
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
xAOD::RingSet_v1::print
void print(std::ostream &stream) const
Definition: RingSet_v1.cxx:115
xAOD::CaloRings_v1::ringAt
float ringAt(const unsigned int rsIdx, const unsigned int ringIdx) const
Navigate through eT rings methods.
RingSet::size
size_t size() const
Definition: CaloRings.cxx:33
xAOD::CaloRings_v1::operator[]
const RingSet * operator[](const unsigned index) const
Return ith RingSet.
Definition: CaloRings_v1.cxx:98
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::RingSet_v1::copyTo
void copyTo(std::vector< float > &vec) const
Copy ringset to std::vector end:
Definition: RingSet_v1.cxx:108
xAOD::CaloRings_v1::addRingSetEL
void addRingSetEL(const ElementLink< RingSetContainer_v1 > &rsEL)
Add ElementLink to holden vector.
xAOD::CaloRings_v1::print
void print(std::ostream &stream) const
Print-out methods:
Definition: CaloRings_v1.cxx:280
xAOD::CaloRings_v1
Class summarizing the particle interaction throughout the Calorimeter (its shower shape).
Definition: CaloRings_v1.h:51
Ringer::CalJointLayer
CalJointLayer
the joint calorimeter layers.
Definition: CaloRingsDefs.h:45
xAOD::CaloRings_v1::exportRingsTo
void exportRingsTo(std::vector< float > &ringStrip) const
Export rings eT in vectorized representation.
Definition: CaloRings_v1.h:221
RingSetContainer.h
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:192
SG::AuxElement::operator=
AuxElement & operator=(const AuxElement &other)
Assignment.
SG::AuxElement::hasStore
bool hasStore() const
Return true if this object has an associated store.
Definition: AuxElement.cxx:398
xAOD::CaloRings_v1::operator=
CaloRings_v1 & operator=(const CaloRings_v1 &clrings)
Assignment Operator.
Definition: CaloRings_v1.cxx:262
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
xAOD::CaloRings_v1::at
const RingSet * at(const unsigned index) const
Return ith RingSet.
Definition: CaloRings_v1.cxx:85
xAOD::CaloRings_v1::begin
RingSetLinks::iterator begin()
returns iterator to the beginning of RingSet Collection.
Definition: CaloRings_v1.cxx:53
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
CaloRings_v1.h
xAOD::CaloRings_v1::clear
void clear()
Clear RingSet EL Collection.
Definition: CaloRings_v1.cxx:47
Ringer::CalJointSection
CalJointSection
the joint calorimeter sections.
Definition: CaloRingsDefs.h:18
xAOD::AUXSTORE_OBJECT_SETTER_AND_GETTER
AUXSTORE_OBJECT_SETTER_AND_GETTER(CaloRings_v1, RingSetLinks, ringSetLinks, setRingSetLinks) unsigned CaloRings_v1
Definition: CaloRings_v1.cxx:27