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
GenParticleCustomSelector::meanPhi_
float meanPhi_
Definition: GenParticleCustomSelector.h:92
HLT_FULL_cff.invertRapidityCut
invertRapidityCut
Definition: HLT_FULL_cff.py:52982
qcdUeDQM_cfi.minRapidity
minRapidity
Definition: qcdUeDQM_cfi.py:24
reco::GenParticle
Definition: GenParticle.h:21
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
GenParticleCustomSelector::tip_
double tip_
Definition: GenParticleCustomSelector.h:94
GenParticleCustomSelector::lip_
double lip_
Definition: GenParticleCustomSelector.h:95
mps_update.status
status
Definition: mps_update.py:69
modules
Definition: MuonCleanerBySegments.cc:35
qcdUeDQM_cfi.maxRapidity
maxRapidity
Definition: qcdUeDQM_cfi.py:27
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
GenParticleCustomSelector::invertRapidityCut_
bool invertRapidityCut_
Definition: GenParticleCustomSelector.h:99
GenParticleCustomSelector::status_
int status_
Definition: GenParticleCustomSelector.h:97
ptMin
constexpr float ptMin
Definition: PhotonIDValueMapProducer.cc:155
GenParticleCustomSelector::GenParticleCustomSelector
GenParticleCustomSelector()
Definition: GenParticleCustomSelector.h:13
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
qcdUeDQM_cfi.lip
lip
Definition: qcdUeDQM_cfi.py:25
GenParticle.h
HLT_FULL_cff.maxPhi
maxPhi
Definition: HLT_FULL_cff.py:52983
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
PVValHelper::eta
Definition: PVValidationHelpers.h:70
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
GenParticleCustomSelector::minRapidity_
double minRapidity_
Definition: GenParticleCustomSelector.h:90
GenParticleCustomSelector::ptMin_
double ptMin_
Definition: GenParticleCustomSelector.h:89
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
qcdUeDQM_cfi.tip
tip
Definition: qcdUeDQM_cfi.py:23
edm::ParameterSet
Definition: ParameterSet.h:47
GenParticleCustomSelector::GenParticleCustomSelector
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)
Definition: GenParticleCustomSelector.h:14
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
reco::modules::ParameterAdapter::make
static S make(const edm::ParameterSet &cfg)
Definition: ParameterAdapter.h:13
GenParticleCustomSelector::rangePhi_
float rangePhi_
Definition: GenParticleCustomSelector.h:93
GenParticleCustomSelector::pdgId_
std::vector< int > pdgId_
Definition: GenParticleCustomSelector.h:98
GenParticleCustomSelector::operator()
bool operator()(const reco::GenParticle &tp) const
Operator() performs the selection: e.g. if (tPSelector(tp)) {...}.
Definition: GenParticleCustomSelector.h:55
reco::modules::ParameterAdapter< GenParticleCustomSelector >::make
static GenParticleCustomSelector make(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
Definition: GenParticleCustomSelector.h:110
reco::modules::GenParticleCustomSelector
SingleObjectSelector< GenParticleCollection, ::GenParticleCustomSelector > GenParticleCustomSelector
Definition: GenParticleCustomSelector.cc:15
SingleObjectSelectorBase
Definition: SingleObjectSelector.h:26
looper.cfg
cfg
Definition: looper.py:297
GenParticleCustomSelector::chargedOnly_
bool chargedOnly_
Definition: GenParticleCustomSelector.h:96
HLT_FULL_cff.minPhi
minPhi
Definition: HLT_FULL_cff.py:52971
Exception
Definition: hltDiff.cc:245
cosmictrackingParticleSelector_cfi.chargedOnly
chargedOnly
Definition: cosmictrackingParticleSelector_cfi.py:5
ParameterAdapter.h
ConsumesCollector.h
reco::modules::ParameterAdapter< GenParticleCustomSelector >::make
static GenParticleCustomSelector make(const edm::ParameterSet &cfg)
Definition: GenParticleCustomSelector.h:114
GenParticleCustomSelector::maxRapidity_
double maxRapidity_
Definition: GenParticleCustomSelector.h:91
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
reco::modules::ParameterAdapter
Definition: ParameterAdapter.h:12
GenParticleCustomSelector
Definition: GenParticleCustomSelector.h:11