CMS 3D CMS Logo

GenParticleCustomSelector.h
Go to the documentation of this file.
1 #ifndef RecoSelectors_GenParticleCustomSelector_h
2 #define RecoSelectors_GenParticleCustomSelector_h
3 /* \class GenParticleCustomSelector
4  *
5  * \author Giuseppe Cerati, UCSD
6  *
7  */
8 
10 
12 public:
15  double minRapidity,
16  double maxRapidity,
17  double tip,
18  double lip,
19  bool chargedOnly,
20  int status,
21  const std::vector<int>& pdgId = std::vector<int>(),
22  bool invertRapidityCut = false,
23  double minPhi = -3.2,
24  double maxPhi = 3.2)
25  : ptMin_(ptMin),
28  meanPhi_((minPhi + maxPhi) / 2.),
29  rangePhi_((maxPhi - minPhi) / 2.),
30  tip_(tip),
31  lip_(lip),
33  status_(status),
34  pdgId_(pdgId),
36  if (minPhi >= maxPhi) {
37  throw cms::Exception("Configuration")
38  << "GenParticleCustomSelector: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi
39  << "). The range is constructed from minPhi to maxPhi around their "
40  "average.";
41  }
42  if (minPhi >= M_PI) {
43  throw cms::Exception("Configuration") << "GenParticleCustomSelector: minPhi (" << minPhi
44  << ") must be smaller than PI. The range is constructed from minPhi "
45  "to maxPhi around their average.";
46  }
47  if (maxPhi <= -M_PI) {
48  throw cms::Exception("Configuration") << "GenParticleCustomSelector: maxPhi (" << maxPhi
49  << ") must be larger than -PI. The range is constructed from minPhi "
50  "to maxPhi around their average.";
51  }
52  }
53 
55  bool operator()(const reco::GenParticle& tp) const {
56  if (chargedOnly_ && tp.charge() == 0)
57  return false; //select only if charge!=0
58  bool testId = false;
59  unsigned int idSize = pdgId_.size();
60  if (idSize == 0)
61  testId = true;
62  else
63  for (unsigned int it = 0; it != idSize; ++it) {
64  if (tp.pdgId() == pdgId_[it])
65  testId = true;
66  }
67 
68  auto etaOk = [&](const reco::GenParticle& p) -> bool {
69  float eta = p.eta();
70  if (!invertRapidityCut_)
71  return (eta >= minRapidity_) && (eta <= maxRapidity_);
72  else
73  return (eta < minRapidity_ || eta > maxRapidity_);
74  };
75  auto phiOk = [&](const reco::GenParticle& p) {
76  float dphi = deltaPhi(atan2f(p.py(), p.px()), meanPhi_);
77  return dphi >= -rangePhi_ && dphi <= rangePhi_;
78  };
79  auto ptOk = [&](const reco::GenParticle& p) {
80  double pt = p.pt();
81  return pt >= ptMin_;
82  };
83 
84  return (ptOk(tp) && etaOk(tp) && phiOk(tp) && sqrt(tp.vertex().perp2()) <= tip_ && fabs(tp.vertex().z()) <= lip_ &&
85  tp.status() == status_ && testId);
86  }
87 
88 private:
89  double ptMin_;
90  double minRapidity_;
91  double maxRapidity_;
92  float meanPhi_;
93  float rangePhi_;
94  double tip_;
95  double lip_;
97  int status_;
98  std::vector<int> pdgId_;
100 };
101 
104 
105 namespace reco {
106  namespace modules {
107 
108  template <>
111  return make(cfg);
112  }
113 
115  return GenParticleCustomSelector(cfg.getParameter<double>("ptMin"),
116  cfg.getParameter<double>("minRapidity"),
117  cfg.getParameter<double>("maxRapidity"),
118  cfg.getParameter<double>("tip"),
119  cfg.getParameter<double>("lip"),
120  cfg.getParameter<bool>("chargedOnly"),
121  cfg.getParameter<int>("status"),
122  cfg.getParameter<std::vector<int> >("pdgId"),
123  cfg.getParameter<bool>("invertRapidityCut"),
124  cfg.getParameter<double>("minPhi"),
125  cfg.getParameter<double>("maxPhi"));
126  }
127  };
128 
129  } // namespace modules
130 } // namespace reco
131 
132 #endif
constexpr float ptMin
GenParticleCustomSelector(double ptMin, double minRapidity, double maxRapidity, double tip, double lip, bool chargedOnly, int status, const std::vector< int > &pdgId=std::vector< int >(), bool invertRapidityCut=false, double minPhi=-3.2, double maxPhi=3.2)
T sqrt(T t)
Definition: SSEVec.h:23
SingleObjectSelector< GenParticleCollection, ::GenParticleCustomSelector > GenParticleCustomSelector
bool operator()(const reco::GenParticle &tp) const
Operator() performs the selection: e.g. if (tPSelector(tp)) {...}.
#define M_PI
static GenParticleCustomSelector make(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
fixed size matrix
static S make(const edm::ParameterSet &cfg)
static GenParticleCustomSelector make(const edm::ParameterSet &cfg)