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){
87 pileupSumInfoTag_ ( PileupSumInfoInputTag )
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 );
167 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
182 std::vector<PileupSummaryInfo>::const_iterator PVI;
185 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
187 int BX = PVI->getBunchCrossing();
190 npv = PVI->getPU_NumInteractions();
196 if(npv < 0)
std::cerr <<
" no in-time beam crossing found\n! " ;
219 for(; PHist_iter<PHist.
end() ;++PHist_iter) {
233 std::vector<PileupSummaryInfo>::const_iterator PVI;
238 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
240 int BX = PVI->getBunchCrossing();
243 npv = PVI->getPU_NumInteractions();
247 npv50ns = PVI->getPU_NumInteractions();
257 std::cerr <<
" no in-time beam crossing found\n! " ;
258 std::cerr <<
" Returning event weight=0\n! ";
262 std::cerr <<
" no out-of-time beam crossing found\n! " ;
263 std::cerr <<
" Returning event weight=0\n! ";
269 double inTimeWeight =
weights_->GetBinContent( bin );
271 double TotalWeight = 1.0;
273 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_
edm::InputTag pileupSumInfoTag_
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_