00001
00002 #include "IMPL/MCParticleImpl.h"
00003 #include "UTIL/LCWarning.h"
00004
00005 #include "EVENT/LCIO.h"
00006 #include <iostream>
00007 #include <stdexcept>
00008 #include <vector>
00009 #include <math.h>
00010 #include <algorithm>
00011
00012 using namespace EVENT ;
00013
00014 namespace IMPL {
00015
00016 MCParticleImpl::MCParticleImpl() :
00017 _pdg(0),
00018 _genstatus(0),
00019 _simstatus(0),
00020 _mass(0),
00021 _charge(0),
00022 _time(0),
00023 _parents(0),
00024 _daughters(0)
00025 {
00026 _vertex[0] = 0.0 ;
00027 _vertex[1] = 0.0 ;
00028 _vertex[2] = 0.0 ;
00029 _p[0] = 0.0 ;
00030 _p[1] = 0.0 ;
00031 _p[2] = 0.0 ;
00032 _endpoint[0] = 0.0 ;
00033 _endpoint[1] = 0.0 ;
00034 _endpoint[2] = 0.0 ;
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 MCParticleImpl::~MCParticleImpl(){
00061
00062
00063
00064
00065
00066
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 const MCParticleVec & MCParticleImpl::getParents() const {
00079 return _parents ;
00080 }
00081
00082 const MCParticleVec & MCParticleImpl::getDaughters() const {
00083 return _daughters ;
00084 }
00085
00086 int MCParticleImpl::getNumberOfParents() const {
00087
00088
00089
00090
00091
00092
00093
00094 UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETNUMBEROFPARENTS" ) ;
00095
00096 return _parents.size() ;
00097 }
00098
00099 MCParticle* MCParticleImpl::getParent(int i) const {
00100
00101
00102
00103
00104
00105
00106
00107
00108 UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETPARENT" ) ;
00109
00110 try{
00111
00112
00113
00114 return _parents[i] ;
00115 }catch( std::out_of_range ){
00116 throw Exception(std::string("MCParticleImpl::getParent(): out_of_range :"
00117 + i ) );
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 int MCParticleImpl::getNumberOfDaughters() const {
00128
00129
00130
00131
00132
00133
00134
00135 UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETNUMBEROFDAUGHTERS" ) ;
00136
00137 return _daughters.size() ;
00138 }
00139
00140 MCParticle* MCParticleImpl::getDaughter(int i) const {
00141
00142
00143
00144
00145
00146
00147
00148
00149 UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETDAUGHTER" ) ;
00150
00151 try{
00152
00153
00154
00155 return _daughters[i] ;
00156 }catch( std::out_of_range ){
00157 throw Exception(std::string("MCParticleImpl::getDaughter(): out_of_range :"
00158 + i ) );
00159 }
00160
00161 }
00162
00163
00164
00165
00166
00167 const double* MCParticleImpl::getEndpoint() const {
00168
00169 if( ! _simstatus.test( BITEndpoint ) ){
00170
00171 if( _daughters.size() == 0 ) return _endpoint ;
00172
00173 for(unsigned int i=0;i<_daughters.size();i++)
00174 {
00175 if(!_daughters[i]->vertexIsNotEndpointOfParent())
00176 return _daughters[i]->getVertex();
00177 }
00178
00179
00180 return _endpoint ;
00181
00182 } else
00183 return _endpoint ;
00184 }
00185
00186
00187 double MCParticleImpl::getEnergy() const {
00188 return sqrt( _p[0]*_p[0] + _p[1]*_p[1] + _p[2]*_p[2] + _mass*_mass ) ;
00189 }
00190
00191
00192 int MCParticleImpl::getPDG() const { return _pdg ;}
00193 int MCParticleImpl::getGeneratorStatus() const { return _genstatus ;}
00194
00195 int MCParticleImpl::getSimulatorStatus() const {
00196
00197
00198 return _simstatus.to_ulong() ;
00199 }
00200
00201
00202 bool MCParticleImpl::isCreatedInSimulation() const { return _simstatus[ BITCreatedInSimulation ] ; }
00203 bool MCParticleImpl::isBackscatter() const { return _simstatus[ BITBackscatter ] ; }
00204 bool MCParticleImpl::vertexIsNotEndpointOfParent() const { return _simstatus[ BITVertexIsNotEndpointOfParent ] ; }
00205 bool MCParticleImpl::isDecayedInTracker() const { return _simstatus[ BITDecayedInTracker ] ; }
00206 bool MCParticleImpl::isDecayedInCalorimeter() const { return _simstatus[ BITDecayedInCalorimeter ] ; }
00207 bool MCParticleImpl::hasLeftDetector() const { return _simstatus[ BITLeftDetector ] ; }
00208 bool MCParticleImpl::isStopped() const { return _simstatus[ BITStopped ] ; }
00209
00210
00211
00212 const double * MCParticleImpl::getVertex() const { return _vertex ;}
00213 float MCParticleImpl::getTime() const { return _time ; }
00214 const double * MCParticleImpl::getMomentum() const { return _p ;}
00215 double MCParticleImpl::getMass() const { return _mass ;}
00216 float MCParticleImpl::getCharge() const { return _charge ; }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 void MCParticleImpl::addDaughter( MCParticle* daughter) {
00228
00229 checkAccess("MCParticleImpl::addDaughter") ;
00230
00231
00232
00233 _daughters.push_back( daughter ) ;
00234 }
00235
00236 void MCParticleImpl::addParent( MCParticle* parent) {
00237
00238 checkAccess("MCParticleImpl::addParent") ;
00239
00240
00241 if( std::find( _parents.begin(), _parents.end(), parent ) != _parents.end() )
00242 return ;
00243
00244
00245 _parents.push_back( parent ) ;
00246
00247 MCParticleImpl* mom = dynamic_cast<MCParticleImpl*>( parent ) ;
00248 if( mom ) mom->addDaughter( this ) ;
00249
00250 }
00251
00252 void MCParticleImpl::setPDG(int pdg ) {
00253 checkAccess("MCParticleImpl::setPDG") ;
00254 _pdg = pdg ;
00255 }
00256 void MCParticleImpl::setGeneratorStatus( int status ) {
00257 checkAccess("MCParticleImpl::setGeneratorStatus") ;
00258 _genstatus = status ;
00259 }
00260
00261 void MCParticleImpl::setSimulatorStatus( int status ) {
00262 checkAccess("MCParticleImpl::setSimulatorStatus") ;
00263
00264
00265 _simstatus = status ;
00266 }
00267
00268 void MCParticleImpl::setVertex( double vtx[3] ){
00269 checkAccess("MCParticleImpl::setVertex") ;
00270 _vertex[0] = vtx[0] ;
00271 _vertex[1] = vtx[1] ;
00272 _vertex[2] = vtx[2] ;
00273 }
00274 void MCParticleImpl::setTime(float time ) {
00275 checkAccess("MCParticleImpl::setTime") ;
00276 _time = time ;
00277 }
00278
00279 void MCParticleImpl::setMomentum( float p[3] ){
00280 checkAccess("MCParticleImpl::setMomentum") ;
00281 _p[0] = p[0] ;
00282 _p[1] = p[1] ;
00283 _p[2] = p[2] ;
00284 }
00285 void MCParticleImpl::setMomentum( double p[3] ){
00286 checkAccess("MCParticleImpl::setMomentum") ;
00287 _p[0] = p[0] ;
00288 _p[1] = p[1] ;
00289 _p[2] = p[2] ;
00290 }
00291
00292 void MCParticleImpl::setMass( float m ) {
00293 checkAccess("MCParticleImpl::setMass") ;
00294 _mass = m ;
00295 }
00296 void MCParticleImpl::setCharge( float c ) {
00297 checkAccess("MCParticleImpl::setCharge") ;
00298 _charge = c ;
00299 }
00300
00301 void MCParticleImpl::setEndpoint( double endpoint[3] ){
00302 checkAccess("MCParticleImpl::setEndpoint") ;
00303
00304 _simstatus.set( BITEndpoint ) ;
00305
00306 _endpoint[0] = endpoint[0] ;
00307 _endpoint[1] = endpoint[1] ;
00308 _endpoint[2] = endpoint[2] ;
00309 }
00310
00311 void MCParticleImpl::setCreatedInSimulation(bool val) { _simstatus[ BITCreatedInSimulation ] = val ; }
00312 void MCParticleImpl::setBackscatter(bool val) { _simstatus[ BITBackscatter ] = val; }
00313 void MCParticleImpl::setVertexIsNotEndpointOfParent(bool val) { _simstatus[ BITVertexIsNotEndpointOfParent ] = val; }
00314 void MCParticleImpl::setDecayedInTracker(bool val) { _simstatus[ BITDecayedInTracker ] = val; }
00315 void MCParticleImpl::setDecayedInCalorimeter(bool val) { _simstatus[ BITDecayedInCalorimeter ] = val; }
00316 void MCParticleImpl::setHasLeftDetector(bool val) { _simstatus[ BITLeftDetector ] = val ; }
00317 void MCParticleImpl::setStopped(bool val) { _simstatus[ BITStopped ] = val; }
00318
00319
00320 }