CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackCutClassifier.cc
Go to the documentation of this file.
2 
3 
5 
6 #include <cassert>
7 
8 #include "getBestVertex.h"
9 
10 
11 namespace {
12 
13 
14  void fillArrayF(float * x,const edm::ParameterSet & cfg, const char * name) {
15  auto v = cfg.getParameter< std::vector<double> >(name);
16  assert(v.size()==3);
18  }
19 
20  void fillArrayI(int * x,const edm::ParameterSet & cfg, const char * name) {
21  auto v = cfg.getParameter< std::vector<int> >(name);
22  assert(v.size()==3);
24  }
25 
26  // fake mva value to return for loose,tight,hp
27  constexpr float mvaVal[3] = {-.5,.5,1.};
28 
29  template<typename T,typename Comp>
30  inline float cut(T val, const T * cuts, Comp comp) {
31  for (int i=2; i>=0; --i) {
32  if ( comp(val,cuts[i]) ) return mvaVal[i];
33  }
34  return -1.f;
35  }
36 
37  inline float chi2(reco::Track const & tk) { return tk.normalizedChi2();}
38 
39  inline int lostLayers(reco::Track const & tk) {
41  }
42 
43  inline int n3DLayers(reco::Track const & tk) {
46  }
47 
48  inline int nPixelHits(reco::Track const & tk) {
49  return tk.hitPattern().numberOfValidPixelHits();
50  }
51 
52  inline float dz(reco::Track const & trk, Point const & bestVertex) {
53  return std::abs(trk.dz(bestVertex));
54  }
55  inline float dr(reco::Track const & trk, Point const & bestVertex) {
56  return std::abs(trk.dxy(bestVertex));
57  }
58 
59  struct Cuts {
60 
61  Cuts(const edm::ParameterSet & cfg) {
62  fillArrayF(maxChi2,cfg,"maxChi2");
63  fillArrayF(maxChi2n,cfg,"maxChi2n");
64  fillArrayI(minPixelHits,cfg,"minPixelHits");
65  fillArrayI(min3DLayers,cfg,"min3DLayers");
66  fillArrayI(minLayers,cfg,"minLayers");
67  fillArrayI(maxLostLayers,cfg,"maxLostLayers");
68  fillArrayF(maxDz,cfg,"maxDz");
69  fillArrayF(maxDr,cfg,"maxDr");
70 
71  }
72 
73 
74 
75  float operator()(reco::Track const & trk,
76  reco::BeamSpot const & beamSpot,
78  GBRForest const *) const {
79 
80 
81 
82  float ret = 1.f;
83  auto nLayers = trk.hitPattern().trackerLayersWithMeasurement();
84  ret = std::min(ret,cut(nLayers,minLayers,std::greater_equal<int>()));
85  if (ret==-1.f) return ret;
86 
87  ret = std::min(ret,cut(chi2(trk)/float(nLayers),maxChi2n,std::less_equal<float>()));
88  if (ret==-1.f) return ret;
89  ret = std::min(ret,cut(chi2(trk),maxChi2,std::less_equal<float>()));
90  if (ret==-1.f) return ret;
91 
92  ret = std::min(ret,cut(n3DLayers(trk),min3DLayers,std::greater_equal<int>()));
93  if (ret==-1.f) return ret;
94  ret = std::min(ret,cut(nPixelHits(trk),minPixelHits,std::greater_equal<int>()));
95  if (ret==-1.f) return ret;
96  ret = std::min(ret,cut(lostLayers(trk),maxLostLayers,std::less_equal<int>()));
97 
99  if (ret==-1.f) return ret;
100  Point bestVertex = getBestVertex(trk,vertices);
101  ret = std::min(ret,cut(dz(trk,bestVertex), maxDz,std::less_equal<float>()));
102  ret = std::min(ret,cut(dr(trk,bestVertex), maxDr,std::less_equal<float>()));
103  }
104 
105 
106 
107  return ret;
108 
109  }
110 
111 
112 
113  static const char * name() { return "TrackCutClassifier";}
114 
115  static void fillDescriptions(edm::ParameterSetDescription & desc) {
116  desc.add<std::vector<int>>("minPixelHits",{0,0,1});
117  desc.add<std::vector<int>>("minLayers",{3,4,5});
118  desc.add<std::vector<int>>("min3DLayers",{1,2,3});
119  desc.add<std::vector<int>>("maxLostLayers",{99,3,3});
120  desc.add<std::vector<double>>("maxChi2",{9999.,25.,16.});
121  desc.add<std::vector<double>>("maxChi2n",{9999.,1.0,0.4});
124 
125  }
126 
127 
128  float maxChi2[3];
129  float maxChi2n[3];
130  int minLayers[3];
131  int min3DLayers[3];
132  int minPixelHits[3];
133  int maxLostLayers[3];
134  float maxDz[3];
135  float maxDr[3];
136 
137  };
138 
139 
140  using TrackCutClassifier = TrackMVAClassifier<Cuts>;
141 
142 }
143 
146 
147 DEFINE_FWK_MODULE(TrackCutClassifier);
148 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
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:548
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:497
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:516
#define constexpr
T x() const
Cartesian x coordinate.
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
Definition: HitPattern.cc:339
math::XYZPoint Point
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
#define end
Definition: vmac.h:37
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:596
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:437
int trackerLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:533
#define begin
Definition: vmac.h:30
int numberOfValidPixelHits() const
Definition: HitPattern.h:816
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:578
long double T