CMS 3D CMS Logo

PFTauExtractor.cc
Go to the documentation of this file.
15 
17 public:
19  ~PFTauExtractor() override {}
20 
22  void fillVetos(const edm::Event&, const edm::EventSetup&, const reco::TrackCollection&) override {}
23  reco::IsoDeposit deposit(const edm::Event& evt, const edm::EventSetup& es, const reco::Track& track) const override {
24  return depositFromObject(evt, es, track);
25  }
27  const edm::EventSetup& es,
28  const reco::Candidate& candidate) const override {
29  return depositFromObject(evt, es, candidate);
30  }
31 
32 private:
36  double maxDxyTrack_;
37  double maxDzTrack_;
38  double dRmatchPFTau_;
39  double dRVetoCone_;
40  double dRIsoCone_;
42 
45  template <typename T>
46  reco::IsoDeposit depositFromObject(const edm::Event&, const edm::EventSetup&, const T&) const;
47 };
48 
50  tauSourceToken_ = iC.consumes<reco::PFTauCollection>(cfg.getParameter<edm::InputTag>("tauSource"));
52  iC.mayConsume<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("candidateSource"));
53  maxDxyTrack_ = cfg.getParameter<double>("Diff_r");
54  maxDzTrack_ = cfg.getParameter<double>("Diff_z");
55  dRmatchPFTau_ = cfg.getParameter<double>("dRmatchPFTau");
56  dRVetoCone_ = cfg.getParameter<double>("DR_Veto");
57  dRIsoCone_ = cfg.getParameter<double>("DR_Max");
58  dRvetoPFTauSignalConeConstituents_ = cfg.getParameter<double>("dRvetoPFTauSignalConeConstituents");
59 }
60 
61 template <typename T>
63  const edm::EventSetup& es,
64  const T& tauCandidate) const {
65  //--- create IsoDeposit to be returned;
66  // set "direction" of IsoDeposit cone to jet-axis of tauCandidate
67  reco::isodeposit::Direction tauCandidateDirection(tauCandidate.eta(), tauCandidate.phi());
68  reco::IsoDeposit isoDeposit(tauCandidateDirection);
69  isoDeposit.addCandEnergy(tauCandidate.pt());
70 
71  //--- find PFTau closest to tauDirection
73  evt.getByToken(tauSourceToken_, pfTaus);
74 
75  double dR_min = -1.;
76  const reco::PFTau* pfTau_matched = nullptr;
77  for (reco::PFTauCollection::const_iterator pfTau = pfTaus->begin(); pfTau != pfTaus->end(); ++pfTau) {
78  double dR = deltaR(pfTau->eta(), pfTau->phi(), tauCandidate.eta(), tauCandidate.phi());
79  if (pfTau_matched == nullptr || dR < dR_min) {
80  dR_min = dR;
81  pfTau_matched = &(*pfTau);
82  }
83  }
84 
85  //--- compute IsoDeposit for matched PFTau
86  if (pfTau_matched != nullptr && dR_min < dRmatchPFTau_) {
89 
90  const reco::Particle::Point& tauVertex = pfTau_matched->vertex();
91  double dRsignalCone_max = 0.;
92  for (edm::View<reco::Candidate>::const_iterator candidate = candidates->begin(); candidate != candidates->end();
93  ++candidate) {
94  double dR = deltaR(candidate->momentum(), pfTau_matched->momentum());
95 
96  //--- check that candidate is inbetween veto and isolation cone,
97  // and is compatible with originating from the same primary event vertex as the PFTau
98  if (dR > dRVetoCone_ && dR < dRIsoCone_ && (candidate->vertex() - tauVertex).Rho() < maxDxyTrack_ &&
99  fabs(candidate->vertex().z() - tauVertex.z()) < maxDzTrack_) {
100  //--- check that the candidate is not associated to one of the tau decay products
101  // within the signal cone of the PFTau
102  bool isSignalCone = false;
103  for (std::vector<reco::CandidatePtr>::const_iterator tauSignalConeConstituent =
104  pfTau_matched->signalCands().begin();
105  tauSignalConeConstituent != pfTau_matched->signalCands().end();
106  ++tauSignalConeConstituent) {
107  double dR = deltaR(candidate->momentum(), (*tauSignalConeConstituent)->momentum());
109  isSignalCone = true;
110  }
111 
112  if (!isSignalCone) {
113  reco::isodeposit::Direction candidateDirection(candidate->eta(), candidate->phi());
114  isoDeposit.addDeposit(candidateDirection, candidate->pt());
115  }
116  }
117  }
118 
119  //--- set size of veto cone of IsoDeposit to largest distance
120  // of any tau decay product within the signal cone of the PFTau
121  // (add a small positive number in order to avoid issues
122  // with rounding errors and "<" versus "<=" comparisson)
123  reco::IsoDeposit::Veto isoDepositVeto;
124  isoDepositVeto.vetoDir = tauCandidateDirection;
125  isoDepositVeto.dR = dRsignalCone_max + 1.e-3;
126  isoDeposit.setVeto(isoDepositVeto);
127  } else {
128  edm::LogWarning("PFTauExtractor::depositFromObject")
129  << " Failed to match PFTau to tauCandidate direction given by"
130  << " eta = " << tauCandidate.eta() << ", phi = " << tauCandidate.phi()
131  << " --> skipping computation of IsoDeposit !!";
132  }
133 
134  return isoDeposit;
135 }
136 
138 
140 
reco::IsoDeposit depositFromObject(const edm::Event &, const edm::EventSetup &, const T &) const
Vector momentum() const final
spatial momentum vector
double dRvetoPFTauSignalConeConstituents_
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
~PFTauExtractor() override
const std::vector< reco::CandidatePtr > & signalCands() const
Candidates in signal region.
Definition: PFTau.cc:74
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
const Point & vertex() const override
vertex position (overwritten by PF...)
edm::EDGetTokenT< reco::PFTauCollection > tauSourceToken_
configuration parameters
edm::EDGetTokenT< edm::View< reco::Candidate > > candidateSourceToken_
math::XYZPoint Point
point in the space
Definition: Particle.h:25
reco::IsoDeposit deposit(const edm::Event &evt, const edm::EventSetup &es, const reco::Candidate &candidate) const override
PFTauExtractor(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
void fillVetos(const edm::Event &, const edm::EventSetup &, const reco::TrackCollection &) override
definition of pure virtual functions inherited from IsoDepositExtractor base-class ...
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
#define DEFINE_EDM_PLUGIN(factory, type, name)
Log< level::Warning, false > LogWarning
long double T
reco::IsoDeposit deposit(const edm::Event &evt, const edm::EventSetup &es, const reco::Track &track) const override