1 #ifndef PhysicsTools_Utilities_interface_LumiReWeighting_cc
2 #define PhysicsTools_Utilities_interface_LumiReWeighting_cc
23 #include "TStopwatch.h"
28 #include <boost/shared_ptr.hpp>
40 std::string GenHistName =
"pileup",
41 std::string DataHistName =
"pileup" ) :
42 generatedFileName_( generatedFile),
43 dataFileName_ ( dataFile ),
44 GenHistName_ ( GenHistName ),
45 DataHistName_ ( DataHistName )
58 MC_distr_->Scale( 1.0/ MC_distr_->Integral() );
64 TH1* den =
dynamic_cast<TH1*
>(MC_distr_->Clone());
70 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
74 for(
int ibin = 1; ibin<NBins+1; ++ibin){
92 if( MC_distr.size() != Lumi_distr.size() ){
94 std::cerr <<
"ERROR: LumiReWeighting: input vectors have different sizes. Quitting... \n";
99 Int_t
NBins = MC_distr.size();
101 MC_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"MC_distr",
"MC dist",NBins,-0.5,
float(NBins)-0.5) );
102 Data_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"Data_distr",
"Data dist",NBins,-0.5,
float(NBins)-0.5) );
104 weights_ = boost::shared_ptr<TH1> (
new TH1F(
"luminumer",
"luminumer",NBins,-0.5,
float(NBins)-0.5) );
105 TH1* den =
new TH1F(
"lumidenom",
"lumidenom",NBins,-0.5,
float(NBins)-0.5) ;
107 for(
int ibin = 1; ibin<NBins+1; ++ibin ) {
108 weights_->SetBinContent(ibin, Lumi_distr[ibin-1]);
109 Data_distr_->SetBinContent(ibin, Lumi_distr[ibin-1]);
110 den->SetBinContent(ibin,MC_distr[ibin-1]);
111 MC_distr_->SetBinContent(ibin,MC_distr[ibin-1]);
116 float deltaH = weights_->Integral();
117 if(fabs(1.0 - deltaH) > 0.02 ) {
118 weights_->Scale( 1.0/ weights_->Integral() );
119 Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
121 float deltaMC = den->Integral();
122 if(fabs(1.0 - deltaMC) > 0.02 ) {
123 den->Scale(1.0/ den->Integral());
127 weights_->Divide( den );
129 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
131 for(
int ibin = 1; ibin<NBins+1; ++ibin){
132 std::cout <<
" " << ibin-1 <<
" " << weights_->GetBinContent(ibin) << std::endl;
143 return weights_->GetBinContent( bin );
148 return weights_->GetBinContent( bin );
167 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
172 if((Process==
"HLT") && (Release==TargetRelease)) {
173 std::cout <<
" **** Warning! You are using in-time-only pileup reweighting for Release " << Release <<
" **** " << std::endl;
174 std::cout <<
" **** There is a weightOOT() function available if needed **** " << std::endl;
186 std::vector<PileupSummaryInfo>::const_iterator PVI;
189 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
191 int BX = PVI->getBunchCrossing();
194 npv = PVI->getPU_NumInteractions();
200 if(npv < 0)
std::cerr <<
" no in-time beam crossing found\n! " ;
215 static double weight_24[25] = {
243 static double weight_23[25] = {
271 static double weight_22[25] = {
299 static double weight_21[25] = {
328 static double weight_20[25] = {
355 static double weight_19[25] = {
383 static double weight_18[25] = {
412 static double weight_17[25] = {
441 static double weight_16[25] = {
470 static double weight_15[25] = {
499 static double weight_14[25] = {
528 static double weight_13[25] = {
556 static double weight_12[25] = {
585 static double weight_11[25] = {
613 static double weight_10[25] = {
642 static double weight_9[25] = {
671 static double weight_8[25] = {
699 static double weight_7[25] = {
727 static double weight_6[25] = {
756 static double weight_5[25] = {
785 static double weight_4[25] = {
814 static double weight_3[25] = {
842 static double weight_2[25] = {
870 static double weight_1[25] = {
898 static double weight_0[25] = {
928 double* WeightPtr = 0;
931 if(
iint ==0) WeightPtr = weight_0;
932 if(
iint ==1) WeightPtr = weight_1;
933 if(
iint ==2) WeightPtr = weight_2;
934 if(
iint ==3) WeightPtr = weight_3;
935 if(
iint ==4) WeightPtr = weight_4;
936 if(
iint ==5) WeightPtr = weight_5;
937 if(
iint ==6) WeightPtr = weight_6;
938 if(
iint ==7) WeightPtr = weight_7;
939 if(
iint ==8) WeightPtr = weight_8;
940 if(
iint ==9) WeightPtr = weight_9;
941 if(
iint ==10) WeightPtr = weight_10;
942 if(
iint ==11) WeightPtr = weight_11;
943 if(
iint ==12) WeightPtr = weight_12;
944 if(
iint ==13) WeightPtr = weight_13;
945 if(
iint ==14) WeightPtr = weight_14;
946 if(
iint ==15) WeightPtr = weight_15;
947 if(
iint ==16) WeightPtr = weight_16;
948 if(
iint ==17) WeightPtr = weight_17;
949 if(
iint ==18) WeightPtr = weight_18;
950 if(
iint ==19) WeightPtr = weight_19;
951 if(
iint ==20) WeightPtr = weight_20;
952 if(
iint ==21) WeightPtr = weight_21;
953 if(
iint ==22) WeightPtr = weight_22;
954 if(
iint ==23) WeightPtr = weight_23;
955 if(
iint ==24) WeightPtr = weight_24;
957 for(
int ibin = 0; ibin<25; ++ibin){
971 static double Correct_Weights2011[25] = {
1014 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
1019 if((Process==
"HLT") && (Release==TargetRelease)) {
1025 std::cout <<
" **** Warning: Out-of-time pileup reweighting appropriate for Release " << Release <<
" **** " << std::endl;
1026 std::cout <<
" **** will be applied **** " << std::endl;
1040 std::vector<PileupSummaryInfo>::const_iterator PVI;
1045 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
1047 int BX = PVI->getBunchCrossing();
1050 npv = PVI->getPU_NumInteractions();
1054 npv50ns = PVI->getPU_NumInteractions();
1064 std::cerr <<
" no in-time beam crossing found\n! " ;
1065 std::cerr <<
" Returning event weight=0\n! ";
1069 std::cerr <<
" no out-of-time beam crossing found\n! " ;
1070 std::cerr <<
" Returning event weight=0\n! ";
1076 double inTimeWeight =
weights_->GetBinContent( bin );
1078 double TotalWeight = 1.0;
1081 TotalWeight = inTimeWeight *
WeightOOTPU_[bin-1][npv50ns] * Correct_Weights2011[bin-1];
1084 TotalWeight = inTimeWeight;
collection_type::const_iterator const_iterator
const_iterator begin() const
std::string DataHistName_
double WeightOOTPU_[25][25]
edm::LuminosityBlockNumber_t luminosityBlock() const
boost::shared_ptr< TH1 > MC_distr_
std::string const & processName() const
double weightOOT(const edm::EventBase &e)
boost::shared_ptr< TFile > dataFile_
boost::shared_ptr< TFile > generatedFile_
virtual ProcessHistory const & processHistory() const =0
ReleaseVersion const & releaseVersion() const
boost::shared_ptr< TH1 > Data_distr_
std::string ReleaseVersion
const_iterator end() const
std::string dataFileName_
bool getByLabel(InputTag const &, Handle< T > &) const
boost::shared_ptr< TH1 > weights_
std::string generatedFileName_