CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Attributes
PFMEtSignInterfaceBase Class Reference

#include <PFMEtSignInterfaceBase.h>

Public Member Functions

template<typename T >
metsig::SigInputObj compResolution (const T *particle) const
 
template<typename T >
std::vector< metsig::SigInputObjcompResolution (const std::list< T *> &particles) const
 
reco::METCovMatrix operator() (const std::vector< metsig::SigInputObj > &) const
 
template<typename T >
reco::METCovMatrix operator() (const std::list< T *> &particles) const
 
 PFMEtSignInterfaceBase (const edm::ParameterSet &)
 
 ~PFMEtSignInterfaceBase ()
 

Protected Member Functions

template<typename T >
void addPFMEtSignObjects (std::vector< metsig::SigInputObj > &metSignObjects, const std::list< T *> &particles) const
 

Private Attributes

TFile * inputFile_
 
TH2 * lut_
 
metsig::SignAlgoResolutionspfMEtResolution_
 
int verbosity_
 

Detailed Description

Auxiliary class interfacing the TauAnalysis software to RecoMET/METAlgorithms/interface/significanceAlgo.h for computing (PF)MEt significance (see CMS AN-10/400 for description of the (PF)MEt significance computation)

Author
Christian Veelken, LLR

Definition at line 40 of file PFMEtSignInterfaceBase.h.

Constructor & Destructor Documentation

◆ PFMEtSignInterfaceBase()

PFMEtSignInterfaceBase::PFMEtSignInterfaceBase ( const edm::ParameterSet cfg)

Definition at line 15 of file PFMEtSignInterfaceBase.cc.

References looper::cfg, Exception, edm::ParameterSet::getParameter(), inputFile_, InefficientDoubleROC::inputFileName, edm::FileInPath::Local, lut_, pfMEtResolution_, AlCaHLTBitMon_QueryRunRegistry::string, and verbosity_.

16  : pfMEtResolution_(nullptr), inputFile_(nullptr), lut_(nullptr) {
18 
19  if (cfg.exists("addJERcorr")) {
20  edm::ParameterSet cfgJERcorr = cfg.getParameter<edm::ParameterSet>("addJERcorr");
21  edm::FileInPath inputFileName = cfgJERcorr.getParameter<edm::FileInPath>("inputFileName");
22  std::string lutName = cfgJERcorr.getParameter<std::string>("lutName");
23  if (inputFileName.location() != edm::FileInPath::Local)
24  throw cms::Exception("PFMEtSignInterfaceBase") << " Failed to find File = " << inputFileName << " !!\n";
25 
26  inputFile_ = new TFile(inputFileName.fullPath().data());
27  lut_ = dynamic_cast<TH2*>(inputFile_->Get(lutName.data()));
28  if (!lut_)
29  throw cms::Exception("PFMEtSignInterfaceBase") << " Failed to load LUT = " << lutName.data()
30  << " from file = " << inputFileName.fullPath().data() << " !!\n";
31  }
32 
33  verbosity_ = cfg.exists("verbosity") ? cfg.getParameter<int>("verbosity") : 0;
34 }
metsig::SignAlgoResolutions * pfMEtResolution_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303

◆ ~PFMEtSignInterfaceBase()

PFMEtSignInterfaceBase::~PFMEtSignInterfaceBase ( )

Definition at line 36 of file PFMEtSignInterfaceBase.cc.

References inputFile_, lut_, and pfMEtResolution_.

36  {
37  delete pfMEtResolution_;
38  delete inputFile_;
39  delete lut_;
40 }
metsig::SignAlgoResolutions * pfMEtResolution_

Member Function Documentation

◆ addPFMEtSignObjects()

template<typename T >
void PFMEtSignInterfaceBase::addPFMEtSignObjects ( std::vector< metsig::SigInputObj > &  metSignObjects,
const std::list< T *> &  particles 
) const
inlineprotected

Definition at line 175 of file PFMEtSignInterfaceBase.h.

References compResolution(), and ecalTrigSettings_cff::particles.

Referenced by compResolution().

175  {
176  for (typename std::list<T*>::const_iterator particle = particles.begin(); particle != particles.end(); ++particle) {
177  metSignObjects.push_back(this->compResolution(*particle));
178  }
179  }
metsig::SigInputObj compResolution(const T *particle) const

◆ compResolution() [1/2]

template<typename T >
metsig::SigInputObj PFMEtSignInterfaceBase::compResolution ( const T particle) const
inline

Definition at line 46 of file PFMEtSignInterfaceBase.h.

