ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSHistoLateralShapeWeight.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <utility>
6
7#include "CLHEP/Random/RandFlat.h"
8#include "CLHEP/Random/RandGaussZiggurat.h"
9
12
13#include "TH1.h"
14#include "TVector2.h"
15#include "TMath.h"
16
17//=============================================
18//======= TFCSHistoLateralShapeWeight =========
19//=============================================
20
24
29
31
33
35 Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState * /*truth*/,
36 const TFCSExtrapolationState * /*extrapol*/) {
37 if (!simulstate.randomEngine()) {
38 return FCSFatal;
39 }
40
41 const double center_eta = hit.center_eta();
42 const double center_phi = hit.center_phi();
43 const double center_r = hit.center_r();
44 const double center_z = hit.center_z();
45
46 const float dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
47 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
48 (1.0 + TMath::Exp(-2 * center_eta)));
49
50 const float delta_eta = hit.eta() - center_eta;
51 const float delta_phi = hit.phi() - center_phi;
52 const float delta_eta_mm = delta_eta * eta_jakobi * dist000;
53 const float delta_phi_mm = delta_phi * center_r;
54 const float delta_r_mm =
55 TMath::Sqrt(delta_eta_mm * delta_eta_mm + delta_phi_mm * delta_phi_mm);
56
57 // TODO: delta_r_mm should perhaps be cached in hit
58
59 Int_t bin = m_hist->FindBin(delta_r_mm);
60 if (bin < 1)
61 bin = 1;
62 if (bin > m_hist->GetNbinsX())
63 bin = m_hist->GetNbinsX();
64 float weight = m_hist->GetBinContent(bin);
65 float RMS = m_hist->GetBinError(bin);
66 if (RMS > 0) {
67 weight =
68 CLHEP::RandGaussZiggurat::shoot(simulstate.randomEngine(), weight, RMS);
69 }
70 hit.E() *= weight;
71
72 ATH_MSG_DEBUG("HIT: E=" << hit.E() << " dR_mm=" << delta_r_mm
73 << " weight=" << weight);
74 return FCSSuccess;
75}
76
78 if (!hist)
79 return false;
80 if (m_hist)
81 delete m_hist;
82 m_hist = (TH1 *)hist->Clone(TString("TFCSHistoLateralShapeWeight_") +
83 hist->GetName());
84 m_hist->SetDirectory(nullptr);
85
86 return true;
87}
88
89void TFCSHistoLateralShapeWeight::Print(Option_t *option) const {
90 TString opt(option);
91 bool shortprint = opt.Index("short") >= 0;
92 bool longprint = msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
93 TString optprint = opt;
94 optprint.ReplaceAll("short", "");
96
97 if (longprint) {
98 if (m_hist)
99 ATH_MSG_INFO(optprint
100 << " Histogram: " << m_hist->GetNbinsX() << " bins ["
101 << std::as_const(m_hist)->GetXaxis()->GetXmin() << ","
102 << std::as_const(m_hist)->GetXaxis()->GetXmax() << "]"
103 << " min weight: " << m_minWeight
104 << " max weight: " << m_maxWeight);
105 else
106 ATH_MSG_INFO(optprint << " no Histogram");
107 }
108}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
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_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
weight the energy of one hit in order to generate fluctuations
virtual void Print(Option_t *option="") const override
bool Initialize(TH1 *hist)
Init from histogram.
TFCSHistoLateralShapeWeight(const char *name=nullptr, const char *title=nullptr)
virtual float getMinWeight() const override
Get minimum and maximum value of weight for hit energy reweighting.
TH1 * m_hist
Histogram to be used for the shape simulation The histogram x-axis should be in dR^2=deta^2+dphi^2.
virtual float getMaxWeight() const override
TFCSLateralShapeParametrizationHitBase(const char *name=nullptr, const char *title=nullptr)
void Print(Option_t *option="") const override
CLHEP::HepRandomEngine * randomEngine()