CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauEnergyRecoveryPlugin.cc
Go to the documentation of this file.
1 /*
2  * =============================================================================
3  * Filename: RecoTauEnergyRecoveryPlugin.cc
4  *
5  * Description: Recovery energy of visible decay products
6  * lost due to photon conversions/nuclear interactions
7  * in tracker material.
8  * Created: 09/02/2011 10:28:00
9  *
10  * Authors: Christian Veelken (LLR)
11  *
12  * =============================================================================
13  */
14 
24 
26 
27 #include <algorithm>
28 
29 namespace reco { namespace tau {
30 
32 {
33  public:
34 
37  void operator()(PFTau&) const;
38  virtual void beginEvent();
39 
40  private:
41 
44 
46 
47  unsigned corrLevel_;
48 
51 };
52 
54  : RecoTauModifierPlugin(cfg),
55  theEventVertex_(0),
56  corrLevel_(cfg.getParameter<unsigned>("corrLevel")),
57  lev1PhiWindow_(cfg.getParameter<double>("lev1PhiWindow")),
58  lev1EtaWindow_(cfg.getParameter<double>("lev1EtaWindow"))
59 {
60  edm::ParameterSet cfgQualityCuts = cfg.getParameter<edm::ParameterSet>("qualityCuts");
61  srcVertices_ = cfgQualityCuts.getParameter<edm::InputTag>("primaryVertexSrc");
62  qcuts_ = new RecoTauQualityCuts(cfgQualityCuts.getParameter<edm::ParameterSet>("signalQualityCuts"));
63 }
64 
66 {
67  delete qcuts_;
68 }
69 
71 {
73  evt()->getByLabel(srcVertices_, vertices);
74 
75  if ( vertices->size() >= 1 ) {
76  qcuts_->setPV(reco::VertexRef(vertices, 0));
77  theEventVertex_ = &vertices->at(0);
78  } else {
79  theEventVertex_ = 0;
80  }
81 }
82 
84 {
85  if ( cand.trackRef().isNonnull() ) return reco::TrackBaseRef(cand.trackRef());
86  else if ( cand.gsfTrackRef().isNonnull() ) return reco::TrackBaseRef(cand.gsfTrackRef());
87  else return reco::TrackBaseRef();
88 }
89 
90 bool isTauSignalPFCandidate(const reco::PFTau& tau, const reco::PFCandidatePtr& pfJetConstituent)
91 {
92  bool retVal = false;
93 
94  const reco::PFCandidateRefVector& signalPFCandidates = tau.signalPFCands();
95  for ( reco::PFCandidateRefVector::const_iterator signalPFCandidate = signalPFCandidates.begin();
96  signalPFCandidate != signalPFCandidates.end(); ++signalPFCandidate ) {
97  if ( pfJetConstituent.key() == signalPFCandidate->key() ) retVal = true;
98  }
99 
100  return retVal;
101 }
102 
103 double square(double x)
104 {
105  return x*x;
106 }
107 
109 {
110  double tauEnergyCorr = 0.;
111 
112  if ( corrLevel_ & 1 && theEventVertex_ ) {
113 
114  bool needsCorrLevel1 = false;
115 
116  std::vector<reco::PFCandidatePtr> pfJetConstituents = tau.jetRef()->getPFConstituents();
117  for ( std::vector<reco::PFCandidatePtr>::const_iterator pfJetConstituent = pfJetConstituents.begin();
118  pfJetConstituent != pfJetConstituents.end(); ++pfJetConstituent ) {
119  const reco::TrackBaseRef track = getTrack(**pfJetConstituent);
120  if ( track.isNonnull() ) {
121  double dIP = fabs(track->dxy(theEventVertex_->position()));
122  double dZ = fabs(track->dz(theEventVertex_->position()));
123  if ( track->pt() > 2.0 && fabs(tau.eta() - (*pfJetConstituent)->eta()) < lev1EtaWindow_ &&
124  !isTauSignalPFCandidate(tau, *pfJetConstituent) && (dZ < 0.2 || dIP > 0.10) ) needsCorrLevel1 = true;
125  }
126  }
127 
128  if ( needsCorrLevel1 ) {
129  std::vector<reco::PFCandidatePtr> pfJetConstituents = tau.jetRef()->getPFConstituents();
130  for ( std::vector<reco::PFCandidatePtr>::const_iterator pfJetConstituent = pfJetConstituents.begin();
131  pfJetConstituent != pfJetConstituents.end(); ++pfJetConstituent ) {
132  if ( fabs(tau.eta() - (*pfJetConstituent)->eta()) < lev1EtaWindow_ &&
133  fabs(tau.phi() - (*pfJetConstituent)->phi()) < lev1PhiWindow_ ) {
134  if ( (*pfJetConstituent)->particleId() == reco::PFCandidate::h0 ) {
135  tauEnergyCorr += (*pfJetConstituent)->energy();
136  } else {
137  if ( !isTauSignalPFCandidate(tau, *pfJetConstituent) ) {
138  double caloEn = (*pfJetConstituent)->ecalEnergy() + (*pfJetConstituent)->hcalEnergy();
139  tauEnergyCorr += caloEn;
140  }
141  }
142  }
143  }
144  }
145  }
146 
147  if ( corrLevel_ & 2 && theEventVertex_ ) {
148 
149  double leadTrackMom = 0.;
150  double leadTrackMomErr = 0.;
151  double jetCaloEn = 0.;
152 
153  std::vector<reco::PFCandidatePtr> pfJetConstituents = tau.jetRef()->getPFConstituents();
154  for ( std::vector<reco::PFCandidatePtr>::const_iterator pfJetConstituent = pfJetConstituents.begin();
155  pfJetConstituent != pfJetConstituents.end(); ++pfJetConstituent ) {
156  const reco::TrackBaseRef track = getTrack(**pfJetConstituent);
157  if ( track.isNonnull() ) {
158  double trackPt = track->pt();
159  double trackPtErr = track->ptError();
160  if ( qcuts_->filter(**pfJetConstituent) &&
161  trackPtErr < (0.20*trackPt) && track->normalizedChi2() < 5.0 && track->hitPattern().numberOfValidPixelHits() >= 1 &&
162  (trackPt - 3.*trackPtErr) > (*pfJetConstituent)->pt() && trackPt < (3.*tau.jetRef()->pt()) ) {
163  if ( track->p() > leadTrackMom ) {
164  leadTrackMom = track->p();
165  leadTrackMomErr = leadTrackMom*(trackPtErr/trackPt);
166  }
167  }
168  }
169 
170  double caloEn = (*pfJetConstituent)->ecalEnergy() + (*pfJetConstituent)->hcalEnergy();
171  jetCaloEn += caloEn;
172  }
173 
174  if ( leadTrackMom > tau.p() ) {
175  const double chargedPionMass = 0.13957; // GeV
176  double leadTrackEn = sqrt(square(leadTrackMom) + square(chargedPionMass));
177  double jetCaloEnErr = 1.00*sqrt(std::max(jetCaloEn, leadTrackEn));
178  double combEn = ((1./square(jetCaloEnErr))*jetCaloEn + (1./square(leadTrackMomErr))*leadTrackEn)/
179  ((1./square(jetCaloEnErr)) + (1./square(leadTrackMomErr)));
180  tauEnergyCorr = std::max(tauEnergyCorr, combEn - tau.energy());
181  }
182  }
183 
184  if ( tau.energy() > 0. ) {
185  double tauEnergy_corrected = tau.energy() + tauEnergyCorr;
186  double scaleFactor = tauEnergy_corrected/tau.energy();
187  double tauPx_corrected = scaleFactor*tau.px();
188  double tauPy_corrected = scaleFactor*tau.py();
189  double tauPz_corrected = scaleFactor*tau.pz();
190  tau.setalternatLorentzVect(reco::Candidate::LorentzVector(tauPx_corrected, tauPy_corrected, tauPz_corrected, tauEnergy_corrected));
191  }
192 }
193 
194 }} // end namespace reco::tau
195 
199  "RecoTauEnergyRecoveryPlugin");
double p() const
momentum vector magnitude
Definition: TrackBase.h:129
virtual double energy() const GCC11_FINAL
energy
T getParameter(std::string const &) const
const PFJetRef & jetRef() const
Definition: PFTau.cc:50
virtual double p() const GCC11_FINAL
magnitude of momentum vector
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:111
tuple trackPt
Definition: listHistos.py:120
bool filter(const reco::PFCandidate &cand) const
Filter a single PFCandidate.
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
virtual double pz() const GCC11_FINAL
z coordinate of momentum vector
const Point & position() const
position
Definition: Vertex.h:93
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
const PFCandidateRefVector & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:73
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:349
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
const T & max(const T &a, const T &b)
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:22
void setPV(const reco::VertexRef &vtx) const
Update the primary vertex.
bool isTauSignalPFCandidate(const reco::PFTau &tau, const reco::PFCandidatePtr &pfJetConstituent)
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:131
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:194
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:223
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:127
key_type key() const
Definition: Ptr.h:169
double square(double x)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:35
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:387
const reco::TrackBaseRef getTrack(const reco::PFCandidate &cand)
int numberOfValidPixelHits() const
Definition: HitPattern.h:582
void setalternatLorentzVect(math::XYZTLorentzVector)
Definition: BaseTau.cc:24
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: DDAxes.h:10
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:121
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279