Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

ChargeService.cxx

Go to the documentation of this file.
00001 //=================================================
00002 //
00003 //
00004 // find particle charge
00005 //
00006 //=================================================
00007 #include "AtlfastUtils/ChargeService.h"
00008 namespace Atlfast {
00009   using std::abs;
00010 
00011   ChargeService::ChargeService(){
00012     HepMC::IO_PDG_ParticleDataTable pdg_io("PDGTABLE");
00013     m_particleDataTable = *pdg_io.read_particle_data_table();
00014     m_particleDataTable.make_antiparticles_from_particles();
00015   }
00016   ChargeService::ChargeService(const ChargeService & other):
00017     m_particleDataTable(other.m_particleDataTable){}
00018   
00019   double ChargeService::operator()(const HepMC::GenParticle* p)const {
00020     
00021     //does particle exist in table only positive ids for neutrals !?
00022     HepMC::ParticleData* ap = m_particleDataTable.find( abs( p->pdg_id() ) );
00023     
00024     if(!ap){ 
00025       std::cout << "ChargeService WARNING: abs(id) " 
00026            << abs(p->pdg_id())
00027            << " is not in particle data table"<<std::endl;
00028       return 0.;
00029     }
00030     
00031     //if in table, and the charge is 0, return 0. 
00032     double c = ap->charge();
00033     if(c==0) return 0.;
00034     
00035     
00036     //if in table, and the charge is not 0, use signed id. 
00037     
00038     HepMC::ParticleData* pp  = m_particleDataTable.find( p->pdg_id() );
00039     
00040     if(!pp){ 
00041       std::cout << "ChargeService WARNING: id " 
00042            << p->pdg_id()<< " is not in particle data table"<<std::endl;
00043       return 0.;
00044     }
00045     
00046     return pp->charge();
00047     
00048   }
00049  
00050   double ChargeService::operator()(const ReconstructedParticle* p)const {
00051     return (*this)(p->truth());
00052   }
00053  
00054 }
00055 
00056 
00057 

Generated on Wed Jan 15 11:00:29 2003 for AtlfastUtils by doxygen1.3-rc1