-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from blinkseb/pu_reweighting
Add new weight for PU reweighting
- Loading branch information
Showing
7 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <map> | ||
#include <memory> | ||
|
||
#include <TH1.h> | ||
|
||
#include <FWCore/ParameterSet/interface/ParameterSet.h> | ||
|
||
namespace Framework { | ||
enum PUProfile : uint8_t { | ||
Run2015_50ns, | ||
Run2015_25ns | ||
}; | ||
|
||
class PUReweighter { | ||
public: | ||
PUReweighter(const edm::ParameterSet&, PUProfile mc_pu_profile); | ||
|
||
float getWeight(float n_interactions); | ||
|
||
private: | ||
std::shared_ptr<TH1> m_pu_weights; | ||
|
||
std::map<PUProfile, std::vector<float>> m_pu_profiles { | ||
{ | ||
Run2015_25ns, | ||
{ | ||
4.8551E-07, | ||
1.74806E-06, | ||
3.30868E-06, | ||
1.62972E-05, | ||
4.95667E-05, | ||
0.000606966, | ||
0.003307249, | ||
0.010340741, | ||
0.022852296, | ||
0.041948781, | ||
0.058609363, | ||
0.067475755, | ||
0.072817826, | ||
0.075931405, | ||
0.076782504, | ||
0.076202319, | ||
0.074502547, | ||
0.072355135, | ||
0.069642102, | ||
0.064920999, | ||
0.05725576, | ||
0.047289348, | ||
0.036528446, | ||
0.026376131, | ||
0.017806872, | ||
0.011249422, | ||
0.006643385, | ||
0.003662904, | ||
0.001899681, | ||
0.00095614, | ||
0.00050028, | ||
0.000297353, | ||
0.000208717, | ||
0.000165856, | ||
0.000139974, | ||
0.000120481, | ||
0.000103826, | ||
8.88868E-05, | ||
7.53323E-05, | ||
6.30863E-05, | ||
5.21356E-05, | ||
4.24754E-05, | ||
3.40876E-05, | ||
2.69282E-05, | ||
2.09267E-05, | ||
1.5989E-05, | ||
4.8551E-06, | ||
2.42755E-06, | ||
4.8551E-07, | ||
2.42755E-07, | ||
1.21378E-07, | ||
4.8551E-08 | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
#include <memory> | ||
|
||
#include <TFile.h> | ||
#include <TH1F.h> | ||
|
||
#include <cp3_llbb/Framework/interface/PUReweighter.h> | ||
|
||
namespace Framework { | ||
|
||
PUReweighter::PUReweighter(const edm::ParameterSet& config, PUProfile mc_pu_profile) { | ||
|
||
std::string file = config.getUntrackedParameter<edm::FileInPath>("data_pu_profile").fullPath(); | ||
|
||
// Retrieve PU histogram from file | ||
std::unique_ptr<TFile> f(TFile::Open(file.c_str())); | ||
TH1* data_pu_histogram = static_cast<TH1*>(f->Get("pileup")); | ||
|
||
size_t x_max = (size_t) data_pu_histogram->GetXaxis()->GetXmax(); | ||
size_t n_bins = data_pu_histogram->GetNbinsX(); | ||
|
||
std::shared_ptr<TH1F> mc_pu_histogram = std::make_shared<TH1F>("pu_mc", "", n_bins, 0, x_max); | ||
mc_pu_histogram->SetDirectory(nullptr); | ||
|
||
const std::vector<float>& coeffs = m_pu_profiles[mc_pu_profile]; | ||
for (size_t i = 1; i <= (size_t) data_pu_histogram->GetNbinsX(); i++) { | ||
size_t coef_index = (size_t) data_pu_histogram->GetBinCenter(i); | ||
float coef = (coef_index) < coeffs.size() ? coeffs[coef_index] : 0.; | ||
|
||
mc_pu_histogram->SetBinContent(i, coef); | ||
} | ||
|
||
data_pu_histogram->Scale(1. / data_pu_histogram->Integral()); | ||
mc_pu_histogram->Scale(1. / mc_pu_histogram->Integral()); | ||
|
||
std::shared_ptr<TH1> pu_weights(static_cast<TH1*>(data_pu_histogram->Clone())); | ||
pu_weights->SetDirectory(nullptr); | ||
|
||
pu_weights->Divide(mc_pu_histogram.get()); | ||
|
||
m_pu_weights = pu_weights; | ||
} | ||
|
||
float PUReweighter::getWeight(float n_interactions) { | ||
|
||
TH1* pu_weights = m_pu_weights.get(); | ||
|
||
if (! pu_weights) | ||
return 1; | ||
|
||
return pu_weights->GetBinContent(pu_weights->GetXaxis()->FindBin(n_interactions)); | ||
} | ||
}; |