ATLAS Offline Software
TFCSSimpleLateralShapeParametrization.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CLHEP/Random/RandGaussZiggurat.h"
6 
11 
12 #include "TMath.h"
13 
14 //=============================================
15 //======= TFCSLateralShapeParametrization =========
16 //=============================================
17 
20 {
21  m_sigmaX = 0;
22  m_sigmaY = 0;
23 }
24 
25 
27 {
28  if (!simulstate.randomEngine()) {
29  return FCSFatal;
30  }
31 
32  int cs=calosample();
33  hit.eta()=0.5*( extrapol->eta(cs, CaloSubPos::SUBPOS_ENT) + extrapol->eta(cs, CaloSubPos::SUBPOS_EXT) );
34  hit.phi()=0.5*( extrapol->phi(cs, CaloSubPos::SUBPOS_ENT) + extrapol->phi(cs, CaloSubPos::SUBPOS_EXT) );
35  hit.E()*=1;
36 
37  double x, y;
38  getHitXY(simulstate.randomEngine(), x, y);
39 
40  // delta_eta and delta_phi;
41  double delta_eta = x;
42  double delta_phi = y;
43 
44  hit.eta() += delta_eta;
45  hit.phi() += delta_phi;
46 
47  return FCSSuccess;
48 }
49 
50 
51 bool TFCSSimpleLateralShapeParametrization::Initialize(float input_sigma_x, float input_sigma_y)
52 {
53  m_sigmaX = input_sigma_x;
54  m_sigmaY = input_sigma_y;
55  return true;
56 }
57 
58 bool TFCSSimpleLateralShapeParametrization::Initialize(const char* filepath, const char* histname)
59 {
60  // input file with histogram to fit
61  TFile *f = new TFile(filepath);
62  if (f == nullptr) return false;
63 
64  // histogram with hit pattern
65  TH2D *inputShape = (TH2D*)f->Get(histname);
66  if (inputShape == nullptr) return false;
67 
68  // Function to fit with
69  double hiEdge = inputShape->GetYaxis()->GetBinLowEdge( inputShape->GetNbinsY() );
70  TF1 *x_func = new TF1("fx","gaus",-hiEdge,hiEdge);
71  TF1 *y_func = new TF1("fy","gaus",-hiEdge,hiEdge);
72 
73  // Project into x and y histograms
74  TH1F *h_xrms = new TH1F("h_xrms","h_xrms",100,-hiEdge,hiEdge);
75  TH1F *h_yrms = new TH1F("h_yrms","h_yrms",100,-hiEdge,hiEdge);
76 
77  double val = 0; // bin content
78  double r = 0; // radius
79  double a = 0; // angle
80  double ypos= 0;
81  double xpos= 0;
82 
83  // Loop over to project along axes, takes bin center as position
84  for (int xbin = 1; xbin < inputShape->GetNbinsX() + 1; xbin++)
85  {
86  a = inputShape->GetXaxis()->GetBinCenter(xbin);
87 
88  for (int ybin = 1; ybin < inputShape->GetNbinsY() + 1; ybin++)
89  {
90  val = inputShape->GetBinContent(xbin,ybin);
91 
92  r = inputShape->GetYaxis()->GetBinCenter(ybin);
93 
94  ypos = r * TMath::Sin( a );
95  xpos = r * TMath::Cos( a );
96 
97  h_xrms->Fill( xpos, val);
98  h_yrms->Fill( ypos, val);
99 
100  }
101  }
102 
103  h_xrms->Fit(x_func,"0");
104  TF1 *fitx = h_xrms->GetFunction("fx");
105  // posibly center
106 
107  h_yrms->Fit(y_func,"0");
108  TF1 *fity = h_yrms->GetFunction("fy");
109  // posibly center
110 
111  // Finally set sigma
112  m_sigmaX = fitx->GetParameter(2);
113  m_sigmaY = fity->GetParameter(2);
114 
115 
116  // clean up
117  delete x_func;
118  delete y_func;
119 
120  delete h_xrms;
121  delete h_yrms;
122  f->Close();
123 
124  return true;
125 }
126 
127 void TFCSSimpleLateralShapeParametrization::getHitXY(CLHEP::HepRandomEngine *engine, double &x, double &y) const
128 {
129  x = CLHEP::RandGaussZiggurat::shoot(engine, 0, m_sigmaX);
130  y = CLHEP::RandGaussZiggurat::shoot(engine, 0, m_sigmaY);
131 }
beamspotman.r
def r
Definition: beamspotman.py:676
TH2D::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:435
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition: TFCSParametrizationBase.h:41
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
TFCSLateralShapeParametrizationHitBase::Hit::phi
float & phi()
Definition: TFCSLateralShapeParametrizationHitBase.h:87
TFCSSimpleLateralShapeParametrization::TFCSSimpleLateralShapeParametrization
TFCSSimpleLateralShapeParametrization(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSSimpleLateralShapeParametrization.cxx:18
TFCSExtrapolationState
Definition: TFCSExtrapolationState.h:13
TFCSSimulationState::randomEngine
CLHEP::HepRandomEngine * randomEngine()
Definition: TFCSSimulationState.h:36
TFCSLateralShapeParametrizationHitBase::Hit
Definition: TFCSLateralShapeParametrizationHitBase.h:42
RunActsMaterialValidation.extrapol
extrapol
Definition: RunActsMaterialValidation.py:90
TFCSSimpleLateralShapeParametrization::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: TFCSSimpleLateralShapeParametrization.cxx:26
x
#define x
TFCSLateralShapeParametrizationHitBase
Definition: TFCSLateralShapeParametrizationHitBase.h:13
TFCSLateralShapeParametrizationHitBase::Hit::E
float & E()
Definition: TFCSLateralShapeParametrizationHitBase.h:90
TFCSSimpleLateralShapeParametrization::m_sigmaY
float m_sigmaY
Definition: TFCSSimpleLateralShapeParametrization.h:40
TFCSSimpleLateralShapeParametrization::Initialize
bool Initialize(const char *filepath, const char *histname)
Definition: TFCSSimpleLateralShapeParametrization.cxx:58
PixelAthClusterMonAlgCfg.histname
histname
Definition: PixelAthClusterMonAlgCfg.py:106
covarianceTool.title
title
Definition: covarianceTool.py:542
TH2D
Definition: rootspy.cxx:430
FCSFatal
@ FCSFatal
Definition: TFCSParametrizationBase.h:41
SUBPOS_ENT
@ SUBPOS_ENT
Definition: FastCaloSim_CaloCell_ID.h:12
FCSSuccess
@ FCSSuccess
Definition: TFCSParametrizationBase.h:41
TFCSSimpleLateralShapeParametrization.h
TFCSSimpleLateralShapeParametrization::getHitXY
void getHitXY(CLHEP::HepRandomEngine *engine, double &x, double &y) const
Definition: TFCSSimpleLateralShapeParametrization.cxx:127
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SUBPOS_EXT
@ SUBPOS_EXT
Definition: FastCaloSim_CaloCell_ID.h:13
a
TList * a
Definition: liststreamerinfos.cxx:10
y
#define y
TH1F
Definition: rootspy.cxx:320
TFCSSimpleLateralShapeParametrization::m_sigmaX
float m_sigmaX
Definition: TFCSSimpleLateralShapeParametrization.h:35
TFCSLateralShapeParametrization::calosample
int calosample() const
Definition: TFCSLateralShapeParametrization.h:34
TFCSExtrapolationState.h
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
eFEXNTuple.delta_phi
def delta_phi(phi1, phi2)
Definition: eFEXNTuple.py:15
TFCSLateralShapeParametrizationHitBase::Hit::eta
float & eta()
Definition: TFCSLateralShapeParametrizationHitBase.h:86
TFCSSimulationState.h
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
FastCaloSim_CaloCell_ID.h
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSSimulationState
Definition: TFCSSimulationState.h:32