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