CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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>
16  template <typename I>
17  MCTruthPairSelector(const I& begin, const I& end, bool checkCharge = false) : checkCharge_(checkCharge) {
18  for (I i = begin; i != end; ++i)
19  matchIds_.insert(std::abs(*i));
20  }
21  bool operator()(const T& c, const reco::Candidate& mc) const {
22  if (mc.status() != 1)
23  return false;
24  if (checkCharge_ && c.charge() != mc.charge())
25  return false;
26  if (matchIds_.empty())
27  return true;
28  return matchIds_.find(std::abs(mc.pdgId())) != matchIds_.end();
29  }
30 
31  private:
32  std::set<int> matchIds_;
34  };
35 } // namespace helpers
36 
38 #include <algorithm>
39 #include <string>
40 #include <vector>
41 
42 namespace reco {
43  namespace modules {
44 
45  template <typename T>
46  struct ParameterAdapter<helpers::MCTruthPairSelector<T> > {
48  const std::string matchPDGId("matchPDGId");
49  const std::string checkCharge("checkCharge");
50  bool ck = false;
51  std::vector<std::string> bools = cfg.template getParameterNamesForType<bool>();
52  bool found = find(bools.begin(), bools.end(), checkCharge) != bools.end();
53  if (found)
54  ck = cfg.template getParameter<bool>(checkCharge);
55  typedef std::vector<int> vint;
56  std::vector<std::string> ints = cfg.template getParameterNamesForType<vint>();
57  found = find(ints.begin(), ints.end(), matchPDGId) != ints.end();
58  if (found) {
59  vint ids = cfg.template getParameter<vint>(matchPDGId);
60  return helpers::MCTruthPairSelector<T>(ids.begin(), ids.end(), ck);
61  } else {
63  }
64  }
65  };
66 
67  } // namespace modules
68 } // namespace reco
69 
70 #endif
const edm::EventSetup & c
tuple cfg
Definition: looper.py:296
virtual int status() const =0
status word
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
double vint[400]
static helpers::MCTruthPairSelector< T > make(const edm::ParameterSet &cfg)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::complex< double > I
Definition: I.h:8
virtual int charge() const =0
electric charge
virtual int pdgId() const =0
PDG identifier.
MCTruthPairSelector(bool checkCharge=false)
MCTruthPairSelector(const I &begin, const I &end, bool checkCharge=false)
string end
Definition: dataset.py:937
bool operator()(const T &c, const reco::Candidate &mc) const
long double T