1 #ifndef PhysicsTools_Utilities_interface_LumiReWeighting_cc
2 #define PhysicsTools_Utilities_interface_LumiReWeighting_cc
23 #include "TStopwatch.h"
29 #include <boost/shared_ptr.hpp>
43 generatedFileName_( generatedFile),
44 dataFileName_ ( dataFile ),
45 GenHistName_ ( GenHistName ),
46 DataHistName_ ( DataHistName )
59 MC_distr_->Scale( 1.0/ MC_distr_->Integral() );
65 TH1* den =
dynamic_cast<TH1*
>(MC_distr_->Clone());
71 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
75 for(
int ibin = 1; ibin<NBins+1; ++ibin){
91 if( MC_distr.size() != Lumi_distr.size() ){
93 std::cerr <<
"ERROR: LumiReWeighting: input vectors have different sizes. Quitting... \n";
98 Int_t
NBins = MC_distr.size();
100 MC_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"MC_distr",
"MC dist",NBins,-0.5,
float(NBins)-0.5) );
101 Data_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"Data_distr",
"Data dist",NBins,-0.5,
float(NBins)-0.5) );
103 weights_ = boost::shared_ptr<TH1> (
new TH1F(
"luminumer",
"luminumer",NBins,-0.5,
float(NBins)-0.5) );
104 TH1* den =
new TH1F(
"lumidenom",
"lumidenom",NBins,-0.5,
float(NBins)-0.5) ;
106 for(
int ibin = 1; ibin<NBins+1; ++ibin ) {
107 weights_->SetBinContent(ibin, Lumi_distr[ibin-1]);
108 Data_distr_->SetBinContent(ibin, Lumi_distr[ibin-1]);
109 den->SetBinContent(ibin,MC_distr[ibin-1]);
110 MC_distr_->SetBinContent(ibin,MC_distr[ibin-1]);
115 float deltaH = weights_->Integral();
116 if(fabs(1.0 - deltaH) > 0.02 ) {
117 weights_->Scale( 1.0/ weights_->Integral() );
118 Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
120 float deltaMC = den->Integral();
121 if(fabs(1.0 - deltaMC) > 0.02 ) {
122 den->Scale(1.0/ den->Integral());
126 weights_->Divide( den );
128 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
130 for(
int ibin = 1; ibin<NBins+1; ++ibin){
131 std::cout <<
" " << ibin-1 <<
" " << weights_->GetBinContent(ibin) << std::endl;
140 return weights_->GetBinContent( bin );
145 return weights_->GetBinContent( bin );
163 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
178 std::vector<PileupSummaryInfo>::const_iterator PVI;
181 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
183 int BX = PVI->getBunchCrossing();
186 npv = PVI->getPU_NumInteractions();
192 if(npv < 0)
std::cerr <<
" no in-time beam crossing found\n! " ;
215 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
229 std::vector<PileupSummaryInfo>::const_iterator PVI;
234 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
236 int BX = PVI->getBunchCrossing();
239 npv = PVI->getPU_NumInteractions();
243 npv50ns = PVI->getPU_NumInteractions();
253 std::cerr <<
" no in-time beam crossing found\n! " ;
254 std::cerr <<
" Returning event weight=0\n! ";
258 std::cerr <<
" no out-of-time beam crossing found\n! " ;
259 std::cerr <<
" Returning event weight=0\n! ";
265 double inTimeWeight =
weights_->GetBinContent( bin );
267 double TotalWeight = 1.0;
269 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_