1 #ifndef PhysicsTools_Utilities_interface_LumiReWeighting_cc
2 #define PhysicsTools_Utilities_interface_LumiReWeighting_cc
23 #include "TStopwatch.h"
28 #include <boost/shared_ptr.hpp>
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){
90 if( MC_distr.size() != Lumi_distr.size() ){
92 std::cerr <<
"ERROR: LumiReWeighting: input vectors have different sizes. Quitting... \n";
97 Int_t
NBins = MC_distr.size();
99 MC_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"MC_distr",
"MC dist",NBins,-0.5,
float(NBins)-0.5) );
100 Data_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"Data_distr",
"Data dist",NBins,-0.5,
float(NBins)-0.5) );
102 weights_ = boost::shared_ptr<TH1> (
new TH1F(
"luminumer",
"luminumer",NBins,-0.5,
float(NBins)-0.5) );
103 TH1* den =
new TH1F(
"lumidenom",
"lumidenom",NBins,-0.5,
float(NBins)-0.5) ;
105 for(
int ibin = 1; ibin<NBins+1; ++ibin ) {
106 weights_->SetBinContent(ibin, Lumi_distr[ibin-1]);
107 Data_distr_->SetBinContent(ibin, Lumi_distr[ibin-1]);
108 den->SetBinContent(ibin,MC_distr[ibin-1]);
109 MC_distr_->SetBinContent(ibin,MC_distr[ibin-1]);
114 float deltaH = weights_->Integral();
115 if(fabs(1.0 - deltaH) > 0.02 ) {
116 weights_->Scale( 1.0/ weights_->Integral() );
117 Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
119 float deltaMC = den->Integral();
120 if(fabs(1.0 - deltaMC) > 0.02 ) {
121 den->Scale(1.0/ den->Integral());
125 weights_->Divide( den );
127 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
129 for(
int ibin = 1; ibin<NBins+1; ++ibin){
130 std::cout <<
" " << ibin-1 <<
" " << weights_->GetBinContent(ibin) << std::endl;
139 return weights_->GetBinContent( bin );
144 return weights_->GetBinContent( bin );
162 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
177 std::vector<PileupSummaryInfo>::const_iterator PVI;
180 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
182 int BX = PVI->getBunchCrossing();
185 npv = PVI->getPU_NumInteractions();
191 if(npv < 0)
std::cerr <<
" no in-time beam crossing found\n! " ;
214 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
228 std::vector<PileupSummaryInfo>::const_iterator PVI;
233 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
235 int BX = PVI->getBunchCrossing();
238 npv = PVI->getPU_NumInteractions();
242 npv50ns = PVI->getPU_NumInteractions();
252 std::cerr <<
" no in-time beam crossing found\n! " ;
253 std::cerr <<
" Returning event weight=0\n! ";
257 std::cerr <<
" no out-of-time beam crossing found\n! " ;
258 std::cerr <<
" Returning event weight=0\n! ";
264 double inTimeWeight =
weights_->GetBinContent( bin );
266 double TotalWeight = 1.0;
268 TotalWeight = inTimeWeight;
collection_type::const_iterator const_iterator
const_iterator begin() const
std::string DataHistName_
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_