Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing CRY generator as a new source inside TRestGeant4ParticleSourceCry #116

Merged
merged 26 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d863831
TRestGeant4PrimaryGeneratorInfo. Adding CRY generator type
jgalan Nov 3, 2023
602f71d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 3, 2023
d009120
CMakeLists.txt adding CRY libraries dependency
jgalan Nov 4, 2023
932c3cc
Adding first TRestGeant4ParticleSourceCry draft
jgalan Nov 4, 2023
bf1c0a4
Merge branch 'jgalan_cry' of github.com:rest-for-physics/geant4lib in…
jgalan Nov 4, 2023
544a528
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2023
7abd379
TRestGeant4ParticleSourceCry. Improving non-CRY libraries message
jgalan Nov 4, 2023
730384d
Merge branch 'jgalan_cry' of github.com:rest-for-physics/geant4lib in…
jgalan Nov 4, 2023
039652c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2023
b28ba40
TRestGeant4Particle. Added official headers and a new Print method
jgalan Nov 4, 2023
ca2f235
Merge branch 'jgalan_cry' of github.com:rest-for-physics/geant4lib in…
jgalan Nov 4, 2023
9255070
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2023
d0bc467
TRestGeant4ParticleSourceCry. commenting debug output
jgalan Nov 4, 2023
e0ac6e7
TRestGeant4ParticleSourceCry. Fixed position units
jgalan Nov 4, 2023
e318c30
Merge branch 'jgalan_cry' of github.com:rest-for-physics/geant4lib in…
jgalan Nov 4, 2023
c6af986
TRestGeant4ParticleSourceCry. Adding metadata members to setup the CR…
jgalan Nov 5, 2023
825bf99
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2023
922b881
TRestGeant4ParticleSourceCry. Adding documentation to metadata members
jgalan Nov 7, 2023
9631410
TRestGeant4ParticleSourceCry. Adding documentation and cleaning up
jgalan Nov 7, 2023
9cea4cd
Merge branch 'jgalan_cry' of github.com:rest-for-physics/geant4lib in…
jgalan Nov 7, 2023
8897c13
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2023
548f4bd
Update inc/TRestGeant4ParticleSourceCry.h
jgalan Nov 13, 2023
3629087
Renaming the generator type to
jgalan Nov 15, 2023
2aaab45
TRestGeant4Metadata. Adding documentation
jgalan Nov 15, 2023
0a72856
Migrating PrintParticleSource to PrintMetadata
jgalan Nov 15, 2023
e432dc2
TRestGeant4ParticleSource. Fixing override warning
jgalan Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/*")
Expand Down
47 changes: 26 additions & 21 deletions inc/TRestGeant4Particle.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +28,7 @@

#include <iostream>

/// A class used to store particle properties
class TRestGeant4Particle {
protected:
TString fParticleName;
Expand All @@ -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;
Expand All @@ -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
Expand Down
80 changes: 80 additions & 0 deletions inc/TRestGeant4ParticleSourceCry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef TRestParticleSourceCry_Class
#define TRestParticleSourceCry_Class

#include <TRandom3.h>

#include <iostream>

#ifdef USE_CRY
#include <CRYGenerator.h>
#include <CRYSetup.h>
#endif

#include <TRestGeant4ParticleSource.h>

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";
jgalan marked this conversation as resolved.
Show resolved Hide resolved

/// 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;
#endif

public:
void Update() override;
void InitFromConfigFile() override;
inline Int_t GetNumberOfParticles() const { return fParticles.size(); }
void PrintMetadata() override;

TRestGeant4ParticleSourceCry();
~TRestGeant4ParticleSourceCry() {}
ClassDefOverride(TRestGeant4ParticleSourceCry, 1);
};
#endif
1 change: 1 addition & 0 deletions inc/TRestGeant4PrimaryGeneratorInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum class SpatialGeneratorTypes {
SURFACE,
POINT,
COSMIC,
CRY,
};

std::string SpatialGeneratorTypesToString(const SpatialGeneratorTypes&);
Expand Down
73 changes: 61 additions & 12 deletions src/TRestGeant4Particle.cxx
Original file line number Diff line number Diff line change
@@ -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
///
/// <hr>
///
/// jul 2015: First concept
/// Created as part of the conceptualization of existing REST
/// software.
/// J. Galan
///_______________________________________________________________________________

#include "TRestGeant4Particle.h"

using namespace std;
Expand All @@ -28,3 +50,30 @@ 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;
}
4 changes: 2 additions & 2 deletions src/TRestGeant4ParticleSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ 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
Expand Down
Loading