CMS 3D CMS Logo

CaloParticleSelector.h
Go to the documentation of this file.
1 #ifndef Validation_HGCalValidation_CaloParticleSelector_h
2 #define Validation_HGCalValidation_CaloParticleSelector_h
3 /* \class CaloParticleSelector
4  *
5  * \author Giuseppe Cerati, INFN
6  *
7  * $Date: 2013/05/14 15:46:46 $
8  * $Revision: 1.5.4.2 $
9  *
10  */
16 
18 public:
21  double ptMax,
22  double minRapidity,
23  double maxRapidity,
24  double lip,
25  double tip,
26  int minHit,
27  bool signalOnly,
28  bool intimeOnly,
29  bool chargedOnly,
30  bool stableOnly,
31  const std::vector<int>& pdgId = std::vector<int>(),
32  double minPhi = -3.2,
33  double maxPhi = 3.2)
34  : ptMin2_(ptMin * ptMin),
35  ptMax2_(ptMax * ptMax),
36  minRapidity_(minRapidity),
37  maxRapidity_(maxRapidity),
38  lip_(lip),
39  tip2_(tip * tip),
40  meanPhi_((minPhi + maxPhi) / 2.),
41  rangePhi_((maxPhi - minPhi) / 2.),
42  minHit_(minHit),
43  signalOnly_(signalOnly),
44  intimeOnly_(intimeOnly),
45  chargedOnly_(chargedOnly),
46  stableOnly_(stableOnly),
47  pdgId_(pdgId) {
48  if (minPhi >= maxPhi) {
49  throw cms::Exception("Configuration")
50  << "CaloParticleSelector: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi
51  << "). The range is constructed from minPhi to maxPhi around their average.";
52  }
53  if (minPhi >= M_PI) {
54  throw cms::Exception("Configuration")
55  << "CaloParticleSelector: minPhi (" << minPhi
56  << ") must be smaller than PI. The range is constructed from minPhi to maxPhi around their average.";
57  }
58  if (maxPhi <= -M_PI) {
59  throw cms::Exception("Configuration")
60  << "CaloParticleSelector: maxPhi (" << maxPhi
61  << ") must be larger than -PI. The range is constructed from minPhi to maxPhi around their average.";
62  }
63  }
64 
65  // Operator() performs the selection: e.g. if (cPSelector(cp)) {...}
66  // For the moment there shouldn't be any SimTracks from different crossings in the CaloParticle.
67  bool operator()(const CaloParticle& tp, std::vector<SimVertex> const& simVertices) const {
68  // signal only means no PU particles
69  if (signalOnly_ && !(tp.eventId().bunchCrossing() == 0 && tp.eventId().event() == 0))
70  return false;
71  // intime only means no OOT PU particles
72  if (intimeOnly_ && !(tp.eventId().bunchCrossing() == 0))
73  return false;
74 
75  auto pdgid = tp.pdgId();
76  if (!pdgId_.empty()) {
77  bool testId = false;
78  for (auto id : pdgId_) {
79  if (id == pdgid) {
80  testId = true;
81  break;
82  }
83  }
84  if (!testId)
85  return false;
86  }
87 
88  if (chargedOnly_ && tp.charge() == 0)
89  return false; //select only if charge!=0
90 
91  // select only stable particles
92  if (stableOnly_) {
94  if (j->get() == nullptr || j->get()->status() != 1) {
95  return false;
96  }
97  }
98 
99  // test for remaining unstabled due to lack of genparticle pointer
100  std::vector<int> pdgids{11, 13, 211, 321, 2212, 3112, 3222, 3312, 3334};
101  if (tp.status() == -99 && (!std::binary_search(pdgids.begin(), pdgids.end(), std::abs(pdgid)))) {
102  return false;
103  }
104  }
105 
106  auto etaOk = [&](const CaloParticle& p) -> bool {
107  float eta = etaFromXYZ(p.px(), p.py(), p.pz());
108  return (eta >= minRapidity_) & (eta <= maxRapidity_);
109  };
110  auto phiOk = [&](const CaloParticle& p) {
111  float dphi = deltaPhi(atan2f(p.py(), p.px()), meanPhi_);
112  return dphi >= -rangePhi_ && dphi <= rangePhi_;
113  };
114  auto ptOk = [&](const CaloParticle& p) {
115  double pt2 = tp.p4().perp2();
116  return pt2 >= ptMin2_ && pt2 <= ptMax2_;
117  };
118 
119  return (ptOk(tp) && etaOk(tp) && phiOk(tp));
120  }
121 
122 private:
123  double ptMin2_;
124  double ptMax2_;
127  double lip_;
128  double tip2_;
129  float meanPhi_;
130  float rangePhi_;
131  int minHit_;
136  std::vector<int> pdgId_;
137 };
138 
141 
142 namespace reco {
143  namespace modules {
144 
145  template <>
148 
150  return CaloParticleSelector(cfg.getParameter<double>("ptMin"),
151  cfg.getParameter<double>("ptMax"),
152  cfg.getParameter<double>("minRapidity"),
153  cfg.getParameter<double>("maxRapidity"),
154  cfg.getParameter<double>("lip"),
155  cfg.getParameter<double>("tip"),
156  cfg.getParameter<int>("minHit"),
157  cfg.getParameter<bool>("signalOnly"),
158  cfg.getParameter<bool>("intimeOnly"),
159  cfg.getParameter<bool>("chargedOnly"),
160  cfg.getParameter<bool>("stableOnly"),
161  cfg.getParameter<std::vector<int> >("pdgId"),
162  cfg.getParameter<double>("minPhi"),
163  cfg.getParameter<double>("maxPhi"));
164  }
165  };
166 
167  } // namespace modules
168 } // namespace reco
169 
170 #endif
T getParameter(std::string const &) const
int event() const
get the contents of the subdetector field (should be protected?)
CaloParticleSelector(double ptMin, double ptMax, double minRapidity, double maxRapidity, double lip, double tip, int minHit, bool signalOnly, bool intimeOnly, bool chargedOnly, bool stableOnly, const std::vector< int > &pdgId=std::vector< int >(), double minPhi=-3.2, double maxPhi=3.2)
static CaloParticleSelector make(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
EncodedEventId eventId() const
Signal source, crossing number.
Definition: CaloParticle.h:54
float charge() const
Electric charge. Note this is taken from the first SimTrack only.
Definition: CaloParticle.h:79
int status() const
Status word.
Definition: CaloParticle.h:155
genp_iterator genParticle_begin() const
iterators
Definition: CaloParticle.h:63
pdgids
Definition: ntuple.py:98
const math::XYZTLorentzVectorF & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
Definition: CaloParticle.h:85
int bunchCrossing() const
get the detector field from this detid
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define M_PI
int pdgId() const
PDG ID.
Definition: CaloParticle.h:43
static CaloParticleSelector make(const edm::ParameterSet &cfg)
fixed size matrix
std::vector< int > pdgId_
bool operator()(const CaloParticle &tp, std::vector< SimVertex > const &simVertices) const
genp_iterator genParticle_end() const
Definition: CaloParticle.h:64