CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/PhysicsTools/HepMCCandAlgos/interface/MCTruthPairSelector.h

Go to the documentation of this file.
00001 #ifndef HepMCCandAlgos_MCTruthPairSelector_h
00002 #define HepMCCandAlgos_MCTruthPairSelector_h
00003 /* \class MCTruthPairSelector
00004  *
00005  * \author Luca Lista, INFN
00006  *
00007  */
00008 
00009 #include <set>
00010 #include "DataFormats/Candidate/interface/Candidate.h"
00011 
00012 namespace helpers {
00013   template<typename T>
00014   struct MCTruthPairSelector {
00015     MCTruthPairSelector( bool checkCharge = false ) : 
00016       checkCharge_( checkCharge ) { }
00017     template<typename I>
00018     MCTruthPairSelector( const I & begin, const I & end, bool checkCharge = false ) :
00019       checkCharge_( checkCharge ) {
00020       for( I i = begin; i != end; ++i )
00021         matchIds_.insert( std::abs( * i ) );
00022     }
00023     bool operator()( const T & c, const reco::Candidate & mc ) const {
00024       if ( mc.status() != 1 ) return false;
00025       if ( checkCharge_ && c.charge() != mc.charge() ) return false;
00026       if ( matchIds_.size() == 0 ) return true;
00027       return matchIds_.find( std::abs( mc.pdgId() ) ) != matchIds_.end();
00028     }
00029   private:
00030     std::set<int> matchIds_;
00031     bool checkCharge_;
00032   };
00033 }
00034 
00035 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00036 #include <algorithm>
00037 #include <string>
00038 #include <vector>
00039 
00040 namespace reco {
00041   namespace modules {
00042     
00043     template<typename T>
00044     struct ParameterAdapter<helpers::MCTruthPairSelector<T> > {
00045       static helpers::MCTruthPairSelector<T> make( const edm::ParameterSet & cfg ) {
00046         const std::string matchPDGId( "matchPDGId" );
00047         const std::string checkCharge( "checkCharge" );
00048         bool ck = false;
00049         std::vector<std::string> bools = cfg.template getParameterNamesForType<bool>();
00050         bool found = find( bools.begin(), bools.end(), checkCharge ) != bools.end();
00051         if (found) ck = cfg.template getParameter<bool>( checkCharge ); 
00052         typedef std::vector<int> vint;
00053         std::vector<std::string> ints = cfg.template getParameterNamesForType<vint>();
00054         found = find( ints.begin(), ints.end(), matchPDGId ) != ints.end();
00055         if ( found ) {
00056           vint ids = cfg.template getParameter<vint>( matchPDGId );
00057           return helpers::MCTruthPairSelector<T>( ids.begin(), ids.end(), ck );
00058         } else {
00059           return helpers::MCTruthPairSelector<T>( ck );
00060         }
00061       }
00062     };   
00063     
00064   }
00065 }
00066 
00067 #endif