References funct::abs(), cms::cuda::assert(), metsig::ET, PVValHelper::eta, metsig::SignAlgoResolutions::eval(), metsig::SignAlgoResolutions::evalPF(), metsig::SignAlgoResolutions::evalPFJet(), Exception, edm::RefToBase< T >::get(), metsig::SigInputObj::get_energy(), metsig::SigInputObj::get_phi(), metsig::SigInputObj::get_sigma_e(), metsig::SigInputObj::get_sigma_tan(), metsig::SigInputObj::get_type(), metsig::jet, reco::PFTau::jetRef(), lut_, PbPb_ZMuSkimMuonDPG_cff::particleType, pat::Tau::pfJetRef(), pfMEtResolution_, metsig::PFtype2, metsig::PFtype3, phi, metsig::PHI, reco::TrackBase::phiError(), DiDispStaMuonMonitor_cfi::pt, reco::TrackBase::ptError(), metsig::SigInputObj::set(), AlCaHLTBitMon_QueryRunRegistry::string, x, and y.

Referenced by addPFMEtSignObjects(), operator()(), and NoPileUpPFMEtProducer::produce().

46  {
47  double pt = particle->pt();
48  double eta = particle->eta();
49  double phi = particle->phi();
50 
51  if (dynamic_cast<const reco::GsfElectron*>(particle) != nullptr ||
52  dynamic_cast<const pat::Electron*>(particle) != nullptr) {
53  std::string particleType = "electron";
54  // WARNING: SignAlgoResolutions::PFtype2 needs to be kept in sync with reco::PFCandidate::e !!
57  //std::cout << "electron: pt = " << pt << ", eta = " << eta << ", phi = " << phi
58  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
59  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
60  } else if (dynamic_cast<const reco::Photon*>(particle) != nullptr ||
61  dynamic_cast<const pat::Photon*>(particle) != nullptr) {
62  // CV: assume resolutions for photons to be identical to electron resolutions
63  std::string particleType = "electron";
64  // WARNING: SignAlgoResolutions::PFtype2 needs to be kept in sync with reco::PFCandidate::e !!
67  //std::cout << "photon: pt = " << pt << ", eta = " << eta << ", phi = " << phi
68  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
69  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
70  } else if (dynamic_cast<const reco::Muon*>(particle) != nullptr ||
71  dynamic_cast<const pat::Muon*>(particle) != nullptr) {
72  std::string particleType = "muon";
73  double dpt, dphi;
74  const reco::Track* muonTrack = nullptr;
75  if (dynamic_cast<const pat::Muon*>(particle) != nullptr) {
76  const pat::Muon* muon = dynamic_cast<const pat::Muon*>(particle);
77  if (muon->track().isNonnull() && muon->track().isAvailable())
78  muonTrack = muon->track().get();
79  } else if (dynamic_cast<const reco::Muon*>(particle) != nullptr) {
80  const reco::Muon* muon = dynamic_cast<const reco::Muon*>(particle);
81  if (muon->track().isNonnull() && muon->track().isAvailable())
82  muonTrack = muon->track().get();
83  } else
84  assert(0);
85  if (muonTrack) {
86  dpt = muonTrack->ptError();
87  dphi = pt * muonTrack->phiError(); // CV: pt*dphi is indeed correct
88  } else {
89  // WARNING: SignAlgoResolutions::PFtype3 needs to be kept in sync with reco::PFCandidate::mu !!
92  }
93  //std::cout << "muon: pt = " << pt << ", eta = " << eta << ", phi = " << phi
94  // << " --> dpt = " << dpt << ", dphi = " << dphi << std::endl;
95  return metsig::SigInputObj(particleType, pt, phi, dpt, dphi);
96  } else if (dynamic_cast<const reco::PFTau*>(particle) != nullptr ||
97  dynamic_cast<const pat::Tau*>(particle) != nullptr) {
98  // CV: use PFJet resolutions for PFTaus for now...
99  // (until PFTau specific resolutions are available)
100  if (dynamic_cast<const pat::Tau*>(particle) != nullptr) {
101  const pat::Tau* pfTau = dynamic_cast<const pat::Tau*>(particle);
102  return pfMEtResolution_->evalPFJet(pfTau->pfJetRef().get());
103  } else if (dynamic_cast<const reco::PFTau*>(particle) != nullptr) {
104  const reco::PFTau* pfTau = dynamic_cast<const reco::PFTau*>(particle);
105  return pfMEtResolution_->evalPFJet(pfTau->jetRef().get());
106  } else
107  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
120  throw cms::Exception("addPFMEtSignObjects") << "PAT jet not of PF-type !!\n";
121  } else
122  assert(0);
123  //std::cout << "pfJet: pt = " << pt << ", eta = " << eta << ", phi = " << phi << std::endl;
124  // CV: apply additional jet energy resolution corrections
125  // not included in (PF)MEt significance algorithm yet
126  // (cf. CMS AN-11/400 vs. CMS AN-11/330)
127  if (lut_ && pt > 10.) {
128  double x = std::abs(eta);
129  double y = pt;
130  if (x > lut_->GetXaxis()->GetXmin() && x < lut_->GetXaxis()->GetXmax() && y > lut_->GetYaxis()->GetXmin() &&
131  y < lut_->GetYaxis()->GetXmax()) {
132  int binIndex = lut_->FindBin(x, y);
133  double addJERcorrFactor = lut_->GetBinContent(binIndex);
134  //std::cout << " addJERcorrFactor = " << addJERcorrFactor << std::endl;
135  pfJetResolution.set(pfJetResolution.get_type(),
136  pfJetResolution.get_energy(),
137  pfJetResolution.get_phi(),
138  addJERcorrFactor * pfJetResolution.get_sigma_e(),
139  pfJetResolution.get_sigma_tan());
140  }
141  }
142  return pfJetResolution;
143  } else if (dynamic_cast<const reco::PFCandidate*>(particle) != nullptr) {
144  const reco::PFCandidate* pfCandidate = dynamic_cast<const reco::PFCandidate*>(particle);
145  //std::cout << "pfCandidate: pt = " << pt << ", eta = " << eta << ", phi = " << phi << std::endl;
146  return pfMEtResolution_->evalPF(pfCandidate);
147  } else
148  throw cms::Exception("addPFMEtSignObjects")
149  << "Invalid type of particle:"
150  << " valid types = { reco::GsfElectron/pat::Electron, reco::Photon/pat::Photon, reco::Muon/pat::Muon, "
151  "reco::PFTau/pat::Tau,"
152  << " reco::PFJet/pat::Jet, reco::PFCandidate } !!\n";
153  }
metsig::SignAlgoResolutions * pfMEtResolution_
double get_phi() const
Definition: SigInputObj.h:38
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:754
metsig::SigInputObj evalPFJet(const reco::Jet *jet) const
const reco::JetBaseRef & pfJetRef() const
Definition: Tau.h:127
double get_sigma_e() const
Definition: SigInputObj.h:39
assert(be >=bs)
Jets made from PFObjects.
Definition: PFJet.h:20
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
metsig::SigInputObj evalPF(const reco::PFCandidate *candidate) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Analysis-level tau class.
Definition: Tau.h:53
double eval(const resolutionType &type, const resolutionFunc &func, const double &et, const double &phi, const double &eta, const double &p) const
Analysis-level calorimeter jet class.
Definition: Jet.h:77
double get_energy() const
Definition: SigInputObj.h:37
double get_sigma_tan() const
Definition: SigInputObj.h:40
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
const JetBaseRef & jetRef() const
Definition: PFTau.cc:56
std::string get_type() const
Definition: SigInputObj.h:36
double phiError() const
error on phi
Definition: TrackBase.h:766
value_type const * get() const
Definition: RefToBase.h:211
Analysis-level muon class.
Definition: Muon.h:51

