ATLAS Offline Software
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 
21  const char *title)
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 }
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
TFCSLateralShapeParametrizationHitBase::Hit::phi
float & phi()
Definition: TFCSLateralShapeParametrizationHitBase.h:87
TFCSHistoLateralShapeWeight
Definition: TFCSHistoLateralShapeWeight.h:13
bin
Definition: BinsDiffFromStripMedian.h:43
TFCSHistoLateralShapeGausLogWeightHitAndMiss.h
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
covarianceTool.prob
prob
Definition: covarianceTool.py:678
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
TFCSLateralShapeParametrizationHitBase::Hit::E
float & E()
Definition: TFCSLateralShapeParametrizationHitBase.h:90
TFCSHistoLateralShapeGausLogWeightHitAndMiss::TFCSHistoLateralShapeGausLogWeightHitAndMiss
TFCSHistoLateralShapeGausLogWeightHitAndMiss(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSHistoLateralShapeGausLogWeightHitAndMiss.cxx:20
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
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
DiTauMassTools::HistInfo::RMS
@ RMS
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TFCSHistoLateralShapeGausLogWeightHitAndMiss::~TFCSHistoLateralShapeGausLogWeightHitAndMiss
virtual ~TFCSHistoLateralShapeGausLogWeightHitAndMiss()
Definition: TFCSHistoLateralShapeGausLogWeightHitAndMiss.cxx:25
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
TFCSLateralShapeParametrizationHitBase::Hit::eta
float & eta()
Definition: TFCSLateralShapeParametrizationHitBase.h:86
TFCSSimulationState.h
TFCSHistoLateralShapeGausLogWeightHitAndMiss::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: TFCSHistoLateralShapeGausLogWeightHitAndMiss.cxx:27
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32