ATLAS Offline Software
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__
17 namespace Gaudi {
18 namespace Units {
19 constexpr double megaelectronvolt = 1.;
20 constexpr double kiloelectronvolt = 1.e-3 * megaelectronvolt;
21 constexpr 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)
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 
92 void 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)
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 }
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
response
MDT_Response response
Definition: MDT_ResponseTest.cxx:28
TFCSEnergyInterpolationSpline::OnlyScaleEnergy
bool OnlyScaleEnergy() const
Definition: TFCSEnergyInterpolationSpline.h:25
TFCSEnergyInterpolationSpline::InitFromArrayInLogEkin
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,...
Definition: TFCSEnergyInterpolationSpline.cxx:36
TFCSEnergyInterpolationSpline.h
TFCSEnergyInterpolationSpline::unit_test
static void unit_test(TFCSSimulationState *simulstate=nullptr, TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr, TGraph *grspline=nullptr)
Definition: TFCSEnergyInterpolationSpline.cxx:109
gr
#define gr
TFCSEnergyInterpolationSpline::Print
void Print(Option_t *option="") const override
Definition: TFCSEnergyInterpolationSpline.cxx:92
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:147
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
RunActsMaterialValidation.extrapol
extrapol
Definition: RunActsMaterialValidation.py:91
PlotPulseshapeFromCool.np
np
Definition: PlotPulseshapeFromCool.py:64
python.SystemOfUnits.keV
int keV
Definition: SystemOfUnits.py:156
lumiFormat.i
int i
Definition: lumiFormat.py:85
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TFCSTruthState::Ekin
double Ekin() const
Definition: TFCSTruthState.h:26
covarianceTool.title
title
Definition: covarianceTool.py:542
TFCSEnergyInterpolationSpline::simulate
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...
Definition: TFCSEnergyInterpolationSpline.cxx:53
python.SystemOfUnits.megaelectronvolt
int megaelectronvolt
Definition: SystemOfUnits.py:144
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
TFCSEnergyInterpolationSpline::TFCSEnergyInterpolationSpline
TFCSEnergyInterpolationSpline(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSEnergyInterpolationSpline.cxx:32
TFCSParametrizationBase::Print
void Print(Option_t *option="") const
Print object information.
Definition: TFCSParametrizationBase.cxx:52
FCSSuccess
@ FCSSuccess
Definition: TFCSParametrizationBase.h:41
python.SystemOfUnits.kiloelectronvolt
int kiloelectronvolt
Definition: SystemOfUnits.py:146
TFCSEnergyInterpolationSpline
Definition: TFCSEnergyInterpolationSpline.h:13
Athena::Units
Definition: Units.h:45
TFCSParametrization
Definition: TFCSParametrization.h:10
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TFCSSimulationState::set_E
void set_E(int sample, double Esample)
Definition: TFCSSimulationState.h:48
TFCSEnergyInterpolationSpline::m_spline
TSpline3 m_spline
Definition: TFCSEnergyInterpolationSpline.h:70
TFCSTruthState.h
TFCSExtrapolationState.h
DEBUG
#define DEBUG
Definition: page_access.h:11
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
TFCSSimulationState::E
double E() const
Definition: TFCSSimulationState.h:42
TFCSSimulationState.h
TFCSTruthState
Definition: TFCSTruthState.h:13
python.compressB64.c
def c
Definition: compressB64.py:93
TFCSSimulationState
Definition: TFCSSimulationState.h:32
ISF_FCS::MLogging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition: MLogging.h:222
TFCSTruthState::set_pdgid
void set_pdgid(int val)
Definition: TFCSTruthState.h:18
TFCSEnergyInterpolationSpline::InitFromArrayInEkin
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,...
Definition: TFCSEnergyInterpolationSpline.cxx:43