CMS 3D CMS Logo

PFTauExtractor.cc
Go to the documentation of this file.
2 
4 
9 
11 
13 {
14  tauSourceToken_ = iC.consumes<reco::PFTauCollection>(cfg.getParameter<edm::InputTag>("tauSource"));
15  candidateSourceToken_ = iC.mayConsume<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("candidateSource"));
16  maxDxyTrack_ = cfg.getParameter<double>("Diff_r");
17  maxDzTrack_ = cfg.getParameter<double>("Diff_z");
18  dRmatchPFTau_ = cfg.getParameter<double>("dRmatchPFTau");
19  dRVetoCone_ = cfg.getParameter<double>("DR_Veto");
20  dRIsoCone_ = cfg.getParameter<double>("DR_Max");
21  dRvetoPFTauSignalConeConstituents_ = cfg.getParameter<double>("dRvetoPFTauSignalConeConstituents");
22 }
23 
24 template<typename T>
25 reco::IsoDeposit PFTauExtractor::depositFromObject(const edm::Event& evt, const edm::EventSetup& es, const T& tauCandidate) const
26 {
27 //--- create IsoDeposit to be returned;
28 // set "direction" of IsoDeposit cone to jet-axis of tauCandidate
29  reco::isodeposit::Direction tauCandidateDirection(tauCandidate.eta(), tauCandidate.phi());
30  reco::IsoDeposit isoDeposit(tauCandidateDirection);
31  isoDeposit.addCandEnergy(tauCandidate.pt());
32 
33 //--- find PFTau closest to tauDirection
35  evt.getByToken(tauSourceToken_, pfTaus);
36 
37  double dR_min = -1.;
38  const reco::PFTau* pfTau_matched = nullptr;
39  for ( reco::PFTauCollection::const_iterator pfTau = pfTaus->begin();
40  pfTau != pfTaus->end(); ++pfTau ) {
41  double dR = deltaR(pfTau->eta(), pfTau->phi(), tauCandidate.eta(), tauCandidate.phi());
42  if ( pfTau_matched == nullptr || dR < dR_min ) {
43  dR_min = dR;
44  pfTau_matched = &(*pfTau);
45  }
46  }
47 
48 //--- compute IsoDeposit for matched PFTau
49  if ( pfTau_matched != nullptr && dR_min < dRmatchPFTau_ ) {
51  evt.getByToken(candidateSourceToken_, candidates);
52 
53  const reco::Particle::Point& tauVertex = pfTau_matched->vertex();
54  double dRsignalCone_max = 0.;
55  for ( edm::View<reco::Candidate>::const_iterator candidate = candidates->begin();
56  candidate != candidates->end(); ++candidate ) {
57  double dR = deltaR(candidate->momentum(), pfTau_matched->momentum());
58 
59 //--- check that candidate is inbetween veto and isolation cone,
60 // and is compatible with originating from the same primary event vertex as the PFTau
61  if ( dR > dRVetoCone_ && dR < dRIsoCone_ &&
62  (candidate->vertex() - tauVertex).Rho() < maxDxyTrack_ &&
63  fabs(candidate->vertex().z() - tauVertex.z()) < maxDzTrack_ ) {
64 
65 //--- check that the candidate is not associated to one of the tau decay products
66 // within the signal cone of the PFTau
67  bool isSignalCone = false;
68  for ( std::vector<reco::PFCandidatePtr>::const_iterator tauSignalConeConstituent = pfTau_matched->signalPFCands().begin();
69  tauSignalConeConstituent != pfTau_matched->signalPFCands().end(); ++tauSignalConeConstituent ) {
70  double dR = deltaR(candidate->momentum(), (*tauSignalConeConstituent)->momentum());
71  if ( dR <= dRvetoPFTauSignalConeConstituents_ ) isSignalCone = true;
72  }
73 
74  if ( !isSignalCone ) {
75  reco::isodeposit::Direction candidateDirection(candidate->eta(), candidate->phi());
76  isoDeposit.addDeposit(candidateDirection, candidate->pt());
77  }
78  }
79  }
80 
81 //--- set size of veto cone of IsoDeposit to largest distance
82 // of any tau decay product within the signal cone of the PFTau
83 // (add a small positive number in order to avoid issues
84 // with rounding errors and "<" versus "<=" comparisson)
85  reco::IsoDeposit::Veto isoDepositVeto;
86  isoDepositVeto.vetoDir = tauCandidateDirection;
87  isoDepositVeto.dR = dRsignalCone_max + 1.e-3;
88  isoDeposit.setVeto(isoDepositVeto);
89  } else {
90  edm::LogWarning ("PFTauExtractor::depositFromObject") << " Failed to match PFTau to tauCandidate direction given by"
91  << " eta = " << tauCandidate.eta() << ", phi = " << tauCandidate.phi()
92  << " --> skipping computation of IsoDeposit !!";
93  }
94 
95  return isoDeposit;
96 }
97 
99 
101 
T getParameter(std::string const &) const
double dRvetoPFTauSignalConeConstituents_
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
reco::IsoDeposit depositFromObject(const edm::Event &, const edm::EventSetup &, const T &) const
const std::vector< reco::PFCandidatePtr > & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:78
edm::EDGetTokenT< reco::PFTauCollection > tauSourceToken_
configuration parameters
Vector momentum() const final
spatial momentum vector
edm::EDGetTokenT< edm::View< reco::Candidate > > candidateSourceToken_
const Point & vertex() const override
vertex position (overwritten by PF...)
math::XYZPoint Point
point in the space
Definition: Particle.h:25
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
PFTauExtractor(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
double dRmatchPFTau_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
#define DEFINE_EDM_PLUGIN(factory, type, name)
long double T