CMS 3D CMS Logo

CovarianceMatrix.h
Go to the documentation of this file.
1 #ifndef CovarianceMatrix_h
2 #define CovarianceMatrix_h
3 
5 
11 
17 
18 /*
19  \class CovarianceMatrix CovarianceMatrix.h "TopQuarkAnalysis/TopKinFitter/interface/CovarianceMatrix.h"
20 
21  \brief Helper class used to setup covariance matrices for given objects and known resolutions
22 
23  More details to be added here...
24 
25 **/
26 
28 public:
30 
34  CovarianceMatrix(const std::vector<edm::ParameterSet>& udscResolutions,
35  const std::vector<edm::ParameterSet>& bResolutions,
36  const std::vector<double>& jetEnergyResolutionScaleFactors,
37  const std::vector<double>& jetEnergyResolutionEtaBinning);
39  CovarianceMatrix(const std::vector<edm::ParameterSet>& udscResolutions,
40  const std::vector<edm::ParameterSet>& bResolutions,
41  const std::vector<edm::ParameterSet>& lepResolutions,
42  const std::vector<edm::ParameterSet>& metResolutions,
43  const std::vector<double>& jetEnergyResolutionScaleFactors,
44  const std::vector<double>& jetEnergyResolutionEtaBinning);
45  // destructor
47 
49  template <class T>
50  TMatrixD setupMatrix(const pat::PATObject<T>& object,
51  const TopKinFitter::Param param,
52  const std::string& resolutionProvider = "");
54  TMatrixD setupMatrix(const TLorentzVector& object, const ObjectType objType, const TopKinFitter::Param param);
56  double getResolution(const TLorentzVector& object, const ObjectType objType, const std::string& whichResolution = "");
58  template <class T>
59  double getResolution(const pat::PATObject<T>& object, const std::string& whichResolution, const bool isBJet = false) {
60  return getResolution(TLorentzVector(object.px(), object.py(), object.pz(), object.energy()),
61  getObjectType(object, isBJet),
62  whichResolution);
63  }
64 
65 private:
67  std::vector<std::string> binsUdsc_, binsB_, binsLep_, binsMet_;
69  std::vector<std::string> funcEtUdsc_, funcEtB_, funcEtLep_, funcEtMet_;
70  std::vector<std::string> funcEtaUdsc_, funcEtaB_, funcEtaLep_, funcEtaMet_;
71  std::vector<std::string> funcPhiUdsc_, funcPhiB_, funcPhiLep_, funcPhiMet_;
73  const std::vector<double> jetEnergyResolutionScaleFactors_;
74  const std::vector<double> jetEnergyResolutionEtaBinning_;
75 
77  template <class T>
78  ObjectType getObjectType(const pat::PATObject<T>& object, const bool isBJet = false);
80  template <class T>
81  double getEtaDependentScaleFactor(const pat::PATObject<T>& object);
83  double getEtaDependentScaleFactor(const TLorentzVector& object);
84 };
85 
86 template <class T>
88  const TopKinFitter::Param param,
89  const std::string& resolutionProvider) {
90  // This part is for pat objects with resolutions embedded
91  if (object.hasKinResolution()) {
92  TMatrixD CovM3(3, 3);
93  CovM3.Zero();
94  TMatrixD CovM4(4, 4);
95  CovM4.Zero();
96  TMatrixD* CovM = &CovM3;
97  switch (param) {
99  CovM3(0, 0) = pow(object.resolEt(resolutionProvider), 2);
100  if (dynamic_cast<const reco::Jet*>(&object))
101  CovM3(0, 0) *= getEtaDependentScaleFactor(object);
102  if (dynamic_cast<const reco::MET*>(&object))
103  CovM3(1, 1) = pow(9999., 2);
104  else
105  CovM3(1, 1) = pow(object.resolEta(resolutionProvider), 2);
106  CovM3(2, 2) = pow(object.resolPhi(resolutionProvider), 2);
107  CovM = &CovM3;
108  break;
110  CovM3(0, 0) = pow(object.resolEt(resolutionProvider), 2);
111  if (dynamic_cast<const reco::Jet*>(&object))
112  CovM3(0, 0) *= getEtaDependentScaleFactor(object);
113  CovM3(1, 1) = pow(object.resolTheta(resolutionProvider), 2);
114  CovM3(2, 2) = pow(object.resolPhi(resolutionProvider), 2);
115  CovM = &CovM3;
116  break;
117  case TopKinFitter::kEMom:
118  CovM4(0, 0) = pow(1, 2);
119  CovM4(1, 1) = pow(1, 2);
120  CovM4(2, 2) = pow(1, 2);
121  CovM4(3, 3) = pow(1, 2);
122  CovM = &CovM4;
123  break;
124  }
125  return *CovM;
126  }
127  // This part is for objects without resolutions embedded
128  else {
129  const ObjectType objType = getObjectType(object, (resolutionProvider == "bjets"));
130  const TLorentzVector p4(object.px(), object.py(), object.pz(), object.energy());
131  return setupMatrix(p4, objType, param);
132  }
133 }
134 
135 template <class T>
138  // jets
139  if (dynamic_cast<const reco::Jet*>(&object)) {
140  if (isBJet)
141  objType = kBJet;
142  else
143  objType = kUdscJet;
144  }
145  // muons
146  else if (dynamic_cast<const reco::Muon*>(&object))
147  objType = kMuon;
148  // electrons
149  else if (dynamic_cast<const reco::GsfElectron*>(&object))
150  objType = kElectron;
151  // MET
152  else if (dynamic_cast<const reco::MET*>(&object))
153  objType = kMet;
154  // catch anything else
155  else
156  throw cms::Exception("UnsupportedObject") << "The object given is not supported!\n";
157  return objType;
158 }
159 
160 template <class T>
162  double etaDependentScaleFactor = 1.;
163  for (unsigned int i = 0; i < jetEnergyResolutionEtaBinning_.size(); i++) {
165  if (i == jetEnergyResolutionEtaBinning_.size() - 1) {
166  edm::LogWarning("CovarianceMatrix") << "object eta (" << std::abs(object.eta()) << ") beyond last eta bin ("
167  << jetEnergyResolutionEtaBinning_[i] << ") using scale factor 1.0!";
168  etaDependentScaleFactor = 1.;
169  break;
170  }
171  etaDependentScaleFactor = jetEnergyResolutionScaleFactors_[i];
172  } else
173  break;
174  }
175  return etaDependentScaleFactor;
176 }
177 
178 #endif
TopKinFitter::kEtEtaPhi
Definition: TopKinFitter.h:20
CovarianceMatrix::jetEnergyResolutionScaleFactors_
const std::vector< double > jetEnergyResolutionScaleFactors_
scale factors for the jet energy resolution
Definition: CovarianceMatrix.h:73
CovarianceMatrix::funcPhiUdsc_
std::vector< std::string > funcPhiUdsc_
Definition: CovarianceMatrix.h:71
mps_fire.i
i
Definition: mps_fire.py:428
TtFullHadKinFitProducer_cfi.udscResolutions
udscResolutions
Definition: TtFullHadKinFitProducer_cfi.py:83
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
Muon.h
CovarianceMatrix::funcEtMet_
std::vector< std::string > funcEtMet_
Definition: CovarianceMatrix.h:69
CovarianceMatrix::CovarianceMatrix
CovarianceMatrix()
default constructor
Definition: CovarianceMatrix.h:32
CovarianceMatrix::binsLep_
std::vector< std::string > binsLep_
Definition: CovarianceMatrix.h:67
CovarianceMatrix::getResolution
double getResolution(const pat::PATObject< T > &object, const std::string &whichResolution, const bool isBJet=false)
get resolution for a given PAT object
Definition: CovarianceMatrix.h:59
CovarianceMatrix::funcPhiLep_
std::vector< std::string > funcPhiLep_
Definition: CovarianceMatrix.h:71
CovarianceMatrix
Definition: CovarianceMatrix.h:27
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
TopKinFitter::kEMom
Definition: TopKinFitter.h:20
TopKinFitter.h
CovarianceMatrix::~CovarianceMatrix
~CovarianceMatrix()
Definition: CovarianceMatrix.h:46
CovarianceMatrix::kElectron
Definition: CovarianceMatrix.h:29
CovarianceMatrix::funcPhiMet_
std::vector< std::string > funcPhiMet_
Definition: CovarianceMatrix.h:71
CovarianceMatrix::funcEtaLep_
std::vector< std::string > funcEtaLep_
Definition: CovarianceMatrix.h:70
PVValHelper::eta
Definition: PVValidationHelpers.h:69
pat::PATObject
Templated PAT object container.
Definition: PATObject.h:45
Jet.h
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
CovarianceMatrix::getResolution
double getResolution(const TLorentzVector &object, const ObjectType objType, const std::string &whichResolution="")
get resolution for a given component of an object
Definition: CovarianceMatrix.cc:106
CovarianceMatrix::kBJet
Definition: CovarianceMatrix.h:29
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Muon.h
CovarianceMatrix::funcEtaMet_
std::vector< std::string > funcEtaMet_
Definition: CovarianceMatrix.h:70
CovarianceMatrix::kMet
Definition: CovarianceMatrix.h:29
CovarianceMatrix::binsB_
std::vector< std::string > binsB_
Definition: CovarianceMatrix.h:67
electrons_cff.objType
objType
Definition: electrons_cff.py:514
CovarianceMatrix::jetEnergyResolutionEtaBinning_
const std::vector< double > jetEnergyResolutionEtaBinning_
Definition: CovarianceMatrix.h:74
CovarianceMatrix::kMuon
Definition: CovarianceMatrix.h:29
p4
double p4[4]
Definition: TauolaWrapper.h:92
CovarianceMatrix::getEtaDependentScaleFactor
double getEtaDependentScaleFactor(const pat::PATObject< T > &object)
get eta dependent smear factor for a PAT object
Definition: CovarianceMatrix.h:161
CovarianceMatrix::funcEtUdsc_
std::vector< std::string > funcEtUdsc_
vectors for the resolution functions
Definition: CovarianceMatrix.h:69
MET.h
Jet.h
TtFullHadKinFitProducer_cfi.jetEnergyResolutionEtaBinning
jetEnergyResolutionEtaBinning
Definition: TtFullHadKinFitProducer_cfi.py:95
TopKinFitter::kEtThetaPhi
Definition: TopKinFitter.h:20
TtFullHadKinFitProducer_cfi.jetEnergyResolutionScaleFactors
jetEnergyResolutionScaleFactors
Definition: TtFullHadKinFitProducer_cfi.py:94
MET.h
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
CovarianceMatrix::funcEtB_
std::vector< std::string > funcEtB_
Definition: CovarianceMatrix.h:69
CovarianceMatrix::getObjectType
ObjectType getObjectType(const pat::PATObject< T > &object, const bool isBJet=false)
determine type for a given PAT object
Definition: CovarianceMatrix.h:136
CovarianceMatrix::funcPhiB_
std::vector< std::string > funcPhiB_
Definition: CovarianceMatrix.h:71
Exception
Definition: hltDiff.cc:246
TtFullHadKinFitProducer_cfi.bResolutions
bResolutions
Definition: TtFullHadKinFitProducer_cfi.py:84
CovarianceMatrix::kUdscJet
Definition: CovarianceMatrix.h:29
Electron.h
CovarianceMatrix::binsMet_
std::vector< std::string > binsMet_
Definition: CovarianceMatrix.h:67
Electron.h
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
CovarianceMatrix::setupMatrix
TMatrixD setupMatrix(const pat::PATObject< T > &object, const TopKinFitter::Param param, const std::string &resolutionProvider="")
return covariance matrix for a PAT object
Definition: CovarianceMatrix.h:87
CovarianceMatrix::binsUdsc_
std::vector< std::string > binsUdsc_
vector of strings for the binning of the resolutions
Definition: CovarianceMatrix.h:67
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CovarianceMatrix::ObjectType
ObjectType
Definition: CovarianceMatrix.h:29
ParameterSet.h
TopKinFitter::Param
Param
supported parameterizations
Definition: TopKinFitter.h:20
CovarianceMatrix::funcEtaUdsc_
std::vector< std::string > funcEtaUdsc_
Definition: CovarianceMatrix.h:70
PATObject.h
CovarianceMatrix::funcEtLep_
std::vector< std::string > funcEtLep_
Definition: CovarianceMatrix.h:69
CovarianceMatrix::funcEtaB_
std::vector< std::string > funcEtaB_
Definition: CovarianceMatrix.h:70