ATLAS Offline Software
TFCSHistoLateralShapeGausLogWeight.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 //======= TFCSHistoLateralShapeGausLogWeight =========
17 //=============================================
18 
20  const char *name, const char *title)
22 
24 #ifdef USE_GPU
25  delete m_LdFH;
26 #endif
27 }
28 
30  Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState * /*truth*/,
31  const TFCSExtrapolationState * /*extrapol*/) {
32  if (!simulstate.randomEngine()) {
33  return FCSFatal;
34  }
35 
36  const double center_eta = hit.center_eta();
37  const double center_phi = hit.center_phi();
38  const double center_r = hit.center_r();
39  const double center_z = hit.center_z();
40 
41  const float dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
42  const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
43  (1.0 + TMath::Exp(-2 * center_eta)));
44 
45  const float delta_eta = hit.eta() - center_eta;
46  const float delta_phi = hit.phi() - center_phi;
47  const float delta_eta_mm = delta_eta * eta_jakobi * dist000;
48  const float delta_phi_mm = delta_phi * center_r;
49  const float delta_r_mm =
50  TMath::Sqrt(delta_eta_mm * delta_eta_mm + delta_phi_mm * delta_phi_mm);
51 
52  // TODO: delta_r_mm should perhaps be cached in hit
53 
54  Int_t bin = m_hist->FindBin(delta_r_mm);
55  if (bin < 1)
56  bin = 1;
57  if (bin > m_hist->GetNbinsX())
58  bin = m_hist->GetNbinsX();
59  float weight = m_hist->GetBinContent(bin);
60  float RMS = m_hist->GetBinError(bin);
61  if (RMS > 0) {
62  float logweight = CLHEP::RandGaussZiggurat::shoot(simulstate.randomEngine(),
63  -0.5 * RMS * RMS, RMS);
64  weight *= TMath::Exp(logweight);
65  }
66  hit.E() *= weight;
67 
68  ATH_MSG_DEBUG("HIT: E=" << hit.E() << " dR_mm=" << delta_r_mm
69  << " weight=" << weight);
70  return FCSSuccess;
71 }
72 
73 #ifdef USE_GPU
74 // for FCS-GPU
75 // make the histograms with GPU EDM
76 void TFCSHistoLateralShapeGausLogWeight::LoadHist() {
77 
78  if (m_LdFH) {
79  return;
80  }
81  m_LdFH = new LoadGpuHist();
82  FH1D fh1d;
83 
84  fh1d.nbins = m_hist->GetNbinsX();
85  fh1d.h_contents = (float *)malloc(fh1d.nbins * sizeof(float));
86  fh1d.h_errors = (float *)malloc(fh1d.nbins * sizeof(float));
87  fh1d.h_borders = (float *)malloc((fh1d.nbins + 1) * sizeof(float));
88 
89  for (int ibin = 0; ibin < fh1d.nbins; ++ibin) {
90  fh1d.h_contents[ibin] = m_hist->GetBinContent(ibin + 1);
91  fh1d.h_errors[ibin] = m_hist->GetBinError(ibin + 1);
92  fh1d.h_borders[ibin] = m_hist->GetXaxis()->GetBinLowEdge(ibin + 1);
93  }
94  fh1d.h_borders[fh1d.nbins] = m_hist->GetXaxis()->GetBinUpEdge(fh1d.nbins);
95 
96  m_LdFH->set_hf1d(&fh1d);
97  m_LdFH->LD1D();
98 
99  return;
100 }
101 #endif
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
TFCSHistoLateralShapeGausLogWeight::TFCSHistoLateralShapeGausLogWeight
TFCSHistoLateralShapeGausLogWeight(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSHistoLateralShapeGausLogWeight.cxx:19
TFCSLateralShapeParametrizationHitBase::Hit::phi
float & phi()
Definition: TFCSLateralShapeParametrizationHitBase.h:87
TFCSHistoLateralShapeWeight
Definition: TFCSHistoLateralShapeWeight.h:13
FH1D::h_contents
float * h_contents
Definition: FH_structs.h:24
bin
Definition: BinsDiffFromStripMedian.h:43
FH1D::nbins
int nbins
Definition: FH_structs.h:26
FH1D::h_borders
float * h_borders
Definition: FH_structs.h:23
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
TFCSSimulationState::randomEngine
CLHEP::HepRandomEngine * randomEngine()
Definition: TFCSSimulationState.h:36
TFCSLateralShapeParametrizationHitBase::Hit
Definition: TFCSLateralShapeParametrizationHitBase.h:42
TFCSLateralShapeParametrizationHitBase::Hit::center_phi
float & center_phi()
Definition: TFCSLateralShapeParametrizationHitBase.h:101
FH1D
Definition: FH_structs.h:22
TFCSHistoLateralShapeGausLogWeight.h
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
TFCSLateralShapeParametrizationHitBase::Hit::E
float & E()
Definition: TFCSLateralShapeParametrizationHitBase.h:90
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
covarianceTool.title
title
Definition: covarianceTool.py:542
TFCSLateralShapeParametrizationHitBase::Hit::center_z
float & center_z()
Definition: TFCSLateralShapeParametrizationHitBase.h:99
FH1D::h_errors
float * h_errors
Definition: FH_structs.h:25
TrigInDetValidation_Base.malloc
malloc
Definition: TrigInDetValidation_Base.py:132
FCSFatal
@ FCSFatal
Definition: TFCSParametrizationBase.h:41
TFCSHistoLateralShapeWeight::m_hist
TH1 * m_hist
Histogram to be used for the shape simulation The histogram x-axis should be in dR^2=deta^2+dphi^2.
Definition: TFCSHistoLateralShapeWeight.h:40
FCSSuccess
@ FCSSuccess
Definition: TFCSParametrizationBase.h:41
TFCSHistoLateralShapeGausLogWeight::simulate_hit
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
Definition: TFCSHistoLateralShapeGausLogWeight.cxx:29
DiTauMassTools::HistInfo::RMS
@ RMS
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LoadGpuHist
Definition: LoadGpuHist.h:10
eFEXNTuple.delta_phi
def delta_phi(phi1, phi2)
Definition: eFEXNTuple.py:15
TFCSLateralShapeParametrizationHitBase::Hit::center_eta
float & center_eta()
Definition: TFCSLateralShapeParametrizationHitBase.h:100
TFCSLateralShapeParametrizationHitBase::Hit::center_r
float & center_r()
Definition: TFCSLateralShapeParametrizationHitBase.h:98
TFCSHistoLateralShapeGausLogWeight::~TFCSHistoLateralShapeGausLogWeight
virtual ~TFCSHistoLateralShapeGausLogWeight()
Definition: TFCSHistoLateralShapeGausLogWeight.cxx:23
TFCSLateralShapeParametrizationHitBase::Hit::eta
float & eta()
Definition: TFCSLateralShapeParametrizationHitBase.h:86
TFCSSimulationState.h
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32
readCCLHist.float
float
Definition: readCCLHist.py:83