/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/IMPL/MCParticleImpl.cc

Go to the documentation of this file.
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 //   MCParticleImpl::MCParticleImpl(const EVENT::MCParticle& p) :
00038 //     _pdg( p.getPDG() ),
00039 //     _genstatus( p.getGeneratorStatus() ),
00040 //     _simstatus( p.getSimulatorStatus() ),
00041 //     _mass( p.getMass() ),
00042 //     _charge( p.getCharge() ),
00043 //     _time( p.getTime() ),
00044 //     _parents( p.getParents() ),
00045 //     _daughters( p.getDaughters() )
00046 //   {
00047 //     _vertex[0] = p.getVertex()[0] ;
00048 //     _vertex[1] = p.getVertex()[1] ;
00049 //     _vertex[2] = p.getVertex()[2] ;
00050 //     _p[0] = p.getMomentum()[0] ;
00051 //     _p[1] = p.getMomentum()[1] ;
00052 //     _p[2] = p.getMomentum()[2] ;
00053 //     _endpoint[0] = p.getEndpoint()[0] ;
00054 //     _endpoint[1] = p.getEndpoint()[1] ;
00055 //     _endpoint[2] = p.getEndpoint()[2] ;
00056 //   }
00057     
00058 
00059 
00060   MCParticleImpl::~MCParticleImpl(){
00061     // no dynamic variables
00062     //    delete [] _readDaughters ;
00063 //     for(MCParticlePVec::iterator iter = _daughters.begin();iter != _daughters.end() ;iter++){
00064 //       delete (*iter) ;
00065 //     }
00066 
00067   }
00068   
00069 //   MCParticle * MCParticleImpl::getParent() const { return _mother0 ; } 
00070 //   MCParticle * MCParticleImpl::getParent() const { return _mother0 ; }
00071 
00072 //   MCParticle * MCParticleImpl::getSecondParent() const { return _mother1; }  
00073 //   MCParticle * MCParticleImpl::getSecondParent() const { return _mother1; }
00074 
00075 //   //  const MCParticleVec * MCParticleImpl::getDaughters() const { return &_daughters ; }
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     //static bool first = true ;
00088     //if( first ){
00089     //  std::cout << " WARNING >>>>>>>  MCParticleImpl::getNumberOfParents() is deprecated "
00090         //      << " - please use  MCParticleImpl::getParents().size() ! " << std::endl ;
00091     //  first = false ;
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     //static bool first = true ;
00102     //if( first ){
00103     //  std::cout << " WARNING >>>>>>>  MCParticleImpl::getParent(i) is deprecated "
00104         //      << " - please use  MCParticleImpl::getParents()[i] ! " << std::endl ;
00105     //  first = false ;
00106     //}
00107 
00108     UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETPARENT" ) ;
00109 
00110     try{
00111       //      return _parents.at(i) ;
00112       //FIXME gcc 2.95 doesn't know at(i) ??
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   //   // unchecked access
00122   //   MCParticle* MCParticleImpl::getParent(int i) const {
00123   //     return _parents[i] ;
00124   //   }
00125 
00126 
00127   int MCParticleImpl::getNumberOfDaughters() const { 
00128     //static bool first = true ;
00129     //if( first ){
00130     //  std::cout << " WARNING >>>>>>>  MCParticleImpl::getNumberOfDaughters() is deprecated "
00131         //      << " - please use  MCParticleImpl::getDaughters().size() ! " << std::endl ;
00132     //  first = false ;
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     //static bool first = true ;
00143     //if( first ){
00144     //  std::cout << " WARNING >>>>>>>  MCParticleImpl::getDaughter(i) is deprecated "
00145         //      << " - please use  MCParticleImpl::getDaughters()[i] ! " << std::endl ;
00146     //  first = false ;
00147     //}
00148 
00149     UTIL::LCWarning::getInstance().printWarning( "MCPARTICLE_DEPRECATED_GETDAUGHTER" ) ;
00150 
00151     try{
00152       //      return _daughters.at(i) ;
00153       //FIXME gcc 2.95 doesn't know at(i) ??
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 //   // unchecked access
00163 //   MCParticle* MCParticleImpl::getDaughter(int i) const {
00164 //     return *_daughters[i] ;
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     // bit 31 reserved for endpoint
00197     //    return ( 0x7fffffff & _simstatus ) ;
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 //   void MCParticleImpl::setParent( MCParticle *mom0 ) { 
00219 //     checkAccess("MCParticleImpl::setParent") ;
00220 //     _mother0 = mom0 ; 
00221 //   }
00222 //   void MCParticleImpl::setSecondParent( MCParticle *mom1 ) {
00223 //     checkAccess("MCParticleImpl::setSecondParent") ;
00224 //     _mother1 = mom1 ; 
00225 //   }
00226 
00227   void MCParticleImpl::addDaughter( MCParticle* daughter) { 
00228     
00229     checkAccess("MCParticleImpl::addDaughter") ;
00230     
00231 //     MCParticle** pD = new (MCParticle*)  ;
00232 //     *pD = daughter ;
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 ; // parent already exists in list
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     // bit 31 reserved for endpoint
00264     //    _simstatus |= ( 0x7fffffff  & status )  ;
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 } /// namespace IMPl

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7