CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
37  edm::ParameterSet psetCopy(pset);
38  psetCopy.addParameter<double>("jetDeltaRMax", 99999.0);
39  return psetCopy;
40 }
41 
43  charmCut(params.getParameter<double>("charmCut")),
44  sortCriterium(TrackSorting::getCriterium(params.getParameter<std::string>("trackSort"))),
45  trackSelector(params.getParameter<edm::ParameterSet>("trackSelection")),
46  trackNoDeltaRSelector(dropDeltaR(params.getParameter<edm::ParameterSet>("trackSelection"))),
47  minTrackWeight(params.getParameter<double>("minimumTrackWeight")),
48  trackPairV0Filter(params.getParameter<edm::ParameterSet>("trackPairV0Filter"))
49 {
50 }
51 
52 const btag::TrackIPData &
54  const btag::SortCriteria sort,
55  const reco::Jet &jet,
56  const GlobalPoint &pv) const
57 {
59  trackIPTagInfo.selectedTracks();
60  const std::vector<btag::TrackIPData> &ipData =
61  trackIPTagInfo.impactParameterData();
62  std::vector<std::size_t> indices = trackIPTagInfo.sortedIndexes(sort);
63 
64  TrackKinematics kin;
65  for(std::vector<std::size_t>::const_iterator iter = indices.begin();
66  iter != indices.end(); ++iter) {
67  const btag::TrackIPData &data = ipData[*iter];
68  const Track &track = *tracks[*iter];
69 
70  if (!trackNoDeltaRSelector(track, data, jet, pv))
71  continue;
72 
73  kin.add(track);
74  if (kin.vectorSum().M() > charmCut)
75  return data;
76  }
77 
78  static const btag::TrackIPData dummy = {
79  GlobalPoint(),
80  GlobalPoint(),
81  Measurement1D(-1.0, 1.0),
82  Measurement1D(-1.0, 1.0),
83  Measurement1D(-1.0, 1.0),
84  Measurement1D(-1.0, 1.0),
85  0.
86  };
87  return dummy;
88 }
89 
90 static void addMeas(std::pair<double, double> &sum, Measurement1D meas)
91 {
92  double weight = 1. / meas.error();
93  weight *= weight;
94  sum.first += weight * meas.value();
95  sum.second += weight;
96 }
97 
100  const SecondaryVertexTagInfo &svInfo) const
101 {
102  using namespace ROOT::Math;
103 
104  edm::RefToBase<Jet> jet = ipInfo.jet();
105  math::XYZVector jetDir = jet->momentum().Unit();
106  bool havePv = ipInfo.primaryVertex().isNonnull();
107  GlobalPoint pv;
108  if (havePv)
109  pv = GlobalPoint(ipInfo.primaryVertex()->x(),
110  ipInfo.primaryVertex()->y(),
111  ipInfo.primaryVertex()->z());
112 
114 
115  TaggingVariableList vars;
116 
117  vars.insert(btau::jetPt, jet->pt(), true);
118  vars.insert(btau::jetEta, jet->eta(), true);
119 
120  TrackKinematics allKinematics;
121  TrackKinematics vertexKinematics;
122  TrackKinematics trackKinematics;
123 
124  std::pair<double, double> vertexDist2D, vertexDist3D;
125  std::pair<double, double> tracksDist2D, tracksDist3D;
126 
127  unsigned int nVertices = 0;
128  unsigned int nVertexTracks = 0;
129  unsigned int nTracks = 0;
130  for(unsigned int i = 0; i < svInfo.nVertices(); i++) {
131  const Vertex &vertex = svInfo.secondaryVertex(i);
132  bool hasRefittedTracks = vertex.hasRefittedTracks();
134  unsigned int n = 0;
135  for(TrackRefVector::const_iterator track = tracks.begin();
136  track != tracks.end(); track++)
137  if (svInfo.trackWeight(i, *track) >= minTrackWeight)
138  n++;
139 
140  if (n < 1)
141  continue;
142  bool isTrackVertex = (n == 1);
143  ++*(isTrackVertex ? &nTracks : &nVertices);
144 
145  addMeas(*(isTrackVertex ? &tracksDist2D : &vertexDist2D),
146  svInfo.flightDistance(i, true));
147  addMeas(*(isTrackVertex ? &tracksDist3D : &vertexDist3D),
148  svInfo.flightDistance(i, false));
149 
150  TrackKinematics &kin = isTrackVertex ? trackKinematics
151  : vertexKinematics;
152  for(TrackRefVector::const_iterator track = tracks.begin();
153  track != tracks.end(); track++) {
154  float w = svInfo.trackWeight(i, *track);
155  if (w < minTrackWeight)
156  continue;
157  if (hasRefittedTracks) {
158  Track actualTrack =
159  vertex.refittedTrack(*track);
160  kin.add(actualTrack, w);
161  vars.insert(btau::trackEtaRel, reco::btau::etaRel(jetDir,
162  actualTrack.momentum()), true);
163  } else {
164  kin.add(**track, w);
165  vars.insert(btau::trackEtaRel, reco::btau::etaRel(jetDir,
166  (*track)->momentum()), true);
167  }
168  if (!isTrackVertex)
169  nVertexTracks++;
170  }
171  }
172 
173  Measurement1D dist2D, dist3D;
174  if (nVertices) {
175  vtxType = btag::Vertices::RecoVertex;
176 
177  if (nVertices == 1 && nTracks) {
178  vertexDist2D.first += tracksDist2D.first;
179  vertexDist2D.second += tracksDist2D.second;
180  vertexDist3D.first += tracksDist3D.first;
181  vertexDist3D.second += tracksDist3D.second;
182  vertexKinematics += trackKinematics;
183  }
184 
185  dist2D = Measurement1D(
186  vertexDist2D.first / vertexDist2D.second,
187  std::sqrt(1. / vertexDist2D.second));
188  dist3D = Measurement1D(
189  vertexDist3D.first / vertexDist3D.second,
190  std::sqrt(1. / vertexDist3D.second));
191 
192  vars.insert(btau::jetNSecondaryVertices, nVertices, true);
193  vars.insert(btau::vertexNTracks, nVertexTracks, true);
194  } else if (nTracks) {
196  vertexKinematics = trackKinematics;
197 
198  dist2D = Measurement1D(
199  tracksDist2D.first / tracksDist2D.second,
200  std::sqrt(1. / tracksDist2D.second));
201  dist3D = Measurement1D(
202  tracksDist3D.first / tracksDist3D.second,
203  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,
212  Geom::deltaR(svInfo.flightDirection(0), jetDir),true);
213  vars.insert(btau::jetNSingleTrackVertices, nTracks, true);
214  }
215 
216  std::vector<std::size_t> indices = ipInfo.sortedIndexes(sortCriterium);
217  const std::vector<btag::TrackIPData> &ipData =
218  ipInfo.impactParameterData();
220  ipInfo.selectedTracks();
221 
222  TrackRef trackPairV0Test[2];
223  for(unsigned int i = 0; i < indices.size(); i++) {
224  std::size_t idx = indices[i];
225  const btag::TrackIPData &data = ipData[idx];
226  const TrackRef &trackRef = tracks[idx];
227  const Track &track = *trackRef;
228 
229  // filter track
230 
231  if (!trackSelector(track, data, *jet, pv))
232  continue;
233 
234  // add track to kinematics for all tracks in jet
235 
236  allKinematics.add(track);
237 
238  // check against all other tracks for V0 track pairs
239 
240  trackPairV0Test[0] = tracks[idx];
241  bool ok = true;
242  for(unsigned int j = 0; j < indices.size(); j++) {
243  if (i == j)
244  continue;
245 
246  std::size_t pairIdx = indices[j];
247  const btag::TrackIPData &pairTrackData =
248  ipData[pairIdx];
249  const TrackRef &pairTrackRef = tracks[pairIdx];
250  const Track &pairTrack = *pairTrackRef;
251 
252  if (!trackSelector(pairTrack, pairTrackData, *jet, pv))
253  continue;
254 
255  trackPairV0Test[1] = pairTrackRef;
256  if (!trackPairV0Filter(trackPairV0Test, 2)) {
257  ok = false;
258  break;
259  }
260  }
261  if (!ok)
262  continue;
263 
264  // add track variables
265 
266  math::XYZVector trackMom = track.momentum();
267  double trackMag = std::sqrt(trackMom.Mag2());
268 
269  vars.insert(btau::trackSip3dVal, data.ip3d.value(), true);
270  vars.insert(btau::trackSip3dSig, data.ip3d.significance(), true);
271  vars.insert(btau::trackSip2dVal, data.ip2d.value(), true);
272  vars.insert(btau::trackSip2dSig, data.ip2d.significance(), true);
273  vars.insert(btau::trackJetDistVal, data.distanceToJetAxis.value(), true);
274  vars.insert(btau::trackGhostTrackDistVal, data.distanceToGhostTrack.value(), true);
275  vars.insert(btau::trackGhostTrackDistSig, data.distanceToGhostTrack.significance(), true);
276  vars.insert(btau::trackGhostTrackWeight, data.ghostTrackWeight, true);
277  vars.insert(btau::trackDecayLenVal, havePv ? (data.closestToGhostTrack - pv).mag() : -1.0, true);
278 
279  vars.insert(btau::trackMomentum, trackMag, true);
280  vars.insert(btau::trackEta, trackMom.Eta(), true);
281 
282  vars.insert(btau::trackChi2, track.normalizedChi2(), true);
283  vars.insert(btau::trackNPixelHits, track.hitPattern().pixelLayersWithMeasurement(), true);
284  vars.insert(btau::trackNTotalHits, track.hitPattern().trackerLayersWithMeasurement(), true);
285  vars.insert(btau::trackPtRel, VectorUtil::Perp(trackMom, jetDir), true);
286  vars.insert(btau::trackDeltaR, VectorUtil::DeltaR(trackMom, jetDir), true);
287  }
288 
289  vars.insert(btau::vertexCategory, vtxType, true);
290  vars.insert(btau::trackSumJetDeltaR,
291  VectorUtil::DeltaR(allKinematics.vectorSum(), jetDir), true);
292  vars.insert(btau::trackSumJetEtRatio,
293  allKinematics.vectorSum().Et() / ipInfo.jet()->et(), true);
294  vars.insert(btau::trackSip3dSigAboveCharm,
296  .ip3d.significance(),
297  true);
298  vars.insert(btau::trackSip2dSigAboveCharm,
300  .ip2d.significance(),
301  true);
302 
303  if (vtxType != btag::Vertices::NoVertex) {
304  math::XYZTLorentzVector allSum = allKinematics.vectorSum();
305  math::XYZTLorentzVector vertexSum = vertexKinematics.vectorSum();
306 
307  vars.insert(btau::vertexMass, vertexSum.M(), true);
308  if (allKinematics.numberOfTracks())
309  vars.insert(btau::vertexEnergyRatio,
310  vertexSum.E() / allSum.E(), true);
311  else
312  vars.insert(btau::vertexEnergyRatio, 1, true);
313  }
314 
315  vars.finalize();
316 
317  return vars;
318 }
Measurement1D flightDistance(unsigned int index, bool in2d=false) const
int i
Definition: DBlmapReader.cc:9
reco::btag::SortCriteria getCriterium(const std::string &name)
Definition: TrackSorting.cc:11
const unsigned int nTracks(const reco::Vertex &sv)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
reco::TaggingVariableList operator()(const reco::TrackIPTagInfo &ipInfo, const reco::SecondaryVertexTagInfo &svInfo) const
tuple trackPairV0Filter
const double w
Definition: UKUtility.cc:23
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:556
void add(const reco::Track &track, double weight=1.0)
const VTX & secondaryVertex(unsigned int index) const
GhostTrackComputer(const edm::ParameterSet &params)
Track refittedTrack(const TrackBaseRef &track) const
Base class for all types of Jets.
Definition: Jet.h:20
double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
bool hasRefittedTracks() const
Checks whether refitted tracks are stored.
Definition: Vertex.h:127
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
double error() const
Definition: Measurement1D.h:30
const Container & selectedTracks() const
Definition: IPTagInfo.h:101
static edm::ParameterSet dropDeltaR(const edm::ParameterSet &pset)
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:508
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:670
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:255
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:527
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:250
const edm::Ref< VertexCollection > & primaryVertex() const
Definition: IPTagInfo.h:133
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
static void addMeas(std::pair< double, double > &sum, Measurement1D meas)
float trackWeight(unsigned int svIndex, unsigned int trackindex) const
T sqrt(T t)
Definition: SSEVec.h:18
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
int j
Definition: DBlmapReader.cc:9
std::vector< size_t > sortedIndexes(btag::SortCriteria mode=reco::btag::IP3DSig) const
Definition: IPTagInfo.h:238
reco::V0Filter trackPairV0Filter
const GlobalVector & flightDirection(unsigned int index) const
const std::vector< btag::TrackIPData > & impactParameterData() const
Definition: IPTagInfo.h:91
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
reco::btag::SortCriteria sortCriterium
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:445
tuple tracks
Definition: testEve_cfg.py:39
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
double value() const
Definition: Measurement1D.h:28
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const math::XYZTLorentzVector & vectorSum() const
reco::TrackSelector trackNoDeltaRSelector
reco::TrackSelector trackSelector
const reco::btag::TrackIPData & threshTrack(const reco::TrackIPTagInfo &trackIPTagInfo, const reco::btag::SortCriteria sort, const reco::Jet &jet, const GlobalPoint &pv) const
void insert(const TaggingVariable &variable, bool delayed=false)
tuple trackSelector
Tracks selection.
Definition: valSkim_cff.py:4