ATLAS Offline Software
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 
22  const char *title)
24 
26  if (m_hist)
27  delete m_hist;
28 }
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 
89 void 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 }
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
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
plotmaker.hist
hist
Definition: plotmaker.py:148
TFCSLateralShapeParametrization::Print
void Print(Option_t *option="") const override
Definition: TFCSLateralShapeParametrization.cxx:53
bin
Definition: BinsDiffFromStripMedian.h:43
TFCSHistoLateralShapeWeight::TFCSHistoLateralShapeWeight
TFCSHistoLateralShapeWeight(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSHistoLateralShapeWeight.cxx:21
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
TFCSHistoLateralShapeWeight::getMinWeight
virtual float getMinWeight() const override
Get minimum and maximum value of weight for hit energy reweighting.
Definition: TFCSHistoLateralShapeWeight.cxx:30
TFCSLateralShapeParametrizationHitBase
Definition: TFCSLateralShapeParametrizationHitBase.h:13
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
TFCSLateralShapeParametrizationHitBase::Hit::E
float & E()
Definition: TFCSLateralShapeParametrizationHitBase.h:90
TFCSHistoLateralShapeWeight::m_minWeight
float m_minWeight
Definition: TFCSHistoLateralShapeWeight.h:41
TFCSHistoLateralShapeWeight::Print
virtual void Print(Option_t *option="") const override
Definition: TFCSHistoLateralShapeWeight.cxx:89
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TFCSHistoLateralShapeWeight::m_maxWeight
float m_maxWeight
Definition: TFCSHistoLateralShapeWeight.h:42
covarianceTool.title
title
Definition: covarianceTool.py:542
TFCSLateralShapeParametrizationHitBase::Hit::center_z
float & center_z()
Definition: TFCSLateralShapeParametrizationHitBase.h:99
TFCSHistoLateralShapeWeight::Initialize
bool Initialize(TH1 *hist)
Init from histogram.
Definition: TFCSHistoLateralShapeWeight.cxx:77
TFCSHistoLateralShapeWeight::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: TFCSHistoLateralShapeWeight.cxx:34
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
TFCSHistoLateralShapeWeight.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
pmontree.opt
opt
Definition: pmontree.py:16
TH1::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:298
TFCSHistoLateralShapeWeight::getMaxWeight
virtual float getMaxWeight() const override
Definition: TFCSHistoLateralShapeWeight.cxx:32
eFEXNTuple.delta_phi
def delta_phi(phi1, phi2)
Definition: eFEXNTuple.py:15
TH1
Definition: rootspy.cxx:268
DEBUG
#define DEBUG
Definition: page_access.h:11
DiTauMassTools::HistInfoV2::RMS
@ RMS
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:31
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
TFCSHistoLateralShapeWeight::~TFCSHistoLateralShapeWeight
virtual ~TFCSHistoLateralShapeWeight()
Definition: TFCSHistoLateralShapeWeight.cxx:25
TFCSTruthState
Definition: TFCSTruthState.h:13
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