CMS 3D CMS Logo

GhostTrackComputer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cstddef>
3 #include <string>
4 #include <cmath>
5 #include <vector>
6 
7 #include <Math/VectorUtil.h>
8 
11 
25 
30 
32 
33 using namespace reco;
34 
36  edm::ParameterSet psetCopy(pset);
37  psetCopy.addParameter<double>("jetDeltaRMax", 99999.0);
38  return psetCopy;
39 }
40 
42  : charmCut(params.getParameter<double>("charmCut")),
43  sortCriterium(TrackSorting::getCriterium(params.getParameter<std::string>("trackSort"))),
44  trackSelector(params.getParameter<edm::ParameterSet>("trackSelection")),
45  trackNoDeltaRSelector(dropDeltaR(params.getParameter<edm::ParameterSet>("trackSelection"))),
46  minTrackWeight(params.getParameter<double>("minimumTrackWeight")),
47  trackPairV0Filter(params.getParameter<edm::ParameterSet>("trackPairV0Filter")) {}
48 
49 const btag::TrackIPData &GhostTrackComputer::threshTrack(const TrackIPTagInfo &trackIPTagInfo,
51  const reco::Jet &jet,
52  const GlobalPoint &pv) const {
53  const edm::RefVector<TrackCollection> &tracks = trackIPTagInfo.selectedTracks();
54  const std::vector<btag::TrackIPData> &ipData = trackIPTagInfo.impactParameterData();
55  std::vector<std::size_t> indices = trackIPTagInfo.sortedIndexes(sort);
56 
57  TrackKinematics kin;
58  for (std::vector<std::size_t>::const_iterator iter = indices.begin(); iter != indices.end(); ++iter) {
59  const btag::TrackIPData &data = ipData[*iter];
60  const Track &track = *tracks[*iter];
61 
63  continue;
64 
65  kin.add(track);
66  if (kin.vectorSum().M() > charmCut)
67  return data;
68  }
69 
70  static const btag::TrackIPData dummy = {GlobalPoint(),
71  GlobalPoint(),
72  Measurement1D(-1.0, 1.0),
73  Measurement1D(-1.0, 1.0),
74  Measurement1D(-1.0, 1.0),
75  Measurement1D(-1.0, 1.0),
76  0.};
77  return dummy;
78 }
79 
80 const btag::TrackIPData &GhostTrackComputer::threshTrack(const CandIPTagInfo &trackIPTagInfo,
82  const reco::Jet &jet,
83  const GlobalPoint &pv) const {
84  const CandIPTagInfo::input_container &tracks = trackIPTagInfo.selectedTracks();
85  const std::vector<btag::TrackIPData> &ipData = trackIPTagInfo.impactParameterData();
86  std::vector<std::size_t> indices = trackIPTagInfo.sortedIndexes(sort);
87 
88  TrackKinematics kin;
89  for (std::vector<std::size_t>::const_iterator iter = indices.begin(); iter != indices.end(); ++iter) {
90  const btag::TrackIPData &data = ipData[*iter];
91  const CandidatePtr &track = tracks[*iter];
92 
94  continue;
95 
96  kin.add(track);
97  if (kin.vectorSum().M() > charmCut)
98  return data;
99  }
100 
101  static const btag::TrackIPData dummy = {GlobalPoint(),
102  GlobalPoint(),
103  Measurement1D(-1.0, 1.0),
104  Measurement1D(-1.0, 1.0),
105  Measurement1D(-1.0, 1.0),
106  Measurement1D(-1.0, 1.0),
107  0.};
108  return dummy;
109 }
110 
111 static void addMeas(std::pair<double, double> &sum, Measurement1D meas) {
112  double weight = 1. / meas.error();
113  weight *= weight;
114  sum.first += weight * meas.value();
115  sum.second += weight;
116 }
117 
119  const SecondaryVertexTagInfo &svInfo) const {
120  using namespace ROOT::Math;
121 
122  edm::RefToBase<Jet> jet = ipInfo.jet();
123  math::XYZVector jetDir = jet->momentum().Unit();
124  bool havePv = ipInfo.primaryVertex().isNonnull();
125  GlobalPoint pv;
126  if (havePv)
127  pv = GlobalPoint(ipInfo.primaryVertex()->x(), ipInfo.primaryVertex()->y(), ipInfo.primaryVertex()->z());
128 
130 
132 
133  vars.insert(btau::jetPt, jet->pt(), true);
134  vars.insert(btau::jetEta, jet->eta(), true);
135 
136  TrackKinematics allKinematics;
137  TrackKinematics vertexKinematics;
138  TrackKinematics trackKinematics;
139 
140  std::pair<double, double> vertexDist2D, vertexDist3D;
141  std::pair<double, double> tracksDist2D, tracksDist3D;
142 
143  unsigned int nVertices = 0;
144  unsigned int nVertexTracks = 0;
145  unsigned int nTracks = 0;
146  for (unsigned int i = 0; i < svInfo.nVertices(); i++) {
147  const Vertex &vertex = svInfo.secondaryVertex(i);
148  bool hasRefittedTracks = vertex.hasRefittedTracks();
150  unsigned int n = 0;
151  for (TrackRefVector::const_iterator track = tracks.begin(); track != tracks.end(); track++)
152  if (svInfo.trackWeight(i, *track) >= minTrackWeight)
153  n++;
154 
155  if (n < 1)
156  continue;
157  bool isTrackVertex = (n == 1);
158  ++*(isTrackVertex ? &nTracks : &nVertices);
159 
160  addMeas(*(isTrackVertex ? &tracksDist2D : &vertexDist2D), svInfo.flightDistance(i, true));
161  addMeas(*(isTrackVertex ? &tracksDist3D : &vertexDist3D), svInfo.flightDistance(i, false));
162 
163  TrackKinematics &kin = isTrackVertex ? trackKinematics : vertexKinematics;
164  for (TrackRefVector::const_iterator track = tracks.begin(); track != tracks.end(); track++) {
165  float w = svInfo.trackWeight(i, *track);
166  if (w < minTrackWeight)
167  continue;
168  if (hasRefittedTracks) {
169  Track actualTrack = vertex.refittedTrack(*track);
170  kin.add(actualTrack, w);
171  vars.insert(btau::trackEtaRel, reco::btau::etaRel(jetDir, actualTrack.momentum()), true);
172  } else {
173  kin.add(**track, w);
174  vars.insert(btau::trackEtaRel, reco::btau::etaRel(jetDir, (*track)->momentum()), true);
175  }
176  if (!isTrackVertex)
177  nVertexTracks++;
178  }
179  }
180 
181  Measurement1D dist2D, dist3D;
182  if (nVertices) {
183  vtxType = btag::Vertices::RecoVertex;
184 
185  if (nVertices == 1 && nTracks) {
186  vertexDist2D.first += tracksDist2D.first;
187  vertexDist2D.second += tracksDist2D.second;
188  vertexDist3D.first += tracksDist3D.first;
189  vertexDist3D.second += tracksDist3D.second;
190  vertexKinematics += trackKinematics;
191  }
192 
193  dist2D = Measurement1D(vertexDist2D.first / vertexDist2D.second, std::sqrt(1. / vertexDist2D.second));
194  dist3D = Measurement1D(vertexDist3D.first / vertexDist3D.second, std::sqrt(1. / vertexDist3D.second));
195 
197  vars.insert(btau::vertexNTracks, nVertexTracks, true);
198  } else if (nTracks) {
200  vertexKinematics = trackKinematics;
201 
202  dist2D = Measurement1D(tracksDist2D.first / tracksDist2D.second, std::sqrt(1. / tracksDist2D.second));
203  dist3D = Measurement1D(tracksDist3D.first / tracksDist3D.second, std::sqrt(1. / tracksDist3D.second));
204  }
205 
206  if (nVertices || nTracks) {
207  vars.insert(btau::flightDistance2dVal, dist2D.value(), true);
208  vars.insert(btau::flightDistance2dSig, dist2D.significance(), true);
209  vars.insert(btau::flightDistance3dVal, dist3D.value(), true);
210  vars.insert(btau::flightDistance3dSig, dist3D.significance(), true);
211  vars.insert(btau::vertexJetDeltaR, Geom::deltaR(svInfo.flightDirection(0), jetDir), true);
213  }
214 
215  std::vector<std::size_t> indices = ipInfo.sortedIndexes(sortCriterium);
216  const std::vector<btag::TrackIPData> &ipData = ipInfo.impactParameterData();
218 
219  TrackRef trackPairV0Test[2];
220  for (unsigned int i = 0; i < indices.size(); i++) {
221  std::size_t idx = indices[i];
222  const btag::TrackIPData &data = ipData[idx];
223  const TrackRef &trackRef = tracks[idx];
224  const Track &track = *trackRef;
225 
226  // filter track
227 
228  if (!trackSelector(track, data, *jet, pv))
229  continue;
230 
231  // add track to kinematics for all tracks in jet
232 
233  allKinematics.add(track);
234 
235  // check against all other tracks for V0 track pairs
236 
237  trackPairV0Test[0] = tracks[idx];
238  bool ok = true;
239  for (unsigned int j = 0; j < indices.size(); j++) {
240  if (i == j)
241  continue;
242 
243  std::size_t pairIdx = indices[j];
244  const btag::TrackIPData &pairTrackData = ipData[pairIdx];
245  const TrackRef &pairTrackRef = tracks[pairIdx];
246  const Track &pairTrack = *pairTrackRef;
247 
248  if (!trackSelector(pairTrack, pairTrackData, *jet, pv))
249  continue;
250 
251  trackPairV0Test[1] = pairTrackRef;
252  if (!trackPairV0Filter(trackPairV0Test, 2)) {
253  ok = false;
254  break;
255  }
256  }
257  if (!ok)
258  continue;
259 
260  // add track variables
261 
262  const math::XYZVector &trackMom = track.momentum();
263  double trackMag = std::sqrt(trackMom.Mag2());
264 
265  vars.insert(btau::trackSip3dVal, data.ip3d.value(), true);
266  vars.insert(btau::trackSip3dSig, data.ip3d.significance(), true);
267  vars.insert(btau::trackSip2dVal, data.ip2d.value(), true);
268  vars.insert(btau::trackSip2dSig, data.ip2d.significance(), true);
269  vars.insert(btau::trackJetDistVal, data.distanceToJetAxis.value(), true);
270  vars.insert(btau::trackGhostTrackDistVal, data.distanceToGhostTrack.value(), true);
271  vars.insert(btau::trackGhostTrackDistSig, data.distanceToGhostTrack.significance(), true);
272  vars.insert(btau::trackGhostTrackWeight, data.ghostTrackWeight, true);
273  vars.insert(btau::trackDecayLenVal, havePv ? (data.closestToGhostTrack - pv).mag() : -1.0, true);
274 
275  vars.insert(btau::trackMomentum, trackMag, true);
276  vars.insert(btau::trackEta, trackMom.Eta(), true);
277 
278  vars.insert(btau::trackChi2, track.normalizedChi2(), true);
279  vars.insert(btau::trackNPixelHits, track.hitPattern().pixelLayersWithMeasurement(), true);
280  vars.insert(btau::trackNTotalHits, track.hitPattern().trackerLayersWithMeasurement(), true);
281  vars.insert(btau::trackPtRel, VectorUtil::Perp(trackMom, jetDir), true);
282  vars.insert(btau::trackDeltaR, VectorUtil::DeltaR(trackMom, jetDir), true);
283  }
284 
285  vars.insert(btau::vertexCategory, vtxType, true);
286  vars.insert(btau::trackSumJetDeltaR, VectorUtil::DeltaR(allKinematics.vectorSum(), jetDir), true);
287  vars.insert(btau::trackSumJetEtRatio, allKinematics.vectorSum().Et() / ipInfo.jet()->et(), true);
288  vars.insert(
289  btau::trackSip3dSigAboveCharm, threshTrack(ipInfo, reco::btag::IP3DSig, *jet, pv).ip3d.significance(), true);
290  vars.insert(
291  btau::trackSip2dSigAboveCharm, threshTrack(ipInfo, reco::btag::IP2DSig, *jet, pv).ip2d.significance(), true);
292 
293  if (vtxType != btag::Vertices::NoVertex) {
294  const math::XYZTLorentzVector &allSum = allKinematics.vectorSum();
295  const math::XYZTLorentzVector &vertexSum = vertexKinematics.vectorSum();
296 
297  vars.insert(btau::vertexMass, vertexSum.M(), true);
298  if (allKinematics.numberOfTracks())
299  vars.insert(btau::vertexEnergyRatio, vertexSum.E() / allSum.E(), true);
300  else
301  vars.insert(btau::vertexEnergyRatio, 1, true);
302  }
303 
304  vars.finalize();
305 
306  return vars;
307 }
308 
310  const CandSecondaryVertexTagInfo &svInfo) const {
311  using namespace ROOT::Math;
312 
313  edm::RefToBase<Jet> jet = ipInfo.jet();
314  math::XYZVector jetDir = jet->momentum().Unit();
315  bool havePv = ipInfo.primaryVertex().isNonnull();
316  GlobalPoint pv;
317  if (havePv)
318  pv = GlobalPoint(ipInfo.primaryVertex()->x(), ipInfo.primaryVertex()->y(), ipInfo.primaryVertex()->z());
319 
321 
323 
324  vars.insert(btau::jetPt, jet->pt(), true);
325  vars.insert(btau::jetEta, jet->eta(), true);
326 
327  TrackKinematics allKinematics;
328  TrackKinematics vertexKinematics;
329  TrackKinematics trackKinematics;
330 
331  std::pair<double, double> vertexDist2D, vertexDist3D;
332  std::pair<double, double> tracksDist2D, tracksDist3D;
333 
334  unsigned int nVertices = 0;
335  unsigned int nVertexTracks = 0;
336  unsigned int nTracks = 0;
337  for (unsigned int i = 0; i < svInfo.nVertices(); i++) {
339  const std::vector<CandidatePtr> &tracks = vertex.daughterPtrVector();
340  unsigned int n = 0;
341  for (std::vector<CandidatePtr>::const_iterator track = tracks.begin(); track != tracks.end(); ++track)
342  n++;
343 
344  if (n < 1)
345  continue;
346  bool isTrackVertex = (n == 1);
347  ++*(isTrackVertex ? &nTracks : &nVertices);
348 
349  addMeas(*(isTrackVertex ? &tracksDist2D : &vertexDist2D), svInfo.flightDistance(i, true));
350  addMeas(*(isTrackVertex ? &tracksDist3D : &vertexDist3D), svInfo.flightDistance(i, false));
351 
352  TrackKinematics &kin = isTrackVertex ? trackKinematics : vertexKinematics;
353 
354  for (std::vector<CandidatePtr>::const_iterator track = tracks.begin(); track != tracks.end(); ++track) {
355  kin.add(*track);
356  vars.insert(btau::trackEtaRel, reco::btau::etaRel(jetDir, (*track)->momentum()), true);
357  if (!isTrackVertex)
358  nVertexTracks++;
359  }
360  }
361 
362  Measurement1D dist2D, dist3D;
363  if (nVertices) {
364  vtxType = btag::Vertices::RecoVertex;
365 
366  if (nVertices == 1 && nTracks) {
367  vertexDist2D.first += tracksDist2D.first;
368  vertexDist2D.second += tracksDist2D.second;
369  vertexDist3D.first += tracksDist3D.first;
370  vertexDist3D.second += tracksDist3D.second;
371  vertexKinematics += trackKinematics;
372  }
373 
374  dist2D = Measurement1D(vertexDist2D.first / vertexDist2D.second, std::sqrt(1. / vertexDist2D.second));
375  dist3D = Measurement1D(vertexDist3D.first / vertexDist3D.second, std::sqrt(1. / vertexDist3D.second));
376 
378  vars.insert(btau::vertexNTracks, nVertexTracks, true);
379  } else if (nTracks) {
381  vertexKinematics = trackKinematics;
382 
383  dist2D = Measurement1D(tracksDist2D.first / tracksDist2D.second, std::sqrt(1. / tracksDist2D.second));
384  dist3D = Measurement1D(tracksDist3D.first / tracksDist3D.second, std::sqrt(1. / tracksDist3D.second));
385  }
386 
387  if (nVertices || nTracks) {
388  vars.insert(btau::flightDistance2dVal, dist2D.value(), true);
389  vars.insert(btau::flightDistance2dSig, dist2D.significance(), true);
390  vars.insert(btau::flightDistance3dVal, dist3D.value(), true);
391  vars.insert(btau::flightDistance3dSig, dist3D.significance(), true);
392  vars.insert(btau::vertexJetDeltaR, Geom::deltaR(svInfo.flightDirection(0), jetDir), true);
394  }
395 
396  std::vector<std::size_t> indices = ipInfo.sortedIndexes(sortCriterium);
397  const std::vector<btag::TrackIPData> &ipData = ipInfo.impactParameterData();
399 
400  const Track *trackPairV0Test[2];
401  for (unsigned int i = 0; i < indices.size(); i++) {
402  std::size_t idx = indices[i];
403  const btag::TrackIPData &data = ipData[idx];
404  const Track *trackPtr = reco::btag::toTrack(tracks[idx]);
405  const Track &track = *trackPtr;
406 
407  // filter track
408 
409  if (!trackSelector(track, data, *jet, pv))
410  continue;
411 
412  // add track to kinematics for all tracks in jet
413 
414  allKinematics.add(track);
415 
416  // check against all other tracks for V0 track pairs
417 
418  trackPairV0Test[0] = reco::btag::toTrack(tracks[idx]);
419  bool ok = true;
420  for (unsigned int j = 0; j < indices.size(); j++) {
421  if (i == j)
422  continue;
423 
424  std::size_t pairIdx = indices[j];
425  const btag::TrackIPData &pairTrackData = ipData[pairIdx];
426  const Track *pairTrackPtr = reco::btag::toTrack(tracks[pairIdx]);
427  const Track &pairTrack = *pairTrackPtr;
428 
429  if (!trackSelector(pairTrack, pairTrackData, *jet, pv))
430  continue;
431 
432  trackPairV0Test[1] = pairTrackPtr;
433  if (!trackPairV0Filter(trackPairV0Test, 2)) {
434  ok = false;
435  break;
436  }
437  }
438  if (!ok)
439  continue;
440 
441  // add track variables
442 
443  const math::XYZVector &trackMom = track.momentum();
444  double trackMag = std::sqrt(trackMom.Mag2());
445 
446  vars.insert(btau::trackSip3dVal, data.ip3d.value(), true);
447  vars.insert(btau::trackSip3dSig, data.ip3d.significance(), true);
448  vars.insert(btau::trackSip2dVal, data.ip2d.value(), true);
449  vars.insert(btau::trackSip2dSig, data.ip2d.significance(), true);
450  vars.insert(btau::trackJetDistVal, data.distanceToJetAxis.value(), true);
451  vars.insert(btau::trackGhostTrackDistVal, data.distanceToGhostTrack.value(), true);
452  vars.insert(btau::trackGhostTrackDistSig, data.distanceToGhostTrack.significance(), true);
453  vars.insert(btau::trackGhostTrackWeight, data.ghostTrackWeight, true);
454  vars.insert(btau::trackDecayLenVal, havePv ? (data.closestToGhostTrack - pv).mag() : -1.0, true);
455 
456  vars.insert(btau::trackMomentum, trackMag, true);
457  vars.insert(btau::trackEta, trackMom.Eta(), true);
458 
459  vars.insert(btau::trackChi2, track.normalizedChi2(), true);
460  vars.insert(btau::trackNPixelHits, track.hitPattern().pixelLayersWithMeasurement(), true);
461  vars.insert(btau::trackNTotalHits, track.hitPattern().trackerLayersWithMeasurement(), true);
462  vars.insert(btau::trackPtRel, VectorUtil::Perp(trackMom, jetDir), true);
463  vars.insert(btau::trackDeltaR, VectorUtil::DeltaR(trackMom, jetDir), true);
464  }
465 
466  vars.insert(btau::vertexCategory, vtxType, true);
467  vars.insert(btau::trackSumJetDeltaR, VectorUtil::DeltaR(allKinematics.vectorSum(), jetDir), true);
468  vars.insert(btau::trackSumJetEtRatio, allKinematics.vectorSum().Et() / ipInfo.jet()->et(), true);
469  vars.insert(
470  btau::trackSip3dSigAboveCharm, threshTrack(ipInfo, reco::btag::IP3DSig, *jet, pv).ip3d.significance(), true);
471  vars.insert(
472  btau::trackSip2dSigAboveCharm, threshTrack(ipInfo, reco::btag::IP2DSig, *jet, pv).ip2d.significance(), true);
473 
474  if (vtxType != btag::Vertices::NoVertex) {
475  const math::XYZTLorentzVector &allSum = allKinematics.vectorSum();
476  const math::XYZTLorentzVector &vertexSum = vertexKinematics.vectorSum();
477 
478  vars.insert(btau::vertexMass, vertexSum.M(), true);
479  if (allKinematics.numberOfTracks())
480  vars.insert(btau::vertexEnergyRatio, vertexSum.E() / allSum.E(), true);
481  else
482  vars.insert(btau::vertexEnergyRatio, 1, true);
483  }
484 
485  vars.finalize();
486 
487  return vars;
488 }
reco::btag::SortCriteria getCriterium(const std::string &name)
Definition: TrackSorting.cc:11
trackSelector
Tracks selection.
void add(const reco::Track &track, double weight=1.0)
T w() const
GhostTrackComputer(const edm::ParameterSet &params)
Base class for all types of Jets.
Definition: Jet.h:20
double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
const Container & selectedTracks() const
Definition: IPTagInfo.h:99
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
float trackWeight(unsigned int svIndex, unsigned int trackindex) const
static edm::ParameterSet dropDeltaR(const edm::ParameterSet &pset)
Definition: weight.py:1
const reco::Track * toTrack(const reco::TrackBaseRef &t)
Definition: IPTagInfo.h:24
unsigned int numberOfTracks() const
const reco::btag::TrackIPData & threshTrack(const reco::TrackIPTagInfo &trackIPTagInfo, const reco::btag::SortCriteria sort, const reco::Jet &jet, const GlobalPoint &pv) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
std::vector< size_t > sortedIndexes(btag::SortCriteria mode=reco::btag::IP3DSig) const
Definition: IPTagInfo.h:231
static void addMeas(std::pair< double, double > &sum, Measurement1D meas)
T sqrt(T t)
Definition: SSEVec.h:19
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
const math::XYZTLorentzVector & vectorSum() const
def pv(vc)
Definition: MetAnalyzer.py:7
const GlobalVector & flightDirection(unsigned int index) const
const std::vector< btag::TrackIPData > & impactParameterData() const
Definition: IPTagInfo.h:90
reco::V0Filter trackPairV0Filter
Measurement1D flightDistance(unsigned int index, int dim=0) const
reco::btag::SortCriteria sortCriterium
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
const VTX & secondaryVertex(unsigned int index) const
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
double value() const
Definition: Measurement1D.h:25
double significance() const
Definition: Measurement1D.h:29
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
reco::TrackSelector trackNoDeltaRSelector
double error() const
Definition: Measurement1D.h:27
reco::TrackSelector trackSelector
Container input_container
Definition: IPTagInfo.h:50
const edm::Ref< VertexCollection > & primaryVertex() const
Definition: IPTagInfo.h:133
vars
Definition: DeepTauId.cc:117
virtual reco::TaggingVariableList operator()(const reco::TrackIPTagInfo &ipInfo, const reco::SecondaryVertexTagInfo &svInfo) const