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 
34 
44 
52 
53 #include "fastjet/PseudoJet.hh"
54 #include "fastjet/contrib/Njettiness.hh"
55 
56 #include <map>
57 
58 //
59 // class declaration
60 //
61 
63 public:
65  ~BoostedDoubleSVProducer() override;
66 
67  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
68 
69 private:
70  void beginStream(edm::StreamID) override;
71  void produce(edm::Event&, const edm::EventSetup&) override;
72  void endStream() override;
73 
75  float& tau1,
76  float& tau2,
77  std::vector<fastjet::PseudoJet>& currentAxes) const;
78  void setTracksPVBase(const reco::TrackRef& trackRef, const reco::VertexRef& vertexRef, float& PVweight) const;
79  void setTracksPV(const reco::CandidatePtr& trackRef, const reco::VertexRef& vertexRef, float& PVweight) const;
81  const fastjet::PseudoJet& tauAxis,
82  std::vector<float>& tau_trackEtaRel) const;
83 
84  // ----------member data ---------------------------
86 
87  const double beta_;
88  const double R0_;
89 
90  const double maxSVDeltaRToJet_;
91  const double maxDistToAxis_;
92  const double maxDecayLen_;
95 
99 
100  // static variables
101  static constexpr float dummyZ_ratio = -3.0f;
102  static constexpr float dummyTrackSip3dSig = -50.0f;
103  static constexpr float dummyTrackSip2dSigAbove = -19.0f;
104  static constexpr float dummyTrackEtaRel = -1.0f;
105  static constexpr float dummyVertexMass = -1.0f;
106  static constexpr float dummyVertexEnergyRatio = -1.0f;
107  static constexpr float dummyVertexDeltaR = -1.0f;
108  static constexpr float dummyFlightDistance2dSig = -1.0f;
109 
110  static constexpr float charmThreshold = 1.5f;
111  static constexpr float bottomThreshold = 5.2f;
112 };
113 
114 //
115 // constants, enums and typedefs
116 //
117 
118 //
119 // static data member definitions
120 //
121 
122 //
123 // constructors and destructor
124 //
126  : svTagInfos_(
127  consumes<std::vector<reco::CandSecondaryVertexTagInfo>>(iConfig.getParameter<edm::InputTag>("svTagInfos"))),
128  beta_(iConfig.getParameter<double>("beta")),
129  R0_(iConfig.getParameter<double>("R0")),
130  maxSVDeltaRToJet_(iConfig.getParameter<double>("maxSVDeltaRToJet")),
131  maxDistToAxis_(iConfig.getParameter<edm::ParameterSet>("trackSelection").getParameter<double>("maxDistToAxis")),
132  maxDecayLen_(iConfig.getParameter<edm::ParameterSet>("trackSelection").getParameter<double>("maxDecayLen")),
133  trackPairV0Filter(iConfig.getParameter<edm::ParameterSet>("trackPairV0Filter")),
134  trackSelector(iConfig.getParameter<edm::ParameterSet>("trackSelection")) {
135  edm::InputTag srcWeights = iConfig.getParameter<edm::InputTag>("weights");
137  esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"));
138  if (!srcWeights.label().empty())
140  produces<std::vector<reco::BoostedDoubleSVTagInfo>>();
141 }
142 
144  // do anything here that needs to be done at destruction time
145  // (e.g. close files, deallocate resources etc.)
146 }
147 
148 //
149 // member functions
150 //
151 
152 // ------------ method called to produce the data ------------
154  // get the track builder
156 
157  // get input secondary vertex TagInfos
159  iEvent.getByToken(svTagInfos_, svTagInfos);
160 
162  iEvent.getByToken(weightsToken_, weightsHandle_);
163 
164  // create the output collection
165  auto tagInfos = std::make_unique<std::vector<reco::BoostedDoubleSVTagInfo>>();
166 
167  // loop over TagInfos
168  for (std::vector<reco::CandSecondaryVertexTagInfo>::const_iterator iterTI = svTagInfos->begin();
169  iterTI != svTagInfos->end();
170  ++iterTI) {
171  // get TagInfos
172  const reco::CandIPTagInfo& ipTagInfo = *(iterTI->trackIPTagInfoRef().get());
173  const reco::CandSecondaryVertexTagInfo& svTagInfo = *(iterTI);
174 
175  // default variable values
176  float z_ratio = dummyZ_ratio;
191  float jetNTracks = 0, nSV = 0, tau1_nSecondaryVertices = 0, tau2_nSecondaryVertices = 0;
192 
193  // get the jet reference
194  const reco::JetBaseRef jet = svTagInfo.jet();
195 
196  std::vector<fastjet::PseudoJet> currentAxes;
197  float tau2, tau1;
198  // calculate N-subjettiness
199  calcNsubjettiness(jet, tau1, tau2, currentAxes);
200 
201  const reco::VertexRef& vertexRef = ipTagInfo.primaryVertex();
202  GlobalPoint pv(0., 0., 0.);
203  if (ipTagInfo.primaryVertex().isNonnull())
204  pv = GlobalPoint(vertexRef->x(), vertexRef->y(), vertexRef->z());
205 
206  const std::vector<reco::CandidatePtr>& selectedTracks = ipTagInfo.selectedTracks();
207  const std::vector<reco::btag::TrackIPData>& ipData = ipTagInfo.impactParameterData();
208  size_t trackSize = selectedTracks.size();
209 
210  reco::TrackKinematics allKinematics;
211  std::vector<float> IP3Ds, IP3Ds_1, IP3Ds_2;
212  int contTrk = 0;
213 
214  // loop over tracks associated to the jet
215  for (size_t itt = 0; itt < trackSize; ++itt) {
216  const reco::CandidatePtr trackRef = selectedTracks[itt];
217 
218  float track_PVweight = 0.;
219  setTracksPV(trackRef, vertexRef, track_PVweight);
220  if (track_PVweight > 0.5)
221  allKinematics.add(trackRef);
222 
223  const reco::btag::TrackIPData& data = ipData[itt];
224  bool isSelected = false;
225  if (trackSelector(trackRef, data, *jet, pv))
226  isSelected = true;
227 
228  // check if the track is from V0
229  bool isfromV0 = false, isfromV0Tight = false;
230  std::vector<reco::CandidatePtr> trackPairV0Test(2);
231 
232  trackPairV0Test[0] = trackRef;
233 
234  for (size_t jtt = 0; jtt < trackSize; ++jtt) {
235  if (itt == jtt)
236  continue;
237 
238  const reco::btag::TrackIPData& pairTrackData = ipData[jtt];
239  const reco::CandidatePtr pairTrackRef = selectedTracks[jtt];
240 
241  trackPairV0Test[1] = pairTrackRef;
242 
243  if (!trackPairV0Filter(trackPairV0Test)) {
244  isfromV0 = true;
245 
246  if (trackSelector(pairTrackRef, pairTrackData, *jet, pv))
247  isfromV0Tight = true;
248  }
249 
250  if (isfromV0 && isfromV0Tight)
251  break;
252  }
253 
254  if (isSelected && !isfromV0Tight)
255  jetNTracks += 1.;
256 
257  reco::TransientTrack transientTrack = trackBuilder->build(trackRef);
258  GlobalVector direction(jet->px(), jet->py(), jet->pz());
259 
260  int index = 0;
261  if (currentAxes.size() > 1 &&
262  reco::deltaR2(trackRef->momentum(), currentAxes[1]) < reco::deltaR2(trackRef->momentum(), currentAxes[0]))
263  index = 1;
264  direction = GlobalVector(currentAxes[index].px(), currentAxes[index].py(), currentAxes[index].pz());
265 
266  // decay distance and track distance wrt to the closest tau axis
267  float decayLengthTau = -1;
268  float distTauAxis = -1;
269 
271  transientTrack.impactPointState(), *vertexRef, direction, transientTrack.field());
272  if (closest.isValid())
273  decayLengthTau = (closest.globalPosition() - RecoVertex::convertPos(vertexRef->position())).mag();
274 
275  distTauAxis = std::abs(IPTools::jetTrackDistance(transientTrack, direction, *vertexRef).second.value());
276 
277  float IP3Dsig = ipTagInfo.impactParameterData()[itt].ip3d.significance();
278 
279  if (!isfromV0 && decayLengthTau < maxDecayLen_ && distTauAxis < maxDistToAxis_) {
280  IP3Ds.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
281  ++contTrk;
282  if (currentAxes.size() > 1) {
283  if (reco::deltaR2(trackRef->momentum(), currentAxes[0]) < reco::deltaR2(trackRef->momentum(), currentAxes[1]))
284  IP3Ds_1.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
285  else
286  IP3Ds_2.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
287  } else
288  IP3Ds_1.push_back(IP3Dsig < -50. ? -50. : IP3Dsig);
289  }
290  }
291 
292  std::vector<size_t> indices = ipTagInfo.sortedIndexes(reco::btag::IP2DSig);
293  bool charmThreshSet = false;
294 
296  for (size_t i = 0; i < indices.size(); ++i) {
297  size_t idx = indices[i];
298  const reco::btag::TrackIPData& data = ipData[idx];
299  const reco::CandidatePtr trackRef = selectedTracks[idx];
300 
301  kin.add(trackRef);
302 
303  if (kin.vectorSum().M() > charmThreshold // charm cut
304  && !charmThreshSet) {
305  trackSip2dSigAboveCharm_0 = data.ip2d.significance();
306 
307  charmThreshSet = true;
308  }
309 
310  if (kin.vectorSum().M() > bottomThreshold) // bottom cut
311  {
312  trackSip2dSigAboveBottom_0 = data.ip2d.significance();
313  if ((i + 1) < indices.size())
314  trackSip2dSigAboveBottom_1 = (ipData[indices[i + 1]]).ip2d.significance();
315 
316  break;
317  }
318  }
319 
320  float dummyTrack = -50.;
321 
322  std::sort(IP3Ds.begin(), IP3Ds.end(), std::greater<float>());
323  std::sort(IP3Ds_1.begin(), IP3Ds_1.end(), std::greater<float>());
324  std::sort(IP3Ds_2.begin(), IP3Ds_2.end(), std::greater<float>());
325  int num_1 = IP3Ds_1.size();
326  int num_2 = IP3Ds_2.size();
327 
328  switch (contTrk) {
329  case 0:
330 
331  trackSip3dSig_0 = dummyTrack;
332  trackSip3dSig_1 = dummyTrack;
333  trackSip3dSig_2 = dummyTrack;
334  trackSip3dSig_3 = dummyTrack;
335 
336  break;
337 
338  case 1:
339 
340  trackSip3dSig_0 = IP3Ds.at(0);
341  trackSip3dSig_1 = dummyTrack;
342  trackSip3dSig_2 = dummyTrack;
343  trackSip3dSig_3 = dummyTrack;
344 
345  break;
346 
347  case 2:
348 
349  trackSip3dSig_0 = IP3Ds.at(0);
350  trackSip3dSig_1 = IP3Ds.at(1);
351  trackSip3dSig_2 = dummyTrack;
352  trackSip3dSig_3 = dummyTrack;
353 
354  break;
355 
356  case 3:
357 
358  trackSip3dSig_0 = IP3Ds.at(0);
359  trackSip3dSig_1 = IP3Ds.at(1);
360  trackSip3dSig_2 = IP3Ds.at(2);
361  trackSip3dSig_3 = dummyTrack;
362 
363  break;
364 
365  default:
366 
367  trackSip3dSig_0 = IP3Ds.at(0);
368  trackSip3dSig_1 = IP3Ds.at(1);
369  trackSip3dSig_2 = IP3Ds.at(2);
370  trackSip3dSig_3 = IP3Ds.at(3);
371  }
372 
373  switch (num_1) {
374  case 0:
375 
376  tau1_trackSip3dSig_0 = dummyTrack;
377  tau1_trackSip3dSig_1 = dummyTrack;
378 
379  break;
380 
381  case 1:
382 
383  tau1_trackSip3dSig_0 = IP3Ds_1.at(0);
384  tau1_trackSip3dSig_1 = dummyTrack;
385 
386  break;
387 
388  default:
389 
390  tau1_trackSip3dSig_0 = IP3Ds_1.at(0);
391  tau1_trackSip3dSig_1 = IP3Ds_1.at(1);
392  }
393 
394  switch (num_2) {
395  case 0:
396 
397  tau2_trackSip3dSig_0 = dummyTrack;
398  tau2_trackSip3dSig_1 = dummyTrack;
399 
400  break;
401 
402  case 1:
403  tau2_trackSip3dSig_0 = IP3Ds_2.at(0);
404  tau2_trackSip3dSig_1 = dummyTrack;
405 
406  break;
407 
408  default:
409 
410  tau2_trackSip3dSig_0 = IP3Ds_2.at(0);
411  tau2_trackSip3dSig_1 = IP3Ds_2.at(1);
412  }
413 
414  math::XYZVector jetDir = jet->momentum().Unit();
415  reco::TrackKinematics tau1Kinematics;
416  reco::TrackKinematics tau2Kinematics;
417  std::vector<float> tau1_trackEtaRels, tau2_trackEtaRels;
418 
419  std::map<double, size_t> VTXmap;
420  for (size_t vtx = 0; vtx < svTagInfo.nVertices(); ++vtx) {
421  const reco::VertexCompositePtrCandidate& vertex = svTagInfo.secondaryVertex(vtx);
422  // get the vertex kinematics
423  reco::TrackKinematics vertexKinematic(vertex);
424 
425  if (currentAxes.size() > 1) {
426  if (reco::deltaR2(svTagInfo.flightDirection(vtx), currentAxes[1]) <
427  reco::deltaR2(svTagInfo.flightDirection(vtx), currentAxes[0])) {
428  tau2Kinematics = tau2Kinematics + vertexKinematic;
429  if (tau2_flightDistance2dSig < 0) {
430  tau2_flightDistance2dSig = svTagInfo.flightDistance(vtx, true).significance();
431  tau2_vertexDeltaR = reco::deltaR(svTagInfo.flightDirection(vtx), currentAxes[1]);
432  }
433  etaRelToTauAxis(vertex, currentAxes[1], tau2_trackEtaRels);
434  tau2_nSecondaryVertices += 1.;
435  } else {
436  tau1Kinematics = tau1Kinematics + vertexKinematic;
437  if (tau1_flightDistance2dSig < 0) {
438  tau1_flightDistance2dSig = svTagInfo.flightDistance(vtx, true).significance();
439  tau1_vertexDeltaR = reco::deltaR(svTagInfo.flightDirection(vtx), currentAxes[0]);
440  }
441  etaRelToTauAxis(vertex, currentAxes[0], tau1_trackEtaRels);
442  tau1_nSecondaryVertices += 1.;
443  }
444 
445  } else if (!currentAxes.empty()) {
446  tau1Kinematics = tau1Kinematics + vertexKinematic;
447  if (tau1_flightDistance2dSig < 0) {
448  tau1_flightDistance2dSig = svTagInfo.flightDistance(vtx, true).significance();
449  tau1_vertexDeltaR = reco::deltaR(svTagInfo.flightDirection(vtx), currentAxes[0]);
450  }
451  etaRelToTauAxis(vertex, currentAxes[0], tau1_trackEtaRels);
452  tau1_nSecondaryVertices += 1.;
453  }
454 
455  const GlobalVector& flightDir = svTagInfo.flightDirection(vtx);
456  if (reco::deltaR2(flightDir, jetDir) < (maxSVDeltaRToJet_ * maxSVDeltaRToJet_))
457  VTXmap[svTagInfo.flightDistance(vtx).error()] = vtx;
458  }
459  nSV = VTXmap.size();
460 
461  math::XYZTLorentzVector allSum = allKinematics.weightedVectorSum();
462  if (tau1_nSecondaryVertices > 0.) {
463  const math::XYZTLorentzVector& tau1_vertexSum = tau1Kinematics.weightedVectorSum();
464  if (allSum.E() > 0.)
465  tau1_vertexEnergyRatio = tau1_vertexSum.E() / allSum.E();
466  if (tau1_vertexEnergyRatio > 50.)
468 
469  tau1_vertexMass = tau1_vertexSum.M();
470  }
471 
472  if (tau2_nSecondaryVertices > 0.) {
473  const math::XYZTLorentzVector& tau2_vertexSum = tau2Kinematics.weightedVectorSum();
474  if (allSum.E() > 0.)
475  tau2_vertexEnergyRatio = tau2_vertexSum.E() / allSum.E();
476  if (tau2_vertexEnergyRatio > 50.)
478 
479  tau2_vertexMass = tau2_vertexSum.M();
480  }
481 
482  float dummyEtaRel = -1.;
483 
484  std::sort(tau1_trackEtaRels.begin(), tau1_trackEtaRels.end());
485  std::sort(tau2_trackEtaRels.begin(), tau2_trackEtaRels.end());
486 
487  switch (tau2_trackEtaRels.size()) {
488  case 0:
489 
490  tau2_trackEtaRel_0 = dummyEtaRel;
491  tau2_trackEtaRel_1 = dummyEtaRel;
492  tau2_trackEtaRel_2 = dummyEtaRel;
493 
494  break;
495 
496  case 1:
497 
498  tau2_trackEtaRel_0 = tau2_trackEtaRels.at(0);
499  tau2_trackEtaRel_1 = dummyEtaRel;
500  tau2_trackEtaRel_2 = dummyEtaRel;
501 
502  break;
503 
504  case 2:
505 
506  tau2_trackEtaRel_0 = tau2_trackEtaRels.at(0);
507  tau2_trackEtaRel_1 = tau2_trackEtaRels.at(1);
508  tau2_trackEtaRel_2 = dummyEtaRel;
509 
510  break;
511 
512  default:
513 
514  tau2_trackEtaRel_0 = tau2_trackEtaRels.at(0);
515  tau2_trackEtaRel_1 = tau2_trackEtaRels.at(1);
516  tau2_trackEtaRel_2 = tau2_trackEtaRels.at(2);
517  }
518 
519  switch (tau1_trackEtaRels.size()) {
520  case 0:
521 
522  tau1_trackEtaRel_0 = dummyEtaRel;
523  tau1_trackEtaRel_1 = dummyEtaRel;
524  tau1_trackEtaRel_2 = dummyEtaRel;
525 
526  break;
527 
528  case 1:
529 
530  tau1_trackEtaRel_0 = tau1_trackEtaRels.at(0);
531  tau1_trackEtaRel_1 = dummyEtaRel;
532  tau1_trackEtaRel_2 = dummyEtaRel;
533 
534  break;
535 
536  case 2:
537 
538  tau1_trackEtaRel_0 = tau1_trackEtaRels.at(0);
539  tau1_trackEtaRel_1 = tau1_trackEtaRels.at(1);
540  tau1_trackEtaRel_2 = dummyEtaRel;
541 
542  break;
543 
544  default:
545 
546  tau1_trackEtaRel_0 = tau1_trackEtaRels.at(0);
547  tau1_trackEtaRel_1 = tau1_trackEtaRels.at(1);
548  tau1_trackEtaRel_2 = tau1_trackEtaRels.at(2);
549  }
550 
551  int cont = 0;
552  GlobalVector flightDir_0, flightDir_1;
553  reco::Candidate::LorentzVector SV_p4_0, SV_p4_1;
554  double vtxMass = 0.;
555 
556  for (std::map<double, size_t>::iterator iVtx = VTXmap.begin(); iVtx != VTXmap.end(); ++iVtx) {
557  ++cont;
558  const reco::VertexCompositePtrCandidate& vertex = svTagInfo.secondaryVertex(iVtx->second);
559  if (cont == 1) {
560  flightDir_0 = svTagInfo.flightDirection(iVtx->second);
561  SV_p4_0 = vertex.p4();
562  vtxMass = SV_p4_0.mass();
563 
564  if (vtxMass > 0.)
565  z_ratio = reco::deltaR(currentAxes[1], currentAxes[0]) * SV_p4_0.pt() / vtxMass;
566  }
567  if (cont == 2) {
568  flightDir_1 = svTagInfo.flightDirection(iVtx->second);
569  SV_p4_1 = vertex.p4();
570  vtxMass = (SV_p4_1 + SV_p4_0).mass();
571 
572  if (vtxMass > 0.)
573  z_ratio = reco::deltaR(flightDir_0, flightDir_1) * SV_p4_1.pt() / vtxMass;
574 
575  break;
576  }
577  }
578 
579  // when only one tau axis has SVs assigned, they are all assigned to the 1st tau axis
580  // in the special case below need to swap values
581  if ((tau1_vertexMass < 0 && tau2_vertexMass > 0)) {
582  float temp = tau1_trackEtaRel_0;
585 
589 
593 
597 
599 
603 
607  }
608 
610 
611  vars.insert(reco::btau::jetNTracks, jetNTracks, true);
612  vars.insert(reco::btau::jetNSecondaryVertices, nSV, true);
621  vars.insert(reco::btau::trackSip2dSigAboveCharm, trackSip2dSigAboveCharm_0, true);
637  vars.insert(reco::btau::z_ratio, z_ratio, true);
638 
639  vars.finalize();
640 
642  vars, edm::Ref<std::vector<reco::CandSecondaryVertexTagInfo>>(svTagInfos, iterTI - svTagInfos->begin())));
643  }
644 
645  // put the output in the event
646  iEvent.put(std::move(tagInfos));
647 }
648 
650  float& tau1,
651  float& tau2,
652  std::vector<fastjet::PseudoJet>& currentAxes) const {
653  std::vector<fastjet::PseudoJet> fjParticles;
654 
655  // loop over jet constituents and push them in the vector of FastJet constituents
656  for (const reco::CandidatePtr& daughter : jet->daughterPtrVector()) {
657  if (daughter.isNonnull() && daughter.isAvailable()) {
658  const reco::Jet* subjet = dynamic_cast<const reco::Jet*>(daughter.get());
659  // if the daughter is actually a subjet
660  if (subjet && daughter->numberOfDaughters() > 1) {
661  // loop over subjet constituents and push them in the vector of FastJet constituents
662  for (size_t i = 0; i < daughter->numberOfDaughters(); ++i) {
663  const reco::CandidatePtr& constit = subjet->daughterPtr(i);
664 
665  if (constit.isNonnull() && constit->pt() > std::numeric_limits<double>::epsilon()) {
666  // Check if any values were nan or inf
667  float valcheck = constit->px() + constit->py() + constit->pz() + constit->energy();
668  if (edm::isNotFinite(valcheck)) {
669  edm::LogWarning("FaultyJetConstituent")
670  << "Jet constituent required for N-subjettiness computation contains Nan/Inf values!";
671  continue;
672  }
673  if (subjet->isWeighted()) {
674  float w = 0.0;
676  w = (*weightsHandle_)[constit];
677  else {
678  throw cms::Exception("MissingConstituentWeight")
679  << "BoostedDoubleSVProducer: No weights (e.g. PUPPI) given for weighted jet collection"
680  << std::endl;
681  }
682  if (w > 0) {
683  fjParticles.push_back(
684  fastjet::PseudoJet(constit->px() * w, constit->py() * w, constit->pz() * w, constit->energy() * w));
685  }
686  } else {
687  fjParticles.push_back(fastjet::PseudoJet(constit->px(), constit->py(), constit->pz(), constit->energy()));
688  }
689  } else
690  edm::LogWarning("MissingJetConstituent")
691  << "Jet constituent required for N-subjettiness computation is missing!";
692  }
693  } else {
694  // Check if any values were nan or inf
695  float valcheck = daughter->px() + daughter->py() + daughter->pz() + daughter->energy();
696  if (edm::isNotFinite(valcheck)) {
697  edm::LogWarning("FaultyJetConstituent")
698  << "Jet constituent required for N-subjettiness computation contains Nan/Inf values!";
699  continue;
700  }
701  if (jet->isWeighted()) {
702  float w = 0.0;
704  w = (*weightsHandle_)[daughter];
705  else {
706  throw cms::Exception("MissingConstituentWeight")
707  << "BoostedDoubleSVProducer: No weights (e.g. PUPPI) given for weighted jet collection" << std::endl;
708  }
709  if (w > 0 && daughter->pt() > std::numeric_limits<double>::epsilon()) {
710  fjParticles.push_back(
711  fastjet::PseudoJet(daughter->px() * w, daughter->py() * w, daughter->pz() * w, daughter->energy() * w));
712  }
713  } else {
714  fjParticles.push_back(fastjet::PseudoJet(daughter->px(), daughter->py(), daughter->pz(), daughter->energy()));
715  }
716  }
717  } else
718  edm::LogWarning("MissingJetConstituent") << "Jet constituent required for N-subjettiness computation is missing!";
719  }
720 
721  // N-subjettiness calculator
722  fastjet::contrib::Njettiness njettiness(fastjet::contrib::OnePass_KT_Axes(),
723  fastjet::contrib::NormalizedMeasure(beta_, R0_));
724 
725  // calculate N-subjettiness
726  tau1 = njettiness.getTau(1, fjParticles);
727  tau2 = njettiness.getTau(2, fjParticles);
728  currentAxes = njettiness.currentAxes();
729 }
730 
732  const reco::VertexRef& vertexRef,
733  float& PVweight) const {
734  PVweight = 0.;
735 
736  const reco::TrackBaseRef trackBaseRef(trackRef);
737 
739 
740  const reco::Vertex& vtx = *(vertexRef);
741  // loop over tracks in vertices
742  for (IT it = vtx.tracks_begin(); it != vtx.tracks_end(); ++it) {
743  const reco::TrackBaseRef& baseRef = *it;
744  // one of the tracks in the vertex is the same as the track considered in the function
745  if (baseRef == trackBaseRef) {
746  PVweight = vtx.trackWeight(baseRef);
747  break;
748  }
749  }
750 }
751 
753  const reco::VertexRef& vertexRef,
754  float& PVweight) const {
755  PVweight = 0.;
756 
757  const pat::PackedCandidate* pcand = dynamic_cast<const pat::PackedCandidate*>(trackRef.get());
758 
759  if (pcand) // MiniAOD case
760  {
761  if (pcand->fromPV() == pat::PackedCandidate::PVUsedInFit) {
762  PVweight = 1.;
763  }
764  } else {
765  const reco::PFCandidate* pfcand = dynamic_cast<const reco::PFCandidate*>(trackRef.get());
766 
767  setTracksPVBase(pfcand->trackRef(), vertexRef, PVweight);
768  }
769 }
770 
772  const fastjet::PseudoJet& tauAxis,
773  std::vector<float>& tau_trackEtaRel) const {
774  math::XYZVector direction(tauAxis.px(), tauAxis.py(), tauAxis.pz());
775  const std::vector<reco::CandidatePtr>& tracks = vertex.daughterPtrVector();
776 
777  for (std::vector<reco::CandidatePtr>::const_iterator track = tracks.begin(); track != tracks.end(); ++track)
778  tau_trackEtaRel.push_back(std::abs(reco::btau::etaRel(direction.Unit(), (*track)->momentum())));
779 }
780 
781 // ------------ method called once each stream before processing any runs, lumis or events ------------
783 
784 // ------------ method called once each stream after processing all runs, lumis and events ------------
786 
787 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
790  desc.add<double>("beta", 1.0);
791  desc.add<double>("R0", 0.8);
792  desc.add<double>("maxSVDeltaRToJet", 0.7);
793  {
795  trackSelection.setAllowAnything();
796  desc.add<edm::ParameterSetDescription>("trackSelection", trackSelection);
797  }
798  {
800  trackPairV0Filter.add<double>("k0sMassWindow", 0.03);
801  desc.add<edm::ParameterSetDescription>("trackPairV0Filter", trackPairV0Filter);
802  }
803  desc.add<edm::InputTag>("svTagInfos", edm::InputTag("pfInclusiveSecondaryVertexFinderAK8TagInfos"));
804  desc.add<edm::InputTag>("weights", edm::InputTag(""));
805  descriptions.addDefault(desc);
806 }
807 
808 //define this as a plug-in
static constexpr float charmThreshold
static constexpr float dummyTrackSip2dSigAbove
reco::Vertex::Point convertPos(const GlobalPoint &p)
const edm::EDGetTokenT< std::vector< reco::CandSecondaryVertexTagInfo > > svTagInfos_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual CandidatePtr daughterPtr(size_type i) const
reference to daughter at given position
void calcNsubjettiness(const reco::JetBaseRef &jet, float &tau1, float &tau2, std::vector< fastjet::PseudoJet > &currentAxes) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
trackSelector
Tracks selection.
void setTracksPVBase(const reco::TrackRef &trackRef, const reco::VertexRef &vertexRef, float &PVweight) const
void add(const reco::Track &track, double weight=1.0)
T w() const
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
vars
Definition: DeepTauIdBase.h:60
Base class for all types of Jets.
Definition: Jet.h:20
double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
int closest(std::vector< int > const &vec, int value)
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:98
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
const Container & selectedTracks() const
Definition: IPTagInfo.h:99
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:232
static constexpr float dummyTrackEtaRel
const PVAssoc fromPV(size_t ipv=0) const
TrajectoryStateOnSurface closestApproachToJet(const TrajectoryStateOnSurface &state, const reco::Vertex &vertex, const GlobalVector &aJetDirection, const MagneticField *field)
Definition: IPTools.cc:182
reco::TrackSelector trackSelector
void setTracksPV(const reco::CandidatePtr &trackRef, const reco::VertexRef &vertexRef, float &PVweight) const
virtual int isWeighted() const
boolean if weights were applied by algorithm (e.g. PUPPI weights)
Definition: Jet.h:118
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
reco::TransientTrack build(const reco::Track *p) const
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
void etaRelToTauAxis(const reco::VertexCompositePtrCandidate &vertex, const fastjet::PseudoJet &tauAxis, std::vector< float > &tau_trackEtaRel) const
void addDefault(ParameterSetDescription const &psetDescription)
static constexpr float dummyTrackSip3dSig
edm::Handle< edm::ValueMap< float > > weightsHandle_
std::vector< size_t > sortedIndexes(btag::SortCriteria mode=reco::btag::IP3DSig) const
Definition: IPTagInfo.h:231
void beginStream(edm::StreamID) override
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:148
const MagneticField * field() const
static constexpr float dummyFlightDistance2dSig
const math::XYZTLorentzVector & vectorSum() const
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector< btag::TrackIPData > & impactParameterData() const
Definition: IPTagInfo.h:90
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static constexpr float dummyVertexEnergyRatio
std::vector< LinkConnSpec >::const_iterator IT
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:141
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
size_t numberOfDaughters() const override
number of daughters
static constexpr float bottomThreshold
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > trackBuilderToken_
bool isSelected(const std::vector< L1HPSPFTauQualityCut > &qualityCuts, const l1t::PFCandidate &pfCand, float_t primaryVertexZ)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
static constexpr float dummyZ_ratio
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
fixed size matrix
HLT enums.
static constexpr float dummyVertexMass
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
const math::XYZTLorentzVector & weightedVectorSum() const
BoostedDoubleSVProducer(const edm::ParameterSet &)
const edm::Ref< VertexCollection > & primaryVertex() const
Definition: IPTagInfo.h:133
Log< level::Warning, false > LogWarning
static constexpr float dummyVertexDeltaR
def move(src, dest)
Definition: eostools.py:511
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:38
TrajectoryStateOnSurface impactPointState() const
cont
load Luminosity info ##
Definition: generateEDF.py:620
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
Global3DVector GlobalVector
Definition: GlobalVector.h:10