CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CommonTools/CandAlgos/interface/GenParticleCustomSelector.h

Go to the documentation of this file.
00001 #ifndef RecoSelectors_GenParticleCustomSelector_h
00002 #define RecoSelectors_GenParticleCustomSelector_h
00003 /* \class GenParticleCustomSelector
00004  *
00005  * \author Giuseppe Cerati, UCSD
00006  *
00007  */
00008 
00009 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00010 
00011 class GenParticleCustomSelector {
00012 
00013 public:
00014   GenParticleCustomSelector(){}
00015   GenParticleCustomSelector ( double ptMin,double minRapidity,double maxRapidity,
00016                         double tip,double lip, bool chargedOnly, int status,
00017                         const std::vector<int>& pdgId = std::vector<int>()) :
00018     ptMin_( ptMin ), minRapidity_( minRapidity ), maxRapidity_( maxRapidity ),
00019     tip_( tip ), lip_( lip ), chargedOnly_(chargedOnly), status_(status), pdgId_( pdgId ) { }
00020   
00022   bool operator()( const reco::GenParticle & tp ) const { 
00023 
00024     if (chargedOnly_ && tp.charge()==0) return false;//select only if charge!=0
00025     bool testId = false;
00026     unsigned int idSize = pdgId_.size();
00027     if (idSize==0) testId = true;
00028     else for (unsigned int it=0;it!=idSize;++it){
00029       if (tp.pdgId()==pdgId_[it]) testId = true;
00030     }
00031 
00032     return (
00033             tp.pt() >= ptMin_ && 
00034             tp.eta() >= minRapidity_ && tp.eta() <= maxRapidity_ && 
00035             sqrt(tp.vertex().perp2()) <= tip_ &&
00036             fabs(tp.vertex().z()) <= lip_ &&
00037             tp.status() == status_ &&
00038             testId 
00039             );
00040   }
00041   
00042 private:
00043   double ptMin_;
00044   double minRapidity_;
00045   double maxRapidity_;
00046   double tip_;
00047   double lip_;
00048   bool chargedOnly_;
00049   int status_;
00050   std::vector<int> pdgId_;
00051 
00052 };
00053 
00054 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00055 
00056 namespace reco {
00057   namespace modules {
00058     
00059     template<>
00060     struct ParameterAdapter<GenParticleCustomSelector> {
00061       static GenParticleCustomSelector make( const edm::ParameterSet & cfg ) {
00062         return GenParticleCustomSelector(    
00063           cfg.getParameter<double>( "ptMin" ),
00064           cfg.getParameter<double>( "minRapidity" ),
00065           cfg.getParameter<double>( "maxRapidity" ),
00066           cfg.getParameter<double>( "tip" ),
00067           cfg.getParameter<double>( "lip" ),
00068           cfg.getParameter<bool>( "chargedOnly" ),
00069           cfg.getParameter<int>( "status" ),
00070           cfg.getParameter<std::vector<int> >( "pdgId" )); 
00071       }
00072     };
00073     
00074   }
00075 }
00076 
00077 #endif