CMS 3D CMS Logo

PFMEtSignInterfaceBase.h
Go to the documentation of this file.
1 #ifndef RecoMET_METPUSubtraction_PFMEtSignInterfaceBase_h
2 #define RecoMET_METPUSubtraction_PFMEtSignInterfaceBase_h
3 
17 
19 
35 
36 
37 #include <TFile.h>
38 #include <TH2.h>
39 
40 
42 {
43  public:
44 
47 
48  template <typename T>
49  metsig::SigInputObj compResolution(const T* particle) const
50  {
51  double pt = particle->pt();
52  double eta = particle->eta();
53  double phi = particle->phi();
54 
55  if ( dynamic_cast<const reco::GsfElectron*>(particle) != nullptr ||
56  dynamic_cast<const pat::Electron*>(particle) != nullptr ) {
57  std::string particleType = "electron";
58  // WARNING: SignAlgoResolutions::PFtype2 needs to be kept in sync with reco::PFCandidate::e !!
59  double dpt = pfMEtResolution_->eval(metsig::PFtype2, metsig::ET, pt, phi, eta);
60  double dphi = pfMEtResolution_->eval(metsig::PFtype2, metsig::PHI, pt, phi, eta);
61  //std::cout << "electron: pt = " << pt << ", eta = " << eta << ", phi = " << phi
62  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
63  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
64  } else if ( dynamic_cast<const reco::Photon*>(particle) != nullptr ||
65  dynamic_cast<const pat::Photon*>(particle) != nullptr ) {
66  // CV: assume resolutions for photons to be identical to electron resolutions
67  std::string particleType = "electron";
68  // WARNING: SignAlgoResolutions::PFtype2 needs to be kept in sync with reco::PFCandidate::e !!
69  double dpt = pfMEtResolution_->eval(metsig::PFtype2, metsig::ET, pt, phi, eta);
70  double dphi = pfMEtResolution_->eval(metsig::PFtype2, metsig::PHI, pt, phi, eta);
71  //std::cout << "photon: pt = " << pt << ", eta = " << eta << ", phi = " << phi
72  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
73  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
74  } else if ( dynamic_cast<const reco::Muon*>(particle) != nullptr ||
75  dynamic_cast<const pat::Muon*>(particle) != nullptr ) {
76  std::string particleType = "muon";
77  double dpt, dphi;
78  const reco::Track* muonTrack = nullptr;
79  if ( dynamic_cast<const pat::Muon*>(particle) != nullptr ) {
80  const pat::Muon* muon = dynamic_cast<const pat::Muon*>(particle);
81  if ( muon->track().isNonnull() && muon->track().isAvailable() ) muonTrack = muon->track().get();
82  } else if ( dynamic_cast<const reco::Muon*>(particle) != nullptr ) {
83  const reco::Muon* muon = dynamic_cast<const reco::Muon*>(particle);
84  if ( muon->track().isNonnull() && muon->track().isAvailable() ) muonTrack = muon->track().get();
85  } else assert(0);
86  if ( muonTrack ) {
87  dpt = muonTrack->ptError();
88  dphi = pt*muonTrack->phiError(); // CV: pt*dphi is indeed correct
89  } else {
90  // WARNING: SignAlgoResolutions::PFtype3 needs to be kept in sync with reco::PFCandidate::mu !!
91  dpt = pfMEtResolution_->eval(metsig::PFtype3, metsig::ET, pt, phi, eta);
92  dphi = pfMEtResolution_->eval(metsig::PFtype3, metsig::PHI, pt, phi, eta);
93  }
94  //std::cout << "muon: pt = " << pt << ", eta = " << eta << ", phi = " << phi
95  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
96  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
97  } else if ( dynamic_cast<const reco::PFTau*>(particle) != nullptr ||
98  dynamic_cast<const pat::Tau*>(particle) != nullptr ) {
99  // CV: use PFJet resolutions for PFTaus for now...
100  // (until PFTau specific resolutions are available)
101  if ( dynamic_cast<const pat::Tau*>(particle) != nullptr ) {
102  const pat::Tau* pfTau = dynamic_cast<const pat::Tau*>(particle);
103  return pfMEtResolution_->evalPFJet(pfTau->pfJetRef().get());
104  } else if ( dynamic_cast<const reco::PFTau*>(particle) != nullptr ) {
105  const reco::PFTau* pfTau = dynamic_cast<const reco::PFTau*>(particle);
106  return pfMEtResolution_->evalPFJet(pfTau->jetRef().get());
107  } else assert(0);
108  } else if ( dynamic_cast<const reco::PFJet*>(particle) != nullptr ||
109  dynamic_cast<const pat::Jet*>(particle) != nullptr ) {
110  metsig::SigInputObj pfJetResolution;
111  if ( dynamic_cast<const reco::PFJet*>(particle) != nullptr ) {
112  const reco::PFJet* pfJet = dynamic_cast<const reco::PFJet*>(particle);
113  pfJetResolution = pfMEtResolution_->evalPFJet(pfJet);
114  } else if ( dynamic_cast<const pat::Jet*>(particle) != nullptr ) {
115  const pat::Jet* jet = dynamic_cast<const pat::Jet*>(particle);
116  if ( jet->isPFJet() ) {
117  reco::PFJet pfJet(jet->p4(), jet->vertex(), jet->pfSpecific(), jet->getJetConstituents());
118  pfJetResolution = pfMEtResolution_->evalPFJet(&pfJet);
119  } else throw cms::Exception("addPFMEtSignObjects")
120  << "PAT jet not of PF-type !!\n";
121  } else assert(0);
122  //std::cout << "pfJet: pt = " << pt << ", eta = " << eta << ", phi = " << phi << std::endl;
123  // CV: apply additional jet energy resolution corrections
124  // not included in (PF)MEt significance algorithm yet
125  // (cf. CMS AN-11/400 vs. CMS AN-11/330)
126  if ( lut_ && pt > 10. ) {
127  double x = std::abs(eta);
128  double y = pt;
129  if ( x > lut_->GetXaxis()->GetXmin() && x < lut_->GetXaxis()->GetXmax() &&
130  y > lut_->GetYaxis()->GetXmin() && y < lut_->GetYaxis()->GetXmax() ) {
131  int binIndex = lut_->FindBin(x, y);
132  double addJERcorrFactor = lut_->GetBinContent(binIndex);
133  //std::cout << " addJERcorrFactor = " << addJERcorrFactor << std::endl;
134  pfJetResolution.set(pfJetResolution.get_type(),
135  pfJetResolution.get_energy(),
136  pfJetResolution.get_phi(),
137  addJERcorrFactor*pfJetResolution.get_sigma_e(),
138  pfJetResolution.get_sigma_tan());
139  }
140  }
141  return pfJetResolution;
142  } else if ( dynamic_cast<const reco::PFCandidate*>(particle) != nullptr ) {
143  const reco::PFCandidate* pfCandidate = dynamic_cast<const reco::PFCandidate*>(particle);
144  //std::cout << "pfCandidate: pt = " << pt << ", eta = " << eta << ", phi = " << phi << std::endl;
145  return pfMEtResolution_->evalPF(pfCandidate);
146  } else throw cms::Exception("addPFMEtSignObjects")
147  << "Invalid type of particle:"
148  << " valid types = { reco::GsfElectron/pat::Electron, reco::Photon/pat::Photon, reco::Muon/pat::Muon, reco::PFTau/pat::Tau,"
149  << " reco::PFJet/pat::Jet, reco::PFCandidate } !!\n";
150  }
151 
152  template <typename T>
153  std::vector<metsig::SigInputObj> compResolution(const std::list<T*>& particles) const
154  {
155  LogDebug("compResolution")
156  << " particles: entries = " << particles.size() << std::endl;
157 
158  std::vector<metsig::SigInputObj> pfMEtSignObjects;
159  addPFMEtSignObjects(pfMEtSignObjects, particles);
160 
161  return pfMEtSignObjects;
162  }
163 
164  reco::METCovMatrix operator()(const std::vector<metsig::SigInputObj>&) const;
165 
166  template <typename T>
167  reco::METCovMatrix operator()(const std::list<T*>& particles) const
168  {
169  std::vector<metsig::SigInputObj> pfMEtSignObjects = compResolution(particles);
170  return this->operator()(pfMEtSignObjects);
171  }
172 
173  protected:
174 
175  template<typename T>
176  void addPFMEtSignObjects(std::vector<metsig::SigInputObj>& metSignObjects,
177  const std::list<T*>& particles) const
178  {
179  for ( typename std::list<T*>::const_iterator particle = particles.begin();
180  particle != particles.end(); ++particle ) {
181  metSignObjects.push_back(this->compResolution(*particle));
182  }
183  }
184 
185  private:
186 
188 
189  // CV: look-up table for additional jet energy resolution corrections
190  // not included in (PF)MEt significance algorithm yet
191  // (cf. CMS AN-11/400 vs. CMS AN-11/330)
192  TFile* inputFile_;
193  TH2* lut_;
194 
196 };
197 
198 #endif
#define LogDebug(id)
bool isAvailable() const
Definition: Ref.h:575
value_type const * get() const
Definition: RefToBase.h:234
const reco::JetBaseRef & pfJetRef() const
Definition: Tau.h:164
double get_sigma_tan() const
Definition: SigInputObj.h:46
metsig::SignAlgoResolutions * pfMEtResolution_
TrackRef track() const override
reference to a Track
Definition: Muon.h:49
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
PFMEtSignInterfaceBase(const edm::ParameterSet &)
double get_phi() const
Definition: SigInputObj.h:44
const PFSpecific & pfSpecific() const
retrieve the pf specific part of the jet
Definition: Jet.h:271
metsig::SigInputObj evalPF(const reco::PFCandidate *candidate) const
#define nullptr
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:40
void addPFMEtSignObjects(std::vector< metsig::SigInputObj > &metSignObjects, const std::list< T * > &particles) const
virtual Constituents getJetConstituents() const
list of constituents
reco::TrackRef track() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
double eval(const resolutionType &type, const resolutionFunc &func, const double &et, const double &phi, const double &eta, const double &p) const
Jets made from PFObjects.
Definition: PFJet.h:21
void set(const std::string &m_type, const double &m_energy, const double &m_phi, const double &m_sigma_e, const double &m_sigma_tan)
Definition: SigInputObj.h:48
metsig::SigInputObj evalPFJet(const reco::Jet *jet) const
std::vector< metsig::SigInputObj > compResolution(const std::list< T * > &particles) const
const JetBaseRef & jetRef() const
Definition: PFTau.cc:58
const Point & vertex() const override
vertex position (overwritten by PF...)
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:808
double phiError() const
error on phi
Definition: TrackBase.h:835
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
Analysis-level tau class.
Definition: Tau.h:56
bool isPFJet() const
check to see if the jet is a reco::PFJet
Definition: Jet.h:255
double get_energy() const
Definition: SigInputObj.h:43
Analysis-level calorimeter jet class.
Definition: Jet.h:80
reco::METCovMatrix operator()(const std::list< T * > &particles) const
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
reco::METCovMatrix operator()(const std::vector< metsig::SigInputObj > &) const
std::string get_type() const
Definition: SigInputObj.h:42
metsig::SigInputObj compResolution(const T *particle) const
long double T
Analysis-level muon class.
Definition: Muon.h:50
double get_sigma_e() const
Definition: SigInputObj.h:45