ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSEnergyInterpolationSpline.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include "TFile.h"
10#include "TCanvas.h"
11#include "TGraph.h"
12#include "TAxis.h"
13#include <iostream>
14#include <vector>
15
16#ifdef __FastCaloSimStandAlone__
17namespace Gaudi {
18namespace Units {
19constexpr double megaelectronvolt = 1.;
20constexpr double kiloelectronvolt = 1.e-3 * megaelectronvolt;
21constexpr double keV = kiloelectronvolt;
22} // namespace Units
23} // namespace Gaudi
24#else
25#include "GaudiKernel/SystemOfUnits.h"
26#endif
27
28//=============================================
29//======= TFCSEnergyInterpolation =========
30//=============================================
31
33 const char *title)
34 : TFCSParametrization(name, title) {}
35
37 Int_t np, Double_t logEkin[], Double_t response[], const char *opt,
38 Double_t valbeg, Double_t valend) {
39 TSpline3 initspline(GetName(), logEkin, response, np, opt, valbeg, valend);
40 m_spline = initspline;
41}
42
44 Int_t np, Double_t Ekin[], Double_t response[], const char *opt,
45 Double_t valbeg, Double_t valend) {
46 std::vector<Double_t> logEkin(np);
47 for (int i = 0; i < np; ++i)
48 logEkin[i] = TMath::Log(Ekin[i]);
49 InitFromArrayInLogEkin(np, logEkin.data(), response, opt, valbeg, valend);
50}
51
54 const TFCSTruthState *truth,
55 const TFCSExtrapolationState *) const {
56 float Emean;
57 float Einit;
58 const float Ekin = truth->Ekin();
59 if (OnlyScaleEnergy())
60 Einit = simulstate.E();
61 else
62 Einit = Ekin;
63 // catch very small values of Ekin (use 1 keV here) and fix the spline lookup
64 // to the 1keV value
65 const float logEkin =
66 (Ekin > Gaudi::Units::keV ? TMath::Log(Ekin)
67 : TMath::Log(Gaudi::Units::keV));
68 if (logEkin < m_spline.GetXmin()) {
69 Emean = m_spline.Eval(m_spline.GetXmin()) * Einit;
70 } else {
71 if (logEkin > m_spline.GetXmax()) {
72 Emean = (m_spline.Eval(m_spline.GetXmax()) +
73 m_spline.Derivative(m_spline.GetXmax()) *
74 (logEkin - m_spline.GetXmax())) *
75 Einit;
76 } else {
77 Emean = m_spline.Eval(logEkin) * Einit;
78 }
79 }
80
81 if (OnlyScaleEnergy()) {
82 ATH_MSG_DEBUG("set E=" << Emean << " for true Ekin=" << truth->Ekin()
83 << " and E=" << Einit);
84 } else {
85 ATH_MSG_DEBUG("set E=" << Emean << " for true Ekin=" << truth->Ekin());
86 }
87 simulstate.set_E(Emean);
88
89 return FCSSuccess;
90}
91
92void TFCSEnergyInterpolationSpline::Print(Option_t *option) const {
93 TString opt(option);
94 bool shortprint = opt.Index("short") >= 0;
95 bool longprint = msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
96 TString optprint = opt;
97 optprint.ReplaceAll("short", "");
99
100 if (longprint)
101 ATH_MSG_INFO(optprint << (OnlyScaleEnergy() ? " E()*" : " Ekin()*")
102 << "Spline N=" << m_spline.GetNp() << " "
103 << m_spline.GetXmin()
104 << "<=log(Ekin)<=" << m_spline.GetXmax() << " "
105 << TMath::Exp(m_spline.GetXmin())
106 << "<=Ekin<=" << TMath::Exp(m_spline.GetXmax()));
107}
108
110 TFCSSimulationState *simulstate, TFCSTruthState *truth,
111 const TFCSExtrapolationState *extrapol, TGraph *grspline) {
112 if (!simulstate)
113 simulstate = new TFCSSimulationState();
114 if (!truth)
115 truth = new TFCSTruthState();
116 if (!extrapol)
117 extrapol = new TFCSExtrapolationState();
118
119 if (!grspline) {
120 const int Graph0_n = 9;
121 Double_t Graph0_fx1001[Graph0_n] = {1.024, 2.048, 4.094, 8.192, 16.384,
122 32.768, 65.536, 131.072, 262.144};
123 for (int i = 0; i < Graph0_n; ++i)
124 Graph0_fx1001[i] *= 1000;
125
126 Double_t Graph0_fy1001[Graph0_n] = {0.6535402, 0.6571529, 0.6843001,
127 0.7172835, 0.7708416, 0.798819,
128 0.8187628, 0.8332745, 0.8443931};
129 grspline = new TGraph(Graph0_n, Graph0_fx1001, Graph0_fy1001);
130 }
131
132 TGraph *grdraw = (TGraph *)grspline->Clone();
133 grdraw->SetMarkerColor(46);
134 grdraw->SetMarkerStyle(8);
135
136 TFCSEnergyInterpolationSpline test("testTFCSEnergyInterpolationSpline",
137 "test TFCSEnergyInterpolationSpline");
138 test.set_pdgid(22);
139 test.set_Ekin_nominal(
140 0.5 * (grdraw->GetX()[0] + grdraw->GetX()[grdraw->GetN() - 1]));
141 test.set_Ekin_min(grdraw->GetX()[0]);
142 test.set_Ekin_max(grdraw->GetX()[grdraw->GetN() - 1]);
143 test.set_eta_nominal(0.225);
144 test.set_eta_min(0.2);
145 test.set_eta_max(0.25);
146 test.InitFromArrayInEkin(grspline->GetN(), grspline->GetX(), grspline->GetY(),
147 "b2e2", 0, 0);
148 // test.set_OnlyScaleEnergy();
149 test.Print();
150
151 truth->set_pdgid(22);
152
153 TGraph *gr = new TGraph();
154 gr->SetNameTitle("testTFCSEnergyInterpolationSplineLogX",
155 "test TFCSEnergyInterpolationSpline log x-axis");
156 gr->GetXaxis()->SetTitle("Ekin [MeV]");
157 gr->GetYaxis()->SetTitle("<E(reco)>/Ekin(true)");
158
159 int ip = 0;
160 for (float Ekin = test.Ekin_min() * 0.25; Ekin <= test.Ekin_max() * 4;
161 Ekin *= 1.05) {
162 // Init LorentzVector for truth. For photon Ekin=E
163 truth->SetPxPyPzE(Ekin, 0, 0, Ekin);
164 simulstate->set_E(Ekin);
165 if (test.simulate(*simulstate, truth, extrapol) != FCSSuccess) {
166 return;
167 }
168 gr->SetPoint(ip, Ekin, simulstate->E() / Ekin);
169 ++ip;
170 }
171
172// Drawing doesn't make sense inside athena and necessary libraries not linked
173// by default
174#if defined(__FastCaloSimStandAlone__)
175 TCanvas *c = new TCanvas(gr->GetName(), gr->GetTitle());
176 gr->Draw("APL");
177 grdraw->Draw("Psame");
178 c->SetLogx();
179#endif
180}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define gr
MDT_Response response
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition MLogging.h:222
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Initialize simulstate with the mean reconstructed energy in the calorimater expeted from the true kin...
static void unit_test(TFCSSimulationState *simulstate=nullptr, TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr, TGraph *grspline=nullptr)
void InitFromArrayInEkin(Int_t np, Double_t Ekin[], Double_t response[], const char *opt=nullptr, Double_t valbeg=0, Double_t valend=0)
Initialize spline interpolation from arrays in Ekin and response=<E(reco)/Ekin(true)> opt,...
void Print(Option_t *option="") const override
void InitFromArrayInLogEkin(Int_t np, Double_t logEkin[], Double_t response[], const char *opt=nullptr, Double_t valbeg=0, Double_t valend=0)
Initialize spline interpolation from arrays in log(Ekin) and response=<E(reco)/Ekin(true)> opt,...
TFCSEnergyInterpolationSpline(const char *name=nullptr, const char *title=nullptr)
void Print(Option_t *option="") const
Print object information.
TFCSParametrization(const char *name=nullptr, const char *title=nullptr)
void set_E(int sample, double Esample)
void set_pdgid(int val)
double Ekin() const
=============================================================================