From d86383162d107037919fca4cc623db76a3ad23e3 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Fri, 3 Nov 2023 11:16:33 +0100 Subject: [PATCH 01/21] TRestGeant4PrimaryGeneratorInfo. Adding CRY generator type --- inc/TRestGeant4PrimaryGeneratorInfo.h | 1 + src/TRestGeant4PrimaryGeneratorInfo.cxx | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/inc/TRestGeant4PrimaryGeneratorInfo.h b/inc/TRestGeant4PrimaryGeneratorInfo.h index e5a49cb..6e52b8a 100644 --- a/inc/TRestGeant4PrimaryGeneratorInfo.h +++ b/inc/TRestGeant4PrimaryGeneratorInfo.h @@ -17,6 +17,7 @@ enum class SpatialGeneratorTypes { SURFACE, POINT, COSMIC, + CRY, }; std::string SpatialGeneratorTypesToString(const SpatialGeneratorTypes&); diff --git a/src/TRestGeant4PrimaryGeneratorInfo.cxx b/src/TRestGeant4PrimaryGeneratorInfo.cxx index 5101473..0e837b0 100644 --- a/src/TRestGeant4PrimaryGeneratorInfo.cxx +++ b/src/TRestGeant4PrimaryGeneratorInfo.cxx @@ -28,6 +28,8 @@ string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const Spa return "Point"; case SpatialGeneratorTypes::COSMIC: return "Cosmic"; + case SpatialGeneratorTypes::CRY: + return "Cry"; } cout << "TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString - Error - Unknown " "SpatialGeneratorTypes" @@ -51,6 +53,9 @@ SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGenerator } else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::COSMIC), TString::ECaseCompare::kIgnoreCase)) { return SpatialGeneratorTypes::COSMIC; + } else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::CRY), + TString::ECaseCompare::kIgnoreCase)) { + return SpatialGeneratorTypes::CRY; } else { cout << "TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes - Error - Unknown " "SpatialGeneratorTypes: " From 602f71d00e228b3d2d3d5fde9c4396d255cf6cf8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:26:43 +0000 Subject: [PATCH 02/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestGeant4PrimaryGeneratorInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/TRestGeant4PrimaryGeneratorInfo.h b/inc/TRestGeant4PrimaryGeneratorInfo.h index 6e52b8a..0b4ec1e 100644 --- a/inc/TRestGeant4PrimaryGeneratorInfo.h +++ b/inc/TRestGeant4PrimaryGeneratorInfo.h @@ -17,7 +17,7 @@ enum class SpatialGeneratorTypes { SURFACE, POINT, COSMIC, - CRY, + CRY, }; std::string SpatialGeneratorTypesToString(const SpatialGeneratorTypes&); From d009120312c926bd803329a55848716474c33c45 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Sat, 4 Nov 2023 06:34:46 +0100 Subject: [PATCH 03/21] CMakeLists.txt adding CRY libraries dependency --- CMakeLists.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2603691..26154f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,33 @@ if (NOT ${REST_EVE} MATCHES "ON") set(excludes ${excludes} TRestGeant4EventViewer) endif () +if (DEFINED REST_CRY_PATH) + find_path(CRY_LIB_PATH libCRY.a HINTS ${REST_CRY_PATH}/lib) + + find_path(CRY_INC_PATH CRYGenerator.h HINTS ${REST_CRY_PATH}/src) + + if (CRY_LIB_PATH AND CRY_INC_PATH) + message(STATUS "Found CRY includes in ${CRY_INC_PATH}") + message(STATUS "Found CRY library in ${CRY_LIB_PATH}") + + add_compile_definitions("USE_CRY") + add_compile_definitions("CRY_DATA_PATH=\"${REST_CRY_PATH}/data\"") + + set(external_include_dirs ${external_include_dirs} ${CRY_INC_PATH}) + set(external_libs "${external_libs} -L${CRY_LIB_PATH} -lCRY") + + set(feature_added "Cry") + set(feature_added + ${feature_added} + PARENT_SCOPE) + else () + message( + FATAL_ERROR + "REST_CRY_PATH was defined with path ${REST_CRY_PATH}, but CRY library was not found there!\n" + ) + endif () +endif (DEFINED REST_CRY_PATH) + compilelib("") file(GLOB_RECURSE MAC "${CMAKE_CURRENT_SOURCE_DIR}/macros/*") From 932c3cc38f1c4516a43dd8398cba817a706ea995 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Sat, 4 Nov 2023 06:36:33 +0100 Subject: [PATCH 04/21] Adding first TRestGeant4ParticleSourceCry draft --- inc/TRestGeant4ParticleSourceCry.h | 30 +++++ src/TRestGeant4ParticleSource.cxx | 6 +- src/TRestGeant4ParticleSourceCry.cxx | 171 +++++++++++++++++++++++++++ 3 files changed, 204 insertions(+), 3 deletions(-) create mode 100644 inc/TRestGeant4ParticleSourceCry.h create mode 100644 src/TRestGeant4ParticleSourceCry.cxx diff --git a/inc/TRestGeant4ParticleSourceCry.h b/inc/TRestGeant4ParticleSourceCry.h new file mode 100644 index 0000000..1633069 --- /dev/null +++ b/inc/TRestGeant4ParticleSourceCry.h @@ -0,0 +1,30 @@ +#ifndef TRestParticleSourceCry_Class +#define TRestParticleSourceCry_Class + +#include + +#ifdef USE_CRY +#include +#include +#endif + +#include + +class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { + protected: + +#ifdef USE_CRY + CRYGenerator* fCRYGenerator = nullptr; +#endif + + public: + void Update() override; + void InitFromConfigFile() override; + inline Int_t GetNumberOfParticles() const { return fParticles.size(); } + void PrintParticleSource() override; + + TRestGeant4ParticleSourceCry(); + ~TRestGeant4ParticleSourceCry() { } + ClassDefOverride(TRestGeant4ParticleSourceCry, 1); +}; +#endif diff --git a/src/TRestGeant4ParticleSource.cxx b/src/TRestGeant4ParticleSource.cxx index c764041..f97c3aa 100644 --- a/src/TRestGeant4ParticleSource.cxx +++ b/src/TRestGeant4ParticleSource.cxx @@ -97,13 +97,13 @@ TRestGeant4ParticleSource* TRestGeant4ParticleSource::instantiate(std::string mo } else { // use specific generator // naming convention: TRestGeant4ParticleSourceXXX - // currently supported generator: decay0 - // in future we may add wrapper of generators: cry(for muon), pythia(for HEP), etc. + // currently supported generators: decay0, cry + // in future we may add wrapper of generators: pythia(for HEP), etc. model[0] = *REST_StringHelper::ToUpper(std::string(&model[0], 1)).c_str(); TClass* c = TClass::GetClass(("TRestGeant4ParticleSource" + model).c_str()); if (c) // this means we have the package installed { - return (TRestGeant4ParticleSource*)c->New(); + return (TRestGeant4ParticleSource*) c->New(); } else { std::cout << "REST ERROR! generator wrapper \"" << ("TRestGeant4ParticleSource" + model) << "\" not found!" << std::endl; diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx new file mode 100644 index 0000000..9462a00 --- /dev/null +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -0,0 +1,171 @@ +#include "TRestGeant4ParticleSourceCry.h" + +using namespace std; + +ClassImp(TRestGeant4ParticleSourceCry); + +TRestGeant4ParticleSourceCry::TRestGeant4ParticleSourceCry() { + +} + +void TRestGeant4ParticleSourceCry::PrintParticleSource() { + /* + metadata << "---------------------------------------" << endl; + if (!fParticleName.empty() && fParticleName != "NO_SUCH_PARA") + metadata << "Particle Source Name: " << fParticleName << endl; + metadata << "Parent Nuclide: " << fParentName << endl; + metadata << "Decay Mode: " << fDecayType << endl; + metadata << "Daughter Level: " << fDaughterLevel << endl; + metadata << "Seed: " << fSeed << endl; + */ +} + +void TRestGeant4ParticleSourceCry::InitFromConfigFile() { + /* + // unsigned int seed = (uintptr_t)this; + // std::default_random_engine generator(seed); + // prng = bxdecay0::std_random(generator); + fParticleName = ((TRestMetadata*)this)->ClassName(); + fParentName = GetParameter("particle"); + fDecayType = GetParameter("decayMode"); + fDaughterLevel = StringToInteger(GetParameter("daughterLevel")); + fSeed = StringToInteger(GetParameter("seed", "0")); + if (fSeed != 0) { + } else { + fSeed = (uintptr_t)this; + } + generator = new std::default_random_engine(fSeed); + prng = new bxdecay0::std_random(*generator); + + fDecay0Model->set_decay_category(bxdecay0::decay0_generator::DECAY_CATEGORY_DBD); + + if (fParentName != "Xe136") { + ferr << "Only Xe136 double beta decay is supported by restDecay0" << endl; + exit(1); + } + if (fDaughterLevel < 0 || fDaughterLevel > 3) { + ferr << "Supported Ba136 excitation level: 0, 1, 2, 3" << endl; + exit(1); + } + + fDecay0Model->set_decay_isotope(fParentName); + + fDecay0Model->set_decay_dbd_level(fDaughterLevel); + + if (fDecayType == "2vbb") { + if (fDaughterLevel == 0 || fDaughterLevel == 3) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_0_2N); + } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_2_2N); + } + } else if (fDecayType == "0vbb") { + if (fDaughterLevel == 0 || fDaughterLevel == 3) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_MN_0_2N); + } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_RHC_LAMBDA_2_2N); + } + } + + fDecay0Model->initialize(*prng); + */ + +#ifdef USE_CRY + /// Of course, we should be able to configure this inside InitFromConfigFile + std::string setupString = "returnNeutrons 1"; + //std::string setupString = "returnNeutrons 1\nreturnProtons 1\nreturnGammas 1\ndate 7-1-2012\nlatitude 90.0\naltitude 0\nsubboxLength 100\n"; + CRYSetup* setup = new CRYSetup(setupString, CRY_DATA_PATH); + fCRYGenerator = new CRYGenerator(setup); +#endif + + Update(); +} + +void TRestGeant4ParticleSourceCry::Update() { + RemoveParticles(); + +#ifdef USE_CRY + std::vector* ev = new std::vector; + ev->clear(); + fCRYGenerator->genEvent(ev); + + std::cout << "CRY particles : " << ev->size() << std::endl; + std::cout << "-----" << std::endl; + + for(const auto &cryParticle : *ev ) + { + std::cout << "id: " << cryParticle->id() << std::endl; + + std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; + std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; + std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; + + TRestGeant4Particle particle; + + /// Particle charge + particle.SetParticleCharge(cryParticle->charge()); + particle.SetExcitationLevel(0); + + /// Particle position + TVector3 position( cryParticle->x(), cryParticle->y(), cryParticle->z() ); + particle.SetOrigin( position ); + + /// Momentum direction + TVector3 momDirection(cryParticle->u(), cryParticle->v(), cryParticle->w()); + momDirection = momDirection.Unit(); + particle.SetDirection(momDirection); + + /// Kinetic energy + particle.SetEnergy(1000. * cryParticle->ke()); // In keV (default REST units) + + /* + * 0 : Neutron + * 1 : Proton + * 2 : Pion + * 3 : Kaon + * 4 : Muon + * 5 : Electron + * 6 : Gamma + */ + + int id = cryParticle->id(); + if (id == 0) particle.SetParticleName("neutron"); + if (id == 1) particle.SetParticleName("proton"); + if (id == 2) { + if( cryParticle->charge() > 0 ) + particle.SetParticleName("pi+"); + else if( cryParticle->charge() == 0 ) + particle.SetParticleName("pi0"); + else if( cryParticle->charge() < 0 ) + particle.SetParticleName("pi-"); + } + if (id == 3) { + if( cryParticle->charge() > 0 ) + particle.SetParticleName("kaon+"); + else if( cryParticle->charge() == 0 ) + particle.SetParticleName("kaon0"); + else if( cryParticle->charge() < 0 ) + particle.SetParticleName("kaon-"); + } + if (id == 4) { + if( cryParticle->charge() > 0 ) + particle.SetParticleName("mu+"); + else if( cryParticle->charge() < 0 ) + particle.SetParticleName("mu-"); + } + if (id == 5) { + if( cryParticle->charge() > 0 ) + particle.SetParticleName("e+"); + else if( cryParticle->charge() < 0 ) + particle.SetParticleName("e-"); + } + if (id == 6) particle.SetParticleName("gamma"); + + AddParticle(particle); + } + std::cout << "-----" << std::endl; +#else + cout << "TRestGeant4ParticleSourceCry - ERROR: restG4 was not linked to CRY libraries" << endl; + exit(1); +#endif + +} From 544a5289e6900f43e9b2821344aec6f253103b20 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Nov 2023 05:37:31 +0000 Subject: [PATCH 05/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CMakeLists.txt | 14 +- inc/TRestGeant4ParticleSourceCry.h | 5 +- src/TRestGeant4ParticleSource.cxx | 2 +- src/TRestGeant4ParticleSourceCry.cxx | 279 +++++++++++++-------------- 4 files changed, 149 insertions(+), 151 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 26154f2..411d982 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,16 +61,16 @@ if (DEFINED REST_CRY_PATH) message(STATUS "Found CRY includes in ${CRY_INC_PATH}") message(STATUS "Found CRY library in ${CRY_LIB_PATH}") - add_compile_definitions("USE_CRY") + add_compile_definitions("USE_CRY") add_compile_definitions("CRY_DATA_PATH=\"${REST_CRY_PATH}/data\"") - set(external_include_dirs ${external_include_dirs} ${CRY_INC_PATH}) - set(external_libs "${external_libs} -L${CRY_LIB_PATH} -lCRY") + set(external_include_dirs ${external_include_dirs} ${CRY_INC_PATH}) + set(external_libs "${external_libs} -L${CRY_LIB_PATH} -lCRY") - set(feature_added "Cry") - set(feature_added - ${feature_added} - PARENT_SCOPE) + set(feature_added "Cry") + set(feature_added + ${feature_added} + PARENT_SCOPE) else () message( FATAL_ERROR diff --git a/inc/TRestGeant4ParticleSourceCry.h b/inc/TRestGeant4ParticleSourceCry.h index 1633069..0cf1583 100644 --- a/inc/TRestGeant4ParticleSourceCry.h +++ b/inc/TRestGeant4ParticleSourceCry.h @@ -12,9 +12,8 @@ class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { protected: - #ifdef USE_CRY - CRYGenerator* fCRYGenerator = nullptr; + CRYGenerator* fCRYGenerator = nullptr; #endif public: @@ -24,7 +23,7 @@ class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { void PrintParticleSource() override; TRestGeant4ParticleSourceCry(); - ~TRestGeant4ParticleSourceCry() { } + ~TRestGeant4ParticleSourceCry() {} ClassDefOverride(TRestGeant4ParticleSourceCry, 1); }; #endif diff --git a/src/TRestGeant4ParticleSource.cxx b/src/TRestGeant4ParticleSource.cxx index f97c3aa..b62d0db 100644 --- a/src/TRestGeant4ParticleSource.cxx +++ b/src/TRestGeant4ParticleSource.cxx @@ -103,7 +103,7 @@ TRestGeant4ParticleSource* TRestGeant4ParticleSource::instantiate(std::string mo TClass* c = TClass::GetClass(("TRestGeant4ParticleSource" + model).c_str()); if (c) // this means we have the package installed { - return (TRestGeant4ParticleSource*) c->New(); + return (TRestGeant4ParticleSource*)c->New(); } else { std::cout << "REST ERROR! generator wrapper \"" << ("TRestGeant4ParticleSource" + model) << "\" not found!" << std::endl; diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index 9462a00..36b8794 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -4,168 +4,167 @@ using namespace std; ClassImp(TRestGeant4ParticleSourceCry); -TRestGeant4ParticleSourceCry::TRestGeant4ParticleSourceCry() { - -} +TRestGeant4ParticleSourceCry::TRestGeant4ParticleSourceCry() {} void TRestGeant4ParticleSourceCry::PrintParticleSource() { - /* - metadata << "---------------------------------------" << endl; - if (!fParticleName.empty() && fParticleName != "NO_SUCH_PARA") - metadata << "Particle Source Name: " << fParticleName << endl; - metadata << "Parent Nuclide: " << fParentName << endl; - metadata << "Decay Mode: " << fDecayType << endl; - metadata << "Daughter Level: " << fDaughterLevel << endl; - metadata << "Seed: " << fSeed << endl; - */ + /* +metadata << "---------------------------------------" << endl; +if (!fParticleName.empty() && fParticleName != "NO_SUCH_PARA") + metadata << "Particle Source Name: " << fParticleName << endl; +metadata << "Parent Nuclide: " << fParentName << endl; +metadata << "Decay Mode: " << fDecayType << endl; +metadata << "Daughter Level: " << fDaughterLevel << endl; +metadata << "Seed: " << fSeed << endl; + */ } void TRestGeant4ParticleSourceCry::InitFromConfigFile() { - /* - // unsigned int seed = (uintptr_t)this; - // std::default_random_engine generator(seed); - // prng = bxdecay0::std_random(generator); - fParticleName = ((TRestMetadata*)this)->ClassName(); - fParentName = GetParameter("particle"); - fDecayType = GetParameter("decayMode"); - fDaughterLevel = StringToInteger(GetParameter("daughterLevel")); - fSeed = StringToInteger(GetParameter("seed", "0")); - if (fSeed != 0) { - } else { - fSeed = (uintptr_t)this; - } - generator = new std::default_random_engine(fSeed); - prng = new bxdecay0::std_random(*generator); + /* +// unsigned int seed = (uintptr_t)this; +// std::default_random_engine generator(seed); +// prng = bxdecay0::std_random(generator); +fParticleName = ((TRestMetadata*)this)->ClassName(); +fParentName = GetParameter("particle"); +fDecayType = GetParameter("decayMode"); +fDaughterLevel = StringToInteger(GetParameter("daughterLevel")); +fSeed = StringToInteger(GetParameter("seed", "0")); +if (fSeed != 0) { +} else { + fSeed = (uintptr_t)this; +} +generator = new std::default_random_engine(fSeed); +prng = new bxdecay0::std_random(*generator); - fDecay0Model->set_decay_category(bxdecay0::decay0_generator::DECAY_CATEGORY_DBD); +fDecay0Model->set_decay_category(bxdecay0::decay0_generator::DECAY_CATEGORY_DBD); - if (fParentName != "Xe136") { - ferr << "Only Xe136 double beta decay is supported by restDecay0" << endl; - exit(1); - } - if (fDaughterLevel < 0 || fDaughterLevel > 3) { - ferr << "Supported Ba136 excitation level: 0, 1, 2, 3" << endl; - exit(1); - } +if (fParentName != "Xe136") { + ferr << "Only Xe136 double beta decay is supported by restDecay0" << endl; + exit(1); +} +if (fDaughterLevel < 0 || fDaughterLevel > 3) { + ferr << "Supported Ba136 excitation level: 0, 1, 2, 3" << endl; + exit(1); +} - fDecay0Model->set_decay_isotope(fParentName); +fDecay0Model->set_decay_isotope(fParentName); - fDecay0Model->set_decay_dbd_level(fDaughterLevel); +fDecay0Model->set_decay_dbd_level(fDaughterLevel); - if (fDecayType == "2vbb") { - if (fDaughterLevel == 0 || fDaughterLevel == 3) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_0_2N); - } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_2_2N); - } - } else if (fDecayType == "0vbb") { - if (fDaughterLevel == 0 || fDaughterLevel == 3) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_MN_0_2N); - } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_RHC_LAMBDA_2_2N); - } +if (fDecayType == "2vbb") { + if (fDaughterLevel == 0 || fDaughterLevel == 3) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_0_2N); + } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_2_2N); } +} else if (fDecayType == "0vbb") { + if (fDaughterLevel == 0 || fDaughterLevel == 3) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_MN_0_2N); + } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { + fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_RHC_LAMBDA_2_2N); + } +} - fDecay0Model->initialize(*prng); - */ +fDecay0Model->initialize(*prng); + */ #ifdef USE_CRY - /// Of course, we should be able to configure this inside InitFromConfigFile - std::string setupString = "returnNeutrons 1"; - //std::string setupString = "returnNeutrons 1\nreturnProtons 1\nreturnGammas 1\ndate 7-1-2012\nlatitude 90.0\naltitude 0\nsubboxLength 100\n"; - CRYSetup* setup = new CRYSetup(setupString, CRY_DATA_PATH); - fCRYGenerator = new CRYGenerator(setup); + /// Of course, we should be able to configure this inside InitFromConfigFile + std::string setupString = "returnNeutrons 1"; + // std::string setupString = "returnNeutrons 1\nreturnProtons 1\nreturnGammas 1\ndate + // 7-1-2012\nlatitude 90.0\naltitude 0\nsubboxLength 100\n"; + CRYSetup* setup = new CRYSetup(setupString, CRY_DATA_PATH); + fCRYGenerator = new CRYGenerator(setup); #endif Update(); } void TRestGeant4ParticleSourceCry::Update() { - RemoveParticles(); + RemoveParticles(); #ifdef USE_CRY - std::vector* ev = new std::vector; - ev->clear(); - fCRYGenerator->genEvent(ev); - - std::cout << "CRY particles : " << ev->size() << std::endl; - std::cout << "-----" << std::endl; - - for(const auto &cryParticle : *ev ) - { - std::cout << "id: " << cryParticle->id() << std::endl; - - std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; - std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; - std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; - - TRestGeant4Particle particle; - - /// Particle charge - particle.SetParticleCharge(cryParticle->charge()); - particle.SetExcitationLevel(0); - - /// Particle position - TVector3 position( cryParticle->x(), cryParticle->y(), cryParticle->z() ); - particle.SetOrigin( position ); - - /// Momentum direction - TVector3 momDirection(cryParticle->u(), cryParticle->v(), cryParticle->w()); - momDirection = momDirection.Unit(); - particle.SetDirection(momDirection); - - /// Kinetic energy - particle.SetEnergy(1000. * cryParticle->ke()); // In keV (default REST units) - - /* - * 0 : Neutron - * 1 : Proton - * 2 : Pion - * 3 : Kaon - * 4 : Muon - * 5 : Electron - * 6 : Gamma - */ - - int id = cryParticle->id(); - if (id == 0) particle.SetParticleName("neutron"); - if (id == 1) particle.SetParticleName("proton"); - if (id == 2) { - if( cryParticle->charge() > 0 ) - particle.SetParticleName("pi+"); - else if( cryParticle->charge() == 0 ) - particle.SetParticleName("pi0"); - else if( cryParticle->charge() < 0 ) - particle.SetParticleName("pi-"); - } - if (id == 3) { - if( cryParticle->charge() > 0 ) - particle.SetParticleName("kaon+"); - else if( cryParticle->charge() == 0 ) - particle.SetParticleName("kaon0"); - else if( cryParticle->charge() < 0 ) - particle.SetParticleName("kaon-"); - } - if (id == 4) { - if( cryParticle->charge() > 0 ) - particle.SetParticleName("mu+"); - else if( cryParticle->charge() < 0 ) - particle.SetParticleName("mu-"); - } - if (id == 5) { - if( cryParticle->charge() > 0 ) - particle.SetParticleName("e+"); - else if( cryParticle->charge() < 0 ) - particle.SetParticleName("e-"); - } - if (id == 6) particle.SetParticleName("gamma"); - - AddParticle(particle); - } - std::cout << "-----" << std::endl; + std::vector* ev = new std::vector; + ev->clear(); + fCRYGenerator->genEvent(ev); + + std::cout << "CRY particles : " << ev->size() << std::endl; + std::cout << "-----" << std::endl; + + for (const auto& cryParticle : *ev) { + std::cout << "id: " << cryParticle->id() << std::endl; + + std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() + << std::endl; + std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() + << std::endl; + std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; + + TRestGeant4Particle particle; + + /// Particle charge + particle.SetParticleCharge(cryParticle->charge()); + particle.SetExcitationLevel(0); + + /// Particle position + TVector3 position(cryParticle->x(), cryParticle->y(), cryParticle->z()); + particle.SetOrigin(position); + + /// Momentum direction + TVector3 momDirection(cryParticle->u(), cryParticle->v(), cryParticle->w()); + momDirection = momDirection.Unit(); + particle.SetDirection(momDirection); + + /// Kinetic energy + particle.SetEnergy(1000. * cryParticle->ke()); // In keV (default REST units) + + /* + * 0 : Neutron + * 1 : Proton + * 2 : Pion + * 3 : Kaon + * 4 : Muon + * 5 : Electron + * 6 : Gamma + */ + + int id = cryParticle->id(); + if (id == 0) particle.SetParticleName("neutron"); + if (id == 1) particle.SetParticleName("proton"); + if (id == 2) { + if (cryParticle->charge() > 0) + particle.SetParticleName("pi+"); + else if (cryParticle->charge() == 0) + particle.SetParticleName("pi0"); + else if (cryParticle->charge() < 0) + particle.SetParticleName("pi-"); + } + if (id == 3) { + if (cryParticle->charge() > 0) + particle.SetParticleName("kaon+"); + else if (cryParticle->charge() == 0) + particle.SetParticleName("kaon0"); + else if (cryParticle->charge() < 0) + particle.SetParticleName("kaon-"); + } + if (id == 4) { + if (cryParticle->charge() > 0) + particle.SetParticleName("mu+"); + else if (cryParticle->charge() < 0) + particle.SetParticleName("mu-"); + } + if (id == 5) { + if (cryParticle->charge() > 0) + particle.SetParticleName("e+"); + else if (cryParticle->charge() < 0) + particle.SetParticleName("e-"); + } + if (id == 6) particle.SetParticleName("gamma"); + + AddParticle(particle); + } + std::cout << "-----" << std::endl; #else - cout << "TRestGeant4ParticleSourceCry - ERROR: restG4 was not linked to CRY libraries" << endl; - exit(1); + cout << "TRestGeant4ParticleSourceCry - ERROR: restG4 was not linked to CRY libraries" << endl; + exit(1); #endif - } From 7abd379f70abd05ed1b49b5e6bbc80bbdf8e51e3 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Sat, 4 Nov 2023 06:44:13 +0100 Subject: [PATCH 06/21] TRestGeant4ParticleSourceCry. Improving non-CRY libraries message --- src/TRestGeant4ParticleSourceCry.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index 9462a00..60c0e3d 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -164,7 +164,18 @@ void TRestGeant4ParticleSourceCry::Update() { } std::cout << "-----" << std::endl; #else - cout << "TRestGeant4ParticleSourceCry - ERROR: restG4 was not linked to CRY libraries" << endl; + cout << "TRestGeant4ParticleSourceCry - ERROR: Geant4lib was not linked to CRY libraries" << endl; + cout << " " << endl; + cout << "Please, compile REST using `cmake -DREST_CRY_PATH=/path/to/cry/installation/directory" << endl; + cout << " " << endl; + cout << "By default CRY libraries will generate just the static library, but REST needs the shared library" << endl; + cout << "In order to generate the SHARED object from the STATIC libCRY.a object, execute the following command" << endl; + cout << "inside the CRY lib directory" << endl; + cout << " " << endl; + cout << "```" << endl; + cout << "gcc -shared -o libCRY.so -Wl,--whole-archive libCRY.a -Wl,--no-whole-archive" << endl; + cout << "```" << endl; + exit(1); #endif From 039652c86921a32e277f4aa6bb6d641dc59df36b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Nov 2023 05:46:03 +0000 Subject: [PATCH 07/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestGeant4ParticleSourceCry.cxx | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index 3b2b4ba..61ed738 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -164,18 +164,22 @@ void TRestGeant4ParticleSourceCry::Update() { } std::cout << "-----" << std::endl; #else - cout << "TRestGeant4ParticleSourceCry - ERROR: Geant4lib was not linked to CRY libraries" << endl; - cout << " " << endl; - cout << "Please, compile REST using `cmake -DREST_CRY_PATH=/path/to/cry/installation/directory" << endl; - cout << " " << endl; - cout << "By default CRY libraries will generate just the static library, but REST needs the shared library" << endl; - cout << "In order to generate the SHARED object from the STATIC libCRY.a object, execute the following command" << endl; - cout << "inside the CRY lib directory" << endl; - cout << " " << endl; - cout << "```" << endl; - cout << "gcc -shared -o libCRY.so -Wl,--whole-archive libCRY.a -Wl,--no-whole-archive" << endl; - cout << "```" << endl; - - exit(1); + cout << "TRestGeant4ParticleSourceCry - ERROR: Geant4lib was not linked to CRY libraries" << endl; + cout << " " << endl; + cout << "Please, compile REST using `cmake -DREST_CRY_PATH=/path/to/cry/installation/directory" << endl; + cout << " " << endl; + cout + << "By default CRY libraries will generate just the static library, but REST needs the shared library" + << endl; + cout << "In order to generate the SHARED object from the STATIC libCRY.a object, execute the following " + "command" + << endl; + cout << "inside the CRY lib directory" << endl; + cout << " " << endl; + cout << "```" << endl; + cout << "gcc -shared -o libCRY.so -Wl,--whole-archive libCRY.a -Wl,--no-whole-archive" << endl; + cout << "```" << endl; + + exit(1); #endif } From b28ba40a8579fe00bb4990de91958ae7c7b5d38a Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Sat, 4 Nov 2023 21:44:47 +0100 Subject: [PATCH 08/21] TRestGeant4Particle. Added official headers and a new Print method --- inc/TRestGeant4Particle.h | 47 +++++++++++++----------- src/TRestGeant4Particle.cxx | 72 ++++++++++++++++++++++++++++++------- 2 files changed, 86 insertions(+), 33 deletions(-) diff --git a/inc/TRestGeant4Particle.h b/inc/TRestGeant4Particle.h index 3722d57..733fad9 100644 --- a/inc/TRestGeant4Particle.h +++ b/inc/TRestGeant4Particle.h @@ -1,17 +1,24 @@ -////////////////////////////////////////////////////////////////////////// -/// -/// RESTSoft : Software for Rare Event Searches with TPCs -/// -/// TRestGeant4Particle.h -/// -/// Class to store a particle definition -/// -/// jul 2015: First concept -/// Created as part of the conceptualization of existing REST -/// software. -/// J. Galan -/// -////////////////////////////////////////////////////////////////////////// +/************************************************************************* + * This file is part of the REST software framework. * + * * + * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) * + * For more information see http://gifna.unizar.es/trex * + * * + * REST is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * REST is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have a copy of the GNU General Public License along with * + * REST in $REST_PATH/LICENSE. * + * If not, see http://www.gnu.org/licenses/. * + * For the list of contributors see $REST_PATH/CREDITS. * + *************************************************************************/ #ifndef RestCore_TRestGeant4Particle #define RestCore_TRestGeant4Particle @@ -21,6 +28,7 @@ #include +/// A class used to store particle properties class TRestGeant4Particle { protected: TString fParticleName; @@ -38,15 +46,10 @@ class TRestGeant4Particle { inline Int_t GetParticleCharge() const { return fCharge; } inline TVector3 GetOrigin() const { return fOrigin; } - void SetParticle(TRestGeant4Particle particle) { - fExcitationLevel = particle.GetExcitationLevel(); - fParticleName = particle.GetParticleName(); - fEnergy = particle.GetEnergy(); - fDirection = particle.GetMomentumDirection(); - fOrigin = particle.fOrigin; - } + void SetParticle(TRestGeant4Particle particle); void SetParticleName(TString particle) { fParticleName = particle; } + void SetExcitationLevel(Double_t excitationEnergy) { fExcitationLevel = excitationEnergy; if (fExcitationLevel < 0) fExcitationLevel = 0; @@ -58,6 +61,8 @@ class TRestGeant4Particle { void SetEnergy(Double_t en) { fEnergy = en; } void SetOrigin(TVector3 pos) { fOrigin = pos; } + void Print() const; + // Constructor TRestGeant4Particle(); // Destructor diff --git a/src/TRestGeant4Particle.cxx b/src/TRestGeant4Particle.cxx index b0ab323..3feb43e 100644 --- a/src/TRestGeant4Particle.cxx +++ b/src/TRestGeant4Particle.cxx @@ -1,20 +1,42 @@ -///_______________________________________________________________________________ -///_______________________________________________________________________________ -///_______________________________________________________________________________ +/************************************************************************* + * This file is part of the REST software framework. * + * * + * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) * + * For more information see http://gifna.unizar.es/trex * + * * + * REST is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * REST is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have a copy of the GNU General Public License along with * + * REST in $REST_PATH/LICENSE. * + * If not, see http://www.gnu.org/licenses/. * + * For the list of contributors see $REST_PATH/CREDITS. * + *************************************************************************/ + +////////////////////////////////////////////////////////////////////////// +/// TRestGeant4Particle is just a container class to store particle properties /// /// -/// RESTSoft : Software for Rare Event Searches with TPCs +///-------------------------------------------------------------------------- /// -/// TRestGeant4Particle.cxx +/// RESTsoft - Software for Rare Event Searches with TPCs /// -/// Base class from which to inherit all other event classes in REST +/// History of developments: +/// +/// 2015-July: First concept and implementation +/// \author Javier Galan +/// +/// \class TRestGeant4Particle +/// +///
/// -/// jul 2015: First concept -/// Created as part of the conceptualization of existing REST -/// software. -/// J. Galan -///_______________________________________________________________________________ - #include "TRestGeant4Particle.h" using namespace std; @@ -28,3 +50,29 @@ TRestGeant4Particle::TRestGeant4Particle() { TRestGeant4Particle::~TRestGeant4Particle() { // TRestGeant4Particle destructor } + +/////////////////////////////////////////////// +/// \brief A copy method +/// +void TRestGeant4Particle::SetParticle(TRestGeant4Particle particle) { + fExcitationLevel = particle.GetExcitationLevel(); + fParticleName = particle.GetParticleName(); + fEnergy = particle.GetEnergy(); + fDirection = particle.GetMomentumDirection(); + fOrigin = particle.fOrigin; +} + +/////////////////////////////////////////////// +/// \brief Prints on screen the details about the Geant4 simulation +/// conditions, stored in TRestGeant4Metadata. +/// +void TRestGeant4Particle::Print() const +{ + std::cout << "Particle name : " << GetParticleName() << std::endl; + std::cout << "Charge : " << GetParticleCharge() << std::endl; + std::cout << "Energy : " << GetEnergy() << " keV" << std::endl; + std::cout << "Excitation level : " << GetExcitationLevel() << std::endl; + std::cout << "X : " << GetOrigin().X() << "mm Y : " << GetOrigin().Y() << "mm Z : " << GetOrigin().Z() << "mm" << std::endl; + std::cout << "Px : " << GetMomentumDirection().X() << " Py : " << GetMomentumDirection().Y() << " Pz : " << GetMomentumDirection().Z() << std::endl; + std::cout << " ---------------------- " << std::endl; +} From 9255070697430e217b9b01c834cef1121763694a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Nov 2023 20:46:13 +0000 Subject: [PATCH 09/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestGeant4Particle.cxx | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/TRestGeant4Particle.cxx b/src/TRestGeant4Particle.cxx index 3feb43e..22ddcd4 100644 --- a/src/TRestGeant4Particle.cxx +++ b/src/TRestGeant4Particle.cxx @@ -55,24 +55,25 @@ TRestGeant4Particle::~TRestGeant4Particle() { /// \brief A copy method /// void TRestGeant4Particle::SetParticle(TRestGeant4Particle particle) { - fExcitationLevel = particle.GetExcitationLevel(); - fParticleName = particle.GetParticleName(); - fEnergy = particle.GetEnergy(); - fDirection = particle.GetMomentumDirection(); - fOrigin = particle.fOrigin; + fExcitationLevel = particle.GetExcitationLevel(); + fParticleName = particle.GetParticleName(); + fEnergy = particle.GetEnergy(); + fDirection = particle.GetMomentumDirection(); + fOrigin = particle.fOrigin; } /////////////////////////////////////////////// /// \brief Prints on screen the details about the Geant4 simulation /// conditions, stored in TRestGeant4Metadata. /// -void TRestGeant4Particle::Print() const -{ - std::cout << "Particle name : " << GetParticleName() << std::endl; - std::cout << "Charge : " << GetParticleCharge() << std::endl; - std::cout << "Energy : " << GetEnergy() << " keV" << std::endl; - std::cout << "Excitation level : " << GetExcitationLevel() << std::endl; - std::cout << "X : " << GetOrigin().X() << "mm Y : " << GetOrigin().Y() << "mm Z : " << GetOrigin().Z() << "mm" << std::endl; - std::cout << "Px : " << GetMomentumDirection().X() << " Py : " << GetMomentumDirection().Y() << " Pz : " << GetMomentumDirection().Z() << std::endl; - std::cout << " ---------------------- " << std::endl; +void TRestGeant4Particle::Print() const { + std::cout << "Particle name : " << GetParticleName() << std::endl; + std::cout << "Charge : " << GetParticleCharge() << std::endl; + std::cout << "Energy : " << GetEnergy() << " keV" << std::endl; + std::cout << "Excitation level : " << GetExcitationLevel() << std::endl; + std::cout << "X : " << GetOrigin().X() << "mm Y : " << GetOrigin().Y() << "mm Z : " << GetOrigin().Z() + << "mm" << std::endl; + std::cout << "Px : " << GetMomentumDirection().X() << " Py : " << GetMomentumDirection().Y() + << " Pz : " << GetMomentumDirection().Z() << std::endl; + std::cout << " ---------------------- " << std::endl; } From d0bc4673c1a238994d1da684736d87dccda99cdc Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Sat, 4 Nov 2023 22:00:40 +0100 Subject: [PATCH 10/21] TRestGeant4ParticleSourceCry. commenting debug output --- src/TRestGeant4ParticleSourceCry.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index 61ed738..9aa4cfa 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -87,10 +87,11 @@ void TRestGeant4ParticleSourceCry::Update() { ev->clear(); fCRYGenerator->genEvent(ev); - std::cout << "CRY particles : " << ev->size() << std::endl; - std::cout << "-----" << std::endl; + // std::cout << "CRY particles : " << ev->size() << std::endl; + // std::cout << "-----" << std::endl; for (const auto& cryParticle : *ev) { + /* std::cout << "id: " << cryParticle->id() << std::endl; std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() @@ -98,6 +99,7 @@ void TRestGeant4ParticleSourceCry::Update() { std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; + */ TRestGeant4Particle particle; @@ -162,7 +164,7 @@ void TRestGeant4ParticleSourceCry::Update() { AddParticle(particle); } - std::cout << "-----" << std::endl; + //std::cout << "-----" << std::endl; #else cout << "TRestGeant4ParticleSourceCry - ERROR: Geant4lib was not linked to CRY libraries" << endl; cout << " " << endl; From e0ac6e7315dfc1cbbbea73db8de9e8f72e275a6c Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Sat, 4 Nov 2023 22:03:16 +0100 Subject: [PATCH 11/21] TRestGeant4ParticleSourceCry. Fixed position units --- src/TRestGeant4ParticleSourceCry.cxx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index 9aa4cfa..de4ac0a 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -93,11 +93,8 @@ void TRestGeant4ParticleSourceCry::Update() { for (const auto& cryParticle : *ev) { /* std::cout << "id: " << cryParticle->id() << std::endl; - - std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() - << std::endl; - std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() - << std::endl; + std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; + std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; */ @@ -109,7 +106,7 @@ void TRestGeant4ParticleSourceCry::Update() { /// Particle position TVector3 position(cryParticle->x(), cryParticle->y(), cryParticle->z()); - particle.SetOrigin(position); + particle.SetOrigin(1000. * position); // In mm (default REST units) /// Momentum direction TVector3 momDirection(cryParticle->u(), cryParticle->v(), cryParticle->w()); From c6af986e320a9f55d7f6289e4abb4ae1a053137b Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Sun, 5 Nov 2023 19:24:38 +0100 Subject: [PATCH 12/21] TRestGeant4ParticleSourceCry. Adding metadata members to setup the CRY generator --- inc/TRestGeant4ParticleSourceCry.h | 25 ++++- src/TRestGeant4ParticleSourceCry.cxx | 131 ++++++++++++++------------- 2 files changed, 94 insertions(+), 62 deletions(-) diff --git a/inc/TRestGeant4ParticleSourceCry.h b/inc/TRestGeant4ParticleSourceCry.h index 0cf1583..9d29dd6 100644 --- a/inc/TRestGeant4ParticleSourceCry.h +++ b/inc/TRestGeant4ParticleSourceCry.h @@ -11,6 +11,29 @@ #include class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { + private: + Int_t fReturnNeutrons = 1; + Int_t fReturnProtons = 1; + Int_t fReturnGammas = 1; + Int_t fReturnElectrons = 1; + Int_t fReturnPions = 1; + Int_t fReturnKaons = 1; + Int_t fReturnMuons = 1; + + Int_t fNParticlesMin = 1; + Int_t fNParticlesMax = 1000000; + + Double_t fXOffset = 0; + Double_t fYOffset = 0; + Double_t fZOffset = 0; + + std::string fDate = "7-1-2012"; + + Double_t fLatitude = 90.0;; + Double_t fAltitude = 0.0;; + + Double_t fSubBoxLength = 100.0;; + protected: #ifdef USE_CRY CRYGenerator* fCRYGenerator = nullptr; @@ -20,7 +43,7 @@ class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { void Update() override; void InitFromConfigFile() override; inline Int_t GetNumberOfParticles() const { return fParticles.size(); } - void PrintParticleSource() override; + void PrintMetadata() override; TRestGeant4ParticleSourceCry(); ~TRestGeant4ParticleSourceCry() {} diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index de4ac0a..f559ffc 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -6,72 +6,83 @@ ClassImp(TRestGeant4ParticleSourceCry); TRestGeant4ParticleSourceCry::TRestGeant4ParticleSourceCry() {} -void TRestGeant4ParticleSourceCry::PrintParticleSource() { - /* -metadata << "---------------------------------------" << endl; -if (!fParticleName.empty() && fParticleName != "NO_SUCH_PARA") - metadata << "Particle Source Name: " << fParticleName << endl; -metadata << "Parent Nuclide: " << fParentName << endl; -metadata << "Decay Mode: " << fDecayType << endl; -metadata << "Daughter Level: " << fDaughterLevel << endl; -metadata << "Seed: " << fSeed << endl; - */ +void TRestGeant4ParticleSourceCry::PrintMetadata() { + + TRestGeant4ParticleSource::PrintMetadata(); + + RESTMetadata << "Return Neutrons : " << fReturnNeutrons << RESTendl; + RESTMetadata << "Return Protons : " << fReturnProtons << RESTendl; + RESTMetadata << "Return Gammas : " << fReturnGammas << RESTendl; + RESTMetadata << "Return Electrons : " << fReturnElectrons << RESTendl; + RESTMetadata << "Return Pions : " << fReturnPions << RESTendl; + RESTMetadata << "Return Kaons : " << fReturnKaons << RESTendl; + RESTMetadata << "Return Muons : " << fReturnMuons << RESTendl; + RESTMetadata << " ======= " << RESTendl; + + RESTMetadata << "N particles min : " << fNParticlesMin << RESTendl; + RESTMetadata << "N particles max : " << fNParticlesMax << RESTendl; + RESTMetadata << " ======= " << RESTendl; + + RESTMetadata << "X-offset : " << fXOffset << "m" << RESTendl; + RESTMetadata << "Y-offset : " << fYOffset << "m" << RESTendl; + RESTMetadata << "Z-offset : " << fZOffset << "m" << RESTendl; + RESTMetadata << "SubBoxLength : " << fSubBoxLength << "m" << RESTendl; + RESTMetadata << " ======= " << RESTendl; + + RESTMetadata << "Date : " << fDate << RESTendl; + RESTMetadata << "Latitude : " << fLatitude << RESTendl; + RESTMetadata << "Altitude : " << fAltitude << RESTendl; + RESTMetadata << "----------------------" << RESTendl; } void TRestGeant4ParticleSourceCry::InitFromConfigFile() { - /* -// unsigned int seed = (uintptr_t)this; -// std::default_random_engine generator(seed); -// prng = bxdecay0::std_random(generator); -fParticleName = ((TRestMetadata*)this)->ClassName(); -fParentName = GetParameter("particle"); -fDecayType = GetParameter("decayMode"); -fDaughterLevel = StringToInteger(GetParameter("daughterLevel")); -fSeed = StringToInteger(GetParameter("seed", "0")); -if (fSeed != 0) { -} else { - fSeed = (uintptr_t)this; -} -generator = new std::default_random_engine(fSeed); -prng = new bxdecay0::std_random(*generator); -fDecay0Model->set_decay_category(bxdecay0::decay0_generator::DECAY_CATEGORY_DBD); + fReturnNeutrons = StringToInteger( GetParameter( "returnNeutrons", "1" ) ); + fReturnProtons = StringToInteger( GetParameter( "returnProtons", "1" ) ); + fReturnGammas = StringToInteger( GetParameter( "returnGammas", "1" ) ); + fReturnElectrons = StringToInteger( GetParameter( "returnElectrons", "1" ) ); + fReturnPions = StringToInteger( GetParameter( "returnPions", "1" ) ); + fReturnKaons = StringToInteger( GetParameter( "returnKaons", "1" ) ); + fReturnMuons = StringToInteger( GetParameter( "returnMuons", "1" ) ); -if (fParentName != "Xe136") { - ferr << "Only Xe136 double beta decay is supported by restDecay0" << endl; - exit(1); -} -if (fDaughterLevel < 0 || fDaughterLevel > 3) { - ferr << "Supported Ba136 excitation level: 0, 1, 2, 3" << endl; - exit(1); -} + fNParticlesMin = StringToInteger( GetParameter( "nParticlesMin", "1" ) ); + fNParticlesMax = StringToInteger( GetParameter( "nParticlesMax", "1000000" ) ); -fDecay0Model->set_decay_isotope(fParentName); + fXOffset = StringToDouble( GetParameter( "xoffset", "0.0" ) ); + fYOffset = StringToDouble( GetParameter( "yoffset", "0.0" ) ); + fZOffset = StringToDouble( GetParameter( "zoffset", "0.0" ) ); + fSubBoxLength = StringToDouble( GetParameter( "subBoxLength", "100.0" ) ); -fDecay0Model->set_decay_dbd_level(fDaughterLevel); + fDate = GetParameter( "date", "7\\1\\2012" ); + fDate = REST_StringHelper::Replace( fDate, "\\", "-" ); + fLatitude = StringToDouble( GetParameter( "latitude", "90.0" ) ); + fAltitude = StringToDouble( GetParameter( "altitude", "0.0" ) ); -if (fDecayType == "2vbb") { - if (fDaughterLevel == 0 || fDaughterLevel == 3) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_0_2N); - } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_2_2N); - } -} else if (fDecayType == "0vbb") { - if (fDaughterLevel == 0 || fDaughterLevel == 3) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_MN_0_2N); - } else if (fDaughterLevel == 1 || fDaughterLevel == 2) { - fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_RHC_LAMBDA_2_2N); - } -} + PrintMetadata(); + + std::string setupString = ""; + setupString += "returnNeutrons " + IntegerToString(fReturnNeutrons); + setupString += " returnProtons " + IntegerToString(fReturnProtons); + setupString += " returnGammas " + IntegerToString(fReturnGammas); + setupString += " returnElectrons " + IntegerToString(fReturnElectrons); + setupString += " returnPions " + IntegerToString(fReturnPions); + setupString += " returnKaons " + IntegerToString(fReturnKaons); + setupString += " returnMuons " + IntegerToString(fReturnMuons); + + setupString += " xoffset " + DoubleToString(fXOffset); + setupString += " yoffset " + DoubleToString(fYOffset); + setupString += " zoffset " + DoubleToString(fZOffset); + setupString += " subboxLength " + DoubleToString(fSubBoxLength); + + setupString += " date " + fDate; + setupString += " latitude " + DoubleToString(fLatitude); + setupString += " altitude " + DoubleToString(fAltitude); + + setupString += " nParticlesMin " + IntegerToString(fNParticlesMin); + setupString += " nParticlesMax " + IntegerToString(fNParticlesMax); -fDecay0Model->initialize(*prng); - */ #ifdef USE_CRY - /// Of course, we should be able to configure this inside InitFromConfigFile - std::string setupString = "returnNeutrons 1"; - // std::string setupString = "returnNeutrons 1\nreturnProtons 1\nreturnGammas 1\ndate - // 7-1-2012\nlatitude 90.0\naltitude 0\nsubboxLength 100\n"; CRYSetup* setup = new CRYSetup(setupString, CRY_DATA_PATH); fCRYGenerator = new CRYGenerator(setup); #endif @@ -91,12 +102,10 @@ void TRestGeant4ParticleSourceCry::Update() { // std::cout << "-----" << std::endl; for (const auto& cryParticle : *ev) { - /* - std::cout << "id: " << cryParticle->id() << std::endl; - std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; - std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; - std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; - */ + // std::cout << "id: " << cryParticle->id() << std::endl; + // std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; + // std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; + // std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; TRestGeant4Particle particle; From 825bf99841754ffca00b5a5baf4a53dd68c470c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 5 Nov 2023 18:24:50 +0000 Subject: [PATCH 13/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestGeant4ParticleSourceCry.h | 47 +++++---- src/TRestGeant4ParticleSourceCry.cxx | 150 +++++++++++++-------------- 2 files changed, 99 insertions(+), 98 deletions(-) diff --git a/inc/TRestGeant4ParticleSourceCry.h b/inc/TRestGeant4ParticleSourceCry.h index 9d29dd6..f83cdff 100644 --- a/inc/TRestGeant4ParticleSourceCry.h +++ b/inc/TRestGeant4ParticleSourceCry.h @@ -11,28 +11,31 @@ #include class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { - private: - Int_t fReturnNeutrons = 1; - Int_t fReturnProtons = 1; - Int_t fReturnGammas = 1; - Int_t fReturnElectrons = 1; - Int_t fReturnPions = 1; - Int_t fReturnKaons = 1; - Int_t fReturnMuons = 1; - - Int_t fNParticlesMin = 1; - Int_t fNParticlesMax = 1000000; - - Double_t fXOffset = 0; - Double_t fYOffset = 0; - Double_t fZOffset = 0; - - std::string fDate = "7-1-2012"; - - Double_t fLatitude = 90.0;; - Double_t fAltitude = 0.0;; - - Double_t fSubBoxLength = 100.0;; + private: + Int_t fReturnNeutrons = 1; + Int_t fReturnProtons = 1; + Int_t fReturnGammas = 1; + Int_t fReturnElectrons = 1; + Int_t fReturnPions = 1; + Int_t fReturnKaons = 1; + Int_t fReturnMuons = 1; + + Int_t fNParticlesMin = 1; + Int_t fNParticlesMax = 1000000; + + Double_t fXOffset = 0; + Double_t fYOffset = 0; + Double_t fZOffset = 0; + + std::string fDate = "7-1-2012"; + + Double_t fLatitude = 90.0; + ; + Double_t fAltitude = 0.0; + ; + + Double_t fSubBoxLength = 100.0; + ; protected: #ifdef USE_CRY diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index f559ffc..2a87a39 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -7,80 +7,77 @@ ClassImp(TRestGeant4ParticleSourceCry); TRestGeant4ParticleSourceCry::TRestGeant4ParticleSourceCry() {} void TRestGeant4ParticleSourceCry::PrintMetadata() { - - TRestGeant4ParticleSource::PrintMetadata(); - - RESTMetadata << "Return Neutrons : " << fReturnNeutrons << RESTendl; - RESTMetadata << "Return Protons : " << fReturnProtons << RESTendl; - RESTMetadata << "Return Gammas : " << fReturnGammas << RESTendl; - RESTMetadata << "Return Electrons : " << fReturnElectrons << RESTendl; - RESTMetadata << "Return Pions : " << fReturnPions << RESTendl; - RESTMetadata << "Return Kaons : " << fReturnKaons << RESTendl; - RESTMetadata << "Return Muons : " << fReturnMuons << RESTendl; - RESTMetadata << " ======= " << RESTendl; - - RESTMetadata << "N particles min : " << fNParticlesMin << RESTendl; - RESTMetadata << "N particles max : " << fNParticlesMax << RESTendl; - RESTMetadata << " ======= " << RESTendl; - - RESTMetadata << "X-offset : " << fXOffset << "m" << RESTendl; - RESTMetadata << "Y-offset : " << fYOffset << "m" << RESTendl; - RESTMetadata << "Z-offset : " << fZOffset << "m" << RESTendl; - RESTMetadata << "SubBoxLength : " << fSubBoxLength << "m" << RESTendl; - RESTMetadata << " ======= " << RESTendl; - - RESTMetadata << "Date : " << fDate << RESTendl; - RESTMetadata << "Latitude : " << fLatitude << RESTendl; - RESTMetadata << "Altitude : " << fAltitude << RESTendl; - RESTMetadata << "----------------------" << RESTendl; + TRestGeant4ParticleSource::PrintMetadata(); + + RESTMetadata << "Return Neutrons : " << fReturnNeutrons << RESTendl; + RESTMetadata << "Return Protons : " << fReturnProtons << RESTendl; + RESTMetadata << "Return Gammas : " << fReturnGammas << RESTendl; + RESTMetadata << "Return Electrons : " << fReturnElectrons << RESTendl; + RESTMetadata << "Return Pions : " << fReturnPions << RESTendl; + RESTMetadata << "Return Kaons : " << fReturnKaons << RESTendl; + RESTMetadata << "Return Muons : " << fReturnMuons << RESTendl; + RESTMetadata << " ======= " << RESTendl; + + RESTMetadata << "N particles min : " << fNParticlesMin << RESTendl; + RESTMetadata << "N particles max : " << fNParticlesMax << RESTendl; + RESTMetadata << " ======= " << RESTendl; + + RESTMetadata << "X-offset : " << fXOffset << "m" << RESTendl; + RESTMetadata << "Y-offset : " << fYOffset << "m" << RESTendl; + RESTMetadata << "Z-offset : " << fZOffset << "m" << RESTendl; + RESTMetadata << "SubBoxLength : " << fSubBoxLength << "m" << RESTendl; + RESTMetadata << " ======= " << RESTendl; + + RESTMetadata << "Date : " << fDate << RESTendl; + RESTMetadata << "Latitude : " << fLatitude << RESTendl; + RESTMetadata << "Altitude : " << fAltitude << RESTendl; + RESTMetadata << "----------------------" << RESTendl; } void TRestGeant4ParticleSourceCry::InitFromConfigFile() { - - fReturnNeutrons = StringToInteger( GetParameter( "returnNeutrons", "1" ) ); - fReturnProtons = StringToInteger( GetParameter( "returnProtons", "1" ) ); - fReturnGammas = StringToInteger( GetParameter( "returnGammas", "1" ) ); - fReturnElectrons = StringToInteger( GetParameter( "returnElectrons", "1" ) ); - fReturnPions = StringToInteger( GetParameter( "returnPions", "1" ) ); - fReturnKaons = StringToInteger( GetParameter( "returnKaons", "1" ) ); - fReturnMuons = StringToInteger( GetParameter( "returnMuons", "1" ) ); - - fNParticlesMin = StringToInteger( GetParameter( "nParticlesMin", "1" ) ); - fNParticlesMax = StringToInteger( GetParameter( "nParticlesMax", "1000000" ) ); - - fXOffset = StringToDouble( GetParameter( "xoffset", "0.0" ) ); - fYOffset = StringToDouble( GetParameter( "yoffset", "0.0" ) ); - fZOffset = StringToDouble( GetParameter( "zoffset", "0.0" ) ); - fSubBoxLength = StringToDouble( GetParameter( "subBoxLength", "100.0" ) ); - - fDate = GetParameter( "date", "7\\1\\2012" ); - fDate = REST_StringHelper::Replace( fDate, "\\", "-" ); - fLatitude = StringToDouble( GetParameter( "latitude", "90.0" ) ); - fAltitude = StringToDouble( GetParameter( "altitude", "0.0" ) ); - - PrintMetadata(); - - std::string setupString = ""; - setupString += "returnNeutrons " + IntegerToString(fReturnNeutrons); - setupString += " returnProtons " + IntegerToString(fReturnProtons); - setupString += " returnGammas " + IntegerToString(fReturnGammas); - setupString += " returnElectrons " + IntegerToString(fReturnElectrons); - setupString += " returnPions " + IntegerToString(fReturnPions); - setupString += " returnKaons " + IntegerToString(fReturnKaons); - setupString += " returnMuons " + IntegerToString(fReturnMuons); - - setupString += " xoffset " + DoubleToString(fXOffset); - setupString += " yoffset " + DoubleToString(fYOffset); - setupString += " zoffset " + DoubleToString(fZOffset); - setupString += " subboxLength " + DoubleToString(fSubBoxLength); - - setupString += " date " + fDate; - setupString += " latitude " + DoubleToString(fLatitude); - setupString += " altitude " + DoubleToString(fAltitude); - - setupString += " nParticlesMin " + IntegerToString(fNParticlesMin); - setupString += " nParticlesMax " + IntegerToString(fNParticlesMax); - + fReturnNeutrons = StringToInteger(GetParameter("returnNeutrons", "1")); + fReturnProtons = StringToInteger(GetParameter("returnProtons", "1")); + fReturnGammas = StringToInteger(GetParameter("returnGammas", "1")); + fReturnElectrons = StringToInteger(GetParameter("returnElectrons", "1")); + fReturnPions = StringToInteger(GetParameter("returnPions", "1")); + fReturnKaons = StringToInteger(GetParameter("returnKaons", "1")); + fReturnMuons = StringToInteger(GetParameter("returnMuons", "1")); + + fNParticlesMin = StringToInteger(GetParameter("nParticlesMin", "1")); + fNParticlesMax = StringToInteger(GetParameter("nParticlesMax", "1000000")); + + fXOffset = StringToDouble(GetParameter("xoffset", "0.0")); + fYOffset = StringToDouble(GetParameter("yoffset", "0.0")); + fZOffset = StringToDouble(GetParameter("zoffset", "0.0")); + fSubBoxLength = StringToDouble(GetParameter("subBoxLength", "100.0")); + + fDate = GetParameter("date", "7\\1\\2012"); + fDate = REST_StringHelper::Replace(fDate, "\\", "-"); + fLatitude = StringToDouble(GetParameter("latitude", "90.0")); + fAltitude = StringToDouble(GetParameter("altitude", "0.0")); + + PrintMetadata(); + + std::string setupString = ""; + setupString += "returnNeutrons " + IntegerToString(fReturnNeutrons); + setupString += " returnProtons " + IntegerToString(fReturnProtons); + setupString += " returnGammas " + IntegerToString(fReturnGammas); + setupString += " returnElectrons " + IntegerToString(fReturnElectrons); + setupString += " returnPions " + IntegerToString(fReturnPions); + setupString += " returnKaons " + IntegerToString(fReturnKaons); + setupString += " returnMuons " + IntegerToString(fReturnMuons); + + setupString += " xoffset " + DoubleToString(fXOffset); + setupString += " yoffset " + DoubleToString(fYOffset); + setupString += " zoffset " + DoubleToString(fZOffset); + setupString += " subboxLength " + DoubleToString(fSubBoxLength); + + setupString += " date " + fDate; + setupString += " latitude " + DoubleToString(fLatitude); + setupString += " altitude " + DoubleToString(fAltitude); + + setupString += " nParticlesMin " + IntegerToString(fNParticlesMin); + setupString += " nParticlesMax " + IntegerToString(fNParticlesMax); #ifdef USE_CRY CRYSetup* setup = new CRYSetup(setupString, CRY_DATA_PATH); @@ -103,9 +100,10 @@ void TRestGeant4ParticleSourceCry::Update() { for (const auto& cryParticle : *ev) { // std::cout << "id: " << cryParticle->id() << std::endl; - // std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; - // std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; - // std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; + // std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() + // << std::endl; std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << + // cryParticle->w() << std::endl; std::cout << "charge: " << cryParticle->charge() << " energy: " << + // cryParticle->ke() << std::endl; TRestGeant4Particle particle; @@ -115,7 +113,7 @@ void TRestGeant4ParticleSourceCry::Update() { /// Particle position TVector3 position(cryParticle->x(), cryParticle->y(), cryParticle->z()); - particle.SetOrigin(1000. * position); // In mm (default REST units) + particle.SetOrigin(1000. * position); // In mm (default REST units) /// Momentum direction TVector3 momDirection(cryParticle->u(), cryParticle->v(), cryParticle->w()); @@ -170,7 +168,7 @@ void TRestGeant4ParticleSourceCry::Update() { AddParticle(particle); } - //std::cout << "-----" << std::endl; + // std::cout << "-----" << std::endl; #else cout << "TRestGeant4ParticleSourceCry - ERROR: Geant4lib was not linked to CRY libraries" << endl; cout << " " << endl; From 922b8816dbea3f86f9d915c23a17ee40d51ebb06 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Tue, 7 Nov 2023 11:20:11 +0100 Subject: [PATCH 14/21] TRestGeant4ParticleSourceCry. Adding documentation to metadata members --- inc/TRestGeant4ParticleSourceCry.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/inc/TRestGeant4ParticleSourceCry.h b/inc/TRestGeant4ParticleSourceCry.h index 9d29dd6..fb9a183 100644 --- a/inc/TRestGeant4ParticleSourceCry.h +++ b/inc/TRestGeant4ParticleSourceCry.h @@ -12,28 +12,51 @@ class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { private: + /// It defines if secondary neutrons will be produced by the generator Int_t fReturnNeutrons = 1; + /// It defines if secondary protons will be produced by the generator Int_t fReturnProtons = 1; + /// It defines if secondary photons will be produced by the generator Int_t fReturnGammas = 1; + /// It defines if secondary gammas will be produced by the generator Int_t fReturnElectrons = 1; + /// It defines if secondary electrons will be produced by the generator Int_t fReturnPions = 1; + /// It defines if secondary pions will be produced by the generator Int_t fReturnKaons = 1; + /// It defines if secondary muons will be produced by the generator Int_t fReturnMuons = 1; + /// Showers with number of particles below this number will be truncated. Int_t fNParticlesMin = 1; + /// Showers with number of particles above this number will be truncated. Int_t fNParticlesMax = 1000000; + /// This is likely the X-coordinate where the box of generated particles is centered. Double_t fXOffset = 0; + /// This is likely the Y-coordinate where the box of generated particles is centered. Double_t fYOffset = 0; + /// This is likely the Z-coordinate where the box of generated particles is centered. Double_t fZOffset = 0; + /// It will adjust the cosmic-ray distributions to the 11-year solar cycle. std::string fDate = "7-1-2012"; + /// The allowed range is -90 to 90. 0 defines the magnetic equator. Double_t fLatitude = 90.0;; + + /// Allowed values are 0, 2100 and 11300 m. Double_t fAltitude = 0.0;; + /// The size of the box where the CRY generator produces particles (in m). Double_t fSubBoxLength = 100.0;; + /// Seed used in random generator + Int_t fSeed = 0; //< + + /// Internal process random generator + TRandom3* fRandom = nullptr; //! + protected: #ifdef USE_CRY CRYGenerator* fCRYGenerator = nullptr; From 963141006863133f419074a9b1a7df67ac6ca9a4 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Tue, 7 Nov 2023 11:29:27 +0100 Subject: [PATCH 15/21] TRestGeant4ParticleSourceCry. Adding documentation and cleaning up --- src/TRestGeant4ParticleSourceCry.cxx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/TRestGeant4ParticleSourceCry.cxx b/src/TRestGeant4ParticleSourceCry.cxx index f559ffc..7aa0476 100644 --- a/src/TRestGeant4ParticleSourceCry.cxx +++ b/src/TRestGeant4ParticleSourceCry.cxx @@ -6,6 +6,9 @@ ClassImp(TRestGeant4ParticleSourceCry); TRestGeant4ParticleSourceCry::TRestGeant4ParticleSourceCry() {} +/////////////////////////////////////////////// +/// \brief It will print on screen the settings used for the CRY generator setup. +/// void TRestGeant4ParticleSourceCry::PrintMetadata() { TRestGeant4ParticleSource::PrintMetadata(); @@ -35,6 +38,9 @@ void TRestGeant4ParticleSourceCry::PrintMetadata() { RESTMetadata << "----------------------" << RESTendl; } +/////////////////////////////////////////////// +/// \brief Initialization of TRestGeant4ParticleSourceCry members through a RML file +/// void TRestGeant4ParticleSourceCry::InitFromConfigFile() { fReturnNeutrons = StringToInteger( GetParameter( "returnNeutrons", "1" ) ); @@ -90,6 +96,9 @@ void TRestGeant4ParticleSourceCry::InitFromConfigFile() { Update(); } +/////////////////////////////////////////////// +/// \brief It is used by restG4 PrimaryGeneratorAction to update the particle source +/// void TRestGeant4ParticleSourceCry::Update() { RemoveParticles(); @@ -102,10 +111,12 @@ void TRestGeant4ParticleSourceCry::Update() { // std::cout << "-----" << std::endl; for (const auto& cryParticle : *ev) { - // std::cout << "id: " << cryParticle->id() << std::endl; - // std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; - // std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; - // std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; + /* + std::cout << "id: " << cryParticle->id() << std::endl; + std::cout << "x: " << cryParticle->x() << " y: " << cryParticle->y() << " z: " << cryParticle->z() << std::endl; + std::cout << "u: " << cryParticle->u() << " v: " << cryParticle->v() << " w: " << cryParticle->w() << std::endl; + std::cout << "charge: " << cryParticle->charge() << " energy: " << cryParticle->ke() << std::endl; + */ TRestGeant4Particle particle; From 8897c13ae497684f2a5d1f91a3aeeb00f6203226 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:34:11 +0000 Subject: [PATCH 16/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestGeant4ParticleSourceCry.h | 97 +++++++++++++++--------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/inc/TRestGeant4ParticleSourceCry.h b/inc/TRestGeant4ParticleSourceCry.h index d908041..c67b5ef 100644 --- a/inc/TRestGeant4ParticleSourceCry.h +++ b/inc/TRestGeant4ParticleSourceCry.h @@ -1,10 +1,10 @@ #ifndef TRestParticleSourceCry_Class #define TRestParticleSourceCry_Class -#include - #include +#include + #ifdef USE_CRY #include #include @@ -13,51 +13,54 @@ #include class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { - private: - /// It defines if secondary neutrons will be produced by the generator - Int_t fReturnNeutrons = 1; - /// It defines if secondary protons will be produced by the generator - Int_t fReturnProtons = 1; - /// It defines if secondary photons will be produced by the generator - Int_t fReturnGammas = 1; - /// It defines if secondary gammas will be produced by the generator - Int_t fReturnElectrons = 1; - /// It defines if secondary electrons will be produced by the generator - Int_t fReturnPions = 1; - /// It defines if secondary pions will be produced by the generator - Int_t fReturnKaons = 1; - /// It defines if secondary muons will be produced by the generator - Int_t fReturnMuons = 1; - - /// Showers with number of particles below this number will be truncated. - Int_t fNParticlesMin = 1; - /// Showers with number of particles above this number will be truncated. - Int_t fNParticlesMax = 1000000; - - /// This is likely the X-coordinate where the box of generated particles is centered. - Double_t fXOffset = 0; - /// This is likely the Y-coordinate where the box of generated particles is centered. - Double_t fYOffset = 0; - /// This is likely the Z-coordinate where the box of generated particles is centered. - Double_t fZOffset = 0; - - /// It will adjust the cosmic-ray distributions to the 11-year solar cycle. - std::string fDate = "7-1-2012"; - - /// The allowed range is -90 to 90. 0 defines the magnetic equator. - Double_t fLatitude = 90.0;; - - /// Allowed values are 0, 2100 and 11300 m. - Double_t fAltitude = 0.0;; - - /// The size of the box where the CRY generator produces particles (in m). - Double_t fSubBoxLength = 100.0;; - - /// Seed used in random generator - Int_t fSeed = 0; //< - - /// Internal process random generator - TRandom3* fRandom = nullptr; //! + private: + /// It defines if secondary neutrons will be produced by the generator + Int_t fReturnNeutrons = 1; + /// It defines if secondary protons will be produced by the generator + Int_t fReturnProtons = 1; + /// It defines if secondary photons will be produced by the generator + Int_t fReturnGammas = 1; + /// It defines if secondary gammas will be produced by the generator + Int_t fReturnElectrons = 1; + /// It defines if secondary electrons will be produced by the generator + Int_t fReturnPions = 1; + /// It defines if secondary pions will be produced by the generator + Int_t fReturnKaons = 1; + /// It defines if secondary muons will be produced by the generator + Int_t fReturnMuons = 1; + + /// Showers with number of particles below this number will be truncated. + Int_t fNParticlesMin = 1; + /// Showers with number of particles above this number will be truncated. + Int_t fNParticlesMax = 1000000; + + /// This is likely the X-coordinate where the box of generated particles is centered. + Double_t fXOffset = 0; + /// This is likely the Y-coordinate where the box of generated particles is centered. + Double_t fYOffset = 0; + /// This is likely the Z-coordinate where the box of generated particles is centered. + Double_t fZOffset = 0; + + /// It will adjust the cosmic-ray distributions to the 11-year solar cycle. + std::string fDate = "7-1-2012"; + + /// The allowed range is -90 to 90. 0 defines the magnetic equator. + Double_t fLatitude = 90.0; + ; + + /// Allowed values are 0, 2100 and 11300 m. + Double_t fAltitude = 0.0; + ; + + /// The size of the box where the CRY generator produces particles (in m). + Double_t fSubBoxLength = 100.0; + ; + + /// Seed used in random generator + Int_t fSeed = 0; //< + + /// Internal process random generator + TRandom3* fRandom = nullptr; //! protected: #ifdef USE_CRY From 548f4bdaa5188791946a30207cdc381766799509 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Mon, 13 Nov 2023 15:34:36 +0100 Subject: [PATCH 17/21] Update inc/TRestGeant4ParticleSourceCry.h --- inc/TRestGeant4ParticleSourceCry.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/TRestGeant4ParticleSourceCry.h b/inc/TRestGeant4ParticleSourceCry.h index c67b5ef..da779d9 100644 --- a/inc/TRestGeant4ParticleSourceCry.h +++ b/inc/TRestGeant4ParticleSourceCry.h @@ -42,7 +42,7 @@ class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource { Double_t fZOffset = 0; /// It will adjust the cosmic-ray distributions to the 11-year solar cycle. - std::string fDate = "7-1-2012"; + std::string fDate = "7\1\2012"; /// The allowed range is -90 to 90. 0 defines the magnetic equator. Double_t fLatitude = 90.0; From 362908734d43c7de74e12af769d0e8bbe211f992 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 15 Nov 2023 21:41:12 +0100 Subject: [PATCH 18/21] Renaming the generator type to --- inc/TRestGeant4PrimaryGeneratorInfo.h | 2 +- src/TRestGeant4ParticleSource.cxx | 2 +- src/TRestGeant4PrimaryGeneratorInfo.cxx | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/inc/TRestGeant4PrimaryGeneratorInfo.h b/inc/TRestGeant4PrimaryGeneratorInfo.h index 0b4ec1e..761ca92 100644 --- a/inc/TRestGeant4PrimaryGeneratorInfo.h +++ b/inc/TRestGeant4PrimaryGeneratorInfo.h @@ -17,7 +17,7 @@ enum class SpatialGeneratorTypes { SURFACE, POINT, COSMIC, - CRY, + SOURCE, }; std::string SpatialGeneratorTypesToString(const SpatialGeneratorTypes&); diff --git a/src/TRestGeant4ParticleSource.cxx b/src/TRestGeant4ParticleSource.cxx index b62d0db..c05463b 100644 --- a/src/TRestGeant4ParticleSource.cxx +++ b/src/TRestGeant4ParticleSource.cxx @@ -97,7 +97,7 @@ TRestGeant4ParticleSource* TRestGeant4ParticleSource::instantiate(std::string mo } else { // use specific generator // naming convention: TRestGeant4ParticleSourceXXX - // currently supported generators: decay0, cry + // currently supported generators: decay0, source // in future we may add wrapper of generators: pythia(for HEP), etc. model[0] = *REST_StringHelper::ToUpper(std::string(&model[0], 1)).c_str(); TClass* c = TClass::GetClass(("TRestGeant4ParticleSource" + model).c_str()); diff --git a/src/TRestGeant4PrimaryGeneratorInfo.cxx b/src/TRestGeant4PrimaryGeneratorInfo.cxx index 0e837b0..1f69cfe 100644 --- a/src/TRestGeant4PrimaryGeneratorInfo.cxx +++ b/src/TRestGeant4PrimaryGeneratorInfo.cxx @@ -28,8 +28,8 @@ string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const Spa return "Point"; case SpatialGeneratorTypes::COSMIC: return "Cosmic"; - case SpatialGeneratorTypes::CRY: - return "Cry"; + case SpatialGeneratorTypes::SOURCE: + return "Source"; } cout << "TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString - Error - Unknown " "SpatialGeneratorTypes" @@ -53,9 +53,9 @@ SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGenerator } else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::COSMIC), TString::ECaseCompare::kIgnoreCase)) { return SpatialGeneratorTypes::COSMIC; - } else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::CRY), + } else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::SOURCE), TString::ECaseCompare::kIgnoreCase)) { - return SpatialGeneratorTypes::CRY; + return SpatialGeneratorTypes::SOURCE; } else { cout << "TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes - Error - Unknown " "SpatialGeneratorTypes: " From 2aaab45412cdff51c672a48e184ae857d5ddf433 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 15 Nov 2023 21:48:39 +0100 Subject: [PATCH 19/21] TRestGeant4Metadata. Adding documentation --- src/TRestGeant4Metadata.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 184bb3b..ce409aa 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -255,6 +255,9 @@ /// x, y, nothing length the rectangle. "rectangle" shape works only for "surface" /// generator type. The initial direction of the rectangle is in parallel to x-y plane. /// +/// * **source**: The positions of the particles will be defined by the particle source +/// generator, see for example TRestGeant4ParticleSourceCry. +/// /// Rotation of the virtual body defined previously is also supported. We need to define /// parameter "rotationAxis" and "rotationAngle" to do this job. The TVector3 parameter /// "rotationAxis" is a virtual axis passing through the center of the virtual body, @@ -289,7 +292,7 @@ /// /// \endcode /// -/// * the in-simulation decay0 generator package +/// * the geant4lib encoded generators, such as decay0 or cry generators /// \code /// // 2. decay0 package /// From 0a7285647de422c2d71b83e1f4976732fb9548df Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Wed, 15 Nov 2023 22:02:12 +0100 Subject: [PATCH 20/21] Migrating PrintParticleSource to PrintMetadata --- inc/TRestGeant4ParticleSource.h | 2 +- inc/TRestGeant4ParticleSourceDecay0.h | 2 +- src/TRestGeant4Metadata.cxx | 2 +- src/TRestGeant4ParticleSource.cxx | 2 +- src/TRestGeant4ParticleSourceDecay0.cxx | 14 +++++++------- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/inc/TRestGeant4ParticleSource.h b/inc/TRestGeant4ParticleSource.h index 87a0999..1799781 100644 --- a/inc/TRestGeant4ParticleSource.h +++ b/inc/TRestGeant4ParticleSource.h @@ -194,7 +194,7 @@ class TRestGeant4ParticleSource : public TRestGeant4Particle, public TRestMetada fParticles.clear(); } - virtual void PrintParticleSource(); + virtual void PrintMetadata() override; // Constructor TRestGeant4ParticleSource(); diff --git a/inc/TRestGeant4ParticleSourceDecay0.h b/inc/TRestGeant4ParticleSourceDecay0.h index b892c93..5998e6e 100644 --- a/inc/TRestGeant4ParticleSourceDecay0.h +++ b/inc/TRestGeant4ParticleSourceDecay0.h @@ -27,7 +27,7 @@ class TRestGeant4ParticleSourceDecay0 : public TRestGeant4ParticleSource { void Update() override; void InitFromConfigFile() override; inline Int_t GetNumberOfParticles() const { return fParticles.size(); } - void PrintParticleSource() override; + void PrintMetadata() override; TRestGeant4ParticleSourceDecay0(); ~TRestGeant4ParticleSourceDecay0() { delete fDecay0Model; } diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index ce409aa..d537d01 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -1456,7 +1456,7 @@ void TRestGeant4Metadata::PrintMetadata() { RESTMetadata << "Number of generated events: " << GetNumberOfEvents() << RESTendl; fGeant4PrimaryGeneratorInfo.Print(); - for (int i = 0; i < GetNumberOfSources(); i++) GetParticleSource(i)->PrintParticleSource(); + for (int i = 0; i < GetNumberOfSources(); i++) GetParticleSource(i)->PrintMetadata(); RESTMetadata << " " << RESTendl; RESTMetadata << " ++++++++++ Detector +++++++++++ " << RESTendl; diff --git a/src/TRestGeant4ParticleSource.cxx b/src/TRestGeant4ParticleSource.cxx index c05463b..35ae00b 100644 --- a/src/TRestGeant4ParticleSource.cxx +++ b/src/TRestGeant4ParticleSource.cxx @@ -32,7 +32,7 @@ TRestGeant4ParticleSource::TRestGeant4ParticleSource() = default; TRestGeant4ParticleSource::~TRestGeant4ParticleSource() = default; -void TRestGeant4ParticleSource::PrintParticleSource() { +void TRestGeant4ParticleSource::PrintMetadata() { RESTMetadata << " " << RESTendl; if (GetParticleName() != "" && GetParticleName() != "NO_SUCH_PARA") RESTMetadata << "Particle Source Name: " << GetParticleName() << RESTendl; diff --git a/src/TRestGeant4ParticleSourceDecay0.cxx b/src/TRestGeant4ParticleSourceDecay0.cxx index be8e250..e1fc15d 100644 --- a/src/TRestGeant4ParticleSourceDecay0.cxx +++ b/src/TRestGeant4ParticleSourceDecay0.cxx @@ -9,14 +9,14 @@ TRestGeant4ParticleSourceDecay0::TRestGeant4ParticleSourceDecay0() fDecay0Model = new bxdecay0::decay0_generator(); } -void TRestGeant4ParticleSourceDecay0::PrintParticleSource() { - metadata << "---------------------------------------" << endl; +void TRestGeant4ParticleSourceDecay0::PrintMetadata() { + RESTMetadata << "---------------------------------------" << RESTendl; if (!fParticleName.empty() && fParticleName != "NO_SUCH_PARA") - metadata << "Particle Source Name: " << fParticleName << endl; - metadata << "Parent Nuclide: " << fParentName << endl; - metadata << "Decay Mode: " << fDecayType << endl; - metadata << "Daughter Level: " << fDaughterLevel << endl; - metadata << "Seed: " << fSeed << endl; + RESTMetadata << "Particle Source Name: " << fParticleName << RESTendl; + RESTMetadata << "Parent Nuclide: " << fParentName << RESTendl; + RESTMetadata << "Decay Mode: " << fDecayType << RESTendl; + RESTMetadata << "Daughter Level: " << fDaughterLevel << RESTendl; + RESTMetadata << "Seed: " << fSeed << RESTendl; } void TRestGeant4ParticleSourceDecay0::InitFromConfigFile() { From e432dc2f5ae46fb9b5965dfb4145b62481cd774a Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Thu, 16 Nov 2023 13:53:10 +0100 Subject: [PATCH 21/21] TRestGeant4ParticleSource. Fixing override warning --- inc/TRestGeant4ParticleSource.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/TRestGeant4ParticleSource.h b/inc/TRestGeant4ParticleSource.h index 1799781..d9086c1 100644 --- a/inc/TRestGeant4ParticleSource.h +++ b/inc/TRestGeant4ParticleSource.h @@ -62,7 +62,7 @@ class TRestGeant4ParticleSource : public TRestGeant4Particle, public TRestMetada public: virtual void Update(); - virtual void InitFromConfigFile(); + virtual void InitFromConfigFile() override; static TRestGeant4ParticleSource* instantiate(std::string model = ""); inline TVector3 GetDirection() const { @@ -201,6 +201,6 @@ class TRestGeant4ParticleSource : public TRestGeant4Particle, public TRestMetada // Destructor virtual ~TRestGeant4ParticleSource(); - ClassDef(TRestGeant4ParticleSource, 5); + ClassDefOverride(TRestGeant4ParticleSource, 5); }; #endif