00001
00002
00003
00004
00005
00006
00007 #include "AtlfastEvent/ChargeService.h"
00008 #include "GaudiKernel/IPartPropSvc.h"
00009 #include "GaudiKernel/Bootstrap.h"
00010 #include "GaudiKernel/ISvcLocator.h"
00011 #include "HepPDT/ParticleData.hh"
00012 #include <sstream>
00013
00014 namespace Atlfast {
00015 using std::abs;
00016
00017 ChargeService::ChargeService(){
00018
00019 IPartPropSvc* p_PartPropSvc;
00020 static const bool CREATEIFNOTTHERE(true);
00021 ISvcLocator* svcLoc = Gaudi::svcLocator( );
00022 StatusCode PartPropStatus = svcLoc->service("PartPropSvc",
00023 p_PartPropSvc,
00024 CREATEIFNOTTHERE
00025 );
00026 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
00027 std::cerr<<"ChargeService: could not find PartPropService"<<std::endl;
00028 std::string errMsg = "ChargeService: could not find PartPropService";
00029 throw errMsg;
00030 }
00031 m_particleDataTable = (HepPDT::ParticleDataTable*)p_PartPropSvc->PDT();
00032 if(m_particleDataTable == 0){
00033 std::cerr<< "ChargeService: PDG table not found"<<std::endl;
00034 std::string errMsg = "ChargeService: PDG table not found";
00035 throw errMsg;
00036 }
00037
00038
00039
00040 HepPDT::ParticleData* ap =
00041 m_particleDataTable->particle( 211 );
00042
00043 if(!ap){
00044 std::cerr<< "ChargeService: Test read of PDG table failed"<<std::endl;
00045 std::string errMsg = "ChargeService: Test read of PDG table failed";
00046 throw errMsg;
00047 }
00048
00049
00050 }
00051 ChargeService::ChargeService(const ChargeService & other):
00052 m_particleDataTable(other.m_particleDataTable){}
00053
00054 double ChargeService::operator()(const HepMC::GenParticle* p)const {
00055
00056
00057 HepPDT::ParticleData* ap =
00058 m_particleDataTable->particle( abs( p->pdg_id() ) );
00059
00060 if(!ap){
00061 std::cout << "Atlfast::ChargeService: PDGID " << p->pdg_id()
00062 << " is not in ParticleDataTable!!!" << std::endl;
00063 return -999.;
00064 }
00065
00066
00067 double c = ap->charge();
00068 if(c==0){ return 0.;}
00069 return (p->pdg_id() > 0)? c:-c;
00070
00071 }
00072
00073 double ChargeService::operator()(const ReconstructedParticle* p)const {
00074 return (*this)(p->truth());
00075 }
00076
00077 }
00078
00079
00080