19 #include <momemta/Logging.h> 20 #include <momemta/Module.h> 21 #include <momemta/ParameterSet.h> 22 #include <momemta/Types.h> 41 m_reco_input = get<LorentzVector>(parameters.get<
InputTag>(
"reco_particle"));
43 std::string file_path = parameters.get<std::string>(
"file");
44 std::string th2_name = parameters.get<std::string>(
"th2_name");
46 std::unique_ptr<TFile> file(TFile::Open(file_path.c_str()));
47 if(!file->IsOpen() || file->IsZombie())
48 throw file_not_found_error(
"Could not open file " + file_path);
50 m_th2 = std::unique_ptr<TH2>(
static_cast<TH2*
>(file->Get(th2_name.c_str())));
51 if(!m_th2->InheritsFrom(
"TH2") || !m_th2.get())
52 throw th2_not_found_error(
"Could not retrieve object " + th2_name +
" deriving from class TH2 in file " + file_path +
".");
53 m_th2->SetDirectory(0);
55 TAxis* yAxis = m_th2->GetYaxis();
56 m_deltaMin = yAxis->GetXmin();
57 m_deltaMax = yAxis->GetXmax();
58 m_deltaRange = m_deltaMax - m_deltaMin;
60 TAxis* xAxis = m_th2->GetXaxis();
61 double Pt_cut = parameters.get<
double>(
"min_Pt", 0.);
62 m_PtgenMin = std::max(xAxis->GetXmin(), Pt_cut);
63 m_PtgenMax = xAxis->GetXmax();
68 m_fallBackPtgenMax = xAxis->GetBinCenter(xAxis->GetNbins());
70 LOG(debug) <<
"Loaded TH2 " << th2_name <<
" from file " << file_path <<
".";
71 LOG(debug) <<
"\tDelta range is " << m_deltaMin <<
" to " << m_deltaMax <<
".";
72 LOG(debug) <<
"\tPt range is " << m_PtgenMin <<
" to " << m_PtgenMax <<
".";
73 LOG(debug) <<
"\tWill use values at Ptgen = " << m_fallBackPtgenMax <<
" for out-of-range values.";
80 std::unique_ptr<TH2> m_th2;
82 double m_deltaMin, m_deltaMax, m_deltaRange;
83 double m_PtgenMin, m_PtgenMax;
84 double m_fallBackPtgenMax;
90 class file_not_found_error:
public std::runtime_error{
91 using std::runtime_error::runtime_error;
94 class th2_not_found_error:
public std::runtime_error{
95 using std::runtime_error::runtime_error;
146 m_ps_point = get<double>(parameters.get<
InputTag>(
"ps_point"));
149 virtual Status
work()
override {
150 const double rec_Pt = m_reco_input->Pt();
151 const double cosh_eta = std::cosh(m_reco_input->Eta());
152 const double range = GetDeltaRange(rec_Pt);
153 const double gen_Pt = rec_Pt - GetDeltaMax(rec_Pt) + range * (*m_ps_point);
154 const double delta = rec_Pt - gen_Pt;
157 const double gen_E = std::sqrt(
SQ(m_reco_input->M()) +
SQ(cosh_eta * gen_Pt));
158 output->SetCoordinates(
159 gen_Pt * std::cos(m_reco_input->Phi()),
160 gen_Pt * std::sin(m_reco_input->Phi()),
161 gen_Pt * std::sinh(m_reco_input->Eta()),
165 const int bin = m_th2->FindFixBin(std::min(gen_Pt, m_fallBackPtgenMax), delta);
168 *TF_times_jacobian = m_th2->GetBinContent(bin) * range * cosh_eta;
179 std::shared_ptr<LorentzVector> output = produce<LorentzVector>(
"output");
180 std::shared_ptr<double> TF_times_jacobian = produce<double>(
"TF_times_jacobian");
185 inline double GetDeltaRange(
const double Ptrec)
const {
186 return GetDeltaMax(Ptrec) - m_deltaMin;
189 inline double GetDeltaMax(
const double Ptrec)
const {
190 return std::min(m_deltaMax, Ptrec - m_PtgenMin);
235 m_gen_input = get<LorentzVector>(parameters.get<
InputTag>(
"gen_particle"));
238 virtual Status
work()
override {
239 const double rec_Pt = m_reco_input->Pt();
240 const double gen_Pt = m_gen_input->Pt();
241 double delta = rec_Pt - gen_Pt;
242 if (delta <= m_deltaMin || delta >= m_deltaMax) {
248 const int bin = m_th2->FindFixBin(std::min(gen_Pt, m_fallBackPtgenMax), delta);
251 *TF_value = m_th2->GetBinContent(bin);
262 std::shared_ptr<double> TF_value = produce<double>(
"TF");
266 .Input(
"reco_particle")
269 .Output(
"TF_times_jacobian")
271 .Attr(
"th2_name:string")
272 .Attr(
"min_Pt:double=0");
275 .Input(
"reco_particle")
276 .Input(
"gen_particle")
279 .Attr(
"th2_name:string")
280 .Attr(
"min_Pt:double=0");
virtual Status work() override
Main function.
Helper class for binned transfer function modules.
virtual Status work() override
Main function.
Integrate over a transfer function on Pt described by a 2D histogram retrieved from a ROOT file...
Evaluate a transfer function on Pt described by a 2D histogram retrieved from a ROOT file...
Parent class for all the modules.
A class encapsulating a lua table.
Module(PoolPtr pool, const std::string &name)
Constructor.