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
Param
supported parameterizations
Definition: TopKinFitter.h:22
std::vector< std::string > binsB_
const std::vector< double > jetEnergyResolutionEtaBinning_
std::vector< std::string > funcEtUdsc_
vectors for the resolution functions
std::vector< std::string > binsMet_
TMatrixD setupMatrix(const pat::PATObject< T > &object, const TopKinFitter::Param param, const std::string &resolutionProvider="")
return covariance matrix for a PAT object
std::vector< std::string > funcEtB_
std::vector< std::string > binsUdsc_
vector of strings for the binning of the resolutions
std::vector< std::string > funcPhiB_
const std::vector< double > jetEnergyResolutionScaleFactors_
scale factors for the jet energy resolution
ObjectType getObjectType(const pat::PATObject< T > &object, const bool isBJet=false)
determine type for a given PAT object
std::vector< std::string > funcEtaB_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CovarianceMatrix()
default constructor
std::vector< std::string > funcPhiUdsc_
std::vector< std::string > funcPhiLep_
std::vector< std::string > funcEtaUdsc_
double getResolution(const pat::PATObject< T > &object, const std::string &whichResolution, const bool isBJet=false)
get resolution for a given PAT object
std::vector< std::string > funcEtLep_
std::vector< std::string > funcEtMet_
std::vector< std::string > funcEtaLep_
std::vector< std::string > binsLep_
Templated PAT object container.
Definition: PATObject.h:43
Log< level::Warning, false > LogWarning
std::vector< std::string > funcEtaMet_
std::vector< std::string > funcPhiMet_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
double getResolution(const TLorentzVector &object, const ObjectType objType, const std::string &whichResolution="")
get resolution for a given component of an object
double getEtaDependentScaleFactor(const pat::PATObject< T > &object)
get eta dependent smear factor for a PAT object