 |
ATLAS Offline Software
|
Go to the documentation of this file.
7 #include "CLHEP/Random/RandFlat.h"
8 #include "CLHEP/Random/RandGauss.h"
9 #include "HepPDT/ParticleData.hh"
10 #include "HepPDT/ParticleDataTable.hh"
21 #if defined(__FastCaloSimStandAlone__)
22 #include "CLHEP/Random/TRandomEngine.h"
24 #include <CLHEP/Random/RanluxEngine.h>
73 const std::string &FastCaloGANInputFolderName) {
79 "Using FastCaloGANInputFolderName: " << FastCaloGANInputFolderName);
94 if (
pid != 22 &&
pid != 11) {
110 Form(
"layer=%d", simulstate.
getAuxInfo<
int>(
"GANlayer"_FCShash)));
130 const float Ekin = truth->
Ekin();
132 Einit = simulstate.
E();
154 double totalEnergy = 0;
156 totalEnergy +=
output.second;
158 if (totalEnergy < 0) {
168 for (
const auto &[
layer,
h] : binsInLayers) {
188 const int xBinNum =
h.GetNbinsX();
189 const int yBinNum =
h.GetNbinsY();
190 const TAxis *
x =
h.GetXaxis();
196 <<
" has only one bin in r, this means is it not used, "
197 "skipping (this is needed to keep correct "
198 "syncronisation of voxel and layers)");
206 for (
int ix = 1; ix <= xBinNum; ++ix) {
208 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
211 <<
" binx " << ix <<
" biny " << iy);
213 if (energyInVoxel <= 0) {
218 simulstate.
add_E(
layer, Einit * energyInVoxel);
224 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
233 for (
const auto &[
layer,
h] : binsInLayers) {
234 const int xBinNum =
h.GetNbinsX();
235 const int yBinNum =
h.GetNbinsY();
236 const TAxis *
x =
h.GetXaxis();
237 const TAxis *
y =
h.GetYaxis();
246 <<
" has only one bin in r, this means is it not used, "
247 "skipping (this is needed to keep correct "
248 "syncronisation of voxel and layers)");
262 <<
chain()[ichain]->GetName());
263 if (
chain()[ichain]->InheritsFrom(
264 TFCSLateralShapeParametrizationHitBase::Class())) {
272 <<
chain()[ichain]->GetName());
279 <<
chain()[ichain]->GetName()
280 <<
" does not inherit from "
281 "TFCSLateralShapeParametrizationHitBase");
292 int binResolution = 5;
297 const double center_eta = hit.center_eta();
298 const double center_phi = hit.center_phi();
299 const double center_r = hit.center_r();
300 const double center_z = hit.center_z();
303 <<
" phi " << center_phi <<
" R " << center_r);
305 const float dist000 =
306 TMath::Sqrt(center_r * center_r + center_z * center_z);
307 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
308 (1.0 + TMath::Exp(-2 * center_eta)));
314 for (
int ix = 1; ix <= xBinNum; ++ix) {
318 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
319 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
321 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
324 <<
" binx " << ix <<
" biny " << iy);
326 if (energyInVoxel <= 0) {
331 if (std::abs(
pdgId) == 22 || std::abs(
pdgId) == 11) {
333 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
334 if (maxHitsInVoxel < 1)
336 nHitsAlpha = std::sqrt(maxHitsInVoxel);
337 nHitsR = std::sqrt(maxHitsInVoxel);
340 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
343 const double r =
x->GetBinUpEdge(ix);
344 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
348 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
349 const double r =
x->GetBinUpEdge(ix);
351 nHitsAlpha = ceil(
d / binResolution);
358 const int maxNhits = 10;
364 for (
int ir = 0;
ir < nHitsR; ++
ir) {
366 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
368 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
369 if (ganVersion > 1) {
370 if (fitResults.at(
layer)[ix - 1] != 0) {
373 x->GetBinLowEdge(ix),
374 x->GetBinUpEdge(ix));
376 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
377 fitResults.at(
layer)[ix - 1];
378 while ((rand_r < x->GetBinLowEdge(ix) ||
379 rand_r >
x->GetBinUpEdge(ix)) &&
382 x->GetBinLowEdge(ix),
383 x->GetBinUpEdge(ix));
385 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
386 fitResults.at(
layer)[ix - 1];
391 <<
x->GetBinLowEdge(ix) <<
"-"
392 <<
x->GetBinUpEdge(ix) <<
"] having slope "
393 << fitResults.at(
layer)[ix - 1]
394 <<
" will use grid (old method)");
402 if (binsInAlphaInRBin == 1) {
404 -TMath::Pi(), TMath::Pi());
407 y->GetBinLowEdge(lowEdgeIndex) +
408 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
412 -TMath::Pi(), TMath::Pi()) < 0) {
419 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
433 delta_eta_mm = -delta_eta_mm;
439 delta_phi_mm = -delta_phi_mm;
441 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
442 const float delta_phi = delta_phi_mm / center_r;
444 hit.eta() = center_eta + delta_eta;
448 <<
" layer " <<
layer);
450 const float hit_r =
r *
cos(
alpha) + center_r;
458 const float hit_phi =
460 hit.x() = hit_r *
cos(hit_phi);
461 hit.y() = hit_r *
sin(hit_phi);
464 <<
" layer " <<
layer);
470 for (
unsigned int ichain =
476 <<
chain()[ichain]->GetName());
477 if (
chain()[ichain]->InheritsFrom(
478 TFCSLateralShapeParametrizationHitBase::Class())) {
488 <<
chain()[ichain]->GetName());
495 <<
chain()[ichain]->GetName()
496 <<
" does not inherit from "
497 "TFCSLateralShapeParametrizationHitBase");
520 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
522 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
533 for (
unsigned int ichain = 0; ichain <
m_bin_start[0]; ++ichain) {
554 const bool shortprint =
opt.Index(
"short") >= 0;
555 const bool longprint =
557 TString optprint =
opt;
558 optprint.ReplaceAll(
"short",
"");
561 for (
unsigned int ichain = 0; ichain <
size(); ++ichain) {
562 if (ichain == 0 && ichain !=
m_bin_start.front()) {
572 prefix = Form(
"%-2d", ibin);
592 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
593 "InputsToBigParamFiles/FastCaloGANWeightsVer02/";
598 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
599 "InputsToBigParamFiles/FastCaloGANWeightsONNXVer08/";
608 const std::string &outputname,
int pid) {
613 #if defined(__FastCaloSimStandAlone__)
628 e->set_IDCaloBoundary_eta(truth->Eta());
629 for (
int i = 0;
i < 24; ++
i) {
652 for (
int i = 0;
i < 24; ++
i)
655 Form(
"center%d",
i), Form(
"center layer %d",
i));
656 c->set_calosample(
i);
657 c->setExtrapWeight(0.5);
664 c->set_eta_min(
etaMin / 100.0);
665 c->set_eta_max(
etaMax / 100.0);
675 const std::string
outname =
"FCSGANtest_" + outputname +
".root";
676 TFile *fGAN = TFile::Open(
outname.c_str(),
"recreate");
679 fGAN->WriteObjectAny(&GAN,
"TFCSEnergyAndHitGANV2",
"GAN");
685 fGAN = TFile::Open(
outname.c_str());
708 double binsInAlphaInRBin = yBinNum;
711 const double widthX =
x->GetBinWidth(ix);
712 const double radious =
x->GetBinCenter(ix);
713 double circumference = radious * 2 * TMath::Pi();
715 circumference = radious * TMath::Pi();
718 const double bins = circumference / widthX;
720 ATH_MSG_DEBUG(
"Bin in alpha: " << binsInAlphaInRBin <<
" for r bin: " << ix
721 <<
" (" <<
x->GetBinLowEdge(ix) <<
"-"
722 <<
x->GetBinUpEdge(ix) <<
")");
724 return binsInAlphaInRBin;
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol)
simulated one hit position with some energy.
const T getAuxInfo(std::uint32_t index) const
virtual const std::string get_bin_text(int bin) const
print the range of a bin; for bin -1, print the allowed range
path
python interpreter configuration --------------------------------------—
std::string find(const std::string &s)
return a remapped string
const TFCSGANXMLParameters::Binning & get_Binning() const
bool initializeNetwork(int const &pid, int const &etaMin, const std::string &FastCaloGANInputFolderName)
void InitialiseFromXML(int pid, int etaMid, const std::string &FastCaloGANInputFolderName)
std::map< std::string, double > NetworkOutputs
virtual void add_pdgid(int id)
static int GetBinsInFours(double const &bins)
virtual void push_back_in_bin(TFCSParametrizationBase *param, unsigned int bin)
std::map< int, TH2D > Binning
bool OnlyScaleEnergy() const
CLHEP::HepRandomEngine * randomEngine()
void set_nr_of_init(unsigned int bin, unsigned int ninit)
#define ATH_MSG_VERBOSE(x)
void Print(Option_t *option="") const
__HOSTDEV__ double Phi_mpi_pi(double)
virtual void set_eta_max(double max)
virtual void set_pdgid(int id)
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)
virtual unsigned int get_number_of_bins() const
void add_E(int sample, double Esample)
const Chain_t & chain() const
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
TFCSGANEtaSlice * m_slice
virtual ~TFCSEnergyAndHitGANV2()
int GetAlphaBinsForRBin(const TAxis *x, int ix, int yBinNum) const
void Print(Option_t *option="") const
Print object information.
std::map< int, std::vector< double > > FitResultsPerLayer
void Print(Option_t *option="") const
bool IsGanCorrectlyLoaded() const
const FitResultsPerLayer & GetFitResults() const
virtual void reset_match_all_pdgid()
virtual void set_eta_nominal(double min)
std::string to_string(const DetectorType &type)
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
void setAuxInfo(std::uint32_t index, const T &val)
void set_E(int sample, double Esample)
double charge(const T &p)
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
int GetGANVersion() const
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
NetworkOutputs GetNetworkOutputs(const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol, TFCSSimulationState simulstate) const
void setRandomEngine(CLHEP::HepRandomEngine *engine)
std::vector< int > m_bin_ninit
int ir
counter of the current depth
TFCSGANXMLParameters m_param
#define ATH_MSG_NOCLASS(logger_name, x)
#define ATH_MSG_WARNING(x)
virtual bool is_match_calosample(int calosample) const override
virtual int get_bin(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
use the layer to be done as binning of the GAN chain
def delta_phi(phi1, phi2)
FCSReturnCode simulate_and_retry(TFCSParametrizationBase *parametrization, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
virtual void set_eta_min(double min)
bool fillEnergy(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
unsigned int get_nr_of_init(unsigned int bin) const
TFCSEnergyAndHitGANV2(const char *name=nullptr, const char *title=nullptr)
static void test_path(const std::string &path, TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr, const std::string &outputname="unnamed", int pid=211)
virtual void Print(Option_t *option="") const override
bool IsSymmetrisedAlpha() const
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
std::vector< unsigned int > m_bin_start
Contains the index where the TFCSParametrizationBase* instances to run for a given bin start.
const Binning & GetBinning() const
void set_Efrac(int sample, double Efracsample)
virtual const std::string get_variable_text(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
virtual unsigned int size() const override
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...