CMS 3D CMS Logo

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  const auto minPhi = cfg.getParameter<double>("minPhi");
34  const auto maxPhi = cfg.getParameter<double>("maxPhi");
35  if(minPhi >= maxPhi) {
36  throw cms::Exception("Configuration") << "RecoTrackSelectorPhase: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi << "). The range is constructed from minPhi to maxPhi around their average.";
37  }
38  if(minPhi >= M_PI) {
39  throw cms::Exception("Configuration") << "RecoTrackSelectorPhase: minPhi (" << minPhi << ") must be smaller than PI. The range is constructed from minPhi to maxPhi around their average.";
40  }
41  if(maxPhi <= -M_PI) {
42  throw cms::Exception("Configuration") << "RecoTrackSelectorPhase: maxPhi (" << maxPhi << ") must be larger than -PI. The range is constructed from minPhi to maxPhi around their average.";
43  }
44 
45  for(const std::string& quality: cfg.getParameter<std::vector<std::string> >("quality"))
47  for(const std::string& algorithm: cfg.getParameter<std::vector<std::string> >("algorithm"))
49  for(const std::string& algorithm: cfg.getParameter<std::vector<std::string> >("originalAlgorithm"))
51  for(const std::string& algorithm: cfg.getParameter<std::vector<std::string> >("algorithmMaskContains"))
53  }
54 
57  usePV_ = cfg.getParameter<bool>("usePV");
59  if (usePV_)
61  }
62 
63  void init(const edm::Event& event, const edm::EventSetup& es) {
65  event.getByToken(bsSrcToken_,beamSpot);
66  vertex_ = beamSpot->position();
67  if (!usePV_) return;
69  event.getByToken(vertexToken_, hVtx);
70  if (hVtx->empty()) return;
71  vertex_ = (*hVtx)[0].position();
72  }
73 
74  bool operator()( const reco::TrackRef& tref ) const {
75  return (*this)(*tref);
76  }
77 
78  bool operator()( const reco::Track & t) const {
79  return (*this)(t, vertex_);
80  }
81 
82  bool operator()(const reco::Track& t, const reco::Track::Point& vertex) const {
83 
84  bool quality_ok = true;
85  if (!quality_.empty()) {
86  quality_ok = false;
87  for (unsigned int i = 0; i<quality_.size();++i) {
88  if (t.quality(quality_[i])){
89  quality_ok = true;
90  break;
91  }
92  }
93  }
94 
95  bool algo_ok = true;
96  if (!algorithm_.empty()) {
97  if (std::find(algorithm_.begin(),algorithm_.end(),t.algo())==algorithm_.end()) algo_ok = false;
98  }
99  if (!originalAlgorithm_.empty() && algo_ok) {
100  if (std::find(originalAlgorithm_.begin(), originalAlgorithm_.end(), t.originalAlgo()) == originalAlgorithm_.end()) algo_ok = false;
101  }
102  if(!algorithmMask_.empty() && algo_ok) {
103  if(std::find_if(algorithmMask_.begin(), algorithmMask_.end(), [&](reco::TrackBase::TrackAlgorithm algo) -> bool { // for some reason I have to either explicitly give the return type, or use static_cast<bool>()
104  return t.algoMask()[algo];
105  }) == algorithmMask_.end()) algo_ok = false;
106  }
107 
108  const auto dphi = deltaPhi(t.phi(), meanPhi_);
109 
110  return
111  (
112  (algo_ok & quality_ok) &&
118  fabs(t.pt()) >= ptMin_ &&
119  t.eta() >= minRapidity_ && t.eta() <= maxRapidity_ &&
120  dphi >= -rangePhi_ && dphi <= rangePhi_ &&
121  fabs(t.dxy(vertex)) <= tip_ &&
122  fabs(t.dsz(vertex)) <= lip_ &&
124  );
125  }
126 
127 
128 private:
129  double ptMin_;
130  double minRapidity_;
131  double maxRapidity_;
132  double meanPhi_;
133  double rangePhi_;
134  double tip_;
135  double lip_;
136  double maxChi2_;
137  int minHit_;
141  bool usePV_;
142 
145 
146  std::vector<reco::TrackBase::TrackQuality> quality_;
147  std::vector<reco::TrackBase::TrackAlgorithm> algorithm_;
148  std::vector<reco::TrackBase::TrackAlgorithm> originalAlgorithm_;
149  std::vector<reco::TrackBase::TrackAlgorithm> algorithmMask_;
150 
152 };
153 
154 #endif
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
void init(const edm::Event &event, const edm::EventSetup &es)
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:561
int numberOfValidHits() const
Definition: HitPattern.h:824
RecoTrackSelectorBase(const edm::ParameterSet &cfg)
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:501
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
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:603
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:520
TrackAlgorithm
track algorithm
Definition: TrackBase.h:99
reco::Track::Point vertex_
TrackAlgorithm algo() const
Definition: TrackBase.h:497
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
Definition: HitPattern.cc:343
double pt() const
track transverse momentum
Definition: TrackBase.h:621
std::vector< reco::TrackBase::TrackAlgorithm > algorithmMask_
math::XYZPoint Point
point in the space
Definition: TrackBase.h:83
std::vector< reco::TrackBase::TrackQuality > quality_
RecoTrackSelectorBase(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
#define M_PI
TrackAlgorithm originalAlgo() const
Definition: TrackBase.h:501
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
AlgoMask algoMask() const
Definition: TrackBase.h:364
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
bool operator()(const reco::Track &t) const
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
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:839
bool operator()(const reco::TrackRef &tref) const
const Point & position() const
position
Definition: BeamSpot.h:62
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:591
std::vector< reco::TrackBase::TrackAlgorithm > originalAlgorithm_
Definition: event.py:1