◆ compResolution() [2/2]

template<typename T >
std::vector<metsig::SigInputObj> PFMEtSignInterfaceBase::compResolution ( const std::list< T *> &  particles) const
inline

Definition at line 156 of file PFMEtSignInterfaceBase.h.

References addPFMEtSignObjects(), LogDebug, and ecalTrigSettings_cff::particles.

156  {
157  LogDebug("compResolution") << " particles: entries = " << particles.size() << std::endl;
158 
159  std::vector<metsig::SigInputObj> pfMEtSignObjects;
160  addPFMEtSignObjects(pfMEtSignObjects, particles);
161 
162  return pfMEtSignObjects;
163  }
void addPFMEtSignObjects(std::vector< metsig::SigInputObj > &metSignObjects, const std::list< T *> &particles) const
#define LogDebug(id)

◆ operator()() [1/2]

reco::METCovMatrix PFMEtSignInterfaceBase::operator() ( const std::vector< metsig::SigInputObj > &  pfMEtSignObjects) const

Definition at line 42 of file PFMEtSignInterfaceBase.cc.

References funct::abs(), metsig::significanceAlgo::addObjects(), defaultPFMEtResolutionX, defaultPFMEtResolutionY, epsilon, and metsig::significanceAlgo::getSignifMatrix().

Referenced by operator()().

