CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFMEtSignInterfaceBase.cc
Go to the documentation of this file.
2 
5 
7 
8 #include <TVectorD.h>
9 
10 const double defaultPFMEtResolutionX = 10.;
11 const double defaultPFMEtResolutionY = 10.;
12 
13 const double epsilon = 1.e-9;
14 
16  : pfMEtResolution_(nullptr),
17  inputFile_(nullptr),
18  lut_(nullptr)
19 {
21 
22  if ( cfg.exists("addJERcorr") ) {
23  edm::ParameterSet cfgJERcorr = cfg.getParameter<edm::ParameterSet>("addJERcorr");
24  edm::FileInPath inputFileName = cfgJERcorr.getParameter<edm::FileInPath>("inputFileName");
25  std::string lutName = cfgJERcorr.getParameter<std::string>("lutName");
26  if ( inputFileName.location()!=edm::FileInPath::Local )
27  throw cms::Exception("PFMEtSignInterfaceBase")
28  << " Failed to find File = " << inputFileName << " !!\n";
29 
30  inputFile_ = new TFile(inputFileName.fullPath().data());
31  lut_ = dynamic_cast<TH2*>(inputFile_->Get(lutName.data()));
32  if ( !lut_ )
33  throw cms::Exception("PFMEtSignInterfaceBase")
34  << " Failed to load LUT = " << lutName.data() << " from file = " << inputFileName.fullPath().data() << " !!\n";
35  }
36 
37  verbosity_ = cfg.exists("verbosity") ?
38  cfg.getParameter<int>("verbosity") : 0;
39 }
40 
42 {
43  delete pfMEtResolution_;
44  delete inputFile_;
45  delete lut_;
46 }
47 
48 reco::METCovMatrix PFMEtSignInterfaceBase::operator()(const std::vector<metsig::SigInputObj>& pfMEtSignObjects) const
49 {
50  // if ( this->verbosity_ ) {
51  // std::cout << "<PFMEtSignInterfaceBase::operator()>:" << std::endl;
52  // std::cout << " pfMEtSignObjects: entries = " << pfMEtSignObjects.size() << std::endl;
53  // double dpt2Sum = 0.;
54  // for ( std::vector<metsig::SigInputObj>::const_iterator pfMEtSignObject = pfMEtSignObjects.begin();
55  // pfMEtSignObject != pfMEtSignObjects.end(); ++pfMEtSignObject ) {
56  // std::cout << pfMEtSignObject->get_type() << ": pt = " << pfMEtSignObject->get_energy() << ","
57  // << " phi = " << pfMEtSignObject->get_phi() << " --> dpt = " << pfMEtSignObject->get_sigma_e() << std::endl;
58  // dpt2Sum += pfMEtSignObject->get_sigma_e();
59  // }
60  // std::cout << "--> sqrt(sum(dpt^2)) = " << sqrt(dpt2Sum) << std::endl;
61  // }
62 
63  reco::METCovMatrix pfMEtCov;
64  if ( pfMEtSignObjects.size() >= 2 ) {
65  metsig::significanceAlgo pfMEtSignAlgorithm;
66  pfMEtSignAlgorithm.addObjects(pfMEtSignObjects);
67  pfMEtCov = pfMEtSignAlgorithm.getSignifMatrix();
68 
69  double det=0;
70  pfMEtCov.Det(det);
71 
72  // if ( this->verbosity_ && std::abs(det) > epsilon ) {
73  // //keep TMatrixD as it is much easier to find
74  // //eigenvectors and values than with SMatrix;
75  // //not used anyway, except for debugging
76  // TMatrixD tmpMatrix(2,2);
77  // tmpMatrix(0,0) = pfMEtCov(0,0);
78  // tmpMatrix(0,1) = pfMEtCov(0,1);
79  // tmpMatrix(1,0) = pfMEtCov(1,0);
80  // tmpMatrix(1,1) = pfMEtCov(1,1);
81 
82  // TVectorD eigenValues(2);
83  // TMatrixD eigenVectors = tmpMatrix.EigenVectors(eigenValues);
84  // // CV: eigenvectors are stored in columns
85  // // and are sorted such that the one corresponding to the highest eigenvalue is in the **first** column
86  // for ( unsigned iEigenVector = 0; iEigenVector < 2; ++iEigenVector ) {
87  // std::cout << "eigenVector #" << iEigenVector << " (eigenValue = " << eigenValues(iEigenVector) << "):"
88  // << " x = " << eigenVectors(0, iEigenVector) << ", y = " << eigenVectors(1, iEigenVector) << std::endl;
89  // }
90  // }
91 
92  //--- substitute (PF)MEt resolution matrix by default values
93  // in case resolution matrix cannot be inverted
94  if (std::abs(det) < epsilon ) {
95  edm::LogWarning("PFMEtSignInterfaceBase::operator()")
96  << "Inversion of PFMEt covariance matrix failed, det = " << det
97  << " --> replacing covariance matrix by resolution defaults !!";
99  pfMEtCov(0,1) = 0.;
100  pfMEtCov(1,0) = 0.;
102  }
103  } else {
104  pfMEtCov(0,0) = 0.;
105  pfMEtCov(0,1) = 0.;
106  pfMEtCov(1,0) = 0.;
107  pfMEtCov(1,1) = 0.;
108  }
109 
110  return pfMEtCov;
111 }
const double defaultPFMEtResolutionY
T getParameter(std::string const &) const
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
metsig::SignAlgoResolutions * pfMEtResolution_
tuple cfg
Definition: looper.py:293
PFMEtSignInterfaceBase(const edm::ParameterSet &)
bool exists(std::string const &parameterName) const
checks if a parameter exists
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:40
#define nullptr
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double defaultPFMEtResolutionX
reco::METCovMatrix getSignifMatrix() const
reco::METCovMatrix operator()(const std::vector< metsig::SigInputObj > &) const