CMS 3D CMS Logo

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