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