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 #include <TFile.h>
37 #include <TH2.h>
38 
40 public:
43 
44  template <typename T>
45  metsig::SigInputObj compResolution(const T* particle) const {
46  double pt = particle->pt();
47  double eta = particle->eta();
48  double phi = particle->phi();
49 
50  if (dynamic_cast<const reco::GsfElectron*>(particle) != nullptr ||
51  dynamic_cast<const pat::Electron*>(particle) != nullptr) {
52  std::string particleType = "electron";
53  // WARNING: SignAlgoResolutions::PFtype2 needs to be kept in sync with reco::PFCandidate::e !!
56  //std::cout << "electron: pt = " << pt << ", eta = " << eta << ", phi = " << phi
57  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
58  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
59  } else if (dynamic_cast<const reco::Photon*>(particle) != nullptr ||
60  dynamic_cast<const pat::Photon*>(particle) != nullptr) {
61  // CV: assume resolutions for photons to be identical to electron resolutions
62  std::string particleType = "electron";
63  // WARNING: SignAlgoResolutions::PFtype2 needs to be kept in sync with reco::PFCandidate::e !!
66  //std::cout << "photon: pt = " << pt << ", eta = " << eta << ", phi = " << phi
67  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
68  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
69  } else if (dynamic_cast<const reco::Muon*>(particle) != nullptr ||
70  dynamic_cast<const pat::Muon*>(particle) != nullptr) {
71  std::string particleType = "muon";
72  double dpt, dphi;
73  const reco::Track* muonTrack = nullptr;
74  if (dynamic_cast<const pat::Muon*>(particle) != nullptr) {
75  const pat::Muon* muon = dynamic_cast<const pat::Muon*>(particle);
76  if (muon->track().isNonnull() && muon->track().isAvailable())
77  muonTrack = muon->track().get();
78  } else if (dynamic_cast<const reco::Muon*>(particle) != nullptr) {
79  const reco::Muon* muon = dynamic_cast<const reco::Muon*>(particle);
80  if (muon->track().isNonnull() && muon->track().isAvailable())
81  muonTrack = muon->track().get();
82  } else
83  assert(0);
84  if (muonTrack) {
85  dpt = muonTrack->ptError();
86  dphi = pt * muonTrack->phiError(); // CV: pt*dphi is indeed correct
87  } else {
88  // WARNING: SignAlgoResolutions::PFtype3 needs to be kept in sync with reco::PFCandidate::mu !!
91  }
92  //std::cout << "muon: pt = " << pt << ", eta = " << eta << ", phi = " << phi
93  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
94  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
95  } else if (dynamic_cast<const reco::PFTau*>(particle) != nullptr ||
96  dynamic_cast<const pat::Tau*>(particle) != nullptr) {
97  // CV: use PFJet resolutions for PFTaus for now...
98  // (until PFTau specific resolutions are available)
99  if (dynamic_cast<const pat::Tau*>(particle) != nullptr) {
100  const pat::Tau* pfTau = dynamic_cast<const pat::Tau*>(particle);
101  return pfMEtResolution_->evalPFJet(pfTau->pfJetRef().get());
102  } else if (dynamic_cast<const reco::PFTau*>(particle) != nullptr) {
103  const reco::PFTau* pfTau = dynamic_cast<const reco::PFTau*>(particle);
104  return pfMEtResolution_->evalPFJet(pfTau->jetRef().get());
105  } else
106  assert(0);
107  } else if (dynamic_cast<const reco::PFJet*>(particle) != nullptr ||
108  dynamic_cast<const pat::Jet*>(particle) != nullptr) {
109  metsig::SigInputObj pfJetResolution;
110  if (dynamic_cast<const reco::PFJet*>(particle) != nullptr) {
111  const reco::PFJet* pfJet = dynamic_cast<const reco::PFJet*>(particle);
112  pfJetResolution = pfMEtResolution_->evalPFJet(pfJet);
113  } else if (dynamic_cast<const pat::Jet*>(particle) != nullptr) {
114  const pat::Jet* jet = dynamic_cast<const pat::Jet*>(particle);
115  if (jet->isPFJet()) {
116  reco::PFJet pfJet(jet->p4(), jet->vertex(), jet->pfSpecific(), jet->getJetConstituents());
117  pfJetResolution = pfMEtResolution_->evalPFJet(&pfJet);
118  } else
119  throw cms::Exception("addPFMEtSignObjects") << "PAT jet not of PF-type !!\n";
120  } else
121  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() && y > lut_->GetYaxis()->GetXmin() &&
130  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
147  throw cms::Exception("addPFMEtSignObjects")
148  << "Invalid type of particle:"
149  << " valid types = { reco::GsfElectron/pat::Electron, reco::Photon/pat::Photon, reco::Muon/pat::Muon, "
150  "reco::PFTau/pat::Tau,"
151  << " reco::PFJet/pat::Jet, reco::PFCandidate } !!\n";
152  }
153 
154  template <typename T>
155  std::vector<metsig::SigInputObj> compResolution(const std::list<T*>& particles) const {
156  LogDebug("compResolution") << " 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  std::vector<metsig::SigInputObj> pfMEtSignObjects = compResolution(particles);
169  return this->operator()(pfMEtSignObjects);
170  }
171 
172 protected:
173  template <typename T>
174  void addPFMEtSignObjects(std::vector<metsig::SigInputObj>& metSignObjects, const std::list<T*>& particles) const {
175  for (typename std::list<T*>::const_iterator particle = particles.begin(); particle != particles.end(); ++particle) {
176  metSignObjects.push_back(this->compResolution(*particle));
177  }
178  }
179 
180 private:
182 
183  // CV: look-up table for additional jet energy resolution corrections
184  // not included in (PF)MEt significance algorithm yet
185  // (cf. CMS AN-11/400 vs. CMS AN-11/330)
186  TFile* inputFile_;
187  TH2* lut_;
188 
190 };
191 
192 #endif
DDAxes::y
PFMEtSignInterfaceBase::addPFMEtSignObjects
void addPFMEtSignObjects(std::vector< metsig::SigInputObj > &metSignObjects, const std::list< T * > &particles) const
Definition: PFMEtSignInterfaceBase.h:174
reco::TrackBase::ptError
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:754
Muon.h
metsig::ET
Definition: SignAlgoResolutions.h:59
metsig::SignAlgoResolutions::evalPF
metsig::SigInputObj evalPF(const reco::PFCandidate *candidate) const
Definition: SignAlgoResolutions.cc:64
muon
Definition: MuonCocktails.h:17
PFMEtSignInterfaceBase::~PFMEtSignInterfaceBase
~PFMEtSignInterfaceBase()
Definition: PFMEtSignInterfaceBase.cc:36
PFCandidate.h
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
Muon.h
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
Photon.h
PFJet.h
metsig::SigInputObj::set
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:42
cms::cuda::assert
assert(be >=bs)
reco::PFTau
Definition: PFTau.h:36
DDAxes::x
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
metsig::SigInputObj::get_energy
double get_energy() const
Definition: SigInputObj.h:37
Tau.h
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
PFMEtSignInterfaceBase::compResolution
metsig::SigInputObj compResolution(const T *particle) const
Definition: PFMEtSignInterfaceBase.h:45
reco::Muon
Definition: Muon.h:27
metsig::SignAlgoResolutions::eval
double eval(const resolutionType &type, const resolutionFunc &func, const double &et, const double &phi, const double &eta, const double &p) const
Definition: SignAlgoResolutions.cc:49
PFMEtSignInterfaceBase::pfMEtResolution_
metsig::SignAlgoResolutions * pfMEtResolution_
Definition: PFMEtSignInterfaceBase.h:181
metsig::SigInputObj::get_phi
double get_phi() const
Definition: SigInputObj.h:38
PFMEtSignInterfaceBase::lut_
TH2 * lut_
Definition: PFMEtSignInterfaceBase.h:187
PFMEtSignInterfaceBase::operator()
reco::METCovMatrix operator()(const std::list< T * > &particles) const
Definition: PFMEtSignInterfaceBase.h:167
SignAlgoResolutions.h
Photon.h
pat::Jet
Analysis-level calorimeter jet class.
Definition: Jet.h:77
Track.h
metsig::SigInputObj::get_sigma_e
double get_sigma_e() const
Definition: SigInputObj.h:39
SigInputObj.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
PFMEtSignInterfaceBase::operator()
reco::METCovMatrix operator()(const std::vector< metsig::SigInputObj > &) const
Definition: PFMEtSignInterfaceBase.cc:42
metsig::PFtype3
Definition: SignAlgoResolutions.h:53
reco::Track
Definition: Track.h:27
GsfElectron.h
edm::RefToBase::get
value_type const * get() const
Definition: RefToBase.h:209
PFMEtSignInterfaceBase::inputFile_
TFile * inputFile_
Definition: PFMEtSignInterfaceBase.h:186
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PFMEtSignInterfaceBase::compResolution
std::vector< metsig::SigInputObj > compResolution(const std::list< T * > &particles) const
Definition: PFMEtSignInterfaceBase.h:155
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
metsig::SigInputObj::get_type
std::string get_type() const
Definition: SigInputObj.h:36
pat::Tau::pfJetRef
const reco::JetBaseRef & pfJetRef() const
Definition: Tau.h:127
metsig::PFtype2
Definition: SignAlgoResolutions.h:52
Jet.h
InputTag.h
DDAxes::phi
MET.h
PFMEtSignInterfaceBase::verbosity_
int verbosity_
Definition: PFMEtSignInterfaceBase.h:189
metsig::PHI
Definition: SignAlgoResolutions.h:59
metsig::SignAlgoResolutions
Definition: SignAlgoResolutions.h:61
T
long double T
Definition: Basic3DVectorLD.h:48
PFMEtSignInterfaceBase::PFMEtSignInterfaceBase
PFMEtSignInterfaceBase(const edm::ParameterSet &)
Definition: PFMEtSignInterfaceBase.cc:15
metsig::jet
Definition: SignAlgoResolutions.h:47
Exception
Definition: hltDiff.cc:246
PFTau.h
reco::PFJet
Jets made from PFObjects.
Definition: PFJet.h:20
Electron.h
PFMEtSignInterfaceBase
Definition: PFMEtSignInterfaceBase.h:39
reco::TrackBase::phiError
double phiError() const
error on phi
Definition: TrackBase.h:766
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
Candidate.h
metsig::SigInputObj::get_sigma_tan
double get_sigma_tan() const
Definition: SigInputObj.h:40
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
PbPb_ZMuSkimMuonDPG_cff.particleType
particleType
Definition: PbPb_ZMuSkimMuonDPG_cff.py:27
metsig::SigInputObj
Definition: SigInputObj.h:29
reco::METCovMatrix
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:39
metsig::SignAlgoResolutions::evalPFJet
metsig::SigInputObj evalPFJet(const reco::Jet *jet) const
Definition: SignAlgoResolutions.cc:121
reco::PFTau::jetRef
const JetBaseRef & jetRef() const
Definition: PFTau.cc:57