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 
29  public:
30 
32 
36  CovarianceMatrix(const std::vector<edm::ParameterSet>& udscResolutions, const std::vector<edm::ParameterSet>& bResolutions,
37  const std::vector<double>& jetEnergyResolutionScaleFactors, const std::vector<double>& jetEnergyResolutionEtaBinning);
39  CovarianceMatrix(const std::vector<edm::ParameterSet>& udscResolutions, const std::vector<edm::ParameterSet>& bResolutions,
40  const std::vector<edm::ParameterSet>& lepResolutions, const std::vector<edm::ParameterSet>& metResolutions,
41  const std::vector<double>& jetEnergyResolutionScaleFactors, const std::vector<double>& jetEnergyResolutionEtaBinning);
42  // destructor
44 
46  template <class T>
47  TMatrixD setupMatrix(const pat::PATObject<T>& object, const TopKinFitter::Param param, const std::string& resolutionProvider = "");
49  TMatrixD setupMatrix(const TLorentzVector& object, const ObjectType objType, const TopKinFitter::Param param);
51  double getResolution(const TLorentzVector& object, const ObjectType objType, const std::string& whichResolution = "");
53  template <class T>
54  double getResolution(const pat::PATObject<T>& object, const std::string& whichResolution, const bool isBJet=false) {
55  return getResolution(TLorentzVector(object.px(), object.py(), object.pz(), object.energy()), getObjectType(object, isBJet), whichResolution); }
56 
57  private:
58 
60  std::vector<std::string> binsUdsc_, binsB_, binsLep_, binsMet_;
62  std::vector<std::string> funcEtUdsc_ , funcEtB_ , funcEtLep_ , funcEtMet_;
63  std::vector<std::string> funcEtaUdsc_, funcEtaB_, funcEtaLep_, funcEtaMet_;
64  std::vector<std::string> funcPhiUdsc_, funcPhiB_, funcPhiLep_, funcPhiMet_;
66  const std::vector<double> jetEnergyResolutionScaleFactors_;
67  const std::vector<double> jetEnergyResolutionEtaBinning_;
68 
70  template <class T>
71  ObjectType getObjectType(const pat::PATObject<T>& object, const bool isBJet=false);
73  template <class T>
74  double getEtaDependentScaleFactor(const pat::PATObject<T>& object);
76  double getEtaDependentScaleFactor(const TLorentzVector& object);
77 
78 };
79 
80 template <class T>
81 TMatrixD CovarianceMatrix::setupMatrix(const pat::PATObject<T>& object, const TopKinFitter::Param param, const std::string& resolutionProvider)
82 {
83  // This part is for pat objects with resolutions embedded
84  if(object.hasKinResolution()) {
85  TMatrixD CovM3 (3,3); CovM3.Zero();
86  TMatrixD CovM4 (4,4); CovM4.Zero();
87  TMatrixD* CovM = &CovM3;
88  switch(param){
90  CovM3(0,0) = pow(object.resolEt(resolutionProvider) , 2);
91  if( dynamic_cast<const reco::Jet*>(&object) )
92  CovM3(0,0)*=getEtaDependentScaleFactor(object);
93  if( dynamic_cast<const reco::MET*>(&object) )
94  CovM3(1,1) = pow(9999., 2);
95  else
96  CovM3(1,1) = pow(object.resolEta(resolutionProvider), 2);
97  CovM3(2,2) = pow(object.resolPhi(resolutionProvider), 2);
98  CovM = &CovM3;
99  break;
101  CovM3(0,0) = pow(object.resolEt(resolutionProvider) , 2);
102  if( dynamic_cast<const reco::Jet*>(&object) )
103  CovM3(0,0)*=getEtaDependentScaleFactor(object);
104  CovM3(1,1) = pow(object.resolTheta(resolutionProvider), 2);
105  CovM3(2,2) = pow(object.resolPhi(resolutionProvider) , 2);
106  CovM = &CovM3;
107  break;
108  case TopKinFitter::kEMom :
109  CovM4(0,0) = pow(1, 2);
110  CovM4(1,1) = pow(1, 2);
111  CovM4(2,2) = pow(1, 2);
112  CovM4(3,3) = pow(1, 2);
113  CovM = &CovM4;
114  break;
115  }
116  return *CovM;
117  }
118  // This part is for objects without resolutions embedded
119  else {
120  const ObjectType objType = getObjectType(object, (resolutionProvider=="bjets"));
121  const TLorentzVector p4(object.px(), object.py(), object.pz(), object.energy());
122  return setupMatrix(p4, objType, param);
123  }
124 }
125 
126 template <class T>
128 {
129  ObjectType objType;
130  // jets
131  if( dynamic_cast<const reco::Jet*>(&object) ) {
132  if(isBJet)
133  objType = kBJet;
134  else
135  objType = kUdscJet;
136  }
137  // muons
138  else if( dynamic_cast<const reco::Muon*>(&object) )
139  objType = kMuon;
140  // electrons
141  else if( dynamic_cast<const reco::GsfElectron*>(&object) )
142  objType = kElectron;
143  // MET
144  else if( dynamic_cast<const reco::MET*>(&object) )
145  objType = kMet;
146  // catch anything else
147  else
148  throw cms::Exception("UnsupportedObject") << "The object given is not supported!\n";
149  return objType;
150 }
151 
152 template <class T>
154 {
155  double etaDependentScaleFactor = 1.;
156  for(unsigned int i=0; i<jetEnergyResolutionEtaBinning_.size(); i++){
158  if(i==jetEnergyResolutionEtaBinning_.size()-1) {
159  edm::LogWarning("CovarianceMatrix") << "object eta ("<<std::abs(object.eta())<<") beyond last eta bin ("<<jetEnergyResolutionEtaBinning_[i]<<") using scale factor 1.0!";
160  etaDependentScaleFactor=1.;
161  break;
162  }
163  etaDependentScaleFactor=jetEnergyResolutionScaleFactors_[i];
164  }
165  else
166  break;
167  }
168  return etaDependentScaleFactor;
169 }
170 
171 #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_
double p4[4]
Definition: TauolaWrapper.h:92
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:49
std::vector< std::string > funcEtaMet_
std::vector< std::string > funcPhiMet_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
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