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_(cfg.getParameter<bool>("usePV")),
33  bsSrcToken_(iC.consumes<reco::BeamSpot>(cfg.getParameter<edm::InputTag>("beamSpot"))) {
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") << "RecoTrackSelectorPhase: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi << "). The range is constructed from minPhi to maxPhi around their average.";
38  }
39  if(minPhi >= M_PI) {
40  throw cms::Exception("Configuration") << "RecoTrackSelectorPhase: minPhi (" << minPhi << ") must be smaller than PI. The range is constructed from minPhi to maxPhi around their average.";
41  }
42  if(maxPhi <= -M_PI) {
43  throw cms::Exception("Configuration") << "RecoTrackSelectorPhase: maxPhi (" << maxPhi << ") must be larger than -PI. The range is constructed from minPhi to maxPhi around their average.";
44  }
45 
46  if (usePV_)
48  for(const std::string& quality: cfg.getParameter<std::vector<std::string> >("quality"))
50  for(const std::string& algorithm: cfg.getParameter<std::vector<std::string> >("algorithm"))
52  for(const std::string& algorithm: cfg.getParameter<std::vector<std::string> >("originalAlgorithm"))
54  for(const std::string& algorithm: cfg.getParameter<std::vector<std::string> >("algorithmMaskContains"))
56  }
57 
58  void init(const edm::Event& event, const edm::EventSetup& es) {
60  event.getByToken(bsSrcToken_,beamSpot);
61  vertex_ = beamSpot->position();
62  if (!usePV_) return;
64  event.getByToken(vertexToken_, hVtx);
65  if (hVtx->empty()) return;
66  vertex_ = (*hVtx)[0].position();
67  }
68 
69  bool operator()( const reco::TrackRef& tref ) const {
70  return (*this)(*tref);
71  }
72 
73  bool operator()( const reco::Track & t) const {
74  bool quality_ok = true;
75  if (quality_.size()!=0) {
76  quality_ok = false;
77  for (unsigned int i = 0; i<quality_.size();++i) {
78  if (t.quality(quality_[i])){
79  quality_ok = true;
80  break;
81  }
82  }
83  }
84 
85  bool algo_ok = true;
86  if (algorithm_.size()!=0) {
87  if (std::find(algorithm_.begin(),algorithm_.end(),t.algo())==algorithm_.end()) algo_ok = false;
88  }
89  if (!originalAlgorithm_.empty() && algo_ok) {
90  if (std::find(originalAlgorithm_.begin(), originalAlgorithm_.end(), t.originalAlgo()) == originalAlgorithm_.end()) algo_ok = false;
91  }
92  if(!algorithmMask_.empty() && algo_ok) {
93  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>()
94  return t.algoMask()[algo];
95  }) == algorithmMask_.end()) algo_ok = false;
96  }
97 
98  const auto dphi = deltaPhi(t.phi(), meanPhi_);
99 
100  return
101  (
102  (algo_ok & quality_ok) &&
108  fabs(t.pt()) >= ptMin_ &&
109  t.eta() >= minRapidity_ && t.eta() <= maxRapidity_ &&
110  dphi >= -rangePhi_ && dphi <= rangePhi_ &&
111  fabs(t.dxy(vertex_)) <= tip_ &&
112  fabs(t.dsz(vertex_)) <= lip_ &&
114  );
115  }
116 
117 
118 private:
119  double ptMin_;
120  double minRapidity_;
121  double maxRapidity_;
122  double meanPhi_;
123  double rangePhi_;
124  double tip_;
125  double lip_;
126  double maxChi2_;
127  int minHit_;
131  bool usePV_;
132 
135 
136  std::vector<reco::TrackBase::TrackQuality> quality_;
137  std::vector<reco::TrackBase::TrackAlgorithm> algorithm_;
138  std::vector<reco::TrackBase::TrackAlgorithm> originalAlgorithm_;
139  std::vector<reco::TrackBase::TrackAlgorithm> algorithmMask_;
140 
142 };
143 
144 #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:823
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:493
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:512
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:335
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_
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::BeamSpot > bsSrcToken_
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
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