CMS 3D CMS Logo

EnergyScaleCorrection_class.h
Go to the documentation of this file.
1 #ifndef EgammaAnalysis_ElectronTools_EnergyScaleCorrection_class_h
2 #define EgammaAnalysis_ElectronTools_EnergyScaleCorrection_class_h
3 
20 #include <TString.h>
21 #include <iostream>
22 #include <fstream>
23 #include <map>
24 #include <cmath>
25 #include <TChain.h>
26 #include <TRandom3.h>
27 #include <string>
28 
29 //============================== First auxiliary class
31 {
32 public:
33  // values
35  float rho, rho_err;
36  float phi, phi_err;
37  float Emean, Emean_err;
38 
40  {
41  scale = 1;
42  scale_err = 0;
43  scale_err_syst=0;
44  rho = 0;
45  rho_err = 0;
46  phi = 0;
47  phi_err = 0;
48  Emean = 0;
49  Emean_err = 0;
50  };
51 
52  friend std::ostream& operator << (std::ostream& os, const correctionValue_class a)
53  {
54  os << "( "
55  << a.scale << " +/- " << a.scale_err << " +/- " << a.scale_err_syst << ")"
56  << "\t"
57  << a.rho << " +/- " << a.rho_err
58  << "\t"
59  << a.phi << " +/- " << a.phi_err
60  << "\t"
61  << a.Emean << " +/- " << a.Emean_err;
62  return os;
63  };
64 };
65 
66 //============================== Second auxiliary class
68 {
69  // for class definition and ordering
70 public:
71  unsigned int runmin;
72  unsigned int runmax;
73 
74 private:
75  // definition of the variables used for binning and the min-max ranges
76  float r9min;
77  float r9max;
78  float etmin;
79  float etmax;
80  float etamin;
81  float etamax;
82 
83 
84 public:
94  correctionCategory_class(TString category_);
95 
97  inline correctionCategory_class(const unsigned int runNumber, const float etaEle, const float R9Ele, const float EtEle)
98  {
99  runmin = runNumber;
100  runmax = runNumber;
101  etamin = fabs(etaEle);
102  etamax = fabs(etaEle);
103  r9min = R9Ele;
104  r9max = R9Ele;
105  etmin = EtEle;
106  etmax = EtEle;
107  }
108 
110  bool operator<(const correctionCategory_class& b) const;
111 
113  friend std::ostream& operator << (std::ostream& os, const correctionCategory_class a)
114  {
115  os << a.runmin << " " << a.runmax
116  << "\t" << a.etamin << " " << a.etamax
117  << "\t" << a.r9min << " " << a.r9max
118  << "\t" << a.etmin << " " << a.etmax;
119  return os;
120  };
121 };
122 
123 
124 //==============================
126 typedef std::map < correctionCategory_class, correctionValue_class > correction_map_t;
127 
128 
129 
130 //============================== Main class
132 {
133 
134 public:
139  ECALELF
140  };
141 
143  kNone = 0,
146  kNParamSmear
147  };
148 
149  bool doScale, doSmearings;
150 
151 public:
152  EnergyScaleCorrection_class(std::string correctionFileName, unsigned int genSeed=0);
155 
156 
157 //------------------------------ scales
158  float ScaleCorrection(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle,
159  double EtEle ) const;
160 
161  float ScaleCorrectionUncertainty(unsigned int runNumber, bool isEBEle,
162  double R9Ele, double etaSCEle, double EtEle) const;
163 
164 private:
165  correctionValue_class getScaleCorrection(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const;
166  float getScaleOffset(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const; // returns the correction value
167  float getScaleStatUncertainty(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const; // returns the stat uncertainty
168  float getScaleSystUncertainty(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const; // technical implementation
169 
170 
171  void ReadFromFile(TString filename);
172 
173  // this method adds the correction values read from the txt file to the map
174  void AddScale(TString category_, int runMin_, int runMax_, double deltaP_, double err_deltaP_, double err_syst_deltaP);
175 
176  //============================== smearings
177 public:
178  float getSmearingSigma(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle, paramSmear_t par, float nSigma = 0.) const;
179  float getSmearingSigma(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle, float nSigma_rho, float nSigma_phi) const;
180 
181 
182 private:
184 
187 
188  void AddSmearing(TString category_, int runMin_, int runMax_, //double smearing_, double err_smearing_);
189  double rho, double err_rho, double phi, double err_phi, double Emean, double err_Emean);
190  void ReadSmearingFromFile(TString filename);
191 public:
193  {
194  if(value >= 0 && value <= 1) {
195  smearingType_ = value;
196  } else {
197  smearingType_ = UNKNOWN;
198  }
199  };
200 
201  float getSmearingRho(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle) const;
202 
203 
204 
205 };
206 
207 
208 #endif
float etmin
min Et value for the bin
friend std::ostream & operator<<(std::ostream &os, const correctionValue_class a)
float r9max
max R9 value for the bin
0: Unidentified isolated particle
Definition: ParticleCode.h:19
float etmax
max Et value for the bin
Definition: value.py:1
void SetSmearingType(fileFormat_t value)
correctionCategory_class(const unsigned int runNumber, const float etaEle, const float R9Ele, const float EtEle)
this constructor is used to assign a category to the electron/photon given values in input ...
float etamin
min eta value for the bin
double b
Definition: hdecay.h:120
std::map< correctionCategory_class, correctionValue_class > correction_map_t
map associating the category and the correction
float r9min
min R9 vaule for the bin
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:73
double a
Definition: hdecay.h:121
Read and get energy scale and smearings from .dat files.
float etamax
max eta value for the bin