42  {
43  // if ( this->verbosity_ ) {
44  // std::cout << "<PFMEtSignInterfaceBase::operator()>:" << std::endl;
45  // std::cout << " pfMEtSignObjects: entries = " << pfMEtSignObjects.size() << std::endl;
46  // double dpt2Sum = 0.;
47  // for ( std::vector<metsig::SigInputObj>::const_iterator pfMEtSignObject = pfMEtSignObjects.begin();
48  // pfMEtSignObject != pfMEtSignObjects.end(); ++pfMEtSignObject ) {
49  // std::cout << pfMEtSignObject->get_type() << ": pt = " << pfMEtSignObject->get_energy() << ","
50  // << " phi = " << pfMEtSignObject->get_phi() << " --> dpt = " << pfMEtSignObject->get_sigma_e() << std::endl;
51  // dpt2Sum += pfMEtSignObject->get_sigma_e();
52  // }
53  // std::cout << "--> sqrt(sum(dpt^2)) = " << sqrt(dpt2Sum) << std::endl;
54  // }
55 
56  reco::METCovMatrix pfMEtCov;
57  if (pfMEtSignObjects.size() >= 2) {
58  metsig::significanceAlgo pfMEtSignAlgorithm;
59  pfMEtSignAlgorithm.addObjects(pfMEtSignObjects);
60  pfMEtCov = pfMEtSignAlgorithm.getSignifMatrix();
61 
62  double det = 0;
63  pfMEtCov.Det(det);
64 
65  // if ( this->verbosity_ && std::abs(det) > epsilon ) {
66  // //keep TMatrixD as it is much easier to find
67  // //eigenvectors and values than with SMatrix;
68  // //not used anyway, except for debugging
69  // TMatrixD tmpMatrix(2,2);
70  // tmpMatrix(0,0) = pfMEtCov(0,0);
71  // tmpMatrix(0,1) = pfMEtCov(0,1);
72  // tmpMatrix(1,0) = pfMEtCov(1,0);
73  // tmpMatrix(1,1) = pfMEtCov(1,1);
74 
75  // TVectorD eigenValues(2);
76  // TMatrixD eigenVectors = tmpMatrix.EigenVectors(eigenValues);
77  // // CV: eigenvectors are stored in columns
78  // // and are sorted such that the one corresponding to the highest eigenvalue is in the **first** column
79  // for ( unsigned iEigenVector = 0; iEigenVector < 2; ++iEigenVector ) {
80  // std::cout << "eigenVector #" << iEigenVector << " (eigenValue = " << eigenValues(iEigenVector) << "):"
81  // << " x = " << eigenVectors(0, iEigenVector) << ", y = " << eigenVectors(1, iEigenVector) << std::endl;
82  // }
83  // }
84 
85  //--- substitute (PF)MEt resolution matrix by default values
86  // in case resolution matrix cannot be inverted
87  if (std::abs(det) < epsilon) {
88  edm::LogWarning("PFMEtSignInterfaceBase::operator()")
89  << "Inversion of PFMEt covariance matrix failed, det = " << det
90  << " --> replacing covariance matrix by resolution defaults !!";
92  pfMEtCov(0, 1) = 0.;
93  pfMEtCov(1, 0) = 0.;
95  }
96  } else {
97  pfMEtCov(0, 0) = 0.;
98  pfMEtCov(0, 1) = 0.;
99  pfMEtCov(1, 0) = 0.;
100  pfMEtCov(1, 1) = 0.;
101  }
102 
103  return pfMEtCov;
104 }
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
const double defaultPFMEtResolutionX
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:39
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double defaultPFMEtResolutionY
Log< level::Warning, false > LogWarning
reco::METCovMatrix getSignifMatrix() const
const double epsilon

◆ operator()() [2/2]

template<typename T >
reco::METCovMatrix PFMEtSignInterfaceBase::operator() ( const std::list< T *> &  particles) const
inline

Definition at line 168 of file PFMEtSignInterfaceBase.h.

References compResolution(), operator()(), and ecalTrigSettings_cff::particles.

168  {
169  std::vector<metsig::SigInputObj> pfMEtSignObjects = compResolution(particles);
170  return this->operator()(pfMEtSignObjects);
171  }
reco::METCovMatrix operator()(const std::vector< metsig::SigInputObj > &) const
metsig::SigInputObj compResolution(const T *particle) const

Member Data Documentation

◆ inputFile_

TFile* PFMEtSignInterfaceBase::inputFile_
private

Definition at line 187 of file PFMEtSignInterfaceBase.h.

Referenced by PFMEtSignInterfaceBase(), and ~PFMEtSignInterfaceBase().

◆ lut_

TH2* PFMEtSignInterfaceBase::lut_
private

◆ pfMEtResolution_

metsig::SignAlgoResolutions* PFMEtSignInterfaceBase::pfMEtResolution_
private

◆ verbosity_

int PFMEtSignInterfaceBase::verbosity_
private

Definition at line 190 of file PFMEtSignInterfaceBase.h.

Referenced by PFMEtSignInterfaceBase().