ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSHistoLateralShapeGausLogWeightHitAndMiss.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "CLHEP/Random/RandFlat.h"
6#include "CLHEP/Random/RandGaussZiggurat.h"
7
10
11#include "TH1.h"
12#include "TVector2.h"
13#include "TMath.h"
14
15//=============================================
16//======= TFCSHistoLateralShapeGausLogWeightHitAndMiss =========
17//=============================================
18
23
26
28 Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState * /*truth*/,
29 const TFCSExtrapolationState * /*extrapol*/) {
30 if (!simulstate.randomEngine()) {
31 return FCSFatal;
32 }
33
34 const double center_eta = hit.center_eta();
35 const double center_phi = hit.center_phi();
36 const double center_r = hit.center_r();
37 const double center_z = hit.center_z();
38
39 const float dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
40 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
41 (1.0 + TMath::Exp(-2 * center_eta)));
42
43 const float delta_eta = hit.eta() - center_eta;
44 const float delta_phi = hit.phi() - center_phi;
45 const float delta_eta_mm = delta_eta * eta_jakobi * dist000;
46 const float delta_phi_mm = delta_phi * center_r;
47 const float delta_r_mm =
48 TMath::Sqrt(delta_eta_mm * delta_eta_mm + delta_phi_mm * delta_phi_mm);
49
50 // TODO: delta_r_mm should perhaps be cached in hit
51
52 Int_t bin = m_hist->FindBin(delta_r_mm);
53 if (bin < 1)
54 bin = 1;
55 if (bin > m_hist->GetNbinsX())
56 bin = m_hist->GetNbinsX();
57 float meanweight = m_hist->GetBinContent(bin);
58 float weight = meanweight;
59 float RMS = m_hist->GetBinError(bin);
60 if (RMS > 0) {
61 float logweight = CLHEP::RandGaussZiggurat::shoot(simulstate.randomEngine(),
62 -0.5 * RMS * RMS, RMS);
63 weight *= TMath::Exp(logweight);
64 }
65 if (meanweight <= 1) {
66 // if meanweight<=1, give lower energy to hit.
67 // TFCSLateralShapeParametrizationHitChain needs to be able to generate more
68 // hits in this case
69 hit.E() *= weight;
70 } else {
71 // if meanweight>1, accept only 1/meanweight events, but give them a higher
72 // energy increased by weight. This leads to larger fluctuations, while
73 // keeping the shape unchanged.
74 float prob = 1.0 / meanweight;
75 float rnd = CLHEP::RandFlat::shoot(simulstate.randomEngine());
76 if (rnd < prob)
77 hit.E() *= weight;
78 else
79 hit.E() = 0;
80 }
81
82 ATH_MSG_DEBUG("HIT: E=" << hit.E() << " dR_mm=" << delta_r_mm
83 << " meanweight=" << meanweight
84 << " weight=" << weight);
85 return FCSSuccess;
86}
#define ATH_MSG_DEBUG(x)
static TRandom * rnd
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
TFCSHistoLateralShapeGausLogWeightHitAndMiss(const char *name=nullptr, const char *title=nullptr)
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.
TFCSHistoLateralShapeWeight(const char *name=nullptr, const char *title=nullptr)
TH1 * m_hist
Histogram to be used for the shape simulation The histogram x-axis should be in dR^2=deta^2+dphi^2.
CLHEP::HepRandomEngine * randomEngine()