LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MCParticleImpl.cc
Go to the documentation of this file.
1 
2 #include "IMPL/MCParticleImpl.h"
3 
4 #include "EVENT/LCIO.h"
5 #include <iostream>
6 #include <sstream>
7 #include <stdexcept>
8 #include <vector>
9 #include <math.h>
10 #include <algorithm>
11 
12 namespace EVENT{
13 
14  // the standard requires static const ints to be defined aoutside the class declaration
15  // so we do this here :
16  const int MCParticle::BITEndpoint ;
18  const int MCParticle::BITBackscatter ;
22  const int MCParticle::BITLeftDetector ;
23  const int MCParticle::BITStopped ;
24  const int MCParticle::BITOverlay ;
25 
26 }
27 
28 using namespace EVENT ;
29 
30 namespace IMPL {
31 
32  MCParticleImpl::MCParticleImpl() :
33  _pdg(0),
34  _genstatus(0),
35  _simstatus(0),
36  _mass(0),
37  _charge(0),
38  _time(0),
39  _parents(0),
40  _daughters(0),
41  _endpointSet(false)
42  {
43  _vertex[0] = 0.0 ;
44  _vertex[1] = 0.0 ;
45  _vertex[2] = 0.0 ;
46  _pEndpoint[0] = 0.0 ;
47  _pEndpoint[1] = 0.0 ;
48  _pEndpoint[2] = 0.0 ;
49  _p[0] = 0.0 ;
50  _p[1] = 0.0 ;
51  _p[2] = 0.0 ;
52  _endpoint[0] = 0.0 ;
53  _endpoint[1] = 0.0 ;
54  _endpoint[2] = 0.0 ;
55 
56  _spin[0] = 0.0 ;
57  _spin[1] = 0.0 ;
58  _spin[2] = 0.0 ;
59 
60  _colorFlow[0] = 0 ;
61  _colorFlow[1] = 0 ;
62  }
63 
65  }
66 
68  return _parents ;
69  }
70 
72  return _daughters ;
73  }
74 
75 // int MCParticleImpl::getNumberOfParents() const {
76 // //static bool first = true ;
77 // //if( first ){
78 // // std::cout << " WARNING >>>>>>> MCParticleImpl::getNumberOfParents() is deprecated "
79 // // << " - please use MCParticleImpl::getParents().size() ! " << std::endl ;
80 // // first = false ;
81 // //}
82 //
83 // UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETNUMBEROFPARENTS" ) ;
84 //
85 // return _parents.size() ;
86 // }
87 //
88 // MCParticle* MCParticleImpl::getParent(int i) const {
89 //
90 // //static bool first = true ;
91 // //if( first ){
92 // // std::cout << " WARNING >>>>>>> MCParticleImpl::getParent(i) is deprecated "
93 // // << " - please use MCParticleImpl::getParents()[i] ! " << std::endl ;
94 // // first = false ;
95 // //}
96 //
97 // UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETPARENT" ) ;
98 //
99 // try{
100 // return _parents.at(i) ;
101 // }catch( std::out_of_range ){
102 // std::stringstream err ; err << "MCParticleImpl::getParent(): out_of_range :" << i ;
103 // throw Exception( err.str() );
104 // }
105 // }
106 //
107 // // // unchecked access
108 // // MCParticle* MCParticleImpl::getParent(int i) const {
109 // // return _parents[i] ;
110 // // }
111 //
112 //
113 // int MCParticleImpl::getNumberOfDaughters() const {
114 // //static bool first = true ;
115 // //if( first ){
116 // // std::cout << " WARNING >>>>>>> MCParticleImpl::getNumberOfDaughters() is deprecated "
117 // // << " - please use MCParticleImpl::getDaughters().size() ! " << std::endl ;
118 // // first = false ;
119 // //}
120 //
121 // UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETNUMBEROFDAUGHTERS" ) ;
122 //
123 // return _daughters.size() ;
124 // }
125 //
126 // MCParticle* MCParticleImpl::getDaughter(int i) const {
127 //
128 // UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETDAUGHTER" ) ;
129 //
130 // try{
131 // return _daughters.at(i) ;
132 // }catch( std::out_of_range ){
133 // std::stringstream err ; err << "MCParticleImpl::getDaughter(): out_of_range :" << i ;
134 // throw Exception( err.str() );
135 // }
136 //
137 // }
138 
139  const double* MCParticleImpl::getEndpoint() const {
140 
141  if( ! _simstatus.test( BITEndpoint ) ){
142 
143  if( _daughters.size() == 0 ) return _endpoint ;
144 
145  for(unsigned int i=0;i<_daughters.size();i++)
146  {
148  return _daughters[i]->getVertex();
149  }
150 
151 
152  return _endpoint ;
153 
154  } else
155  return _endpoint ;
156  }
157 
158 
159  double MCParticleImpl::getEnergy() const {
160  return sqrt( _p[0]*_p[0] + _p[1]*_p[1] + _p[2]*_p[2] + _mass*_mass ) ;
161  }
162 
163  const float* MCParticleImpl::getSpin() const {
164  return _spin ;
165  }
166 
167  const int* MCParticleImpl::getColorFlow() const {
168  return _colorFlow ;
169  }
170 
171 
172  int MCParticleImpl::getPDG() const { return _pdg ;}
174 
176  // bit 31 reserved for endpoint
177  // return ( 0x7fffffff & _simstatus ) ;
178  return _simstatus.to_ulong() ;
179  }
180 
181 
188  bool MCParticleImpl::isStopped() const { return _simstatus[ BITStopped ] ; }
189  bool MCParticleImpl::isOverlay() const { return _simstatus[ BITOverlay ] ; }
190 
191 
192 
193  const double * MCParticleImpl::getVertex() const { return _vertex ;}
194  float MCParticleImpl::getTime() const { return _time ; }
195  const double * MCParticleImpl::getMomentum() const { return _p ;}
196  const double * MCParticleImpl::getMomentumAtEndpoint() const { return _pEndpoint ;}
197  double MCParticleImpl::getMass() const { return _mass ;}
198  float MCParticleImpl::getCharge() const { return _charge ; }
199 
200 // void MCParticleImpl::setParent( MCParticle *mom0 ) {
201 // checkAccess("MCParticleImpl::setParent") ;
202 // _mother0 = mom0 ;
203 // }
204 // void MCParticleImpl::setSecondParent( MCParticle *mom1 ) {
205 // checkAccess("MCParticleImpl::setSecondParent") ;
206 // _mother1 = mom1 ;
207 // }
208 
210 
211  checkAccess("MCParticleImpl::addDaughter") ;
212 
213 // MCParticle** pD = new (MCParticle*) ;
214 // *pD = daughter ;
215  _daughters.push_back( daughter ) ;
216  }
217 
219 
220  checkAccess("MCParticleImpl::addParent") ;
221 
222 
223  if( std::find( _parents.begin(), _parents.end(), parent ) != _parents.end() )
224  return ; // parent already exists in list
225 
226 
227  _parents.push_back( parent ) ;
228 
229  MCParticleImpl* mom = dynamic_cast<MCParticleImpl*>( parent ) ;
230  if( mom ) mom->addDaughter( this ) ;
231 
232  }
233 
234  void MCParticleImpl::setPDG(int pdg ) {
235  checkAccess("MCParticleImpl::setPDG") ;
236  _pdg = pdg ;
237  }
239  checkAccess("MCParticleImpl::setGeneratorStatus") ;
240  _genstatus = status ;
241  }
242 
244  checkAccess("MCParticleImpl::setSimulatorStatus") ;
245  // bit 31 reserved for endpoint
246  // _simstatus |= ( 0x7fffffff & status ) ;
247  _simstatus = status ;
248  }
249 
250  void MCParticleImpl::setVertex( const double vtx[3] ){
251  checkAccess("MCParticleImpl::setVertex") ;
252  _vertex[0] = vtx[0] ;
253  _vertex[1] = vtx[1] ;
254  _vertex[2] = vtx[2] ;
255  }
256  void MCParticleImpl::setTime(float time ) {
257  checkAccess("MCParticleImpl::setTime") ;
258  _time = time ;
259  }
260 
261  void MCParticleImpl::setMomentum( const float p[3] ){
262  checkAccess("MCParticleImpl::setMomentum") ;
263  _p[0] = p[0] ;
264  _p[1] = p[1] ;
265  _p[2] = p[2] ;
266  }
267  void MCParticleImpl::setMomentum( const double p[3] ){
268  checkAccess("MCParticleImpl::setMomentum") ;
269  _p[0] = p[0] ;
270  _p[1] = p[1] ;
271  _p[2] = p[2] ;
272  }
273 
274  void MCParticleImpl::setMomentumAtEndpoint( const float p[3] ){
275  checkAccess("MCParticleImpl::setMomentumAtEndpoint") ;
276  _pEndpoint[0] = p[0] ;
277  _pEndpoint[1] = p[1] ;
278  _pEndpoint[2] = p[2] ;
279  }
280  void MCParticleImpl::setMomentumAtEndpoint( const double p[3] ){
281  checkAccess("MCParticleImpl::setMomentumAtEndpoint") ;
282  _pEndpoint[0] = p[0] ;
283  _pEndpoint[1] = p[1] ;
284  _pEndpoint[2] = p[2] ;
285  }
286 
287  void MCParticleImpl::setMass( float m ) {
288  checkAccess("MCParticleImpl::setMass") ;
289  _mass = m ;
290  }
291  void MCParticleImpl::setCharge( float c ) {
292  checkAccess("MCParticleImpl::setCharge") ;
293  _charge = c ;
294  }
295 
296  void MCParticleImpl::setEndpoint( const double endpoint[3] ){
297  checkAccess("MCParticleImpl::setEndpoint") ;
298 
300 
301  _endpoint[0] = endpoint[0] ;
302  _endpoint[1] = endpoint[1] ;
303  _endpoint[2] = endpoint[2] ;
304  }
305 
306  void MCParticleImpl::setSpin( const float spin[3] ){
307  checkAccess("MCParticleImpl::setSpin") ;
308  _spin[0] = spin[0] ;
309  _spin[1] = spin[1] ;
310  _spin[2] = spin[2] ;
311  }
312 
313  void MCParticleImpl::setColorFlow( const int cflow[2] ){
314  checkAccess("MCParticleImpl::setColorFlow") ;
315  _colorFlow[0] = cflow[0] ;
316  _colorFlow[1] = cflow[1] ;
317  }
318 
325  void MCParticleImpl::setStopped(bool val) { _simstatus[ BITStopped ] = val; }
326  void MCParticleImpl::setOverlay(bool val) { _simstatus[ BITOverlay ] = val; }
327 
328 
329 }
static const int BITOverlay
Definition: MCParticle.h:95
EVENT::MCParticleVec _daughters
virtual bool vertexIsNotEndpointOfParent() const
True if the particle&#39;s vertex is not the endpoint of the parent particle.
virtual const int * getColorFlow() const
Returns the color flow.
virtual const double * getMomentumAtEndpoint() const
Returns the particle momentum at the endpoint.
void setTime(float time)
Sets the createion time.
virtual const double * getMomentum() const
Returns the particle momentum at the production vertex.
void setEndpoint(const double pnt[3])
Sets the particle endpoint.
static const int BITStopped
Definition: MCParticle.h:94
virtual float getTime() const
The creation time of the particle in [ns] wrt.
T to_ulong(T...args)
virtual double getMass() const
Returns the mass of the particle in [GeV].
static const int BITDecayedInCalorimeter
Definition: MCParticle.h:92
virtual const EVENT::MCParticleVec & getParents() const
Returns the parents of this particle.
virtual bool hasLeftDetector() const
True if the particle has left the world volume undecayed.
T end(T...args)
virtual int getGeneratorStatus() const
Returns the status for particles from the generator 0 empty line 1 undecayed particle, stable in the generator 2 particle decayed in the generator 3 documentation line.
virtual bool isBackscatter() const
True if the particle is the result of a backscatter from a calorimeter shower.
std::bitset< 32 > _simstatus
void setGeneratorStatus(int status)
Sets the Generator status.
virtual const double * getEndpoint() const
Returns the i-th daughter of this particle.
void addParent(EVENT::MCParticle *mom)
Adds a parent particle.
virtual void setDecayedInCalorimeter(bool val)
T test(T...args)
void addDaughter(EVENT::MCParticle *daughter)
Adds a daughter particle - only called from addParent().
virtual bool isDecayedInTracker() const
True if the particle has interacted in a tracking region.
void setColorFlow(const int cflow[2])
Sets the color flow.
T push_back(T...args)
void setSimulatorStatus(int status)
Sets the Simulator status.
void setMass(float m)
Sets the mass.
virtual void setCreatedInSimulation(bool val)
virtual void setDecayedInTracker(bool val)
void setMomentum(const float p[3])
Sets the momentum.
void setMomentumAtEndpoint(const float p[3])
Sets the momentum at the endpoint.
static const int BITLeftDetector
Definition: MCParticle.h:93
void setVertex(const double vtx[3])
Sets the production vertex.
static const int BITVertexIsNotEndpointOfParent
Definition: MCParticle.h:90
virtual void setVertexIsNotEndpointOfParent(bool val)
void setCharge(float c)
Sets the charge.
virtual const EVENT::MCParticleVec & getDaughters() const
Returns the daughters of this particle.
virtual double getEnergy() const
Returns the energy of the particle (at the vertex) in [GeV] computed from the particle&#39;s momentum and...
The LCIO Monte Carlo particle.
Definition: MCParticle.h:27
virtual bool isCreatedInSimulation() const
True if the particle has been created by the simulation program (rather than the generator).
void setPDG(int pdg)
Sets the parent.
T find(T...args)
T size(T...args)
virtual bool isStopped() const
True if the particle has been stopped by the simulation program.
T set(T...args)
virtual void setStopped(bool val)
virtual void setHasLeftDetector(bool val)
T begin(T...args)
virtual bool isDecayedInCalorimeter() const
True if the particle has interacted in a calorimeter region.
virtual bool isOverlay() const
True if the particle has been overlayed by the simulation (or digitization) program.
static const int BITBackscatter
Definition: MCParticle.h:89
virtual void setOverlay(bool val)
virtual const double * getVertex() const
Returns the production vertex of the particle.
void setSpin(const float spin[3])
Sets the spin.
virtual int getPDG() const
Returns the number of daughters of this particle.
virtual int getSimulatorStatus() const
Returns the status for particles from the simulation, e.g.
EVENT::MCParticleVec _parents
virtual void setBackscatter(bool val)
static const int BITCreatedInSimulation
Definition: MCParticle.h:88
static const int BITDecayedInTracker
Definition: MCParticle.h:91
virtual float getCharge() const
Returns the particle&#39;s charge.
Implementation of MCParticle.
virtual ~MCParticleImpl()
Copy c&#39;tor.
virtual const float * getSpin() const
Returns the spin.
static const int BITEndpoint
Definition: MCParticle.h:87