CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/PhysicsTools/Utilities/interface/LumiReWeighting.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_Utilities_interface_LumiReWeighting_h
00002 #define PhysicsTools_Utilities_interface_LumiReWeighting_h
00003 
00004 
00018 #include "TH1.h"
00019 #include "TFile.h"
00020 #include <cmath>
00021 #include <string>
00022 #include <boost/shared_ptr.hpp>
00023 #include <vector>
00024 
00025 namespace reweight{
00026 
00027   // add a class to shift the mean of a poisson-like luminosity distribution by an arbitrary amount. 
00028   // Only valid for small (<1.5) shifts about the 2011 lumi distribution for now, because shifts are non-linear
00029   // Each PoissonMeanShifter does one shift, so defining multiples can give you an arbitrary collection
00030 
00031   class PoissonMeanShifter {
00032 
00033   public:
00034 
00035     PoissonMeanShifter() { };
00036 
00037     PoissonMeanShifter( float Shift ){
00038 
00039       // these are the polynomial or exponential coefficients for each bin of a 25-bin sequence that
00040       // convert the Distribution of the 2011 luminosity to something with a lower or higher peak luminosity.
00041       // The distributions aren't quite poisson because they model luminosity decreasing during a fill. This implies that
00042       // they do get wider as the mean increases, so the weights are not linear with increasing mean.
00043 
00044       static double p0_minus[20] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
00045       static double p1_minus[20] = {
00046         -0.677786,
00047         -0.619614,
00048         -0.49465,
00049         -0.357963,
00050         -0.238359,
00051         -0.110002,
00052         0.0348629,
00053         0.191263,
00054         0.347648,
00055         0.516615,
00056         0.679646,
00057         0.836673,
00058         0.97764,
00059         1.135,
00060         1.29922,
00061         1.42467,
00062         1.55901,
00063         1.61762,
00064         1.67275,
00065         1.96008
00066       };
00067       static double p2_minus[20] = {
00068         0.526164,
00069         0.251816,
00070         0.11049,
00071         0.026917,
00072         -0.0464692,
00073         -0.087022,
00074         -0.0931581,
00075         -0.0714295,
00076         -0.0331772,
00077         0.0347473,
00078         0.108658,
00079         0.193048,
00080         0.272314,
00081         0.376357,
00082         0.4964,
00083         0.58854,
00084         0.684959,
00085         0.731063,
00086         0.760044,
00087         1.02386
00088       };
00089 
00090       static double p1_expoM[5] = {
00091         1.63363e-03,
00092         6.79290e-04,
00093         3.69900e-04,
00094         2.24349e-04,
00095         9.87156e-06
00096       };
00097 
00098       static double p2_expoM[5] = {
00099         2.64692,
00100         3.26585,
00101         3.53229,
00102         4.18035,
00103         5.64027
00104       };
00105 
00106 
00107       static double p0_plus[20] = { 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1. };
00108       static double p1_plus[20] = {
00109         -0.739059,
00110         -0.594445,
00111         -0.477276,
00112         -0.359707,
00113         -0.233573,
00114         -0.103458,
00115         0.0373401,
00116         0.176571,
00117         0.337617,
00118         0.499074,
00119         0.675126,
00120         0.840522,
00121         1.00917,
00122         1.15847,
00123         1.23816,
00124         1.44271,
00125         1.52982,
00126         1.46385,
00127         1.5802,
00128         0.988689
00129       };
00130       static double p2_plus[20] = {
00131         0.208068,
00132         0.130033,
00133         0.0850356,
00134         0.0448344,
00135         0.000749832,
00136         -0.0331347,
00137         -0.0653281,
00138         -0.0746009,
00139         -0.0800667,
00140         -0.0527636,
00141         -0.00402649,
00142         0.103338,
00143         0.261261,
00144         0.491084,
00145         0.857966,
00146         1.19495,
00147         1.75071,
00148         2.65559,
00149         3.35433,
00150         5.48835
00151       };
00152 
00153       static double p1_expoP[5] = {
00154         1.42463e-01,
00155         4.18966e-02,
00156         1.12697e-01,
00157         1.66197e-01,
00158         1.50768e-01
00159       };
00160 
00161       static double p2_expoP[5] = {
00162         1.98758,
00163         2.27217,
00164         2.26799,
00165         2.38455,
00166         2.52428
00167       };
00168 
00169       // initialize weights based on desired Shift
00170 
00171 
00172 
00173       for (int ibin=0;ibin<20;ibin++) {
00174 
00175         if( Shift < .0) {
00176           Pweight_[ibin] = p0_minus[ibin] + p1_minus[ibin]*Shift + p2_minus[ibin]*Shift*Shift;
00177         }
00178         else {
00179           Pweight_[ibin] = p0_plus[ibin] + p1_plus[ibin]*Shift + p2_plus[ibin]*Shift*Shift;
00180         }
00181       }
00182 
00183       // last few bins fit better to an exponential...
00184 
00185       for (int ibin=20;ibin<25;ibin++) {
00186         if( Shift < 0.) {
00187           Pweight_[ibin] = p1_expoM[ibin-20]*exp(p2_expoM[ibin-20]*Shift);
00188         }
00189         else {
00190           Pweight_[ibin] = p1_expoP[ibin-20]*exp(p2_expoP[ibin-20]*Shift);
00191         }
00192       } 
00193 
00194     };
00195 
00196     double ShiftWeight( int ibin ) {
00197 
00198       if(ibin<25 && ibin>=0) { return Pweight_[ibin]; }
00199       else { return 0;}
00200 
00201     };
00202 
00203     double ShiftWeight( float pvnum ) {
00204 
00205       int ibin = int(pvnum);
00206 
00207       if(ibin<25 && ibin>=0) { return Pweight_[ibin]; }
00208       else { return 0;}
00209 
00210     };
00211 
00212   private:
00213 
00214     double Pweight_[25];
00215 
00216   };
00217 
00218 
00219 
00220 } // end of reweight namespace
00221 
00222 
00223 namespace edm {
00224   class EventBase;
00225   class LumiReWeighting {
00226   public:
00227     LumiReWeighting( std::string generatedFile,
00228                      std::string dataFile,
00229                      std::string GenHistName,
00230                      std::string DataHistName);
00231     
00232     LumiReWeighting( std::vector< float > MC_distr, std::vector< float > Lumi_distr);
00233 
00234     LumiReWeighting ( ) { } ;
00235 
00236     double weight( int npv ) ;
00237 
00238     double weight( float npv ) ;
00239 
00240     double weight( const edm::EventBase &e ) ;
00241 
00242     double weightOOT( const edm::EventBase &e ) ;
00243 
00244     void weightOOT_init(); 
00245 
00246   protected:
00247 
00248     std::string generatedFileName_;
00249     std::string dataFileName_;
00250     std::string GenHistName_;
00251     std::string DataHistName_;
00252     boost::shared_ptr<TFile>     generatedFile_;
00253     boost::shared_ptr<TFile>     dataFile_;
00254     boost::shared_ptr<TH1>      weights_;
00255 
00256     //keep copies of normalized distributions:
00257 
00258     boost::shared_ptr<TH1>      MC_distr_;
00259     boost::shared_ptr<TH1>      Data_distr_;
00260 
00261     double WeightOOTPU_[25][25];
00262 
00263     int  OldLumiSection_;
00264     bool Reweight_4_2_2p2_;
00265     bool FirstWarning_;
00266 
00267 
00268   };
00269 }
00270 
00271 
00272 
00273 #endif