CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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       constexpr 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       constexpr 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       constexpr 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       constexpr 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       constexpr double p2_expoM[5] = {
00099         2.64692,
00100         3.26585,
00101         3.53229,
00102         4.18035,
00103         5.64027
00104       };
00105 
00106 
00107       constexpr 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       constexpr 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       constexpr 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       constexpr 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       constexpr 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       if(ibin<25 && ibin>=0) { return Pweight_[ibin]; }
00198       else { return 0;}
00199 
00200     };
00201 
00202     double ShiftWeight( float pvnum ) {
00203       return ShiftWeight(int(pvnum));
00204     };
00205 
00206   private:
00207 
00208     double Pweight_[25];
00209 
00210   };
00211 
00212 
00213 
00214 } // end of reweight namespace
00215 
00216 
00217 namespace edm {
00218   class EventBase;
00219   class LumiReWeighting {
00220   public:
00221     LumiReWeighting( std::string generatedFile,
00222                      std::string dataFile,
00223                      std::string GenHistName,
00224                      std::string DataHistName);
00225     
00226     LumiReWeighting( std::vector< float > MC_distr, std::vector< float > Lumi_distr);
00227 
00228     LumiReWeighting ( ) { } ;
00229 
00230     double weight( int npv ) ;
00231 
00232     double weight( float npv ) ;
00233 
00234     double weight( const edm::EventBase &e ) ;
00235 
00236     double weightOOT( const edm::EventBase &e ) ;
00237 
00238   protected:
00239 
00240     std::string generatedFileName_;
00241     std::string dataFileName_;
00242     std::string GenHistName_;
00243     std::string DataHistName_;
00244     boost::shared_ptr<TFile>     generatedFile_;
00245     boost::shared_ptr<TFile>     dataFile_;
00246     boost::shared_ptr<TH1>      weights_;
00247 
00248     //keep copies of normalized distributions:
00249 
00250     boost::shared_ptr<TH1>      MC_distr_;
00251     boost::shared_ptr<TH1>      Data_distr_;
00252 
00253     int  OldLumiSection_;
00254     bool FirstWarning_;
00255 
00256 
00257   };
00258 }
00259 
00260 
00261 
00262 #endif