CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CombinedSVComputer.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 
24 
26 
32 
34 
35 using namespace reco;
36 
39 };
40 
41 #define range_for(i, x) \
42  for(int i = (x).begin; i != (x).end; i += (x).increment)
43 
45 {
46  edm::ParameterSet psetCopy(pset);
47  psetCopy.addParameter<double>("jetDeltaRMax", 99999.0);
48  return psetCopy;
49 }
50 
52  trackFlip(params.getParameter<bool>("trackFlip")),
53  vertexFlip(params.getParameter<bool>("vertexFlip")),
54  charmCut(params.getParameter<double>("charmCut")),
55  sortCriterium(TrackSorting::getCriterium(params.getParameter<std::string>("trackSort"))),
56  trackSelector(params.getParameter<edm::ParameterSet>("trackSelection")),
57  trackNoDeltaRSelector(dropDeltaR(params.getParameter<edm::ParameterSet>("trackSelection"))),
58  trackPseudoSelector(params.getParameter<edm::ParameterSet>("trackPseudoSelection")),
59  pseudoMultiplicityMin(params.getParameter<unsigned int>("pseudoMultiplicityMin")),
60  trackMultiplicityMin(params.getParameter<unsigned int>("trackMultiplicityMin")),
61  minTrackWeight(params.getParameter<double>("minimumTrackWeight")),
62  useTrackWeights(params.getParameter<bool>("useTrackWeights")),
63  vertexMassCorrection(params.getParameter<bool>("correctVertexMass")),
64  pseudoVertexV0Filter(params.getParameter<edm::ParameterSet>("pseudoVertexV0Filter")),
65  trackPairV0Filter(params.getParameter<edm::ParameterSet>("trackPairV0Filter"))
66 {
67 }
68 
69 inline double CombinedSVComputer::flipValue(double value, bool vertex) const
70 {
71  return (vertex ? vertexFlip : trackFlip) ? -value : value;
72 }
73 
75  int size, bool vertex) const
76 {
77  IterationRange range;
78  if (vertex ? vertexFlip : trackFlip) {
79  range.begin = size - 1;
80  range.end = -1;
81  range.increment = -1;
82  } else {
83  range.begin = 0;
84  range.end = size;
85  range.increment = +1;
86  }
87 
88  return range;
89 }
90 
94  const reco::Jet &jet,
95  const GlobalPoint &pv) const
96 {
98  trackIPTagInfo.selectedTracks();
99  const std::vector<TrackIPTagInfo::TrackIPData> &ipData =
100  trackIPTagInfo.impactParameterData();
101  std::vector<std::size_t> indices = trackIPTagInfo.sortedIndexes(sort);
102 
103  IterationRange range = flipIterate(indices.size(), false);
104  TrackKinematics kin;
105  range_for(i, range) {
106  std::size_t idx = indices[i];
107  const TrackIPTagInfo::TrackIPData &data = ipData[idx];
108  const Track &track = *tracks[idx];
109 
110  if (!trackNoDeltaRSelector(track, data, jet, pv))
111  continue;
112 
113  kin.add(track);
114  if (kin.vectorSum().M() > charmCut)
115  return data;
116  }
117 
118  static const TrackIPTagInfo::TrackIPData dummy = {
119  GlobalPoint(),
120  GlobalPoint(),
121  Measurement1D(-1.0, 1.0),
122  Measurement1D(-1.0, 1.0),
123  Measurement1D(-1.0, 1.0),
124  Measurement1D(-1.0, 1.0),
125  0.
126  };
127  return dummy;
128 }
129 
130 static double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
131 {
132  double momPar = dir.Dot(track);
133  double energy = std::sqrt(track.Mag2() +
134  ROOT::Math::Square(ParticleMasses::piPlus));
135 
136  return 0.5 * std::log((energy + momPar) / (energy - momPar));
137 }
138 
141  const SecondaryVertexTagInfo &svInfo) const
142 {
143  using namespace ROOT::Math;
144 
145  edm::RefToBase<Jet> jet = ipInfo.jet();
146  math::XYZVector jetDir = jet->momentum().Unit();
147  bool havePv = ipInfo.primaryVertex().isNonnull();
148  GlobalPoint pv;
149  if (havePv)
150  pv = GlobalPoint(ipInfo.primaryVertex()->x(),
151  ipInfo.primaryVertex()->y(),
152  ipInfo.primaryVertex()->z());
153 
155 
156  TaggingVariableList vars; // = ipInfo.taggingVariables();
157 
158  vars.insert(btau::jetPt, jet->pt(), true);
159  vars.insert(btau::jetEta, jet->eta(), true);
160 
161  if (ipInfo.tracks().size() < trackMultiplicityMin)
162  return vars;
163 
164  TrackKinematics allKinematics;
165  TrackKinematics vertexKinematics;
166 
167  int vtx = -1;
168  IterationRange range = flipIterate(svInfo.nVertices(), true);
169  range_for(i, range) {
170  if (vtx < 0)
171  vtx = i;
172 
173  const Vertex &vertex = svInfo.secondaryVertex(i);
174  bool hasRefittedTracks = vertex.hasRefittedTracks();
176  for(TrackRefVector::const_iterator track = tracks.begin();
177  track != tracks.end(); track++) {
178  double w = svInfo.trackWeight(i, *track);
179  if (w < minTrackWeight)
180  continue;
181  if (hasRefittedTracks) {
182  Track actualTrack =
183  vertex.refittedTrack(*track);
184  vertexKinematics.add(actualTrack, w);
185  vars.insert(btau::trackEtaRel, etaRel(jetDir,
186  actualTrack.momentum()), true);
187  } else {
188  vertexKinematics.add(**track, w);
189  vars.insert(btau::trackEtaRel, etaRel(jetDir,
190  (*track)->momentum()), true);
191  }
192  }
193  }
194 
195  if (vtx >= 0) {
196  vtxType = btag::Vertices::RecoVertex;
197 
198  vars.insert(btau::flightDistance2dVal,
199  flipValue(
200  svInfo.flightDistance(vtx, true).value(),
201  true),
202  true);
203  vars.insert(btau::flightDistance2dSig,
204  flipValue(
205  svInfo.flightDistance(vtx, true).significance(),
206  true),
207  true);
208  vars.insert(btau::flightDistance3dVal,
209  flipValue(
210  svInfo.flightDistance(vtx, false).value(),
211  true),
212  true);
213  vars.insert(btau::flightDistance3dSig,
214  flipValue(
215  svInfo.flightDistance(vtx, false).significance(),
216  true),
217  true);
218  vars.insert(btau::vertexJetDeltaR,
219  Geom::deltaR(svInfo.flightDirection(vtx), jetDir),true);
220  vars.insert(btau::jetNSecondaryVertices, svInfo.nVertices(), true);
221  vars.insert(btau::vertexNTracks, svInfo.nVertexTracks(), true);
222  }
223 
224  std::vector<std::size_t> indices = ipInfo.sortedIndexes(sortCriterium);
225  const std::vector<TrackIPTagInfo::TrackIPData> &ipData =
226  ipInfo.impactParameterData();
228  ipInfo.selectedTracks();
229  std::vector<TrackRef> pseudoVertexTracks;
230 
231  TrackRef trackPairV0Test[2];
232  range = flipIterate(indices.size(), false);
233  range_for(i, range) {
234  std::size_t idx = indices[i];
235  const TrackIPTagInfo::TrackIPData &data = ipData[idx];
236  const TrackRef &trackRef = tracks[idx];
237  const Track &track = *trackRef;
238 
239  // filter track
240 
241  if (!trackSelector(track, data, *jet, pv))
242  continue;
243 
244  // add track to kinematics for all tracks in jet
245 
246  allKinematics.add(track);
247 
248  // if no vertex was reconstructed, attempt pseudo vertex
249 
250  if (vtxType == btag::Vertices::NoVertex &&
251  trackPseudoSelector(track, data, *jet, pv)) {
252  pseudoVertexTracks.push_back(trackRef);
253  vertexKinematics.add(track);
254  }
255 
256  // check against all other tracks for V0 track pairs
257 
258  trackPairV0Test[0] = tracks[idx];
259  bool ok = true;
260  range_for(j, range) {
261  if (i == j)
262  continue;
263 
264  std::size_t pairIdx = indices[j];
265  const TrackIPTagInfo::TrackIPData &pairTrackData =
266  ipData[pairIdx];
267  const TrackRef &pairTrackRef = tracks[pairIdx];
268  const Track &pairTrack = *pairTrackRef;
269 
270  if (!trackSelector(pairTrack, pairTrackData, *jet, pv))
271  continue;
272 
273  trackPairV0Test[1] = pairTrackRef;
274  if (!trackPairV0Filter(trackPairV0Test, 2)) {
275  ok = false;
276  break;
277  }
278  }
279  if (!ok)
280  continue;
281 
282  // add track variables
283 
284  math::XYZVector trackMom = track.momentum();
285  double trackMag = std::sqrt(trackMom.Mag2());
286 
287  vars.insert(btau::trackSip3dVal,
288  flipValue(data.ip3d.value(), false), true);
289  vars.insert(btau::trackSip3dSig,
290  flipValue(data.ip3d.significance(), false), true);
291  vars.insert(btau::trackSip2dVal,
292  flipValue(data.ip2d.value(), false), true);
293  vars.insert(btau::trackSip2dSig,
294  flipValue(data.ip2d.significance(), false), true);
295  vars.insert(btau::trackJetDistVal, data.distanceToJetAxis.value(), true);
296 // vars.insert(btau::trackJetDistSig, data.distanceToJetAxis.significance(), true);
297 // vars.insert(btau::trackFirstTrackDist, data.distanceToFirstTrack, true);
298 // vars.insert(btau::trackGhostTrackVal, data.distanceToGhostTrack.value(), true);
299 // vars.insert(btau::trackGhostTrackSig, data.distanceToGhostTrack.significance(), true);
300  vars.insert(btau::trackDecayLenVal, havePv ? (data.closestToJetAxis - pv).mag() : -1.0, true);
301 
302  vars.insert(btau::trackMomentum, trackMag, true);
303  vars.insert(btau::trackEta, trackMom.Eta(), true);
304 
305  vars.insert(btau::trackPtRel, VectorUtil::Perp(trackMom, jetDir), true);
306  vars.insert(btau::trackPPar, jetDir.Dot(trackMom), true);
307  vars.insert(btau::trackDeltaR, VectorUtil::DeltaR(trackMom, jetDir), true);
308  vars.insert(btau::trackPtRatio, VectorUtil::Perp(trackMom, jetDir) / trackMag, true);
309  vars.insert(btau::trackPParRatio, jetDir.Dot(trackMom) / trackMag, true);
310  }
311 
312  if (vtxType == btag::Vertices::NoVertex &&
313  vertexKinematics.numberOfTracks() >= pseudoMultiplicityMin &&
314  pseudoVertexV0Filter(pseudoVertexTracks)) {
316  for(std::vector<TrackRef>::const_iterator track =
317  pseudoVertexTracks.begin();
318  track != pseudoVertexTracks.end(); ++track)
319  vars.insert(btau::trackEtaRel, etaRel(jetDir,
320  (*track)->momentum()), true);
321  }
322 
323  vars.insert(btau::vertexCategory, vtxType, true);
324  vars.insert(btau::trackSumJetDeltaR,
325  VectorUtil::DeltaR(allKinematics.vectorSum(), jetDir), true);
326  vars.insert(btau::trackSumJetEtRatio,
327  allKinematics.vectorSum().Et() / ipInfo.jet()->et(), true);
328  vars.insert(btau::trackSip3dSigAboveCharm,
329  flipValue(
330  threshTrack(ipInfo, TrackIPTagInfo::IP3DSig, *jet, pv)
331  .ip3d.significance(),
332  false),
333  true);
334  vars.insert(btau::trackSip2dSigAboveCharm,
335  flipValue(
336  threshTrack(ipInfo, TrackIPTagInfo::IP2DSig, *jet, pv)
337  .ip2d.significance(),
338  false),
339  true);
340 
341  if (vtxType != btag::Vertices::NoVertex) {
343  ? allKinematics.weightedVectorSum()
344  : allKinematics.vectorSum();
346  ? vertexKinematics.weightedVectorSum()
347  : vertexKinematics.vectorSum();
348 
349  if (vtxType != btag::Vertices::RecoVertex) {
350  vars.insert(btau::vertexNTracks,
351  vertexKinematics.numberOfTracks(), true);
352  vars.insert(btau::vertexJetDeltaR,
353  VectorUtil::DeltaR(vertexSum, jetDir), true);
354  }
355 
356  double vertexMass = vertexSum.M();
357  if (vtxType == btag::Vertices::RecoVertex &&
359  GlobalVector dir = svInfo.flightDirection(vtx);
360  double vertexPt2 =
361  math::XYZVector(dir.x(), dir.y(), dir.z()).
362  Cross(vertexSum).Mag2() / dir.mag2();
363  vertexMass = std::sqrt(vertexMass * vertexMass +
364  vertexPt2) + std::sqrt(vertexPt2);
365  }
366  vars.insert(btau::vertexMass, vertexMass, true);
367  if (allKinematics.numberOfTracks())
368  vars.insert(btau::vertexEnergyRatio,
369  vertexSum.E() / allSum.E(), true);
370  else
371  vars.insert(btau::vertexEnergyRatio, 1, true);
372  }
373 
374  vars.finalize();
375 
376  return vars;
377 }
reco::TrackSelector trackSelector
virtual double et() const GCC11_FINAL
transverse energy
int i
Definition: DBlmapReader.cc:9
T mag2() const
Definition: PV3DBase.h:66
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:148
static edm::ParameterSet dropDeltaR(const edm::ParameterSet &pset)
reco::TrackIPTagInfo::SortCriteria getCriterium(const std::string &name)
Definition: TrackSorting.cc:11
Measurement1D flightDistance(unsigned int index, bool in2d=false) const
unsigned int pseudoMultiplicityMin
const edm::Ref< VertexCollection > & primaryVertex() const
Track refittedTrack(const TrackBaseRef &track) const
Base class for all types of Jets.
Definition: Jet.h:20
reco::TrackSelector trackNoDeltaRSelector
bool hasRefittedTracks() const
Checks whether refitted tracks are stored.
Definition: Vertex.h:120
reco::V0Filter pseudoVertexV0Filter
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
#define range_for(i, x)
T y() const
Definition: PV3DBase.h:63
reco::TaggingVariableList operator()(const reco::TrackIPTagInfo &ipInfo, const reco::SecondaryVertexTagInfo &svInfo) const
CombinedSVComputer(const edm::ParameterSet &params)
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
virtual TrackRefVector tracks(void) const
returns a list of tracks associated to the jet
Definition: JTATagInfo.h:21
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
const GlobalVector & flightDirection(unsigned int index) const
const Vertex & secondaryVertex(unsigned int index) const
reco::TrackSelector trackPseudoSelector
T sqrt(T t)
Definition: SSEVec.h:48
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:142
T z() const
Definition: PV3DBase.h:64
int j
Definition: DBlmapReader.cc:9
const reco::TrackIPTagInfo::TrackIPData & threshTrack(const reco::TrackIPTagInfo &trackIPTagInfo, const reco::TrackIPTagInfo::SortCriteria sort, const reco::Jet &jet, const GlobalPoint &pv) const
#define end
Definition: vmac.h:37
float trackWeight(unsigned int svIndex, unsigned int trackindex) const
IterationRange flipIterate(int size, bool vertex) const
virtual edm::RefToBase< Jet > jet(void) const
returns a polymorphic reference to the tagged jet
Definition: JTATagInfo.h:20
TrackRefVector vertexTracks() const
reco::V0Filter trackPairV0Filter
std::vector< size_t > sortedIndexes(SortCriteria mode=IP3DSig) const
static double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
double significance() const
Definition: Measurement1D.h:32
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 flipValue(double value, bool vertex) const
double value() const
Definition: Measurement1D.h:28
#define begin
Definition: vmac.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double deltaR(const Vector1 &v1, const Vector2 &v2)
Definition: VectorUtil.h:84
const std::vector< TrackIPData > & impactParameterData() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
T w() const
dbl *** dir
Definition: mlp_gen.cc:35
const edm::RefVector< TrackCollection > & selectedTracks() const
T x() const
Definition: PV3DBase.h:62
reco::TrackIPTagInfo::SortCriteria sortCriterium
tuple size
Write out results.
void insert(const TaggingVariable &variable, bool delayed=false)
unsigned int trackMultiplicityMin
tuple trackSelector
Tracks selection.
Definition: valSkim_cff.py:4
tuple useTrackWeights
Definition: alignBH_cfg.py:24