CMS 3D CMS Logo

BoostedDoubleSVProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ​RecoBTag/​SecondaryVertex
4 // Class: BoostedDoubleSVProducer
5 //
14 //
15 // Original Author: Dinko Ferencek
16 // Created: Thu, 06 Oct 2016 14:02:30 GMT
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
33 
43 
51 
52 #include "fastjet/PseudoJet.hh"
53 #include "fastjet/contrib/Njettiness.hh"
54 
55 #include <map>
56 
57 //
58 // class declaration
59 //
60 
62 public:
64  ~BoostedDoubleSVProducer() override;
65 
66  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
67 
68 private:
69  void beginStream(edm::StreamID) override;
70  void produce(edm::Event&, const edm::EventSetup&) override;
71  void endStream() override;
72 
74  float& tau1,
75  float& tau2,
76  std::vector<fastjet::PseudoJet>& currentAxes) const;
77  void setTracksPVBase(const reco::TrackRef& trackRef, const reco::VertexRef& vertexRef, float& PVweight) const;
78  void setTracksPV(const reco::CandidatePtr& trackRef, const reco::VertexRef& vertexRef, float& PVweight) const;
80  const fastjet::PseudoJet& tauAxis,
81  std::vector<float>& tau_trackEtaRel) const;
82 
83  // ----------member data ---------------------------
85 
86  const double beta_;
87  const double R0_;
88 
89  const double maxSVDeltaRToJet_;
90  const double maxDistToAxis_;
91  const double maxDecayLen_;
94 
95  // static variables
96  static constexpr float dummyZ_ratio = -3.0f;
97  static constexpr float dummyTrackSip3dSig = -50.0f;
98  static constexpr float dummyTrackSip2dSigAbove = -19.0f;
99  static constexpr float dummyTrackEtaRel = -1.0f;
100  static constexpr float dummyVertexMass = -1.0f;
101  static constexpr float dummyVertexEnergyRatio = -1.0f;
102  static constexpr float dummyVertexDeltaR = -1.0f;
103  static constexpr float dummyFlightDistance2dSig = -1.0f;
104 
105  static constexpr float charmThreshold = 1.5f;
106  static constexpr float bottomThreshold = 5.2f;
107 };
108 
109 //
110 // constants, enums and typedefs
111 //
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121  : svTagInfos_(
122  consumes<std::vector<reco::CandSecondaryVertexTagInfo> >(iConfig.getParameter<edm::InputTag>("svTagInfos"))),
123  beta_(iConfig.getParameter<double>("beta")),
124  R0_(iConfig.getParameter<double>("R0")),
125  maxSVDeltaRToJet_(iConfig.getParameter<double>("maxSVDeltaRToJet")),
126  maxDistToAxis_(iConfig.getParameter<edm::ParameterSet>("trackSelection").getParameter<double>("maxDistToAxis")),
127  maxDecayLen_(iConfig.getParameter<edm::ParameterSet>("trackSelection").getParameter<double>("maxDecayLen")),
128  trackPairV0Filter(iConfig.getParameter<edm::ParameterSet>("trackPairV0Filter")),
129  trackSelector(iConfig.getParameter<edm::ParameterSet>("trackSelection")) {
130  produces<std::vector<reco::BoostedDoubleSVTagInfo> >();
131 }
132 
134  // do anything here that needs to be done at destruction time
135  // (e.g. close files, deallocate resources etc.)
136 }
137 
138 //
139 // member functions
140 //
141 
142 // ------------ method called to produce the data ------------
144  // get the track builder
146  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilder);
147 
148  // get input secondary vertex TagInfos
150  iEvent.getByToken(svTagInfos_, svTagInfos);
151 
152  // create the output collection
153  auto tagInfos = std::make_unique<std::vector<reco::BoostedDoubleSVTagInfo> >();
154 
155  // loop over TagInfos
156  for (std::vector<reco::CandSecondaryVertexTagInfo>::const_iterator iterTI = svTagInfos->begin();
157  iterTI != svTagInfos->end();
158  ++iterTI) {
159  // get TagInfos
160  const reco::CandIPTagInfo& ipTagInfo = *(iterTI->trackIPTagInfoRef().get());
161  const reco::CandSecondaryVertexTagInfo& svTagInfo = *(iterTI);
162 
163  // default variable values
164  float z_ratio = dummyZ_ratio;
179  float jetNTracks = 0, nSV = 0, tau1_nSecondaryVertices = 0, tau2_nSecondaryVertices = 0;
180 
181  // get the jet reference
182  const reco::JetBaseRef jet = svTagInfo.jet();
183 
184  std::vector<fastjet::PseudoJet> currentAxes;
185  float tau2, tau1;
186  // calculate N-subjettiness
187  calcNsubjettiness(jet, tau1, tau2, currentAxes);
188 
189  const reco::VertexRef& vertexRef = ipTagInfo.primaryVertex();
190  GlobalPoint pv(0., 0., 0.);
191  if (ipTagInfo.primaryVertex().isNonnull())
192  pv = GlobalPoint(vertexRef->x(), vertexRef->y(), vertexRef->z());
193 
194  const std::vector<reco::CandidatePtr>& selectedTracks = ipTagInfo.selectedTracks();
195  const std::vector<reco::btag::TrackIPData>& ipData = ipTagInfo.impactParameterData();
196  size_t trackSize = selectedTracks.size();
197 
198  reco::TrackKinematics allKinematics;
199  std::vector<float> IP3Ds, IP3Ds_1, IP3Ds_2;
200  int contTrk = 0;
201 
202  // loop over tracks associated to the jet
203  for (size_t itt = 0; itt < trackSize; ++itt) {
204  const reco::CandidatePtr trackRef = selectedTracks[itt];
205 
206  float track_PVweight = 0.;
207  setTracksPV(trackRef, vertexRef, track_PVweight);
208  if (track_PVweight > 0.5)
209  allKinematics.add(trackRef);
210 
211  const reco::btag::TrackIPData& data = ipData[itt];
212  bool isSelected = false;
213  if (trackSelector(trackRef, data, *jet, pv))
214  isSelected = true;
215 
216  // check if the track is from V0
217  bool isfromV0 = false, isfromV0Tight = false;
218  std::vector<reco::CandidatePtr> trackPairV0Test(2);
219 
220  trackPairV0Test[0] = trackRef;
221 
222  for (size_t jtt = 0; jtt < trackSize; ++jtt) {
223  if (itt == jtt)
224  continue;
225 
226  const reco::btag::TrackIPData& pairTrackData = ipData[jtt];
227  const reco::CandidatePtr pairTrackRef = selectedTracks[jtt];
228 
229  trackPairV0Test[1] = pairTrackRef;
230 
231  if (!trackPairV0Filter(trackPairV0Test)) {
232  isfromV0 = true;
233 
234  if (trackSelector(pairTrackRef, pairTrackData, *jet, pv))
235  isfromV0Tight = true;
236  }
237 
238  if (isfromV0 && isfromV0Tight)
239  break;
240  }
241 
242  if (isSelected && !isfromV0Tight)
243  jetNTracks += 1.;
244 
245  reco::TransientTrack transientTrack = trackBuilder->build(trackRef);
246  GlobalVector direction(jet->px(), jet->py(), jet->pz());
247 
248  int index = 0;
249  if (currentAxes.size() > 1 &&
250  reco::deltaR2(trackRef->momentum(), currentAxes[1]) < reco::deltaR2(trackRef->momentum(), currentAxes[0]))
251  index = 1;
252  direction = GlobalVector(currentAxes[index].px(), currentAxes[index].py(), currentAxes[index].pz());
253 
254  // decay distance and track distance wrt to the closest tau axis
255  float decayLengthTau = -1;
256  float distTauAxis = -1;
257 
259  transientTrack.impactPointState(), *vertexRef, direction, transientTrack.field());
260  if (closest.isValid())
261  decayLengthTau = (closest.globalPosition() - RecoVertex::convertPos(vertexRef->position())).mag();
262 
263  distTauAxis = std::abs(IPTools::jetTrackDistance(transientTrack, direction, *vertexRef).second.value());
264 
265  float IP3Dsig = ipTagInfo.impactParameterData()[itt].ip3d.significance();
266 
267  if (!isfromV0 && decayLengthTau < maxDecayLen_ && distTauAxis < maxDistToAxis_) {
268  IP3Ds.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
269  ++contTrk;
270  if (currentAxes.size() > 1) {
271  if (reco::deltaR2(trackRef->momentum(), currentAxes[0]) < reco::deltaR2(trackRef->momentum(), currentAxes[1]))
272  IP3Ds_1.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
273  else
274  IP3Ds_2.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
275  } else
276  IP3Ds_1.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
277  }
278  }
279 
280  std::vector<size_t> indices = ipTagInfo.sortedIndexes(reco::btag::IP2DSig);
281  bool charmThreshSet = false;
282 
284  for (size_t i = 0; i < indices.size(); ++i) {
285  size_t idx = indices[i];
286  const reco::btag::TrackIPData& data = ipData[idx];
287  const reco::CandidatePtr trackRef = selectedTracks[idx];
288 
289  kin.add(trackRef);
290 
291  if (kin.vectorSum().M() > charmThreshold // charm cut
292  && !charmThreshSet) {
293  trackSip2dSigAboveCharm_0 = data.ip2d.significance();
294 
295  charmThreshSet = true;
296  }
297 
298  if (kin.vectorSum().M() > bottomThreshold) // bottom cut
299  {
300  trackSip2dSigAboveBottom_0 = data.ip2d.significance();
301  if ((i + 1) < indices.size())
302  trackSip2dSigAboveBottom_1 = (ipData[indices[i + 1]]).ip2d.significance();
303 
304  break;
305  }
306  }
307 
308  float dummyTrack = -50.;
309 
310  std::sort(IP3Ds.begin(), IP3Ds.end(), std::greater<float>());
311  std::sort(IP3Ds_1.begin(), IP3Ds_1.end(), std::greater<float>());
312  std::sort(IP3Ds_2.begin(), IP3Ds_2.end(), std::greater<float>());
313  int num_1 = IP3Ds_1.size();
314  int num_2 = IP3Ds_2.size();
315 
316  switch (contTrk) {
317  case 0:
318 
319  trackSip3dSig_0 = dummyTrack;
320  trackSip3dSig_1 = dummyTrack;
321  trackSip3dSig_2 = dummyTrack;
322  trackSip3dSig_3 = dummyTrack;
323 
324  break;
325 
326  case 1:
327 
328  trackSip3dSig_0 = IP3Ds.at(0);
329  trackSip3dSig_1 = dummyTrack;
330  trackSip3dSig_2 = dummyTrack;
331  trackSip3dSig_3 = dummyTrack;
332 
333  break;
334 
335  case 2:
336 
337  trackSip3dSig_0 = IP3Ds.at(0);
338  trackSip3dSig_1 = IP3Ds.at(1);
339  trackSip3dSig_2 = dummyTrack;
340  trackSip3dSig_3 = dummyTrack;
341 
342  break;
343 
344  case 3:
345 
346  trackSip3dSig_0 = IP3Ds.at(0);
347  trackSip3dSig_1 = IP3Ds.at(1);
348  trackSip3dSig_2 = IP3Ds.at(2);
349  trackSip3dSig_3 = dummyTrack;
350 
351  break;
352 
353  default:
354 
355  trackSip3dSig_0 = IP3Ds.at(0);
356  trackSip3dSig_1 = IP3Ds.at(1);
357  trackSip3dSig_2 = IP3Ds.at(2);
358  trackSip3dSig_3 = IP3Ds.at(3);
359  }
360 
361  switch (num_1) {
362  case 0:
363 
364  tau1_trackSip3dSig_0 = dummyTrack;
365  tau1_trackSip3dSig_1 = dummyTrack;
366 
367  break;
368 
369  case 1:
370 
371  tau1_trackSip3dSig_0 = IP3Ds_1.at(0);
372  tau1_trackSip3dSig_1 = dummyTrack;
373 
374  break;
375 
376  default:
377 
378  tau1_trackSip3dSig_0 = IP3Ds_1.at(0);
379  tau1_trackSip3dSig_1 = IP3Ds_1.at(1);
380  }
381 
382  switch (num_2) {
383  case 0:
384 
385  tau2_trackSip3dSig_0 = dummyTrack;
386  tau2_trackSip3dSig_1 = dummyTrack;
387 
388  break;
389 
390  case 1:
391  tau2_trackSip3dSig_0 = IP3Ds_2.at(0);
392  tau2_trackSip3dSig_1 = dummyTrack;
393 
394  break;
395 
396  default:
397 
398  tau2_trackSip3dSig_0 = IP3Ds_2.at(0);
399  tau2_trackSip3dSig_1 = IP3Ds_2.at(1);
400  }
401 
402  math::XYZVector jetDir = jet->momentum().Unit();
403  reco::TrackKinematics tau1Kinematics;
404  reco::TrackKinematics tau2Kinematics;
405  std::vector<float> tau1_trackEtaRels, tau2_trackEtaRels;
406 
407  std::map<double, size_t> VTXmap;
408  for (size_t vtx = 0; vtx < svTagInfo.nVertices(); ++vtx) {
410  // get the vertex kinematics
411  reco::TrackKinematics vertexKinematic(vertex);
412 
413  if (currentAxes.size() > 1) {
414  if (reco::deltaR2(svTagInfo.flightDirection(vtx), currentAxes[1]) <
415  reco::deltaR2(svTagInfo.flightDirection(vtx), currentAxes[0])) {
416  tau2Kinematics = tau2Kinematics + vertexKinematic;
417  if (tau2_flightDistance2dSig < 0) {
418  tau2_flightDistance2dSig = svTagInfo.flightDistance(vtx, true).significance();
419  tau2_vertexDeltaR = reco::deltaR(svTagInfo.flightDirection(vtx), currentAxes[1]);
420  }
421  etaRelToTauAxis(vertex, currentAxes[1], tau2_trackEtaRels);
422  tau2_nSecondaryVertices += 1.;
423  } else {
424  tau1Kinematics = tau1Kinematics + vertexKinematic;
425  if (tau1_flightDistance2dSig < 0) {
426  tau1_flightDistance2dSig = svTagInfo.flightDistance(vtx, true).significance();
427  tau1_vertexDeltaR = reco::deltaR(svTagInfo.flightDirection(vtx), currentAxes[0]);
428  }
429  etaRelToTauAxis(vertex, currentAxes[0], tau1_trackEtaRels);
430  tau1_nSecondaryVertices += 1.;
431  }
432 
433  } else if (!currentAxes.empty()) {
434  tau1Kinematics = tau1Kinematics + vertexKinematic;
435  if (tau1_flightDistance2dSig < 0) {
436  tau1_flightDistance2dSig = svTagInfo.flightDistance(vtx, true).significance();
437  tau1_vertexDeltaR = reco::deltaR(svTagInfo.flightDirection(vtx), currentAxes[0]);
438  }
439  etaRelToTauAxis(vertex, currentAxes[0], tau1_trackEtaRels);
440  tau1_nSecondaryVertices += 1.;
441  }
442 
443  const GlobalVector& flightDir = svTagInfo.flightDirection(vtx);
444  if (reco::deltaR2(flightDir, jetDir) < (maxSVDeltaRToJet_ * maxSVDeltaRToJet_))
445  VTXmap[svTagInfo.flightDistance(vtx).error()] = vtx;
446  }
447  nSV = VTXmap.size();
448 
449  math::XYZTLorentzVector allSum = allKinematics.weightedVectorSum();
450  if (tau1_nSecondaryVertices > 0.) {
451  const math::XYZTLorentzVector& tau1_vertexSum = tau1Kinematics.weightedVectorSum();
452  if (allSum.E() > 0.)
453  tau1_vertexEnergyRatio = tau1_vertexSum.E() / allSum.E();
454  if (tau1_vertexEnergyRatio > 50.)
455  tau1_vertexEnergyRatio = 50.;
456 
457  tau1_vertexMass = tau1_vertexSum.M();
458  }
459 
460  if (tau2_nSecondaryVertices > 0.) {
461  const math::XYZTLorentzVector& tau2_vertexSum = tau2Kinematics.weightedVectorSum();
462  if (allSum.E() > 0.)
463  tau2_vertexEnergyRatio = tau2_vertexSum.E() / allSum.E();
464  if (tau2_vertexEnergyRatio > 50.)
465  tau2_vertexEnergyRatio = 50.;
466 
467  tau2_vertexMass = tau2_vertexSum.M();
468  }
469 
470  float dummyEtaRel = -1.;
471 
472  std::sort(tau1_trackEtaRels.begin(), tau1_trackEtaRels.end());
473  std::sort(tau2_trackEtaRels.begin(), tau2_trackEtaRels.end());
474 
475  switch (tau2_trackEtaRels.size()) {
476  case 0:
477 
478  tau2_trackEtaRel_0 = dummyEtaRel;
479  tau2_trackEtaRel_1 = dummyEtaRel;
480  tau2_trackEtaRel_2 = dummyEtaRel;
481 
482  break;
483 
484  case 1:
485 
486  tau2_trackEtaRel_0 = tau2_trackEtaRels.at(0);
487  tau2_trackEtaRel_1 = dummyEtaRel;
488  tau2_trackEtaRel_2 = dummyEtaRel;
489 
490  break;
491 
492  case 2:
493 
494  tau2_trackEtaRel_0 = tau2_trackEtaRels.at(0);
495  tau2_trackEtaRel_1 = tau2_trackEtaRels.at(1);
496  tau2_trackEtaRel_2 = dummyEtaRel;
497 
498  break;
499 
500  default:
501 
502  tau2_trackEtaRel_0 = tau2_trackEtaRels.at(0);
503  tau2_trackEtaRel_1 = tau2_trackEtaRels.at(1);
504  tau2_trackEtaRel_2 = tau2_trackEtaRels.at(2);
505  }
506 
507  switch (tau1_trackEtaRels.size()) {
508  case 0:
509 
510  tau1_trackEtaRel_0 = dummyEtaRel;
511  tau1_trackEtaRel_1 = dummyEtaRel;
512  tau1_trackEtaRel_2 = dummyEtaRel;
513 
514  break;
515 
516  case 1:
517 
518  tau1_trackEtaRel_0 = tau1_trackEtaRels.at(0);
519  tau1_trackEtaRel_1 = dummyEtaRel;
520  tau1_trackEtaRel_2 = dummyEtaRel;
521 
522  break;
523 
524  case 2:
525 
526  tau1_trackEtaRel_0 = tau1_trackEtaRels.at(0);
527  tau1_trackEtaRel_1 = tau1_trackEtaRels.at(1);
528  tau1_trackEtaRel_2 = dummyEtaRel;
529 
530  break;
531 
532  default:
533 
534  tau1_trackEtaRel_0 = tau1_trackEtaRels.at(0);
535  tau1_trackEtaRel_1 = tau1_trackEtaRels.at(1);
536  tau1_trackEtaRel_2 = tau1_trackEtaRels.at(2);
537  }
538 
539  int cont = 0;
540  GlobalVector flightDir_0, flightDir_1;
541  reco::Candidate::LorentzVector SV_p4_0, SV_p4_1;
542  double vtxMass = 0.;
543 
544  for (std::map<double, size_t>::iterator iVtx = VTXmap.begin(); iVtx != VTXmap.end(); ++iVtx) {
545  ++cont;
546  const reco::VertexCompositePtrCandidate& vertex = svTagInfo.secondaryVertex(iVtx->second);
547  if (cont == 1) {
548  flightDir_0 = svTagInfo.flightDirection(iVtx->second);
549  SV_p4_0 = vertex.p4();
550  vtxMass = SV_p4_0.mass();
551 
552  if (vtxMass > 0.)
553  z_ratio = reco::deltaR(currentAxes[1], currentAxes[0]) * SV_p4_0.pt() / vtxMass;
554  }
555  if (cont == 2) {
556  flightDir_1 = svTagInfo.flightDirection(iVtx->second);
557  SV_p4_1 = vertex.p4();
558  vtxMass = (SV_p4_1 + SV_p4_0).mass();
559 
560  if (vtxMass > 0.)
561  z_ratio = reco::deltaR(flightDir_0, flightDir_1) * SV_p4_1.pt() / vtxMass;
562 
563  break;
564  }
565  }
566 
567  // when only one tau axis has SVs assigned, they are all assigned to the 1st tau axis
568  // in the special case below need to swap values
569  if ((tau1_vertexMass < 0 && tau2_vertexMass > 0)) {
570  float temp = tau1_trackEtaRel_0;
571  tau1_trackEtaRel_0 = tau2_trackEtaRel_0;
572  tau2_trackEtaRel_0 = temp;
573 
574  temp = tau1_trackEtaRel_1;
575  tau1_trackEtaRel_1 = tau2_trackEtaRel_1;
576  tau2_trackEtaRel_1 = temp;
577 
578  temp = tau1_trackEtaRel_2;
579  tau1_trackEtaRel_2 = tau2_trackEtaRel_2;
580  tau2_trackEtaRel_2 = temp;
581 
583  tau1_flightDistance2dSig = tau2_flightDistance2dSig;
584  tau2_flightDistance2dSig = temp;
585 
586  tau1_vertexDeltaR = tau2_vertexDeltaR;
587 
588  temp = tau1_vertexEnergyRatio;
589  tau1_vertexEnergyRatio = tau2_vertexEnergyRatio;
590  tau2_vertexEnergyRatio = temp;
591 
592  temp = tau1_vertexMass;
593  tau1_vertexMass = tau2_vertexMass;
594  tau2_vertexMass = temp;
595  }
596 
598 
599  vars.insert(reco::btau::jetNTracks, jetNTracks, true);
600  vars.insert(reco::btau::jetNSecondaryVertices, nSV, true);
601  vars.insert(reco::btau::trackSip3dSig_0, trackSip3dSig_0, true);
602  vars.insert(reco::btau::trackSip3dSig_1, trackSip3dSig_1, true);
603  vars.insert(reco::btau::trackSip3dSig_2, trackSip3dSig_2, true);
604  vars.insert(reco::btau::trackSip3dSig_3, trackSip3dSig_3, true);
605  vars.insert(reco::btau::tau1_trackSip3dSig_0, tau1_trackSip3dSig_0, true);
606  vars.insert(reco::btau::tau1_trackSip3dSig_1, tau1_trackSip3dSig_1, true);
607  vars.insert(reco::btau::tau2_trackSip3dSig_0, tau2_trackSip3dSig_0, true);
608  vars.insert(reco::btau::tau2_trackSip3dSig_1, tau2_trackSip3dSig_1, true);
609  vars.insert(reco::btau::trackSip2dSigAboveCharm, trackSip2dSigAboveCharm_0, true);
610  vars.insert(reco::btau::trackSip2dSigAboveBottom_0, trackSip2dSigAboveBottom_0, true);
611  vars.insert(reco::btau::trackSip2dSigAboveBottom_1, trackSip2dSigAboveBottom_1, true);
612  vars.insert(reco::btau::tau1_trackEtaRel_0, tau1_trackEtaRel_0, true);
613  vars.insert(reco::btau::tau1_trackEtaRel_1, tau1_trackEtaRel_1, true);
614  vars.insert(reco::btau::tau1_trackEtaRel_2, tau1_trackEtaRel_2, true);
615  vars.insert(reco::btau::tau2_trackEtaRel_0, tau2_trackEtaRel_0, true);
616  vars.insert(reco::btau::tau2_trackEtaRel_1, tau2_trackEtaRel_1, true);
617  vars.insert(reco::btau::tau2_trackEtaRel_2, tau2_trackEtaRel_2, true);
618  vars.insert(reco::btau::tau1_vertexMass, tau1_vertexMass, true);
619  vars.insert(reco::btau::tau1_vertexEnergyRatio, tau1_vertexEnergyRatio, true);
620  vars.insert(reco::btau::tau1_flightDistance2dSig, tau1_flightDistance2dSig, true);
621  vars.insert(reco::btau::tau1_vertexDeltaR, tau1_vertexDeltaR, true);
622  vars.insert(reco::btau::tau2_vertexMass, tau2_vertexMass, true);
623  vars.insert(reco::btau::tau2_vertexEnergyRatio, tau2_vertexEnergyRatio, true);
624  vars.insert(reco::btau::tau2_flightDistance2dSig, tau2_flightDistance2dSig, true);
625  vars.insert(reco::btau::z_ratio, z_ratio, true);
626 
627  vars.finalize();
628 
630  vars, edm::Ref<std::vector<reco::CandSecondaryVertexTagInfo> >(svTagInfos, iterTI - svTagInfos->begin())));
631  }
632 
633  // put the output in the event
634  iEvent.put(std::move(tagInfos));
635 }
636 
638  float& tau1,
639  float& tau2,
640  std::vector<fastjet::PseudoJet>& currentAxes) const {
641  std::vector<fastjet::PseudoJet> fjParticles;
642 
643  // loop over jet constituents and push them in the vector of FastJet constituents
644  for (const reco::CandidatePtr& daughter : jet->daughterPtrVector()) {
645  if (daughter.isNonnull() && daughter.isAvailable()) {
646  const reco::Jet* subjet = dynamic_cast<const reco::Jet*>(daughter.get());
647  // if the daughter is actually a subjet
648  if (subjet && daughter->numberOfDaughters() > 1) {
649  // loop over subjet constituents and push them in the vector of FastJet constituents
650  for (size_t i = 0; i < daughter->numberOfDaughters(); ++i) {
651  const reco::Candidate* constit = daughter->daughter(i);
652 
653  if (constit) {
654  // Check if any values were nan or inf
655  float valcheck = constit->px() + constit->py() + constit->pz() + constit->energy();
656  if (edm::isNotFinite(valcheck)) {
657  edm::LogWarning("FaultyJetConstituent")
658  << "Jet constituent required for N-subjettiness computation contains Nan/Inf values!";
659  continue;
660  }
661  fjParticles.push_back(fastjet::PseudoJet(constit->px(), constit->py(), constit->pz(), constit->energy()));
662  } else
663  edm::LogWarning("MissingJetConstituent")
664  << "Jet constituent required for N-subjettiness computation is missing!";
665  }
666  } else {
667  // Check if any values were nan or inf
668  float valcheck = daughter->px() + daughter->py() + daughter->pz() + daughter->energy();
669  if (edm::isNotFinite(valcheck)) {
670  edm::LogWarning("FaultyJetConstituent")
671  << "Jet constituent required for N-subjettiness computation contains Nan/Inf values!";
672  continue;
673  }
674  fjParticles.push_back(fastjet::PseudoJet(daughter->px(), daughter->py(), daughter->pz(), daughter->energy()));
675  }
676  } else
677  edm::LogWarning("MissingJetConstituent") << "Jet constituent required for N-subjettiness computation is missing!";
678  }
679 
680  // N-subjettiness calculator
681  fastjet::contrib::Njettiness njettiness(fastjet::contrib::OnePass_KT_Axes(),
682  fastjet::contrib::NormalizedMeasure(beta_, R0_));
683 
684  // calculate N-subjettiness
685  tau1 = njettiness.getTau(1, fjParticles);
686  tau2 = njettiness.getTau(2, fjParticles);
687  currentAxes = njettiness.currentAxes();
688 }
689 
691  const reco::VertexRef& vertexRef,
692  float& PVweight) const {
693  PVweight = 0.;
694 
695  const reco::TrackBaseRef trackBaseRef(trackRef);
696 
698 
699  const reco::Vertex& vtx = *(vertexRef);
700  // loop over tracks in vertices
701  for (IT it = vtx.tracks_begin(); it != vtx.tracks_end(); ++it) {
702  const reco::TrackBaseRef& baseRef = *it;
703  // one of the tracks in the vertex is the same as the track considered in the function
704  if (baseRef == trackBaseRef) {
705  PVweight = vtx.trackWeight(baseRef);
706  break;
707  }
708  }
709 }
710 
712  const reco::VertexRef& vertexRef,
713  float& PVweight) const {
714  PVweight = 0.;
715 
716  const pat::PackedCandidate* pcand = dynamic_cast<const pat::PackedCandidate*>(trackRef.get());
717 
718  if (pcand) // MiniAOD case
719  {
720  if (pcand->fromPV() == pat::PackedCandidate::PVUsedInFit) {
721  PVweight = 1.;
722  }
723  } else {
724  const reco::PFCandidate* pfcand = dynamic_cast<const reco::PFCandidate*>(trackRef.get());
725 
726  setTracksPVBase(pfcand->trackRef(), vertexRef, PVweight);
727  }
728 }
729 
731  const fastjet::PseudoJet& tauAxis,
732  std::vector<float>& tau_trackEtaRel) const {
733  math::XYZVector direction(tauAxis.px(), tauAxis.py(), tauAxis.pz());
734  const std::vector<reco::CandidatePtr>& tracks = vertex.daughterPtrVector();
735 
736  for (std::vector<reco::CandidatePtr>::const_iterator track = tracks.begin(); track != tracks.end(); ++track)
737  tau_trackEtaRel.push_back(std::abs(reco::btau::etaRel(direction.Unit(), (*track)->momentum())));
738 }
739 
740 // ------------ method called once each stream before processing any runs, lumis or events ------------
742 
743 // ------------ method called once each stream after processing all runs, lumis and events ------------
745 
746 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
748  //The following says we do not know what parameters are allowed so do no validation
749  // Please change this to state exactly what you do use, even if it is no parameters
751  desc.setUnknown();
752  descriptions.addDefault(desc);
753 }
754 
755 //define this as a plug-in
reco::Vertex::Point convertPos(const GlobalPoint &p)
const edm::EDGetTokenT< std::vector< reco::CandSecondaryVertexTagInfo > > svTagInfos_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const math::XYZTLorentzVector & weightedVectorSum() const
virtual double pz() const =0
z coordinate of momentum vector
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:73
void add(const reco::Track &track, double weight=1.0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
const VTX & secondaryVertex(unsigned int index) const
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
Base class for all types of Jets.
Definition: Jet.h:20
double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
Measurement1D ip2d
Definition: IPTagInfo.h:31
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
reco::TransientTrack build(const reco::Track *p) const
double error() const
Definition: Measurement1D.h:27
edm::RefToBase< Jet > jet(void) const override
returns a polymorphic reference to the tagged jet
GlobalPoint globalPosition() const
const Container & selectedTracks() const
Definition: IPTagInfo.h:99
TrajectoryStateOnSurface closestApproachToJet(const TrajectoryStateOnSurface &state, const reco::Vertex &vertex, const GlobalVector &aJetDirection, const MagneticField *field)
Definition: IPTools.cc:182
const MagneticField * field() const
void setTracksPVBase(const reco::TrackRef &trackRef, const reco::VertexRef &vertexRef, float &PVweight) const
void etaRelToTauAxis(const reco::VertexCompositePtrCandidate &vertex, const fastjet::PseudoJet &tauAxis, std::vector< float > &tau_trackEtaRel) const
reco::TrackSelector trackSelector
virtual const daughters & daughterPtrVector() const
references to daughtes
const edm::Ref< VertexCollection > & primaryVertex() const
Definition: IPTagInfo.h:133
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:206
reco::TemplatedSecondaryVertexTagInfo< reco::CandIPTagInfo, reco::VertexCompositePtrCandidate > CandSecondaryVertexTagInfo
size_t numberOfDaughters() const override
number of daughters
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:408
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void calcNsubjettiness(const reco::JetBaseRef &jet, float &tau1, float &tau2, std::vector< fastjet::PseudoJet > &currentAxes) const
void produce(edm::Event &, const edm::EventSetup &) override
virtual double energy() const =0
energy
virtual double py() const =0
y coordinate of momentum vector
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
void beginStream(edm::StreamID) override
const PVAssoc fromPV(size_t ipv=0) const
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const LorentzVector & p4() const final
four-momentum Lorentz vector
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:84
std::vector< LinkConnSpec >::const_iterator IT
std::vector< size_t > sortedIndexes(btag::SortCriteria mode=reco::btag::IP3DSig) const
Definition: IPTagInfo.h:231
const GlobalVector & flightDirection(unsigned int index) const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
const std::vector< btag::TrackIPData > & impactParameterData() const
Definition: IPTagInfo.h:90
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
double significance() const
Definition: Measurement1D.h:29
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const math::XYZTLorentzVector & vectorSum() const
Measurement1D flightDistance(unsigned int index, int dim=0) const
void setTracksPV(const reco::CandidatePtr &trackRef, const reco::VertexRef &vertexRef, float &PVweight) const
T get() const
Definition: EventSetup.h:73
BoostedDoubleSVProducer(const edm::ParameterSet &)
TrajectoryStateOnSurface impactPointState() const
vars
Definition: DeepTauId.cc:158
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:71
virtual double px() const =0
x coordinate of momentum vector
def move(src, dest)
Definition: eostools.py:511
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:37
#define constexpr
cont
load Luminosity info ##
Definition: generateEDF.py:629
Global3DVector GlobalVector
Definition: GlobalVector.h:10
void insert(const TaggingVariable &variable, bool delayed=false)