HepMC_helper.cxx

Go to the documentation of this file.
00001 #include "AtlfastUtils/HepMC_helper/HepMC_helper.h"
00002 #include "AtlfastEvent/ParticleCodes.h"
00003 #include "HepMC/GenParticle.h"
00004 #include "HepMC/GenVertex.h"
00005 #include "HepMC/GenEvent.h"
00006 #include "AtlfastEvent/ChargeService.h"
00007 
00008 #include <cassert>
00009 namespace HepMC_helper {
00010   using std::vector;
00011   using std::abs;
00012   //****************************************************************
00013   //*                    All                                       *
00014   //****************************************************************
00015   bool All::operator()( const Particle* const) const {
00016     return true;
00017   }
00018   bool All::operator() ( const Particle& p ) const {
00019     return this->operator()(&p);
00020   } 
00021   IMCselector* All::create() const {return new All();}
00022   //****************************************************************
00023   //*                    IsFinalState                              *
00024   //***********************final*****************************************
00025   IsFinalState::IsFinalState()
00026     : m_igs() {}
00027   
00028   bool IsFinalState::operator()( const Particle* const p ) const {
00029     if ( !m_igs(p) ) return false;
00030     if ( m_chargeService.operator()(p) == -999. ){
00031       std::cout << "HepMC_helper::IsFinalState ignoring this one, particle will NOT be fast-simulated" << std::endl;
00032       return false;
00033     }    
00034     return true;
00035   }
00036   
00037   bool IsFinalState::operator() ( const Particle& p ) const {
00038     return this->operator()(&p);
00039   } 
00040   
00041   IMCselector* IsFinalState::create() const {return new IsFinalState(*this);}
00042 
00043   //****************************************************************
00044   //*                    IsStatusxx                              *
00045   //***********************final**************************************
00046   bool IsStatusxx::operator()( const Particle* const p ) const {
00047     const int fsCode = 3;
00048 
00049     int pStatus1 = p->status();
00050     int pStatus2 = pStatus1%100;
00051     
00052     if(m_stat != fsCode){return ( pStatus2 == m_stat)? true:false;}
00053     
00054     //This IsStatus has been initialised with the "usual" final state code.
00055     
00056     //Apply herwig history if the generator is Herwig. 
00057 
00058     int generCode  = p->parent_event()->signal_process_id()/1000000;
00059     
00060     //Herwig
00061     if (generCode == 2){
00062       return ((pStatus1 >= 101 && pStatus1 <= 103) ||
00063               (pStatus1 >= 120 && pStatus1 <= 125)) ? true:false;
00064     }
00065 
00066     //All other generators.....
00067     return ( pStatus2 == fsCode)? true:false;
00068 
00069   }
00070   bool IsStatusxx::operator() ( const Particle& p ) const {
00071     return this->operator()(&p);
00072   } 
00073   IMCselector* IsStatusxx::create() const {return new IsStatusxx(*this);}
00074   //****************************************************************
00075   //*                    IsFromHardScatter                           *
00076   //*****************************************************************
00077   bool IsFromHardScatter::operator()( const Particle* const /*p*/ ) const {
00078 
00079     // This just returns true for the moment
00080     // Expect to be able to query GenEvent for status in future
00081     // p->parent_event()
00082     
00083     return true;
00084 
00085   }
00086   bool IsFromHardScatter::operator() ( const Particle& p ) const {
00087     return this->operator()(&p);
00088   } 
00089   IMCselector* IsFromHardScatter::create() const {return new IsFromHardScatter(*this);}
00090   //****************************************************************
00091   //* RMS                  NCutter                                 *
00092   //****************************************************************
00093   bool NCutter::operator()( const Particle* const p ) const {
00094     for (vector<IMCselector*>::const_iterator i = m_selectors.begin();
00095          i != m_selectors.end(); i++) { 
00096       if ( !(*i)->operator()(p) ) return false;
00097     }
00098     return true;
00099   }
00100   bool NCutter::operator() ( const Particle& p ) const {
00101     return this->operator()(&p);
00102   } 
00103   IMCselector* NCutter::create() const {return new NCutter(*this);}
00104   //****************************************************************
00105   //*                    SelectType                                *
00106   //****************************************************************
00107   SelectType::SelectType(vector<int> types):m_requiredTypes(types){}
00108   SelectType::SelectType(int type){m_requiredTypes.push_back(type);}
00109   SelectType::SelectType(const SelectType& rhs):
00110     IMCselector(),
00111     m_requiredTypes(rhs.m_requiredTypes){}
00112 
00113   bool SelectType::operator() ( const Particle* const p ) const {
00114     vector<int>::const_iterator itype = m_requiredTypes.begin();
00115     for(; itype < m_requiredTypes.end(); ++itype ){ 
00116       if( abs(p->pdg_id()) == (*itype) ){
00117         return true ;
00118       }
00119     }
00120     return false ;
00121   }
00122   bool SelectType::operator() ( const Particle& p ) const {
00123     return this->operator()(&p);
00124   } 
00125   IMCselector* SelectType::create() const {return new SelectType(*this);}
00126   
00127   //****************************************************************
00128   //*                    RejectType                                *
00129   //****************************************************************
00130   
00131   RejectType::RejectType(int type): m_selectType(type){}
00132   RejectType::RejectType(vector<int> types): m_selectType(types){}
00133   RejectType::RejectType(const RejectType& rhs):
00134     IMCselector(), 
00135     m_selectType(rhs.m_selectType){}
00136 
00137   bool RejectType::operator() ( const Particle* const p ) const{
00138       return !m_selectType(p);}
00139   bool RejectType::operator()( const Particle& p ) const {
00140       return this->operator()(&p);} 
00141   IMCselector* RejectType::create() const {return new RejectType(*this);}
00142 
00143   //****************************************************************
00144   //*                     IsCharged                                *
00145   //****************************************************************
00146 
00147 
00148   IsCharged::IsCharged(){}
00149 
00150   bool IsCharged::operator() ( const Particle* const p )const{
00151     
00152     double charge = m_chargeService.operator()(p);
00153     if ( charge == 0 ) return false;
00154     if ( charge == -999. ){
00155       std::cout << "HepMC_helper::IsCharged ignoring this one" << std::endl;
00156       return false;
00157     }
00158     return true ;       
00159   }
00160 
00161   bool IsCharged::operator() ( const Particle& p ) const {
00162     return this->operator()(&p);
00163   } 
00164 
00165   IMCselector* IsCharged::create() const {
00166     IMCselector* p = 0;
00167     try{
00168       p = new IsCharged(*this);
00169     }catch(std::string errMsg){
00170       throw errMsg;
00171     }
00172     return p;
00173   }
00174 
00175   //****************************************************************
00176   //*                     MCCuts                                   *
00177   //****************************************************************
00178   MCCuts::MCCuts(double ptMin, double etaMax): 
00179     m_ptMin(ptMin),m_etaMax(etaMax){}
00180   bool MCCuts::operator() ( const Particle* const p )const {
00181     if (p->momentum().perp() < m_ptMin) return false;
00182     if (abs(p->momentum().pseudoRapidity()) > m_etaMax) return false;
00183     return true;
00184   }
00185 
00186   bool MCCuts::operator() ( const Particle& p ) const {
00187     return this->operator()(&p);
00188   } 
00189   IMCselector* MCCuts::create() const  {return new MCCuts(*this);}
00190   
00191 
00192   //****************************************************************
00193   //*                    Unseen                                    *
00194   //****************************************************************
00195   Unseen::Unseen( vector<int> requiredTypes,
00196                   double muonPtMax,
00197                   double muonEtaMax): 
00198     m_seltype( SelectType(requiredTypes) ),
00199     m_muonPtMax( muonPtMax ),
00200     m_muonEtaMax( muonEtaMax ){
00201   }
00202   
00203   Unseen::Unseen(const Unseen& src ): 
00204     IMCselector(),
00205     m_seltype( src.m_seltype ),
00206     m_muonPtMax( src.m_muonPtMax ),
00207     m_muonEtaMax( src.m_muonEtaMax ){ 
00208   }
00209   bool Unseen::operator() ( const Particle* const p )const{
00210     if(m_seltype(p)) return true;
00211     if( abs(p->pdg_id()) == 13){
00212       if(!m_ifs(p)) return false;
00213       if(abs(p->momentum().pseudoRapidity()) > m_muonEtaMax) return true;
00214       if(    p->momentum().perp()            < m_muonPtMax ) return true;
00215     }
00216     return false ;       
00217   }
00218   IMCselector* Unseen::create() const {return new Unseen(*this);}
00219   // The operator() method to determine acceptability of particle
00220   bool Unseen::operator() ( const Particle& p ) const {
00221     return this->operator()(&p);
00222   } 
00223   //****************************************************************
00224   //*                    SelectJetTag                              *
00225   //****************************************************************
00226   
00227   SelectJetTag::SelectJetTag(int id, double pt, double eta):
00228     m_id(abs(id)), m_ptMin(pt), m_etaMax(eta) { }
00229   bool SelectJetTag::operator() ( const Particle* const p ) const{
00230     // check on kinematics
00231     if( abs(p->pdg_id())                    !=     m_id) return false ; 
00232     if( p->momentum().perp()                 <  m_ptMin) return false ; 
00233     if((abs(p->momentum().pseudoRapidity())) > m_etaMax) return false ; 
00234 
00235     // No documentary quark
00236     if (p->status() == 3)                                return false ;
00237     // No quark from B/D decays (Herwig)
00238     bool fromHadron        = false;
00239     HepMC::GenVertex *pvtx = p->production_vertex();
00240     if (pvtx) {
00241       HepMC::GenVertex::particle_iterator firstParent = pvtx->particles_begin(HepMC::ancestors);
00242       HepMC::GenVertex::particle_iterator endParent   = pvtx->particles_end(HepMC::ancestors);
00243       HepMC::GenVertex::particle_iterator thisParent  = firstParent;
00244       for(; thisParent != endParent; ++thisParent){
00245        int pdgAnces = (*thisParent)->pdg_id();
00246        if (isBBaryon(pdgAnces) || isBMeson(pdgAnces) || // B --> b,c
00247            isDBaryon(pdgAnces) || isDMeson(pdgAnces) )  // D --> c
00248          fromHadron = true;
00249        if (fromHadron) break;
00250       }
00251     }
00252     if (fromHadron) return false;
00253 
00254     if(p->end_vertex()){
00255       
00256       HepMC::GenVertex::particle_iterator firstChild = 
00257         p->end_vertex()->particles_begin(HepMC::children);
00258       
00259       HepMC::GenVertex::particle_iterator endChild = 
00260         p->end_vertex()->particles_end(HepMC::children);
00261       
00262       HepMC::GenVertex::particle_iterator thisChild = firstChild; 
00263       
00264       //Should be vetoing this tag if it has a child of the same pdg id
00265       // following kludge due to fact that parents are included in
00266       // the list of children!
00267       for(; thisChild!=endChild; ++thisChild){
00268         if(abs((*thisChild)->pdg_id()) == m_id) return false;
00269       }
00270     }
00271     return true ;       
00272   }
00273   IMCselector* SelectJetTag::create() const {return new SelectJetTag(*this);}
00274   bool SelectJetTag::operator() ( const Particle& p ) const {
00275     return this->operator()(&p);
00276   } 
00277 
00278   //Taken from BSignalFilter
00279   bool SelectJetTag::isBBaryon(const int pID) const {
00280     // PdgID of B-baryon is of form ...xxx5xxx
00281     std::string idStr = longToStr( abs(pID) );
00282     char digit4 = idStr[ idStr.length() - 4 ];
00283     if( (digit4=='5') ) 
00284       return true;
00285     else 
00286       return false;
00287   }
00288 
00289   bool SelectJetTag::isBMeson(const int pID) const {
00290     // PdgID of B-meson is of form ...xxx05xx
00291     std::string idStr = longToStr( abs(pID) );
00292     char digit3 = idStr[ idStr.length() - 3 ];
00293     char digit4;
00294     if( idStr.length() < 4 ) { digit4 = '0'; }
00295     else { digit4 = idStr[ idStr.length() - 4 ]; };
00296     if( (digit4=='0') && (digit3=='5') ) 
00297       return true;
00298     else 
00299       return false;
00300   }
00301     bool SelectJetTag::isDBaryon(const int pID) const {
00302       // PdgID of D-baryon is of form ...xxx4xxx
00303       std::string idStr = longToStr( abs(pID) );
00304       char digit4 = idStr[ idStr.length() - 4 ];
00305       if( (digit4=='4') ) 
00306         return true;
00307       else 
00308         return false;
00309     }
00310 
00311     bool SelectJetTag::isDMeson(const int pID) const {
00312       // PdgID of D-meson is of form ...xxx04xx
00313       std::string idStr = longToStr( abs(pID) );
00314       char digit3 = idStr[ idStr.length() - 3 ];
00315       char digit4;
00316       if( idStr.length() < 4 ) { digit4 = '0'; }
00317       else { digit4 = idStr[ idStr.length() - 4 ]; };
00318       if( (digit4=='0') && (digit3=='4') ) 
00319         return true;
00320       else 
00321         return false;
00322     }
00323 
00324     std::string SelectJetTag::longToStr( const long n ) const {
00325       if (0==n) return "0"; 
00326       std::string str = "";
00327       for ( long m = n; m!=0; m/=10 )
00328         str = char( '0' + abs(m%10) ) + str;
00329       if ( n<0 )
00330         str = "-" + str;
00331       return str;
00332     }
00333 
00334   //****************************************************************
00335   //*                    SelectTauTag                              *
00336   //****************************************************************
00337 
00338   SelectTauTag::SelectTauTag(double pt, double eta):
00339     m_jetTagSelector(ParticleCodes::TAU, pt, eta){
00340   }
00341   bool SelectTauTag::operator() ( const Particle* const p ) const{
00342     if(p->end_vertex()){
00343       
00344       HepMC::GenVertex::particle_iterator firstChild = 
00345         p->end_vertex()->particles_begin(HepMC::children);
00346       
00347       HepMC::GenVertex::particle_iterator endChild = 
00348         p->end_vertex()->particles_end(HepMC::children);
00349       
00350       HepMC::GenVertex::particle_iterator thisChild = firstChild; 
00351       
00352       // Reject if the Tau does not decay hadronically
00353       for(; thisChild!=endChild; ++thisChild){
00354         if(abs((*thisChild)->pdg_id()) == 11 || 
00355            abs((*thisChild)->pdg_id()) == 13 || 
00356            abs((*thisChild)->pdg_id()) == 15 ) return false;
00357       }
00358     }
00359     return m_jetTagSelector(p);
00360   }
00361   
00362   IMCselector* SelectTauTag::create() const {return new SelectTauTag(*this);}
00363   
00364   bool SelectTauTag::operator() ( const Particle& p ) const {
00365     return this->operator()(&p);
00366   } 
00367 
00368   //****************************************************************
00369   //*                    SelectZ0                                  *
00370   //****************************************************************
00371 
00372   bool SelectZ0::operator() ( const Particle* const p ) const{
00373     if(!m_z0Type(p))   return false;
00374     if(!m_kineCuts(p)) return false;
00375     return true;
00376   } 
00377   IMCselector* SelectZ0::create() const {return new SelectZ0(*this);}
00378   bool SelectZ0::operator() ( const Particle& p ) const {
00379     return this->operator()(&p);
00380   } 
00381 
00382 
00383   //****************************************************************
00384   //*                    SelectPid                                 *
00385   //****************************************************************
00386 
00387   bool SelectPid::operator() ( const Particle* const p ) const{
00388     if(!m_selType(p))  return false;
00389     if(!m_kineCuts(p)) return false;
00390     return true;
00391   } 
00392   IMCselector* SelectPid::create() const {return new SelectPid(*this);}
00393   bool SelectPid::operator() ( const Particle& p ) const {
00394     return this->operator()(&p);
00395   } 
00396 
00397   //****************************************************************
00398   //*                    BFieldCutter                              *
00399   //****************************************************************
00400   
00401   bool BFieldCutter::operator()(const Particle* const a) const {
00402     if(m_chargeService->operator()(a) == 0.) return true;
00403     return (a->momentum().perp()<m_ptCut) ? false:true;
00404   }
00405    
00406   IMCselector* BFieldCutter::create() const {return new BFieldCutter(*this);}
00407   bool BFieldCutter::operator()( const Particle& p ) const {
00408     return this->operator()(&p);
00409   } 
00410 
00411   //****************************************************************
00412   //*                    AscendingEta                              *
00413   //****************************************************************
00414 
00415   bool AscendingEta::operator() ( const Particle* const a, 
00416                                   const Particle* const b  ) const{ 
00417     return( a->momentum().pseudoRapidity() < 
00418             b->momentum().pseudoRapidity() ); }
00419   bool AscendingEta::operator() ( const Particle& a, 
00420                                   const Particle& b  ) const{ 
00421     return( a.momentum().pseudoRapidity() < 
00422             b.momentum().pseudoRapidity() ); 
00423   }
00424 
00425 }  // closing the namespace
00426 
00427 
00428 
00429 
00430 
00431 
00432 
00433 

Generated on Fri Sep 21 13:20:37 2007 for AtlfastUtils by  doxygen 1.5.1