ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSEnergyInterpolationHistogram.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 *name, const char *title)
34 : TFCSParametrization(name, title) {}
35
37 TFCSSimulationState &simulstate, const TFCSTruthState *truth,
38 const TFCSExtrapolationState *) const {
39 float Emean;
40 float Einit;
41 const float Ekin = truth->Ekin();
42 if (OnlyScaleEnergy())
43 Einit = simulstate.E();
44 else
45 Einit = Ekin;
46 if (Einit < m_hist.GetXaxis()->GetBinLowEdge(1)) {
47 Emean = m_hist.GetBinContent(1) * Einit;
48 } else {
49 if (Einit > m_hist.GetXaxis()->GetBinUpEdge(m_hist.GetNbinsX())) {
50 Emean = m_hist.GetBinContent(m_hist.GetNbinsX()) * Einit;
51 } else {
52 Emean = m_hist.GetBinContent(m_hist.GetXaxis()->FindBin(Einit)) * Einit;
53 }
54 }
55
56 if (OnlyScaleEnergy()) {
57 ATH_MSG_DEBUG("set E=" << Emean << " for true Ekin=" << truth->Ekin()
58 << " and E=" << Einit);
59 } else {
60 ATH_MSG_DEBUG("set E=" << Emean << " for true Ekin=" << truth->Ekin());
61 }
62 simulstate.set_E(Emean);
63
64 return FCSSuccess;
65}
66
67void TFCSEnergyInterpolationHistogram::Print(Option_t *option) const {
68 TString opt(option);
69 bool shortprint = opt.Index("short") >= 0;
70 bool longprint = msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
71 TString optprint = opt;
72 optprint.ReplaceAll("short", "");
74
75 if (longprint)
77 optprint << (OnlyScaleEnergy() ? " E()*" : " Ekin()*")
78 << "histNbins=" << m_hist.GetNbinsX() << " "
79 << m_hist.GetXaxis()->GetBinLowEdge(1) << "<=Ekin<="
80 << m_hist.GetXaxis()->GetBinUpEdge(m_hist.GetNbinsX()));
81}
82
84 TFCSSimulationState *simulstate, TFCSTruthState *truth,
85 const TFCSExtrapolationState *extrapol, TH1F *hist) {
86 if (!simulstate)
87 simulstate = new TFCSSimulationState();
88 if (!truth)
89 truth = new TFCSTruthState();
90 if (!extrapol)
91 extrapol = new TFCSExtrapolationState();
92
93 if (!hist) {
94 hist = new TH1F("h1", "h1 title", 16, 0., 512.);
95 hist->SetBinContent(1, 0.687165);
96 hist->SetBinContent(2, 0.756837);
97 hist->SetBinContent(3, 0.836673);
98 hist->SetBinContent(4, 0.896336);
99 hist->SetBinContent(5, 0.889785);
100 hist->SetBinContent(6, 0.901266);
101 hist->SetBinContent(7, 0.888937);
102 hist->SetBinContent(8, 0.919943);
103 hist->SetBinContent(9, 0.941806);
104 hist->SetBinContent(10, 0.934668);
105 hist->SetBinContent(11, 0.939502);
106 hist->SetBinContent(12, 0.940796);
107 hist->SetBinContent(13, 0.945894);
108 hist->SetBinContent(14, 0.955445);
109 hist->SetBinContent(15, 0.955593);
110 hist->SetBinContent(16, 0.943673);
111 }
112
113 TH1F *hdraw = (TH1F *)hist->Clone();
114 hdraw->SetMarkerColor(46);
115 hdraw->SetMarkerStyle(8);
116
118 "testTFCSEnergyInterpolationHistogram",
119 "test TFCSEnergyInterpolationHistogram");
120 test.set_pdgid(22);
121 test.set_Ekin_nominal(0.5 *
122 (hdraw->GetXaxis()->GetBinLowEdge(1) +
123 hdraw->GetXaxis()->GetBinUpEdge(hdraw->GetNbinsX())));
124 test.set_Ekin_min(hdraw->GetXaxis()->GetBinLowEdge(1));
125 test.set_Ekin_max(hdraw->GetXaxis()->GetBinUpEdge(hdraw->GetNbinsX()));
126 test.set_eta_nominal(0.225);
127 test.set_eta_min(0.2);
128 test.set_eta_max(0.25);
129 test.InitFromHist(*hist);
130 // test.set_OnlyScaleEnergy();
131 test.Print();
132 test.hist().Dump();
133
134 truth->set_pdgid(22);
135
136 TGraph *gr = new TGraph();
137 gr->SetNameTitle("testTFCSEnergyInterpolationHistogramLogX",
138 "test TFCSEnergyInterpolationHistogram");
139 gr->GetXaxis()->SetTitle("Ekin [MeV]");
140 gr->GetYaxis()->SetTitle("<E(reco)>/Ekin(true)");
141
142 int ip = 0;
143 for (float Ekin = std::max(test.Ekin_min() * 0.25, 0.1);
144 Ekin <= test.Ekin_max() * 4; Ekin *= 1.05) {
145 // Init LorentzVector for truth. For photon Ekin=E
146 truth->SetPxPyPzE(Ekin, 0, 0, Ekin);
147 simulstate->set_E(Ekin);
148 if (test.simulate(*simulstate, truth, extrapol) != FCSSuccess) {
149 return;
150 }
151 gr->SetPoint(ip, Ekin, simulstate->E() / Ekin);
152 ++ip;
153 }
154
155// Drawing doesn't make sense inside athena and necessary libraries not linked
156// by default
157#if defined(__FastCaloSimStandAlone__)
158 TCanvas *c = new TCanvas(hdraw->GetName(), hdraw->GetTitle());
159 hdraw->Draw("HIST");
160 gr->Draw("same,APL");
161 c->SetLogx();
162#endif
163}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define gr
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...
TFCSEnergyInterpolationHistogram(const char *name=nullptr, const char *title=nullptr)
static void unit_test(TFCSSimulationState *simulstate=nullptr, TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr, TH1F *hist=nullptr)
void Print(Option_t *option="") const override
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
=============================================================================