CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RecoTrackSelectorBase.h
Go to the documentation of this file.
1 #ifndef CommonTools_RecoAlgos_RecoTrackSelectorBase_h
2 #define CommonTools_RecoAlgos_RecoTrackSelectorBase_h
3 
8 
15 
17 public:
20  : ptMin_(cfg.getParameter<double>("ptMin")),
21  minRapidity_(cfg.getParameter<double>("minRapidity")),
22  maxRapidity_(cfg.getParameter<double>("maxRapidity")),
23  meanPhi_((cfg.getParameter<double>("minPhi") + cfg.getParameter<double>("maxPhi")) / 2.),
24  rangePhi_((cfg.getParameter<double>("maxPhi") - cfg.getParameter<double>("minPhi")) / 2.),
25  tip_(cfg.getParameter<double>("tip")),
26  lip_(cfg.getParameter<double>("lip")),
27  maxChi2_(cfg.getParameter<double>("maxChi2")),
28  minHit_(cfg.getParameter<int>("minHit")),
29  minPixelHit_(cfg.getParameter<int>("minPixelHit")),
30  minLayer_(cfg.getParameter<int>("minLayer")),
31  min3DLayer_(cfg.getParameter<int>("min3DLayer")),
32  usePV_(false),
33  invertRapidityCut_(cfg.getParameter<bool>("invertRapidityCut")) {
34  const auto minPhi = cfg.getParameter<double>("minPhi");
35  const auto maxPhi = cfg.getParameter<double>("maxPhi");
36  if (minPhi >= maxPhi) {
37  throw cms::Exception("Configuration")
38  << "RecoTrackSelectorPhase: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi
39  << "). The range is constructed from minPhi to maxPhi around their average.";
40  }
41  if (minPhi >= M_PI) {
42  throw cms::Exception("Configuration")
43  << "RecoTrackSelectorPhase: minPhi (" << minPhi
44  << ") must be smaller than PI. The range is constructed from minPhi to maxPhi around their average.";
45  }
46  if (maxPhi <= -M_PI) {
47  throw cms::Exception("Configuration")
48  << "RecoTrackSelectorPhase: maxPhi (" << maxPhi
49  << ") must be larger than -PI. The range is constructed from minPhi to maxPhi around their average.";
50  }
51 
52  for (const std::string& quality : cfg.getParameter<std::vector<std::string> >("quality"))
54  for (const std::string& algorithm : cfg.getParameter<std::vector<std::string> >("algorithm"))
56  for (const std::string& algorithm : cfg.getParameter<std::vector<std::string> >("originalAlgorithm"))
58  for (const std::string& algorithm : cfg.getParameter<std::vector<std::string> >("algorithmMaskContains"))
60  }
61 
63  usePV_ = cfg.getParameter<bool>("usePV");
65  if (usePV_)
67  }
68 
69  void init(const edm::Event& event, const edm::EventSetup& es) {
71  event.getByToken(bsSrcToken_, beamSpot);
72  vertex_ = beamSpot->position();
73  if (!usePV_)
74  return;
76  event.getByToken(vertexToken_, hVtx);
77  if (hVtx->empty())
78  return;
79  vertex_ = (*hVtx)[0].position();
80  }
81 
82  bool operator()(const reco::TrackRef& tref) const { return (*this)(*tref); }
83 
84  bool operator()(const reco::Track& t) const { return (*this)(t, vertex_); }
85 
86  bool operator()(const reco::Track& t, const reco::Track::Point& vertex) const {
87  bool quality_ok = true;
88  if (!quality_.empty()) {
89  quality_ok = false;
90  for (unsigned int i = 0; i < quality_.size(); ++i) {
91  if (t.quality(quality_[i])) {
92  quality_ok = true;
93  break;
94  }
95  }
96  }
97 
98  bool algo_ok = true;
99  if (!algorithm_.empty()) {
100  if (std::find(algorithm_.begin(), algorithm_.end(), t.algo()) == algorithm_.end())
101  algo_ok = false;
102  }
103  if (!originalAlgorithm_.empty() && algo_ok) {
105  algo_ok = false;
106  }
107  if (!algorithmMask_.empty() && algo_ok) {
108  if (std::find_if(algorithmMask_.begin(),
109  algorithmMask_.end(),
110  // for some reason I have to either explicitly give the return type, or use static_cast<bool>()
111  [&](reco::TrackBase::TrackAlgorithm algo) -> bool { return t.algoMask()[algo]; }) ==
112  algorithmMask_.end())
113  algo_ok = false;
114  }
115 
116  const auto dphi = deltaPhi(t.phi(), meanPhi_);
117 
118  auto etaOk = [&](const reco::Track& p) -> bool {
119  float eta = p.eta();
120  if (!invertRapidityCut_)
121  return (eta >= minRapidity_) && (eta <= maxRapidity_);
122  else
123  return (eta < minRapidity_ || eta > maxRapidity_);
124  };
125 
126  return ((algo_ok & quality_ok) && t.hitPattern().numberOfValidHits() >= minHit_ &&
130  min3DLayer_ &&
131  fabs(t.pt()) >= ptMin_ && etaOk(t) && dphi >= -rangePhi_ && dphi <= rangePhi_ &&
132  fabs(t.dxy(vertex)) <= tip_ && fabs(t.dsz(vertex)) <= lip_ && t.normalizedChi2() <= maxChi2_);
133  }
134 
135 private:
136  double ptMin_;
137  double minRapidity_;
138  double maxRapidity_;
139  double meanPhi_;
140  double rangePhi_;
141  double tip_;
142  double lip_;
143  double maxChi2_;
144  int minHit_;
148  bool usePV_;
150 
153 
154  std::vector<reco::TrackBase::TrackQuality> quality_;
155  std::vector<reco::TrackBase::TrackAlgorithm> algorithm_;
156  std::vector<reco::TrackBase::TrackAlgorithm> originalAlgorithm_;
157  std::vector<reco::TrackBase::TrackAlgorithm> algorithmMask_;
158 
160 };
161 
162 #endif
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void init(const edm::Event &event, const edm::EventSetup &es)
tuple cfg
Definition: looper.py:296
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:593
uint32_t const *__restrict__ Quality * quality
int numberOfValidHits() const
Definition: HitPattern.h:811
RecoTrackSelectorBase(const edm::ParameterSet &cfg)
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:500
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
double dsz() const
dsz parameter (THIS IS NOT the SZ impact parameter to (0,0,0) if refPoint is far from (0...
Definition: TrackBase.h:614
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:521
TrackAlgorithm
track algorithm
Definition: TrackBase.h:89
reco::Track::Point vertex_
TrackAlgorithm algo() const
Definition: TrackBase.h:547
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
Definition: HitPattern.cc:356
double pt() const
track transverse momentum
Definition: TrackBase.h:637
std::vector< reco::TrackBase::TrackAlgorithm > algorithmMask_
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
std::vector< reco::TrackBase::TrackQuality > quality_
RecoTrackSelectorBase(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
#define M_PI
TrackAlgorithm originalAlgo() const
Definition: TrackBase.h:548
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
AlgoMask algoMask() const
Definition: TrackBase.h:415
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool operator()(const reco::Track &t) const
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:552
std::vector< reco::TrackBase::TrackAlgorithm > algorithm_
bool operator()(const reco::Track &t, const reco::Track::Point &vertex) const
edm::EDGetTokenT< reco::BeamSpot > bsSrcToken_
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
int numberOfValidPixelHits() const
Definition: HitPattern.h:825
bool operator()(const reco::TrackRef &tref) const
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:608
std::vector< reco::TrackBase::TrackAlgorithm > originalAlgorithm_