CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCTruthPairSelector.h
Go to the documentation of this file.
1 #ifndef HepMCCandAlgos_MCTruthPairSelector_h
2 #define HepMCCandAlgos_MCTruthPairSelector_h
3 /* \class MCTruthPairSelector
4  *
5  * \author Luca Lista, INFN
6  *
7  */
8 
9 #include <set>
11 
12 namespace helpers {
13  template<typename T>
15  MCTruthPairSelector( bool checkCharge = false ) :
16  checkCharge_( checkCharge ) { }
17  template<typename I>
18  MCTruthPairSelector( const I & begin, const I & end, bool checkCharge = false ) :
19  checkCharge_( checkCharge ) {
20  for( I i = begin; i != end; ++i )
21  matchIds_.insert( std::abs( * i ) );
22  }
23  bool operator()( const T & c, const reco::Candidate & mc ) const {
24  if ( mc.status() != 1 ) return false;
25  if ( checkCharge_ && c.charge() != mc.charge() ) return false;
26  if ( matchIds_.size() == 0 ) return true;
27  return matchIds_.find( std::abs( mc.pdgId() ) ) != matchIds_.end();
28  }
29  private:
30  std::set<int> matchIds_;
32  };
33 }
34 
36 #include <algorithm>
37 #include <string>
38 #include <vector>
39 
40 namespace reco {
41  namespace modules {
42 
43  template<typename T>
44  struct ParameterAdapter<helpers::MCTruthPairSelector<T> > {
46  const std::string matchPDGId( "matchPDGId" );
47  const std::string checkCharge( "checkCharge" );
48  bool ck = false;
49  std::vector<std::string> bools = cfg.template getParameterNamesForType<bool>();
50  bool found = find( bools.begin(), bools.end(), checkCharge ) != bools.end();
51  if (found) ck = cfg.template getParameter<bool>( checkCharge );
52  typedef std::vector<int> vint;
53  std::vector<std::string> ints = cfg.template getParameterNamesForType<vint>();
54  found = find( ints.begin(), ints.end(), matchPDGId ) != ints.end();
55  if ( found ) {
56  vint ids = cfg.template getParameter<vint>( matchPDGId );
57  return helpers::MCTruthPairSelector<T>( ids.begin(), ids.end(), ck );
58  } else {
60  }
61  }
62  };
63 
64  }
65 }
66 
67 #endif
int i
Definition: DBlmapReader.cc:9
virtual int status() const =0
status word
#define abs(x)
Definition: mlp_lapack.h:159
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double vint[400]
static helpers::MCTruthPairSelector< T > make(const edm::ParameterSet &cfg)
const std::complex< double > I
Definition: I.h:8
virtual int charge() const =0
electric charge
#define end
Definition: vmac.h:38
virtual int pdgId() const =0
PDG identifier.
MCTruthPairSelector(bool checkCharge=false)
MCTruthPairSelector(const I &begin, const I &end, bool checkCharge=false)
#define begin
Definition: vmac.h:31
bool operator()(const T &c, const reco::Candidate &mc) const
long double T