1 #ifndef PhysicsTools_Utilities_interface_LumiReWeighting_cc 2 #define PhysicsTools_Utilities_interface_LumiReWeighting_cc 23 #include "TStopwatch.h" 29 #include <boost/shared_ptr.hpp> 44 generatedFileName_( generatedFile),
45 dataFileName_ ( dataFile ),
46 GenHistName_ ( GenHistName ),
47 DataHistName_ ( DataHistName ),
48 pileupSumInfoTag_ ( PileupSumInfoInputTag )
61 MC_distr_->Scale( 1.0/ MC_distr_->Integral() );
67 TH1* den =
dynamic_cast<TH1*
>(MC_distr_->Clone());
73 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
77 for(
int ibin = 1; ibin<NBins+1; ++ibin){
95 if( MC_distr.size() != Lumi_distr.size() ){
97 std::cerr <<
"ERROR: LumiReWeighting: input vectors have different sizes. Quitting... \n";
102 Int_t NBins = MC_distr.size();
104 MC_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"MC_distr",
"MC dist",NBins,-0.5,
float(NBins)-0.5) );
105 Data_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"Data_distr",
"Data dist",NBins,-0.5,
float(NBins)-0.5) );
107 weights_ = boost::shared_ptr<TH1> (
new TH1F(
"luminumer",
"luminumer",NBins,-0.5,
float(NBins)-0.5) );
108 TH1* den =
new TH1F(
"lumidenom",
"lumidenom",NBins,-0.5,
float(NBins)-0.5) ;
110 for(
int ibin = 1; ibin<NBins+1; ++ibin ) {
111 weights_->SetBinContent(ibin, Lumi_distr[ibin-1]);
112 Data_distr_->SetBinContent(ibin, Lumi_distr[ibin-1]);
113 den->SetBinContent(ibin,MC_distr[ibin-1]);
114 MC_distr_->SetBinContent(ibin,MC_distr[ibin-1]);
119 float deltaH = weights_->Integral();
120 if(fabs(1.0 - deltaH) > 0.02 ) {
121 weights_->Scale( 1.0/ weights_->Integral() );
122 Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
124 float deltaMC = den->Integral();
125 if(fabs(1.0 - deltaMC) > 0.02 ) {
126 den->Scale(1.0/ den->Integral());
130 weights_->Divide( den );
132 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
134 for(
int ibin = 1; ibin<NBins+1; ++ibin){
135 std::cout <<
" " << ibin-1 <<
" " << weights_->GetBinContent(ibin) << std::endl;
144 return weights_->GetBinContent( bin );
149 return weights_->GetBinContent( bin );
168 std::vector<PileupSummaryInfo>::const_iterator PVI;
171 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
173 int BX = PVI->getBunchCrossing();
176 npv = PVI->getPU_NumInteractions();
182 if(npv < 0)
std::cerr <<
" no in-time beam crossing found\n! " ;
208 std::vector<PileupSummaryInfo>::const_iterator PVI;
213 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
215 int BX = PVI->getBunchCrossing();
218 npv = PVI->getPU_NumInteractions();
222 npv50ns = PVI->getPU_NumInteractions();
232 std::cerr <<
" no in-time beam crossing found\n! " ;
233 std::cerr <<
" Returning event weight=0\n! ";
237 std::cerr <<
" no out-of-time beam crossing found\n! " ;
238 std::cerr <<
" Returning event weight=0\n! ";
244 double inTimeWeight =
weights_->GetBinContent( bin );
246 double TotalWeight = 1.0;
248 TotalWeight = inTimeWeight;
virtual ProcessHistory const & processHistory() const =0
std::string DataHistName_
edm::LuminosityBlockNumber_t luminosityBlock() const
boost::shared_ptr< TH1 > MC_distr_
double weightOOT(const edm::EventBase &e)
boost::shared_ptr< TFile > dataFile_
edm::InputTag pileupSumInfoTag_
bin
set the eta bin as selection string.
boost::shared_ptr< TFile > generatedFile_
boost::shared_ptr< TH1 > Data_distr_
std::string dataFileName_
bool getByLabel(InputTag const &, Handle< T > &) const
boost::shared_ptr< TH1 > weights_
std::string generatedFileName_