CMS 3D CMS Logo

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