ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
51bool 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
58bool 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
127void 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}
static Double_t a
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
#define y
#define x
TFCSLateralShapeParametrizationHitBase(const char *name=nullptr, const char *title=nullptr)
TFCSSimpleLateralShapeParametrization(const char *name=nullptr, const char *title=nullptr)
void getHitXY(CLHEP::HepRandomEngine *engine, double &x, double &y) const
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
simulated one hit position with some energy.
bool Initialize(const char *filepath, const char *histname)
CLHEP::HepRandomEngine * randomEngine()
int r
Definition globals.cxx:22