test
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.selectedTracks().size() < trackMultiplicityMin)
162  return vars;
163 
164  TrackKinematics allKinematics;
165  TrackKinematics vertexKinematics;
166 
167  int vtx = -1;
168  unsigned int numberofvertextracks = 0;
169 
170  IterationRange range = flipIterate(svInfo.nVertices(), true);
171  range_for(i, range) {
172  if (vtx < 0)
173  vtx = i;
174 
175  numberofvertextracks = numberofvertextracks + (svInfo.secondaryVertex(i)).nTracks();
176 
177  const Vertex &vertex = svInfo.secondaryVertex(i);
178  bool hasRefittedTracks = vertex.hasRefittedTracks();
179  for(reco::Vertex::trackRef_iterator track = vertex.tracks_begin(); track != vertex.tracks_end(); track++) {
180  double w = vertex.trackWeight(*track);
181  if (w < minTrackWeight)
182  continue;
183  if (hasRefittedTracks) {
184  Track actualTrack =
185  vertex.refittedTrack(*track);
186  vertexKinematics.add(actualTrack, w);
187  vars.insert(btau::trackEtaRel, etaRel(jetDir,
188  actualTrack.momentum()), true);
189  } else {
190  vertexKinematics.add(**track, w);
191  vars.insert(btau::trackEtaRel, etaRel(jetDir,
192  (*track)->momentum()), true);
193  }
194  }
195  }
196 
197  if (vtx >= 0) {
198  vtxType = btag::Vertices::RecoVertex;
199 
200  vars.insert(btau::flightDistance2dVal,
201  flipValue(
202  svInfo.flightDistance(vtx, true).value(),
203  true),
204  true);
205  vars.insert(btau::flightDistance2dSig,
206  flipValue(
207  svInfo.flightDistance(vtx, true).significance(),
208  true),
209  true);
210  vars.insert(btau::flightDistance3dVal,
211  flipValue(
212  svInfo.flightDistance(vtx, false).value(),
213  true),
214  true);
215  vars.insert(btau::flightDistance3dSig,
216  flipValue(
217  svInfo.flightDistance(vtx, false).significance(),
218  true),
219  true);
220  vars.insert(btau::vertexJetDeltaR,
221  Geom::deltaR(svInfo.flightDirection(vtx), jetDir),true);
222  vars.insert(btau::jetNSecondaryVertices, svInfo.nVertices(), true);
223  vars.insert(btau::vertexNTracks, numberofvertextracks, true);
224  }
225 
226  std::vector<std::size_t> indices = ipInfo.sortedIndexes(sortCriterium);
227  const std::vector<TrackIPTagInfo::TrackIPData> &ipData =
228  ipInfo.impactParameterData();
230  ipInfo.selectedTracks();
231  std::vector<TrackRef> pseudoVertexTracks;
232 
233  TrackRef trackPairV0Test[2];
234  range = flipIterate(indices.size(), false);
235  range_for(i, range) {
236  std::size_t idx = indices[i];
237  const TrackIPTagInfo::TrackIPData &data = ipData[idx];
238  const TrackRef &trackRef = tracks[idx];
239  const Track &track = *trackRef;
240 
241  // filter track
242 
243  if (!trackSelector(track, data, *jet, pv))
244  continue;
245 
246  // add track to kinematics for all tracks in jet
247 
248  allKinematics.add(track);
249 
250  // if no vertex was reconstructed, attempt pseudo vertex
251 
252  if (vtxType == btag::Vertices::NoVertex &&
253  trackPseudoSelector(track, data, *jet, pv)) {
254  pseudoVertexTracks.push_back(trackRef);
255  vertexKinematics.add(track);
256  }
257 
258  // check against all other tracks for V0 track pairs
259 
260  trackPairV0Test[0] = tracks[idx];
261  bool ok = true;
262  range_for(j, range) {
263  if (i == j)
264  continue;
265 
266  std::size_t pairIdx = indices[j];
267  const TrackIPTagInfo::TrackIPData &pairTrackData =
268  ipData[pairIdx];
269  const TrackRef &pairTrackRef = tracks[pairIdx];
270  const Track &pairTrack = *pairTrackRef;
271 
272  if (!trackSelector(pairTrack, pairTrackData, *jet, pv))
273  continue;
274 
275  trackPairV0Test[1] = pairTrackRef;
276  if (!trackPairV0Filter(trackPairV0Test, 2)) {
277  ok = false;
278  break;
279  }
280  }
281  if (!ok)
282  continue;
283 
284  // add track variables
285 
286  math::XYZVector trackMom = track.momentum();
287  double trackMag = std::sqrt(trackMom.Mag2());
288 
289  vars.insert(btau::trackSip3dVal,
290  flipValue(data.ip3d.value(), false), true);
291  vars.insert(btau::trackSip3dSig,
292  flipValue(data.ip3d.significance(), false), true);
293  vars.insert(btau::trackSip2dVal,
294  flipValue(data.ip2d.value(), false), true);
295  vars.insert(btau::trackSip2dSig,
296  flipValue(data.ip2d.significance(), false), true);
297  vars.insert(btau::trackJetDistVal, data.distanceToJetAxis.value(), true);
298 // vars.insert(btau::trackJetDistSig, data.distanceToJetAxis.significance(), true);
299 // vars.insert(btau::trackFirstTrackDist, data.distanceToFirstTrack, true);
300 // vars.insert(btau::trackGhostTrackVal, data.distanceToGhostTrack.value(), true);
301 // vars.insert(btau::trackGhostTrackSig, data.distanceToGhostTrack.significance(), true);
302  vars.insert(btau::trackDecayLenVal, havePv ? (data.closestToJetAxis - pv).mag() : -1.0, true);
303 
304  vars.insert(btau::trackMomentum, trackMag, true);
305  vars.insert(btau::trackEta, trackMom.Eta(), true);
306 
307  vars.insert(btau::trackPtRel, VectorUtil::Perp(trackMom, jetDir), true);
308  vars.insert(btau::trackPPar, jetDir.Dot(trackMom), true);
309  vars.insert(btau::trackDeltaR, VectorUtil::DeltaR(trackMom, jetDir), true);
310  vars.insert(btau::trackPtRatio, VectorUtil::Perp(trackMom, jetDir) / trackMag, true);
311  vars.insert(btau::trackPParRatio, jetDir.Dot(trackMom) / trackMag, true);
312  }
313 
314  if (vtxType == btag::Vertices::NoVertex &&
315  vertexKinematics.numberOfTracks() >= pseudoMultiplicityMin &&
316  pseudoVertexV0Filter(pseudoVertexTracks)) {
318  for(std::vector<TrackRef>::const_iterator track =
319  pseudoVertexTracks.begin();
320  track != pseudoVertexTracks.end(); ++track)
321  vars.insert(btau::trackEtaRel, etaRel(jetDir,
322  (*track)->momentum()), true);
323  }
324 
325  vars.insert(btau::vertexCategory, vtxType, true);
326  vars.insert(btau::trackSumJetDeltaR,
327  VectorUtil::DeltaR(allKinematics.vectorSum(), jetDir), true);
328  vars.insert(btau::trackSumJetEtRatio,
329  allKinematics.vectorSum().Et() / ipInfo.jet()->et(), true);
330  vars.insert(btau::trackSip3dSigAboveCharm,
331  flipValue(
332  threshTrack(ipInfo, TrackIPTagInfo::IP3DSig, *jet, pv)
333  .ip3d.significance(),
334  false),
335  true);
336  vars.insert(btau::trackSip2dSigAboveCharm,
337  flipValue(
338  threshTrack(ipInfo, TrackIPTagInfo::IP2DSig, *jet, pv)
339  .ip2d.significance(),
340  false),
341  true);
342 
343  if (vtxType != btag::Vertices::NoVertex) {
345  ? allKinematics.weightedVectorSum()
346  : allKinematics.vectorSum();
348  ? vertexKinematics.weightedVectorSum()
349  : vertexKinematics.vectorSum();
350 
351  if (vtxType != btag::Vertices::RecoVertex) {
352  vars.insert(btau::vertexNTracks,
353  vertexKinematics.numberOfTracks(), true);
354  vars.insert(btau::vertexJetDeltaR,
355  VectorUtil::DeltaR(vertexSum, jetDir), true);
356  }
357 
358  double vertexMass = vertexSum.M();
359  if (vtxType == btag::Vertices::RecoVertex &&
361  GlobalVector dir = svInfo.flightDirection(vtx);
362  double vertexPt2 =
363  math::XYZVector(dir.x(), dir.y(), dir.z()).
364  Cross(vertexSum).Mag2() / dir.mag2();
365  vertexMass = std::sqrt(vertexMass * vertexMass +
366  vertexPt2) + std::sqrt(vertexPt2);
367  }
368  vars.insert(btau::vertexMass, vertexMass, true);
369  if (allKinematics.numberOfTracks())
370  vars.insert(btau::vertexEnergyRatio,
371  vertexSum.E() / allSum.E(), true);
372  else
373  vars.insert(btau::vertexEnergyRatio, 1, true);
374  }
375 
376  vars.finalize();
377 
378  return vars;
379 }
reco::TrackSelector trackSelector
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
const double w
Definition: UKUtility.cc:23
Measurement1D flightDistance(unsigned int index, bool in2d=false) const
unsigned int pseudoMultiplicityMin
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
virtual double et() const
transverse energy
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:134
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)
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
float trackWeight(const TrackBaseRef &r) const
returns the weight with which a Track has contributed to the vertex-fit.
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
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
reco::V0Filter trackPairV0Filter
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
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
const std::vector< TrackIPData > & impactParameterData() const
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:37
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
dbl *** dir
Definition: mlp_gen.cc:35
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39
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