Skip to content

Commit

Permalink
Merge pull request #116 from rest-for-physics/jgalan_cry
Browse files Browse the repository at this point in the history
Implementing CRY generator as a new source inside `TRestGeant4ParticleSourceCry`
  • Loading branch information
jgalan authored Nov 18, 2023
2 parents 5c51ec5 + e432dc2 commit 2502b87
Show file tree
Hide file tree
Showing 12 changed files with 419 additions and 49 deletions.
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
6 changes: 3 additions & 3 deletions inc/TRestGeant4ParticleSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -194,13 +194,13 @@ class TRestGeant4ParticleSource : public TRestGeant4Particle, public TRestMetada
fParticles.clear();
}

virtual void PrintParticleSource();
virtual void PrintMetadata() override;

// Constructor
TRestGeant4ParticleSource();
// Destructor
virtual ~TRestGeant4ParticleSource();

ClassDef(TRestGeant4ParticleSource, 5);
ClassDefOverride(TRestGeant4ParticleSource, 5);
};
#endif
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";

/// 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
2 changes: 1 addition & 1 deletion inc/TRestGeant4ParticleSourceDecay0.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
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,
SOURCE,
};

std::string SpatialGeneratorTypesToString(const SpatialGeneratorTypes&);
Expand Down
7 changes: 5 additions & 2 deletions src/TRestGeant4Metadata.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -289,7 +292,7 @@
/// <source use="Xe136bb0n.dat" />
/// \endcode
///
/// * the in-simulation decay0 generator package
/// * the geant4lib encoded generators, such as decay0 or cry generators
/// \code
/// // 2. decay0 package
/// <source use="decay0" particle="Xe136" decayMode="0vbb" daughterLevel="3" />
Expand Down Expand Up @@ -1453,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;
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;
}
6 changes: 3 additions & 3 deletions src/TRestGeant4ParticleSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down 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, 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());
if (c) // this means we have the package installed
Expand Down
Loading

0 comments on commit 2502b87

Please sign in to comment.