CMS 3D CMS Logo

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