|
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"
20 #if defined(__FastCaloSimStandAlone__)
21 #include "CLHEP/Random/TRandomEngine.h"
23 #include <CLHEP/Random/RanluxEngine.h>
72 const std::string &FastCaloGANInputFolderName) {
78 "Using FastCaloGANInputFolderName: " << FastCaloGANInputFolderName);
93 if (
pid != 22 &&
pid != 11) {
109 Form(
"layer=%d", simulstate.
getAuxInfo<
int>(
"GANlayer"_FCShash)));
125 const int pdgId = truth->
pdgid();
129 const float Ekin = truth->
Ekin();
131 Einit = simulstate.
E();
153 double totalEnergy = 0;
155 totalEnergy +=
output.second;
157 if (totalEnergy < 0) {
167 for (
const auto &element : binsInLayers) {
168 const int layer = element.first;
169 const TH2D *
h = &element.second;
190 const int xBinNum =
h->GetNbinsX();
191 const int yBinNum =
h->GetNbinsY();
192 const TAxis *
x =
h->GetXaxis();
198 <<
" has only one bin in r, this means is it not used, "
199 "skipping (this is needed to keep correct "
200 "syncronisation of voxel and layers)");
208 for (
int ix = 1; ix <= xBinNum; ++ix) {
210 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
213 <<
" binx " << ix <<
" biny " << iy);
215 if (energyInVoxel <= 0) {
220 simulstate.
add_E(
layer, Einit * energyInVoxel);
226 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
235 for (
const auto &element : binsInLayers) {
236 const int layer = element.first;
237 const TH2D *
h = &element.second;
238 const int xBinNum =
h->GetNbinsX();
239 const int yBinNum =
h->GetNbinsY();
240 const TAxis *
x =
h->GetXaxis();
241 const TAxis *
y =
h->GetYaxis();
250 <<
" has only one bin in r, this means is it not used, "
251 "skipping (this is needed to keep correct "
252 "syncronisation of voxel and layers)");
266 <<
chain()[ichain]->GetName());
267 if (
chain()[ichain]->InheritsFrom(
268 TFCSLateralShapeParametrizationHitBase::Class())) {
276 <<
chain()[ichain]->GetName());
283 <<
chain()[ichain]->GetName()
284 <<
" does not inherit from "
285 "TFCSLateralShapeParametrizationHitBase");
296 int binResolution = 5;
301 const double center_eta = hit.center_eta();
302 const double center_phi = hit.center_phi();
303 const double center_r = hit.center_r();
304 const double center_z = hit.center_z();
307 <<
" phi " << center_phi <<
" R " << center_r);
309 const float dist000 =
310 TMath::Sqrt(center_r * center_r + center_z * center_z);
311 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
312 (1.0 + TMath::Exp(-2 * center_eta)));
318 for (
int ix = 1; ix <= xBinNum; ++ix) {
322 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
323 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
325 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
328 <<
" binx " << ix <<
" biny " << iy);
330 if (energyInVoxel <= 0) {
335 if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
337 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
338 if (maxHitsInVoxel < 1)
340 nHitsAlpha = std::sqrt(maxHitsInVoxel);
341 nHitsR = std::sqrt(maxHitsInVoxel);
344 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
347 const double r =
x->GetBinUpEdge(ix);
348 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
352 const TAxis *
y =
h->GetYaxis();
353 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
354 const double r =
x->GetBinUpEdge(ix);
356 nHitsAlpha = ceil(
d / binResolution);
363 const int maxNhits = 10;
369 for (
int ir = 0;
ir < nHitsR; ++
ir) {
371 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
373 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
374 if (ganVersion > 1) {
375 if (fitResults.at(
layer)[ix - 1] != 0) {
378 x->GetBinLowEdge(ix),
379 x->GetBinUpEdge(ix));
381 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
382 fitResults.at(
layer)[ix - 1];
383 while ((rand_r < x->GetBinLowEdge(ix) ||
384 rand_r >
x->GetBinUpEdge(ix)) &&
387 x->GetBinLowEdge(ix),
388 x->GetBinUpEdge(ix));
390 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
391 fitResults.at(
layer)[ix - 1];
396 <<
x->GetBinLowEdge(ix) <<
"-"
397 <<
x->GetBinUpEdge(ix) <<
"] having slope "
398 << fitResults.at(
layer)[ix - 1]
399 <<
" will use grid (old method)");
407 if (binsInAlphaInRBin == 1) {
408 alpha = CLHEP::RandFlat::shoot(simulstate.
randomEngine(),
409 -TMath::Pi(), TMath::Pi());
412 y->GetBinLowEdge(lowEdgeIndex) +
413 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
417 -TMath::Pi(), TMath::Pi()) < 0) {
424 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
427 float delta_eta_mm =
r *
cos(alpha);
428 float delta_phi_mm =
r *
sin(alpha);
438 delta_eta_mm = -delta_eta_mm;
443 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
444 delta_phi_mm = -delta_phi_mm;
446 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
447 const float delta_phi = delta_phi_mm / center_r;
449 hit.eta() = center_eta + delta_eta;
453 <<
" layer " <<
layer);
455 const float hit_r =
r *
cos(alpha) + center_r;
461 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
463 const float hit_phi =
465 hit.x() = hit_r *
cos(hit_phi);
466 hit.y() = hit_r *
sin(hit_phi);
469 <<
" layer " <<
layer);
475 for (
unsigned int ichain =
481 <<
chain()[ichain]->GetName());
482 if (
chain()[ichain]->InheritsFrom(
483 TFCSLateralShapeParametrizationHitBase::Class())) {
493 <<
chain()[ichain]->GetName());
500 <<
chain()[ichain]->GetName()
501 <<
" does not inherit from "
502 "TFCSLateralShapeParametrizationHitBase");
525 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
527 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
538 for (
unsigned int ichain = 0; ichain <
m_bin_start[0]; ++ichain) {
559 const bool shortprint =
opt.Index(
"short") >= 0;
560 const bool longprint =
562 TString optprint =
opt;
563 optprint.ReplaceAll(
"short",
"");
566 for (
unsigned int ichain = 0; ichain <
size(); ++ichain) {
567 if (ichain == 0 && ichain !=
m_bin_start.front()) {
577 prefix = Form(
"%-2d", ibin);
597 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
598 "InputsToBigParamFiles/FastCaloGANWeightsVer02/";
603 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
604 "InputsToBigParamFiles/FastCaloGANWeightsONNXVer08/";
613 const std::string &outputname,
int pid) {
618 #if defined(__FastCaloSimStandAlone__)
627 t->SetPtEtaPhiM(65536, 0, 0, 139.6);
633 e->set_IDCaloBoundary_eta(truth->Eta());
634 for (
int i = 0;
i < 24; ++
i) {
657 for (
int i = 0;
i < 24; ++
i)
660 Form(
"center%d",
i), Form(
"center layer %d",
i));
661 c->set_calosample(
i);
662 c->setExtrapWeight(0.5);
663 c->setLevel(MSG::INFO);
669 c->set_eta_min(
etaMin / 100.0);
670 c->set_eta_max(
etaMax / 100.0);
680 const std::string
outname =
"FCSGANtest_" + outputname +
".root";
681 TFile *fGAN = TFile::Open(
outname.c_str(),
"recreate");
684 fGAN->WriteObjectAny(&GAN,
"TFCSEnergyAndHitGANV2",
"GAN");
690 fGAN = TFile::Open(
outname.c_str());
713 double binsInAlphaInRBin = yBinNum;
716 const double widthX =
x->GetBinWidth(ix);
717 const double radious =
x->GetBinCenter(ix);
718 double circumference = radious * 2 * TMath::Pi();
720 circumference = radious * TMath::Pi();
723 const double bins = circumference / widthX;
725 ATH_MSG_DEBUG(
"Bin in alpha: " << binsInAlphaInRBin <<
" for r bin: " << ix
726 <<
" (" <<
x->GetBinLowEdge(ix) <<
"-"
727 <<
x->GetBinUpEdge(ix) <<
")");
729 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)
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...