CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiTrackSelector.cc
Go to the documentation of this file.
1 #include "MultiTrackSelector.h"
2 
8 
9 #include <Math/DistFunc.h>
10 #include <TMath.h>
11 #include <TFile.h>
12 
13 using namespace reco;
14 
16 {
17  useForestFromDB_ = true;
18  forest_ = nullptr;
19 }
20 
22  src_( consumes<reco::TrackCollection>( cfg.getParameter<edm::InputTag>( "src" ) ) ),
23  beamspot_( consumes<reco::BeamSpot>( cfg.getParameter<edm::InputTag>( "beamspot" ) ) ),
24  useVertices_( cfg.getParameter<bool>( "useVertices" ) ),
25  useVtxError_( cfg.getParameter<bool>( "useVtxError" ) )
26  // now get the pset for each selector
27 {
28  if (useVertices_) vertices_ = consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>( "vertices" ));
29 
30  useAnyMVA_ = false;
31  forestLabel_ = "MVASelectorIter0";
32  std::string type = "BDTG";
33  useForestFromDB_ = true;
34  dbFileName_ = "";
35 
36  forest_ = nullptr;
37 
38  if(cfg.exists("useAnyMVA")) useAnyMVA_ = cfg.getParameter<bool>("useAnyMVA");
39 
40  if(useAnyMVA_){
41  if(cfg.exists("mvaType"))type = cfg.getParameter<std::string>("mvaType");
42  if(cfg.exists("GBRForestLabel"))forestLabel_ = cfg.getParameter<std::string>("GBRForestLabel");
43  if(cfg.exists("GBRForestFileName")){
44  dbFileName_ = cfg.getParameter<std::string>("GBRForestFileName");
45  useForestFromDB_ = false;
46  }
47 
48  mvaType_ = type;
49  }
50  std::vector<edm::ParameterSet> trkSelectors( cfg.getParameter<std::vector< edm::ParameterSet> >("trackSelectors") );
51  qualityToSet_.reserve(trkSelectors.size());
52  vtxNumber_.reserve(trkSelectors.size());
53  vertexCut_.reserve(trkSelectors.size());
54  res_par_.reserve(trkSelectors.size());
55  chi2n_par_.reserve(trkSelectors.size());
56  chi2n_no1Dmod_par_.reserve(trkSelectors.size());
57  d0_par1_.reserve(trkSelectors.size());
58  dz_par1_.reserve(trkSelectors.size());
59  d0_par2_.reserve(trkSelectors.size());
60  dz_par2_.reserve(trkSelectors.size());
61  applyAdaptedPVCuts_.reserve(trkSelectors.size());
62  max_d0_.reserve(trkSelectors.size());
63  max_z0_.reserve(trkSelectors.size());
64  nSigmaZ_.reserve(trkSelectors.size());
65  min_layers_.reserve(trkSelectors.size());
66  min_3Dlayers_.reserve(trkSelectors.size());
67  max_lostLayers_.reserve(trkSelectors.size());
68  min_hits_bypass_.reserve(trkSelectors.size());
69  applyAbsCutsIfNoPV_.reserve(trkSelectors.size());
70  max_d0NoPV_.reserve(trkSelectors.size());
71  max_z0NoPV_.reserve(trkSelectors.size());
72  preFilter_.reserve(trkSelectors.size());
73  max_relpterr_.reserve(trkSelectors.size());
74  min_nhits_.reserve(trkSelectors.size());
75  max_minMissHitOutOrIn_.reserve(trkSelectors.size());
76  max_lostHitFraction_.reserve(trkSelectors.size());
77  min_eta_.reserve(trkSelectors.size());
78  max_eta_.reserve(trkSelectors.size());
79  useMVA_.reserve(trkSelectors.size());
80  //mvaReaders_.reserve(trkSelectors.size());
81  min_MVA_.reserve(trkSelectors.size());
82  //mvaType_.reserve(trkSelectors.size());
83 
84  produces<edm::ValueMap<float> >("MVAVals");
85 
86  for ( unsigned int i=0; i<trkSelectors.size(); i++) {
87 
88  qualityToSet_.push_back( TrackBase::undefQuality );
89  // parameters for vertex selection
90  vtxNumber_.push_back( useVertices_ ? trkSelectors[i].getParameter<int32_t>("vtxNumber") : 0 );
91  vertexCut_.push_back( useVertices_ ? trkSelectors[i].getParameter<std::string>("vertexCut") : 0);
92  // parameters for adapted optimal cuts on chi2 and primary vertex compatibility
93  res_par_.push_back(trkSelectors[i].getParameter< std::vector<double> >("res_par") );
94  chi2n_par_.push_back( trkSelectors[i].getParameter<double>("chi2n_par") );
95  chi2n_no1Dmod_par_.push_back( trkSelectors[i].getParameter<double>("chi2n_no1Dmod_par") );
96  d0_par1_.push_back(trkSelectors[i].getParameter< std::vector<double> >("d0_par1"));
97  dz_par1_.push_back(trkSelectors[i].getParameter< std::vector<double> >("dz_par1"));
98  d0_par2_.push_back(trkSelectors[i].getParameter< std::vector<double> >("d0_par2"));
99  dz_par2_.push_back(trkSelectors[i].getParameter< std::vector<double> >("dz_par2"));
100  // Boolean indicating if adapted primary vertex compatibility cuts are to be applied.
101  applyAdaptedPVCuts_.push_back(trkSelectors[i].getParameter<bool>("applyAdaptedPVCuts"));
102  // Impact parameter absolute cuts.
103  max_d0_.push_back(trkSelectors[i].getParameter<double>("max_d0"));
104  max_z0_.push_back(trkSelectors[i].getParameter<double>("max_z0"));
105  nSigmaZ_.push_back(trkSelectors[i].getParameter<double>("nSigmaZ"));
106  // Cuts on numbers of layers with hits/3D hits/lost hits.
107  min_layers_.push_back(trkSelectors[i].getParameter<uint32_t>("minNumberLayers") );
108  min_3Dlayers_.push_back(trkSelectors[i].getParameter<uint32_t>("minNumber3DLayers") );
109  max_lostLayers_.push_back(trkSelectors[i].getParameter<uint32_t>("maxNumberLostLayers"));
110  min_hits_bypass_.push_back(trkSelectors[i].getParameter<uint32_t>("minHitsToBypassChecks"));
111  // Flag to apply absolute cuts if no PV passes the selection
112  applyAbsCutsIfNoPV_.push_back(trkSelectors[i].getParameter<bool>("applyAbsCutsIfNoPV"));
113  keepAllTracks_.push_back( trkSelectors[i].getParameter<bool>("keepAllTracks"));
114  max_relpterr_.push_back(trkSelectors[i].getParameter<double>("max_relpterr"));
115  min_nhits_.push_back(trkSelectors[i].getParameter<uint32_t>("min_nhits"));
116  max_minMissHitOutOrIn_.push_back(
117  trkSelectors[i].existsAs<int32_t>("max_minMissHitOutOrIn") ?
118  trkSelectors[i].getParameter<int32_t>("max_minMissHitOutOrIn") : 99);
119  max_lostHitFraction_.push_back(
120  trkSelectors[i].existsAs<double>("max_lostHitFraction") ?
121  trkSelectors[i].getParameter<double>("max_lostHitFraction") : 1.0);
122  min_eta_.push_back(trkSelectors[i].existsAs<double>("min_eta") ?
123  trkSelectors[i].getParameter<double>("min_eta"):-9999);
124  max_eta_.push_back(trkSelectors[i].existsAs<double>("max_eta") ?
125  trkSelectors[i].getParameter<double>("max_eta"):9999);
126 
127  setQualityBit_.push_back( false );
128  std::string qualityStr = trkSelectors[i].getParameter<std::string>("qualityBit");
129  if (qualityStr != "") {
130  setQualityBit_[i] = true;
131  qualityToSet_[i] = TrackBase::qualityByName(trkSelectors[i].getParameter<std::string>("qualityBit"));
132  }
133 
134  if (setQualityBit_[i] && (qualityToSet_[i] == TrackBase::undefQuality)) throw cms::Exception("Configuration") <<
135  "You can't set the quality bit " << trkSelectors[i].getParameter<std::string>("qualityBit") << " as it is 'undefQuality' or unknown.\n";
136 
137  if (applyAbsCutsIfNoPV_[i]) {
138  max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>("max_d0NoPV"));
139  max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>("max_z0NoPV"));
140  }
141  else{//dummy values
142  max_d0NoPV_.push_back(0.);
143  max_z0NoPV_.push_back(0.);
144  }
145 
146  name_.push_back( trkSelectors[i].getParameter<std::string>("name") );
147 
148  preFilter_[i]=trkSelectors.size(); // no prefilter
149 
150  std::string pfName=trkSelectors[i].getParameter<std::string>("preFilterName");
151  if (pfName!="") {
152  bool foundPF=false;
153  for ( unsigned int j=0; j<i; j++)
154  if (name_[j]==pfName ) {
155  foundPF=true;
156  preFilter_[i]=j;
157  }
158  if ( !foundPF)
159  throw cms::Exception("Configuration") << "Invalid prefilter name in MultiTrackSelector "
160  << trkSelectors[i].getParameter<std::string>("preFilterName");
161 
162  }
163 
164  // produces<std::vector<int> >(name_[i]).setBranchAlias( name_[i] + "TrackQuals");
165  produces<edm::ValueMap<int> >(name_[i]).setBranchAlias( name_[i] + "TrackQuals");
166  if(useAnyMVA_){
167  bool thisMVA = false;
168  if(trkSelectors[i].exists("useMVA"))thisMVA = trkSelectors[i].getParameter<bool>("useMVA");
169  useMVA_.push_back(thisMVA);
170  if(thisMVA){
171  double minVal = -1;
172  if(trkSelectors[i].exists("minMVA"))minVal = trkSelectors[i].getParameter<double>("minMVA");
173  min_MVA_.push_back(minVal);
174 
175  }else{
176  min_MVA_.push_back(-9999.0);
177  }
178  }else{
179  min_MVA_.push_back(-9999.0);
180  }
181 
182  }
183 }
184 
186  delete forest_;
187 }
188 
189 
191  if(!useForestFromDB_){
192  TFile gbrfile(dbFileName_.c_str());
193  forest_ = (GBRForest*)gbrfile.Get(forestLabel_.c_str());
194  }
195 
196 }
197 
198 
199 
201 {
202  using namespace std;
203  using namespace edm;
204  using namespace reco;
205 
206  // Get tracks
207  Handle<TrackCollection> hSrcTrack;
208  evt.getByToken( src_, hSrcTrack );
209  const TrackCollection& srcTracks(*hSrcTrack);
210 
211  // looking for the beam spot
213  evt.getByToken(beamspot_, hBsp);
214  const reco::BeamSpot& vertexBeamSpot(*hBsp);
215 
216 
217  // Select good primary vertices for use in subsequent track selection
219  if (useVertices_) evt.getByToken(vertices_, hVtx);
220 
221  unsigned int trkSize=srcTracks.size();
222  std::vector<int> selTracksSave( qualityToSet_.size()*trkSize,0);
223 
224  std::vector<float> mvaVals_(srcTracks.size(),-99.f);
225  processMVA(evt,es, mvaVals_);
226 
227  for (unsigned int i=0; i<qualityToSet_.size(); i++) {
228  std::vector<int> selTracks(trkSize,0);
229  auto_ptr<edm::ValueMap<int> > selTracksValueMap = auto_ptr<edm::ValueMap<int> >(new edm::ValueMap<int>);
230  edm::ValueMap<int>::Filler filler(*selTracksValueMap);
231 
232  std::vector<Point> points;
233  std::vector<float> vterr, vzerr;
234  if (useVertices_) selectVertices(i,*hVtx, points, vterr, vzerr);
235 
236  // Loop over tracks
237  size_t current = 0;
238  for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
239  const Track & trk = * it;
240  // Check if this track passes cuts
241 
242  LogTrace("TrackSelection") << "ready to check track with pt="<< trk.pt() ;
243 
244  //already removed
245  bool ok=true;
246  if (preFilter_[i]<i && selTracksSave[preFilter_[i]*trkSize+current] < 0) {
247  selTracks[current]=-1;
248  ok=false;
249  if ( !keepAllTracks_[i])
250  continue;
251  }
252  else {
253  float mvaVal = 0;
254  if(useAnyMVA_) mvaVal = mvaVals_[current];
255  ok = select(i,vertexBeamSpot, trk, points, vterr, vzerr,mvaVal);
256  if (!ok) {
257  LogTrace("TrackSelection") << "track with pt="<< trk.pt() << " NOT selected";
258  if (!keepAllTracks_[i]) {
259  selTracks[current]=-1;
260  continue;
261  }
262  }
263  else
264  LogTrace("TrackSelection") << "track with pt="<< trk.pt() << " selected";
265  }
266 
267  if (preFilter_[i]<i ) {
268  selTracks[current]=selTracksSave[preFilter_[i]*trkSize+current];
269  }
270  else {
271  selTracks[current]=trk.qualityMask();
272  }
273  if ( ok && setQualityBit_[i]) {
274  selTracks[current]= (selTracks[current] | (1<<qualityToSet_[i]));
275  if (qualityToSet_[i]==TrackBase::tight) {
276  selTracks[current]=(selTracks[current] | (1<<TrackBase::loose));
277  }
278  else if (qualityToSet_[i]==TrackBase::highPurity) {
279  selTracks[current]=(selTracks[current] | (1<<TrackBase::loose));
280  selTracks[current]=(selTracks[current] | (1<<TrackBase::tight));
281  }
282  if (!points.empty()) {
283  if (qualityToSet_[i]==TrackBase::loose) {
284  selTracks[current]=(selTracks[current] | (1<<TrackBase::looseSetWithPV));
285  }
286  else if (qualityToSet_[i]==TrackBase::highPurity) {
287  selTracks[current]=(selTracks[current] | (1<<TrackBase::looseSetWithPV));
288  selTracks[current]=(selTracks[current] | (1<<TrackBase::highPuritySetWithPV));
289  }
290  }
291  }
292  }
293  for ( unsigned int j=0; j< trkSize; j++ ) selTracksSave[j+i*trkSize]=selTracks[j];
294  filler.insert(hSrcTrack, selTracks.begin(),selTracks.end());
295  filler.fill();
296 
297  // evt.put(selTracks,name_[i]);
298  evt.put(selTracksValueMap,name_[i]);
299  }
300 }
301 
302 
303  bool MultiTrackSelector::select(unsigned int tsNum,
304  const reco::BeamSpot &vertexBeamSpot,
305  const reco::Track &tk,
306  const std::vector<Point> &points,
307  std::vector<float> &vterr,
308  std::vector<float> &vzerr,
309  double mvaVal) const {
310  // Decide if the given track passes selection cuts.
311 
312  using namespace std;
313 
314  if(tk.found()>=min_hits_bypass_[tsNum]) return true;
315  if ( tk.ndof() < 1E-5 ) return false;
316 
317  // Cuts on numbers of layers with hits/3D hits/lost hits.
318  uint32_t nlayers = tk.hitPattern().trackerLayersWithMeasurement();
319  uint32_t nlayers3D = tk.hitPattern().pixelLayersWithMeasurement() +
322  LogDebug("TrackSelection") << "cuts on nlayers: " << nlayers << " " << nlayers3D << " " << nlayersLost << " vs "
323  << min_layers_[tsNum] << " " << min_3Dlayers_[tsNum] << " " << max_lostLayers_[tsNum];
324  if (nlayers < min_layers_[tsNum]) return false;
325  if (nlayers3D < min_3Dlayers_[tsNum]) return false;
326  if (nlayersLost > max_lostLayers_[tsNum]) return false;
327  LogTrace("TrackSelection") << "cuts on nlayers passed";
328 
329  float chi2n = tk.normalizedChi2();
330  float chi2n_no1Dmod = chi2n;
331 
332  int count1dhits = 0;
333  for (trackingRecHit_iterator ith = tk.recHitsBegin(), edh = tk.recHitsEnd(); ith != edh; ++ith) {
334  const TrackingRecHit * hit = ith->get();
335  if (hit->isValid()) {
336  if (typeid(*hit) == typeid(SiStripRecHit1D)) ++count1dhits;
337  }
338  }
339  if (count1dhits > 0) {
340  float chi2 = tk.chi2();
341  float ndof = tk.ndof();
342  chi2n = (chi2+count1dhits)/float(ndof+count1dhits);
343  }
344  // For each 1D rechit, the chi^2 and ndof is increased by one. This is a way of retaining approximately
345  // the same normalized chi^2 distribution as with 2D rechits.
346  if (chi2n > chi2n_par_[tsNum]*nlayers) return false;
347 
348  if (chi2n_no1Dmod > chi2n_no1Dmod_par_[tsNum]*nlayers) return false;
349 
350  // Get track parameters
351  float pt = std::max(float(tk.pt()),0.000001f);
352  float eta = tk.eta();
353  if (eta<min_eta_[tsNum] || eta>max_eta_[tsNum]) return false;
354 
355  //cuts on relative error on pt and number of valid hits
356  float relpterr = float(tk.ptError())/pt;
357  uint32_t nhits = tk.numberOfValidHits();
358  if(relpterr > max_relpterr_[tsNum]) return false;
359  if(nhits < min_nhits_[tsNum]) return false;
360 
363  int minLost = std::min(lostIn,lostOut);
364  if (minLost > max_minMissHitOutOrIn_[tsNum]) return false;
365  float lostMidFrac = tk.numberOfLostHits() / (tk.numberOfValidHits() + tk.numberOfLostHits());
366  if (lostMidFrac > max_lostHitFraction_[tsNum]) return false;
367 
368 
369 
371  //Adding the MVA selection before vertex cuts//
373 
374  if(useAnyMVA_ && useMVA_[tsNum]){
375  if(mvaVal < min_MVA_[tsNum])return false;
376  }
377 
379  //End of MVA selection section//
381 
382  //other track parameters
383  float d0 = -tk.dxy(vertexBeamSpot.position()), d0E = tk.d0Error(),
384  dz = tk.dz(vertexBeamSpot.position()), dzE = tk.dzError();
385 
386  // parametrized d0 resolution for the track pt
387  float nomd0E = sqrt(res_par_[tsNum][0]*res_par_[tsNum][0]+(res_par_[tsNum][1]/pt)*(res_par_[tsNum][1]/pt));
388  // parametrized z0 resolution for the track pt and eta
389  float nomdzE = nomd0E*(std::cosh(eta));
390 
391  float dzCut = min( pow(dz_par1_[tsNum][0]*nlayers,dz_par1_[tsNum][1])*nomdzE,
392  pow(dz_par2_[tsNum][0]*nlayers,dz_par2_[tsNum][1])*dzE );
393  float d0Cut = min( pow(d0_par1_[tsNum][0]*nlayers,d0_par1_[tsNum][1])*nomd0E,
394  pow(d0_par2_[tsNum][0]*nlayers,d0_par2_[tsNum][1])*d0E );
395 
396 
397  // ---- PrimaryVertex compatibility cut
398  bool primaryVertexZCompatibility(false);
399  bool primaryVertexD0Compatibility(false);
400 
401  if (points.empty()) { //If not primaryVertices are reconstructed, check just the compatibility with the BS
402  //z0 within (n sigma + dzCut) of the beam spot z, if no good vertex is found
403  if ( abs(dz) < hypot(vertexBeamSpot.sigmaZ()*nSigmaZ_[tsNum],dzCut) ) primaryVertexZCompatibility = true;
404  // d0 compatibility with beam line
405  if (abs(d0) < d0Cut) primaryVertexD0Compatibility = true;
406  }
407 
408  int iv=0;
409  for (std::vector<Point>::const_iterator point = points.begin(), end = points.end(); point != end; ++point) {
410  LogTrace("TrackSelection") << "Test track w.r.t. vertex with z position " << point->z();
411  if(primaryVertexZCompatibility && primaryVertexD0Compatibility) break;
412  float dzPV = tk.dz(*point); //re-evaluate the dz with respect to the vertex position
413  float d0PV = tk.dxy(*point); //re-evaluate the dxy with respect to the vertex position
414  if(useVtxError_){
415  float dzErrPV = sqrt(dzE*dzE+vzerr[iv]*vzerr[iv]); // include vertex error in z
416  float d0ErrPV = sqrt(d0E*d0E+vterr[iv]*vterr[iv]); // include vertex error in xy
417  iv++;
418  if (abs(dzPV) < dz_par1_[tsNum][0]*pow(nlayers,dz_par1_[tsNum][1])*nomdzE &&
419  abs(dzPV) < dz_par2_[tsNum][0]*pow(nlayers,dz_par2_[tsNum][1])*dzErrPV &&
420  abs(dzPV) < max_z0_[tsNum]) primaryVertexZCompatibility = true;
421  if (abs(d0PV) < d0_par1_[tsNum][0]*pow(nlayers,d0_par1_[tsNum][1])*nomd0E &&
422  abs(d0PV) < d0_par2_[tsNum][0]*pow(nlayers,d0_par2_[tsNum][1])*d0ErrPV &&
423  abs(d0PV) < max_d0_[tsNum]) primaryVertexD0Compatibility = true;
424  }else{
425  if (abs(dzPV) < dzCut) primaryVertexZCompatibility = true;
426  if (abs(d0PV) < d0Cut) primaryVertexD0Compatibility = true;
427  }
428  LogTrace("TrackSelection") << "distances " << dzPV << " " << d0PV << " vs " << dzCut << " " << d0Cut;
429  }
430 
431  if (points.empty() && applyAbsCutsIfNoPV_[tsNum]) {
432  if ( abs(dz) > max_z0NoPV_[tsNum] || abs(d0) > max_d0NoPV_[tsNum]) return false;
433  } else {
434  // Absolute cuts on all tracks impact parameters with respect to beam-spot.
435  // If BS is not compatible, verify if at least the reco-vertex is compatible (useful for incorrect BS settings)
436  if (abs(d0) > max_d0_[tsNum] && !primaryVertexD0Compatibility) return false;
437  LogTrace("TrackSelection") << "absolute cuts on d0 passed";
438  if (abs(dz) > max_z0_[tsNum] && !primaryVertexZCompatibility) return false;
439  LogTrace("TrackSelection") << "absolute cuts on dz passed";
440  }
441 
442  LogTrace("TrackSelection") << "cuts on PV: apply adapted PV cuts? " << applyAdaptedPVCuts_[tsNum]
443  << " d0 compatibility? " << primaryVertexD0Compatibility
444  << " z compatibility? " << primaryVertexZCompatibility ;
445 
446  if (applyAdaptedPVCuts_[tsNum]) {
447  return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
448  } else {
449  return true;
450  }
451 
452 }
453 
454  void MultiTrackSelector::selectVertices(unsigned int tsNum,
455  const reco::VertexCollection &vtxs,
456  std::vector<Point> &points,
457  std::vector<float> &vterr,
458  std::vector<float> &vzerr) const {
459  // Select good primary vertices
460  using namespace reco;
461  int32_t toTake = vtxNumber_[tsNum];
462  for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
463 
464  LogDebug("SelectVertex") << " select vertex with z position " << it->z() << " "
465  << it->chi2() << " " << it->ndof() << " " << TMath::Prob(it->chi2(), static_cast<int32_t>(it->ndof()));
466  Vertex vtx = *it;
467  bool pass = vertexCut_[tsNum]( vtx );
468  if( pass ) {
469  points.push_back(it->position());
470  vterr.push_back(sqrt(it->yError()*it->xError()));
471  vzerr.push_back(it->zError());
472  LogTrace("SelectVertex") << " SELECTED vertex with z position " << it->z();
473  toTake--; if (toTake == 0) break;
474  }
475  }
476 }
477 
478 void MultiTrackSelector::processMVA(edm::Event& evt, const edm::EventSetup& es, std::vector<float> & mvaVals_) const
479 {
480 
481  using namespace std;
482  using namespace edm;
483  using namespace reco;
484 
485  // Get tracks
486  Handle<TrackCollection> hSrcTrack;
487  evt.getByToken( src_, hSrcTrack );
488  const TrackCollection& srcTracks(*hSrcTrack);
489  assert(mvaVals_.size()==srcTracks.size());
490 
491  auto_ptr<edm::ValueMap<float> >mvaValValueMap = auto_ptr<edm::ValueMap<float> >(new edm::ValueMap<float>);
492  edm::ValueMap<float>::Filler mvaFiller(*mvaValValueMap);
493 
494 
495  if(!useAnyMVA_){
496  // mvaVals_ already initalized...
497  mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
498  mvaFiller.fill();
499  evt.put(mvaValValueMap,"MVAVals");
500  return;
501  }
502 
503 
504  size_t current = 0;
505  for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
506  const Track & trk = * it;
507  auto tmva_ndof_ = trk.ndof();
508  auto tmva_nlayers_ = trk.hitPattern().trackerLayersWithMeasurement();
509  auto tmva_nlayers3D_ = trk.hitPattern().pixelLayersWithMeasurement()
512  float chi2n = trk.normalizedChi2();
513  float chi2n_no1Dmod = chi2n;
514 
515  int count1dhits = 0;
516  for (trackingRecHit_iterator ith = trk.recHitsBegin(), edh = trk.recHitsEnd(); ith != edh; ++ith) {
517  const TrackingRecHit * hit = ith->get();
518  if ((*hit).dimension()==1) ++count1dhits;
519  }
520  if (count1dhits > 0) {
521  float chi2 = trk.chi2();
522  float ndof = trk.ndof();
523  chi2n = (chi2+count1dhits)/float(ndof+count1dhits);
524  }
525  auto tmva_chi2n_ = chi2n;
526  auto tmva_chi2n_no1dmod_ = chi2n_no1Dmod;
527  auto tmva_eta_ = trk.eta();
528  auto tmva_relpterr_ = float(trk.ptError())/std::max(float(trk.pt()),0.000001f);
529  auto tmva_nhits_ = trk.numberOfValidHits();
532  auto tmva_minlost_ = std::min(lostIn,lostOut);
533  auto tmva_lostmidfrac_ = trk.numberOfLostHits() / (trk.numberOfValidHits() + trk.numberOfLostHits());
534 
535  float gbrVals_[11];
536  gbrVals_[0] = tmva_lostmidfrac_;
537  gbrVals_[1] = tmva_minlost_;
538  gbrVals_[2] = tmva_nhits_;
539  gbrVals_[3] = tmva_relpterr_;
540  gbrVals_[4] = tmva_eta_;
541  gbrVals_[5] = tmva_chi2n_no1dmod_;
542  gbrVals_[6] = tmva_chi2n_;
543  gbrVals_[7] = tmva_nlayerslost_;
544  gbrVals_[8] = tmva_nlayers3D_;
545  gbrVals_[9] = tmva_nlayers_;
546  gbrVals_[10] = tmva_ndof_;
547 
548 
549  GBRForest const * forest = forest_;
550  if(useForestFromDB_){
551  edm::ESHandle<GBRForest> forestHandle;
552  es.get<GBRWrapperRcd>().get(forestLabel_,forestHandle);
553  forest = forestHandle.product();
554  }
555 
556  auto gbrVal = forest->GetClassifier(gbrVals_);
557  mvaVals_[current] = gbrVal;
558  }
559  mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
560  mvaFiller.fill();
561  evt.put(mvaValValueMap,"MVAVals");
562 
563 }
564 
567 
569 
#define LogDebug(id)
std::vector< double > chi2n_no1Dmod_par_
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
std::vector< uint32_t > min_nhits_
std::vector< double > chi2n_par_
int i
Definition: DBlmapReader.cc:9
std::vector< std::vector< double > > d0_par1_
std::vector< double > max_d0NoPV_
double d0Error() const
error on d0
Definition: TrackBase.h:778
std::vector< double > max_z0_
std::vector< uint32_t > min_layers_
Cuts on numbers of layers with hits/3D hits/lost hits.
std::vector< std::string > name_
std::vector< double > max_z0NoPV_
MultiTrackSelector()
constructor
std::vector< bool > useMVA_
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:537
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
std::vector< bool > keepAllTracks_
void beginStream(edm::StreamID) overridefinal
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< uint32_t > min_hits_bypass_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
bool exists(std::string const &parameterName) const
checks if a parameter exists
int pixelLayersWithMeasurement() const
Definition: HitPattern.h:917
std::vector< bool > applyAdaptedPVCuts_
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:802
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
int trackerLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.h:928
virtual void run(edm::Event &evt, const edm::EventSetup &es) const
std::vector< double > nSigmaZ_
std::vector< unsigned int > preFilter_
bool select(unsigned tsNum, const reco::BeamSpot &vertexBeamSpot, const reco::Track &tk, const std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr, double mvaVal) const
return class, or -1 if rejected
T eta() const
virtual ~MultiTrackSelector()
destructor
edm::EDGetTokenT< reco::VertexCollection > vertices_
std::vector< uint32_t > min_3Dlayers_
int numberOfLostTrackerHits(HitCategory category) const
Definition: HitPattern.h:812
std::vector< uint32_t > max_lostLayers_
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:627
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
Definition: HitPattern.cc:298
std::vector< int32_t > max_lostHitFraction_
edm::EDGetTokenT< reco::BeamSpot > beamspot_
const T & max(const T &a, const T &b)
std::vector< double > min_eta_
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:525
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:531
int trackerLayersWithMeasurement() const
Definition: HitPattern.h:912
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< bool > setQualityBit_
do I have to set a quality bit?
double pt() const
track transverse momentum
Definition: TrackBase.h:597
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:739
int qualityMask() const
Definition: TrackBase.h:832
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
std::vector< std::vector< double > > dz_par1_
double f[11][100]
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:796
#define end
Definition: vmac.h:37
std::vector< std::vector< double > > dz_par2_
std::vector< std::vector< double > > res_par_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
#define LogTrace(id)
std::vector< double > max_relpterr_
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:585
double dzError() const
error on dz
Definition: TrackBase.h:790
std::vector< int32_t > vtxNumber_
vertex cuts
void selectVertices(unsigned int tsNum, const reco::VertexCollection &vtxs, std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr) const
std::vector< reco::TrackBase::TrackQuality > qualityToSet_
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:364
const T & get() const
Definition: EventSetup.h:55
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
void processMVA(edm::Event &evt, const edm::EventSetup &es, std::vector< float > &mvaVals_) const
T const * product() const
Definition: ESHandle.h:86
bool isValid() const
double dzPV(const LorentzVector &vtx, const LorentzVector &p4, const LorentzVector &pv)
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:194
std::vector< StringCutObjectSelector< reco::Vertex > > vertexCut_
std::vector< bool > applyAbsCutsIfNoPV_
const Point & position() const
position
Definition: BeamSpot.h:62
std::vector< int32_t > max_minMissHitOutOrIn_
std::vector< double > min_MVA_
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
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:567
std::vector< std::vector< double > > d0_par2_
double GetClassifier(const float *vector) const
Definition: GBRForest.h:64
std::vector< double > max_d0_
Impact parameter absolute cuts.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
std::vector< double > max_eta_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109