ATLAS Offline Software
TFCSBinnedShowerBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 #include <cstdlib>
9 
10 #include "HepPDT/ParticleData.hh"
12 // #include "ISF_FastCaloSimEvent/TFCSInitWithEkin.h"
16 
17 #if defined(__FastCaloSimStandAlone__)
18 #include "CLHEP/Random/TRandomEngine.h"
19 #else
20 #include <CLHEP/Random/RanluxEngine.h>
21 #endif
22 
23 #include <H5Cpp.h>
24 #include <TFile.h>
25 #include <TH2.h>
26 
27 #include <algorithm>
28 
29 #include "CLHEP/Random/RandFlat.h"
31 #include "TBuffer.h"
32 #include "TClass.h"
33 
34 //=============================================
35 //======= TFCSBinnedShowerBase =========
36 //=============================================
37 
41 }
42 
44 
46  TFCSSimulationState &simulstate, const TFCSTruthState *truth,
47  const TFCSExtrapolationState *extrapol) const {
48 
49  // select a random event from the library
50  float eta_center, phi_center;
51  long unsigned int reference_layer_index = CaloCell_ID_FCS::CaloSample_FCS::EMB2;
52  eta_center =
53  extrapol->eta(reference_layer_index, TFCSExtrapolationState::SUBPOS_MID);
54  if (eta_center > 1.4) { // Endcap becomes more relevant
55  reference_layer_index = CaloCell_ID_FCS::CaloSample_FCS::EME2;
56  }
57  // TODO: What about the endcap?
58  eta_center =
59  extrapol->eta(reference_layer_index, TFCSExtrapolationState::SUBPOS_MID);
60  phi_center =
61  extrapol->phi(reference_layer_index, TFCSExtrapolationState::SUBPOS_MID);
62 
63  // Fill the total energy and layer energies into simulstate
64  float Einit;
65  const float Ekin = truth->Ekin();
66 
67  if (OnlyScaleEnergy())
68  Einit = simulstate.E();
69  else
70  Einit = Ekin;
71 
72  // Reset the total energy
73  simulstate.set_E(0);
74 
75  get_event(simulstate, eta_center, phi_center, Einit, reference_layer_index);
76 
77  for (long unsigned int layer_index = 0;
78  layer_index < CaloCell_ID_FCS::MaxSample; ++layer_index) {
79 
80  float layer_energy = get_layer_energy(simulstate, layer_index);
81 
82  // Reset and set the layer energy
83  simulstate.set_E(layer_index, 0);
84  simulstate.add_E(layer_index, layer_energy);
85  }
86 
87  if (simulstate.E() > std::numeric_limits<double>::epsilon()) {
88  for (int ilayer = 0; ilayer < CaloCell_ID_FCS::MaxSample; ++ilayer) {
89  simulstate.set_Efrac(ilayer, simulstate.E(ilayer) / simulstate.E());
90  }
91  }
92  return FCSSuccess;
93 }
94 
96  Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth,
98 
99  // Extrapol unused, but needed for the interface
100  (void)extrapol;
101 
102  const int pdgId = truth->pdgid();
103  const float charge = HepPDT::ParticleID(pdgId).charge();
104  long unsigned int layer_index = calosample();
105 
106  const double center_eta = hit.center_eta();
107  const double center_phi = hit.center_phi();
108  const double center_r = hit.center_r();
109  const double center_z = hit.center_z();
110 
111  ATH_MSG_VERBOSE(" Layer " << layer_index << " Extrap eta " << center_eta
112  << " phi " << center_phi << " R " << center_r);
113 
114  const float dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
115  const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
116  (1.0 + TMath::Exp(-2 * center_eta)));
117 
118  long unsigned int hit_index = hit.idx();
119 
120  // Get necessary the hit information
121  float r, alpha, E;
122  std::tie(r, alpha, E) =
123  get_hit_position_and_energy(simulstate, layer_index, hit_index);
124 
125  hit.reset();
126  hit.E() = E;
127 
128  if (layer_index <= CaloCell_ID_FCS::CaloSample_FCS::FCAL0) {
129  float delta_eta_mm = r * cos(alpha);
130  float delta_phi_mm = r * sin(alpha);
131 
132  // Particles with negative eta are expected to have the same shape
133  // as those with positive eta after transformation: delta_eta -->
134  // -delta_eta
135  if (center_eta < 0.) {
136  delta_eta_mm = -delta_eta_mm;
137  }
138 
139  // We derive the shower shapes for electrons and positively charged
140  // hadrons. Particle with the opposite charge are expected to have the
141  // same shower shape after the transformation: delta_phi -->
142  // -delta_phi
143  if ((charge < 0. && pdgId != 11) || pdgId == -11)
144  delta_phi_mm = -delta_phi_mm;
145 
146  const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
147  const float delta_phi = delta_phi_mm / center_r;
148 
149  hit.eta() = center_eta + delta_eta;
150  hit.phi() = TVector2::Phi_mpi_pi(center_phi + delta_phi);
151 
152  ATH_MSG_VERBOSE(" Hit eta " << hit.eta() << " phi " << hit.phi()
153  << " layer " << layer_index);
154 
155  } else { // FCAL is in (x,y,z)
156  const float hit_r = r * cos(alpha) + center_r;
157  float delta_phi = r * sin(alpha) / center_r;
158  // We derive the shower shapes for electrons and positively charged
159  // hadrons. Particle with the opposite charge are expected to have the
160  // same shower shape after the transformation: delta_phi -->
161  // -delta_phi
162  if ((charge < 0. && pdgId != 11) || pdgId == -11)
163  delta_phi = -delta_phi;
164  const float hit_phi = TVector2::Phi_mpi_pi(center_phi + delta_phi);
165  hit.x() = hit_r * cos(hit_phi);
166  hit.y() = hit_r * sin(hit_phi);
167  hit.z() = center_z;
168  ATH_MSG_VERBOSE(" Hit x " << hit.x() << " y " << hit.y() << " layer "
169  << layer_index);
170  }
171 
172  return FCSSuccess;
173 }
beamspotman.r
def r
Definition: beamspotman.py:672
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
TFCSLateralShapeParametrizationHitBase::Hit::x
float & x()
Definition: TFCSLateralShapeParametrizationHitBase.h:88
TFCSLateralShapeParametrizationHitBase::Hit::phi
float & phi()
Definition: TFCSLateralShapeParametrizationHitBase.h:87
add-xsec-uncert-quadrature-N.alpha
alpha
Definition: add-xsec-uncert-quadrature-N.py:110
TFCSBinnedShowerBase::~TFCSBinnedShowerBase
virtual ~TFCSBinnedShowerBase()
Definition: TFCSBinnedShowerBase.cxx:43
TFCSLateralShapeParametrizationHitBase::Hit::y
float & y()
Definition: TFCSLateralShapeParametrizationHitBase.h:89
TFCSLateralShapeParametrizationHitBase::Hit::reset
void reset()
Definition: TFCSLateralShapeParametrizationHitBase.h:78
TFCSBinnedShowerBase::get_layer_energy
virtual float get_layer_energy(TFCSSimulationState &simulstate, long unsigned int layer_index) const =0
CaloClusterMLCalib::epsilon
constexpr float epsilon
Definition: CaloClusterMLGaussianMixture.h:16
TFCSBinnedShowerBase::OnlyScaleEnergy
bool OnlyScaleEnergy() const
Definition: TFCSBinnedShowerBase.h:35
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
TFCSLateralShapeParametrizationHitBase::Hit
Definition: TFCSLateralShapeParametrizationHitBase.h:42
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
TFCSExtrapolationState::SUBPOS_MID
@ SUBPOS_MID
Definition: TFCSExtrapolationState.h:20
RunActsMaterialValidation.extrapol
extrapol
Definition: RunActsMaterialValidation.py:91
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TFCSLateralShapeParametrizationHitBase::Hit::center_phi
float & center_phi()
Definition: TFCSLateralShapeParametrizationHitBase.h:102
Phi_mpi_pi
__HOSTDEV__ double Phi_mpi_pi(double)
Definition: GeoRegion.cxx:10
TFCSLateralShapeParametrizationHitBase
Definition: TFCSLateralShapeParametrizationHitBase.h:13
TFCSLateralShapeParametrizationHitBase::Hit::E
float & E()
Definition: TFCSLateralShapeParametrizationHitBase.h:90
TFCSSimulationState::add_E
void add_E(int sample, double Esample)
Definition: TFCSSimulationState.h:53
TFCSBinnedShowerBase.h
TFCSLateralShapeParametrizationHitBase.h
CaloCell_ID_FCS::MaxSample
@ MaxSample
Definition: FastCaloSim_CaloCell_ID.h:47
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
TFCSTruthState::Ekin
double Ekin() const
Definition: TFCSTruthState.h:26
covarianceTool.title
title
Definition: covarianceTool.py:542
TFCSLateralShapeParametrizationHitBase::Hit::center_z
float & center_z()
Definition: TFCSLateralShapeParametrizationHitBase.h:100
jobOptions.ParticleID
ParticleID
Definition: jobOptions.decayer.py:85
TFCSBinnedShowerBase::TFCSBinnedShowerBase
TFCSBinnedShowerBase(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSBinnedShowerBase.cxx:38
TFCSLateralShapeParametrizationHitBase::Hit::idx
long unsigned int & idx()
Definition: TFCSLateralShapeParametrizationHitBase.h:92
FCSSuccess
@ FCSSuccess
Definition: TFCSParametrizationBase.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
TFCSSimulationState::set_E
void set_E(int sample, double Esample)
Definition: TFCSSimulationState.h:48
charge
double charge(const T &p)
Definition: AtlasPID.h:997
runIDPVM.pdgId
pdgId
Definition: runIDPVM.py:91
TFCSTruthState::pdgid
int pdgid() const
Definition: TFCSTruthState.h:25
TFCSLateralShapeParametrizationHitBase::Hit::z
float & z()
Definition: TFCSLateralShapeParametrizationHitBase.h:91
TFCSBinnedShowerBase::simulate_hit
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
simulated one hit position with some energy.
Definition: TFCSBinnedShowerBase.cxx:95
TFCSTruthState.h
TFCSLateralShapeParametrization::calosample
int calosample() const
Definition: TFCSLateralShapeParametrization.h:34
TFCSExtrapolationState.h
eFEXNTuple.delta_phi
def delta_phi(phi1, phi2)
Definition: eFEXNTuple.py:14
TFCSBinnedShowerBase::get_event
virtual void get_event(TFCSSimulationState &simulstate, float eta_center, float phi_center, float e_init, long unsigned int reference_layer_index) const =0
do not persistify
TFCSLateralShapeParametrizationHitBase::Hit::center_eta
float & center_eta()
Definition: TFCSLateralShapeParametrizationHitBase.h:101
TFCSLateralShapeParametrizationHitBase::Hit::center_r
float & center_r()
Definition: TFCSLateralShapeParametrizationHitBase.h:99
TFCSLateralShapeParametrizationHitBase::Hit::eta
float & eta()
Definition: TFCSLateralShapeParametrizationHitBase.h:86
TFCSSimulationState::E
double E() const
Definition: TFCSSimulationState.h:42
TFCSBinnedShowerBase::get_hit_position_and_energy
virtual std::tuple< float, float, float > get_hit_position_and_energy(TFCSSimulationState &simulstate, long unsigned int layer_index, long unsigned int hit_index) const =0
TFCSSimulationState.h
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
ICaloGeometry.h
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
TFCSBinnedShowerBase::reset_OnlyScaleEnergy
void reset_OnlyScaleEnergy()
Definition: TFCSBinnedShowerBase.h:39
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
TFCSBinnedShowerBase::simulate
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
Definition: TFCSBinnedShowerBase.cxx:45
TFCSSimulationState::set_Efrac
void set_Efrac(int sample, double Efracsample)
Definition: TFCSSimulationState.h:49