1 #ifndef PhysicsTools_Utilities_interface_LumiReWeighting_cc
2 #define PhysicsTools_Utilities_interface_LumiReWeighting_cc
24 #include "TStopwatch.h"
44 : generatedFileName_(generatedFile),
45 dataFileName_(dataFile),
46 GenHistName_(GenHistName),
47 DataHistName_(DataHistName),
48 pileupSumInfoTag_(PileupSumInfoInputTag) {
66 TH1* den = dynamic_cast<TH1*>(
MC_distr_->Clone());
72 std::cout <<
" Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
76 for (
int ibin = 1; ibin <
NBins + 1; ++ibin) {
77 std::cout <<
" " << ibin - 1 <<
" " <<
weights_->GetBinContent(ibin) << std::endl;
85 const std::vector<float>& Lumi_distr,
87 : pileupSumInfoTag_(PileupSumInfoInputTag) {
94 if (MC_distr.size() != Lumi_distr.size()) {
95 std::cerr <<
"ERROR: LumiReWeighting: input vectors have different sizes. Quitting... \n";
99 Int_t
NBins = MC_distr.size();
101 MC_distr_ = std::shared_ptr<TH1>(
new TH1F(
"MC_distr",
"MC dist",
NBins, -0.5,
float(
NBins) - 0.5));
102 Data_distr_ = std::shared_ptr<TH1>(
new TH1F(
"Data_distr",
"Data dist",
NBins, -0.5,
float(
NBins) - 0.5));
104 weights_ = std::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) {
121 float deltaMC = den->Integral();
122 if (fabs(1.0 - deltaMC) > 0.02) {
123 den->Scale(1.0 / den->Integral());
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;
161 std::vector<PileupSummaryInfo>::const_iterator PVI;
164 for (PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
165 int BX = PVI->getBunchCrossing();
168 npv = PVI->getPU_NumInteractions();
174 std::cerr <<
" no in-time beam crossing found\n! ";
185 int LumiSection =
e.luminosityBlock();
197 std::vector<PileupSummaryInfo>::const_iterator PVI;
202 for (PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
203 int BX = PVI->getBunchCrossing();
206 npv = PVI->getPU_NumInteractions();
210 npv50ns = PVI->getPU_NumInteractions();
219 std::cerr <<
" no in-time beam crossing found\n! ";
220 std::cerr <<
" Returning event weight=0\n! ";
224 std::cerr <<
" no out-of-time beam crossing found\n! ";
225 std::cerr <<
" Returning event weight=0\n! ";
231 double inTimeWeight =
weights_->GetBinContent(
bin);
233 double TotalWeight = 1.0;
235 TotalWeight = inTimeWeight;