LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimCalorimeterHitImpl.cc
Go to the documentation of this file.
2 #include <iostream>
3 #include <sstream>
4 
5 namespace IMPL{
6 
7 
8 
9 
11  _cellID0(0),
12  _cellID1(0),
13  _energy(0){
14  _position[0] = 0. ;
15  _position[1] = 0. ;
16  _position[2] = 0. ;
17  }
18 
19  // // copy of the SimCalorimeterHit hit
20  SimCalorimeterHitImpl::SimCalorimeterHitImpl(const SimCalorimeterHit& hit) :
21 
22  _cellID0( hit.getCellID0() ),
23  _cellID1( hit.getCellID1() ),
24  _energy( hit.getEnergy() ) {
25 
26  const float* p = hit.getPosition() ;
27  _position[0] = p[0] ;
28  _position[1] = p[1] ;
29  _position[2] = p[2] ;
30 
31  int nMC = hit.getNMCContributions() ;
32  _vec.reserve( nMC ) ;
33 
34  // now copy all the MCParticle contributions
35  for(int i=0; i<nMC ;i++){
36 
37  MCParticleCont* con = new MCParticleCont( hit.getParticleCont(i),
38  hit.getEnergyCont(i),
39  hit.getTimeCont(i),
40  hit.getLengthCont(i),
41  hit.getPDGCont(i),
42  hit.getStepPosition(i) ) ;
43  _vec.push_back( con ) ;
44  }
45  }
46 
47  // EVENT::LCObject* SimCalorimeterHitImpl::clone() const{
48  // // shallow copy ... more thought needed
49  // return new SimCalorimeterHitImpl( *this ) ;
50  // }
51 
52 
54  // delete all MCParticle contributions
55  MCParticleContVec::iterator iter = _vec.begin() ;
56 
57  while( iter != _vec.end() ){
58  delete *iter++ ;
59  }
60 
61  }
62 
64  return _cellID0 ;
65  }
66 
68  return _cellID1 ;
69  }
70 
72  return _energy ;
73  }
74 
75  const float* SimCalorimeterHitImpl::getPosition() const {
76  return _position ;
77  }
78 
79  const float* SimCalorimeterHitImpl::getStepPosition( int i ) const {
80  return _vec[i]->StepPosition ;
81  }
82 
84  //static bool first = true ;
85  //if( first ){
86  // std::cout << " WARNING >>>>>>> SimCalorimeterHitImpl::getNMCParticles() is deprecated "
87  // << " - please use SimCalorimeterHitImpl::getNMCContributions() ! " << std::endl ;
88  // first = false ;
89  //}
90  return getNMCContributions() ;
91  }
92 
94  return _vec.size() ;
95  }
96 
98  try{
99  return _vec.at(i)->Particle ;
100  }catch(const std::out_of_range& ){
101  std::stringstream err ; err << "SimCalorimeterHitImpl::getParticleCont(): out_of_range :" << i ;
102  throw EVENT::Exception( err.str() );
103  }
104  }
105 
107  return _vec[i]->Energy ;
108  }
109 
111  return _vec[i]->Time ;
112  }
114  return _vec[i]->Length ;
115  }
116 
118  return _vec[i]->PDG ;
119  }
120 
122  checkAccess("SimCalorimeterHitImpl::setCellID0") ;
123  _cellID0 = id0 ;
124  }
125 
127  checkAccess("SimCalorimeterHitImpl::setCellID1") ;
128  _cellID1 = id1 ;
129  }
130 
132  checkAccess("SimCalorimeterHitImpl::setEnergy") ;
133  _energy = en ;
134  }
135 
136  void SimCalorimeterHitImpl::setPosition(const float pos[3]){
137  checkAccess("SimCalorimeterHitImpl::setPosition") ;
138  _position[0] = pos[0] ;
139  _position[1] = pos[1] ;
140  _position[2] = pos[2] ;
141  }
142 
143 
145  float en,
146  float t ) {
147 
148  checkAccess("SimCalorimeterHitImpl::addMCParticleContribution") ;
149 
150  _energy += en ;
151 
152  static const float nullStep[3] = { 0.,0.,0. } ;
153 
154  // if we already have the particle, just add the energy
155  for( std::vector<MCParticleCont*>::iterator it=_vec.begin(), End = _vec.end() ; it != End ; ++it ) {
156 
157 
158  if( (*it)->Particle == p ) {
159 
160  (*it)->Energy += en ;
161  return ;
162  }
163  }
164  // else create a new contribution
165  _vec.push_back( new MCParticleCont( p , en , t , 0 , 0 , nullStep ) ) ;
166 
167  }
168 
169 
170 
172  float en,
173  float t,
174  float l,
175  int pdg,
176  float* stepPos
177  ) {
178 
179  checkAccess("SimCalorimeterHitImpl::addMCParticleContribution") ;
180 
181  _energy += en ;
182 
183  static const float nullStep[3] = { 0.,0.,0. } ;
184 
185  // add a new contribution :
186 
187  _vec.push_back( new MCParticleCont( p , en , t , l , pdg , ( stepPos ? stepPos : nullStep ) ) ) ;
188 
189  }
190 } // namespace IMPL
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
virtual float getEnergy() const
Returns the energy of the hit.
void setCellID1(int id1)
Sets the second cell id; Only store if the flag word (bit CHBIT_ID1) of the collection is set...
virtual const float * getStepPosition(int i) const
Returns the position where the energy deposited (step) occurred optional, only if bit LCIO::CHBIT_STE...
virtual int getCellID0() const
Create a deep copy of itself.
T end(T...args)
virtual const float * getPosition() const
Returns the position of the hit in world coordinates.
T at(T...args)
T push_back(T...args)
void setEnergy(float en)
Sets the energy.
virtual ~SimCalorimeterHitImpl()
Destructor.
virtual int getNMCParticles() const =0
Returns the number of MC contributions to the hit.
void addMCParticleContribution(EVENT::MCParticle *p, float en, float t)
Adds an MCParticle contribution to the hit - contributions for the same MCParticle are combined into ...
T str(T...args)
EVENT::MCParticle * Particle
virtual int getNMCContributions() const
Returns the number of MC contributions to the hit.
The LCIO Monte Carlo particle.
Definition: MCParticle.h:27
SimCalorimeterHitImpl()
Default constructor, initializes values to 0.
T size(T...args)
STL class.
void setCellID0(int id0)
Sets the first cell id;.
T begin(T...args)
virtual float getLengthCont(int i) const
Returns the step length of the i-th contribution to the hit.
virtual int getCellID1() const
Returns the second detector specific (geometrical) cell id.
virtual int getPDGCont(int i) const
Returns the PDG code of the shower particle that caused this contribution.
virtual EVENT::MCParticle * getParticleCont(int i) const
Returns the MCParticle that caused the shower responsible for this contribution to the hit...
void setPosition(const float pos[3])
Sets the position.
virtual float getEnergyCont(int i) const
Returns the energy in [GeV] of the i-th contribution to the hit.
virtual float getTimeCont(int i) const
Returns the time of the i-th in [ns] contribution to the hit.
T reserve(T...args)