Skip to content

Commit 2502b87

Browse files
authored
Merge pull request #116 from rest-for-physics/jgalan_cry
Implementing CRY generator as a new source inside `TRestGeant4ParticleSourceCry`
2 parents 5c51ec5 + e432dc2 commit 2502b87

12 files changed

+419
-49
lines changed

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,33 @@ if (NOT ${REST_EVE} MATCHES "ON")
5252
set(excludes ${excludes} TRestGeant4EventViewer)
5353
endif ()
5454

55+
if (DEFINED REST_CRY_PATH)
56+
find_path(CRY_LIB_PATH libCRY.a HINTS ${REST_CRY_PATH}/lib)
57+
58+
find_path(CRY_INC_PATH CRYGenerator.h HINTS ${REST_CRY_PATH}/src)
59+
60+
if (CRY_LIB_PATH AND CRY_INC_PATH)
61+
message(STATUS "Found CRY includes in ${CRY_INC_PATH}")
62+
message(STATUS "Found CRY library in ${CRY_LIB_PATH}")
63+
64+
add_compile_definitions("USE_CRY")
65+
add_compile_definitions("CRY_DATA_PATH=\"${REST_CRY_PATH}/data\"")
66+
67+
set(external_include_dirs ${external_include_dirs} ${CRY_INC_PATH})
68+
set(external_libs "${external_libs} -L${CRY_LIB_PATH} -lCRY")
69+
70+
set(feature_added "Cry")
71+
set(feature_added
72+
${feature_added}
73+
PARENT_SCOPE)
74+
else ()
75+
message(
76+
FATAL_ERROR
77+
"REST_CRY_PATH was defined with path ${REST_CRY_PATH}, but CRY library was not found there!\n"
78+
)
79+
endif ()
80+
endif (DEFINED REST_CRY_PATH)
81+
5582
compilelib("")
5683

5784
file(GLOB_RECURSE MAC "${CMAKE_CURRENT_SOURCE_DIR}/macros/*")

inc/TRestGeant4Particle.h

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
//////////////////////////////////////////////////////////////////////////
2-
///
3-
/// RESTSoft : Software for Rare Event Searches with TPCs
4-
///
5-
/// TRestGeant4Particle.h
6-
///
7-
/// Class to store a particle definition
8-
///
9-
/// jul 2015: First concept
10-
/// Created as part of the conceptualization of existing REST
11-
/// software.
12-
/// J. Galan
13-
///
14-
//////////////////////////////////////////////////////////////////////////
1+
/*************************************************************************
2+
* This file is part of the REST software framework. *
3+
* *
4+
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5+
* For more information see http://gifna.unizar.es/trex *
6+
* *
7+
* REST is free software: you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation, either version 3 of the License, or *
10+
* (at your option) any later version. *
11+
* *
12+
* REST is distributed in the hope that it will be useful, *
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15+
* GNU General Public License for more details. *
16+
* *
17+
* You should have a copy of the GNU General Public License along with *
18+
* REST in $REST_PATH/LICENSE. *
19+
* If not, see http://www.gnu.org/licenses/. *
20+
* For the list of contributors see $REST_PATH/CREDITS. *
21+
*************************************************************************/
1522

1623
#ifndef RestCore_TRestGeant4Particle
1724
#define RestCore_TRestGeant4Particle
@@ -21,6 +28,7 @@
2128

2229
#include <iostream>
2330

31+
/// A class used to store particle properties
2432
class TRestGeant4Particle {
2533
protected:
2634
TString fParticleName;
@@ -38,15 +46,10 @@ class TRestGeant4Particle {
3846
inline Int_t GetParticleCharge() const { return fCharge; }
3947
inline TVector3 GetOrigin() const { return fOrigin; }
4048

41-
void SetParticle(TRestGeant4Particle particle) {
42-
fExcitationLevel = particle.GetExcitationLevel();
43-
fParticleName = particle.GetParticleName();
44-
fEnergy = particle.GetEnergy();
45-
fDirection = particle.GetMomentumDirection();
46-
fOrigin = particle.fOrigin;
47-
}
49+
void SetParticle(TRestGeant4Particle particle);
4850

4951
void SetParticleName(TString particle) { fParticleName = particle; }
52+
5053
void SetExcitationLevel(Double_t excitationEnergy) {
5154
fExcitationLevel = excitationEnergy;
5255
if (fExcitationLevel < 0) fExcitationLevel = 0;
@@ -58,6 +61,8 @@ class TRestGeant4Particle {
5861
void SetEnergy(Double_t en) { fEnergy = en; }
5962
void SetOrigin(TVector3 pos) { fOrigin = pos; }
6063

64+
void Print() const;
65+
6166
// Constructor
6267
TRestGeant4Particle();
6368
// Destructor

inc/TRestGeant4ParticleSource.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TRestGeant4ParticleSource : public TRestGeant4Particle, public TRestMetada
6262

6363
public:
6464
virtual void Update();
65-
virtual void InitFromConfigFile();
65+
virtual void InitFromConfigFile() override;
6666
static TRestGeant4ParticleSource* instantiate(std::string model = "");
6767

6868
inline TVector3 GetDirection() const {
@@ -194,13 +194,13 @@ class TRestGeant4ParticleSource : public TRestGeant4Particle, public TRestMetada
194194
fParticles.clear();
195195
}
196196

197-
virtual void PrintParticleSource();
197+
virtual void PrintMetadata() override;
198198

199199
// Constructor
200200
TRestGeant4ParticleSource();
201201
// Destructor
202202
virtual ~TRestGeant4ParticleSource();
203203

204-
ClassDef(TRestGeant4ParticleSource, 5);
204+
ClassDefOverride(TRestGeant4ParticleSource, 5);
205205
};
206206
#endif

inc/TRestGeant4ParticleSourceCry.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#ifndef TRestParticleSourceCry_Class
2+
#define TRestParticleSourceCry_Class
3+
4+
#include <TRandom3.h>
5+
6+
#include <iostream>
7+
8+
#ifdef USE_CRY
9+
#include <CRYGenerator.h>
10+
#include <CRYSetup.h>
11+
#endif
12+
13+
#include <TRestGeant4ParticleSource.h>
14+
15+
class TRestGeant4ParticleSourceCry : public TRestGeant4ParticleSource {
16+
private:
17+
/// It defines if secondary neutrons will be produced by the generator
18+
Int_t fReturnNeutrons = 1;
19+
/// It defines if secondary protons will be produced by the generator
20+
Int_t fReturnProtons = 1;
21+
/// It defines if secondary photons will be produced by the generator
22+
Int_t fReturnGammas = 1;
23+
/// It defines if secondary gammas will be produced by the generator
24+
Int_t fReturnElectrons = 1;
25+
/// It defines if secondary electrons will be produced by the generator
26+
Int_t fReturnPions = 1;
27+
/// It defines if secondary pions will be produced by the generator
28+
Int_t fReturnKaons = 1;
29+
/// It defines if secondary muons will be produced by the generator
30+
Int_t fReturnMuons = 1;
31+
32+
/// Showers with number of particles below this number will be truncated.
33+
Int_t fNParticlesMin = 1;
34+
/// Showers with number of particles above this number will be truncated.
35+
Int_t fNParticlesMax = 1000000;
36+
37+
/// This is likely the X-coordinate where the box of generated particles is centered.
38+
Double_t fXOffset = 0;
39+
/// This is likely the Y-coordinate where the box of generated particles is centered.
40+
Double_t fYOffset = 0;
41+
/// This is likely the Z-coordinate where the box of generated particles is centered.
42+
Double_t fZOffset = 0;
43+
44+
/// It will adjust the cosmic-ray distributions to the 11-year solar cycle.
45+
std::string fDate = "7\1\2012";
46+
47+
/// The allowed range is -90 to 90. 0 defines the magnetic equator.
48+
Double_t fLatitude = 90.0;
49+
;
50+
51+
/// Allowed values are 0, 2100 and 11300 m.
52+
Double_t fAltitude = 0.0;
53+
;
54+
55+
/// The size of the box where the CRY generator produces particles (in m).
56+
Double_t fSubBoxLength = 100.0;
57+
;
58+
59+
/// Seed used in random generator
60+
Int_t fSeed = 0; //<
61+
62+
/// Internal process random generator
63+
TRandom3* fRandom = nullptr; //!
64+
65+
protected:
66+
#ifdef USE_CRY
67+
CRYGenerator* fCRYGenerator = nullptr;
68+
#endif
69+
70+
public:
71+
void Update() override;
72+
void InitFromConfigFile() override;
73+
inline Int_t GetNumberOfParticles() const { return fParticles.size(); }
74+
void PrintMetadata() override;
75+
76+
TRestGeant4ParticleSourceCry();
77+
~TRestGeant4ParticleSourceCry() {}
78+
ClassDefOverride(TRestGeant4ParticleSourceCry, 1);
79+
};
80+
#endif

inc/TRestGeant4ParticleSourceDecay0.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TRestGeant4ParticleSourceDecay0 : public TRestGeant4ParticleSource {
2727
void Update() override;
2828
void InitFromConfigFile() override;
2929
inline Int_t GetNumberOfParticles() const { return fParticles.size(); }
30-
void PrintParticleSource() override;
30+
void PrintMetadata() override;
3131

3232
TRestGeant4ParticleSourceDecay0();
3333
~TRestGeant4ParticleSourceDecay0() { delete fDecay0Model; }

inc/TRestGeant4PrimaryGeneratorInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum class SpatialGeneratorTypes {
1717
SURFACE,
1818
POINT,
1919
COSMIC,
20+
SOURCE,
2021
};
2122

2223
std::string SpatialGeneratorTypesToString(const SpatialGeneratorTypes&);

src/TRestGeant4Metadata.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@
255255
/// x, y, nothing length the rectangle. "rectangle" shape works only for "surface"
256256
/// generator type. The initial direction of the rectangle is in parallel to x-y plane.
257257
///
258+
/// * **source**: The positions of the particles will be defined by the particle source
259+
/// generator, see for example TRestGeant4ParticleSourceCry.
260+
///
258261
/// Rotation of the virtual body defined previously is also supported. We need to define
259262
/// parameter "rotationAxis" and "rotationAngle" to do this job. The TVector3 parameter
260263
/// "rotationAxis" is a virtual axis passing through the center of the virtual body,
@@ -289,7 +292,7 @@
289292
/// <source use="Xe136bb0n.dat" />
290293
/// \endcode
291294
///
292-
/// * the in-simulation decay0 generator package
295+
/// * the geant4lib encoded generators, such as decay0 or cry generators
293296
/// \code
294297
/// // 2. decay0 package
295298
/// <source use="decay0" particle="Xe136" decayMode="0vbb" daughterLevel="3" />
@@ -1453,7 +1456,7 @@ void TRestGeant4Metadata::PrintMetadata() {
14531456
RESTMetadata << "Number of generated events: " << GetNumberOfEvents() << RESTendl;
14541457
fGeant4PrimaryGeneratorInfo.Print();
14551458

1456-
for (int i = 0; i < GetNumberOfSources(); i++) GetParticleSource(i)->PrintParticleSource();
1459+
for (int i = 0; i < GetNumberOfSources(); i++) GetParticleSource(i)->PrintMetadata();
14571460

14581461
RESTMetadata << " " << RESTendl;
14591462
RESTMetadata << " ++++++++++ Detector +++++++++++ " << RESTendl;

src/TRestGeant4Particle.cxx

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
1-
///_______________________________________________________________________________
2-
///_______________________________________________________________________________
3-
///_______________________________________________________________________________
1+
/*************************************************************************
2+
* This file is part of the REST software framework. *
3+
* *
4+
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5+
* For more information see http://gifna.unizar.es/trex *
6+
* *
7+
* REST is free software: you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation, either version 3 of the License, or *
10+
* (at your option) any later version. *
11+
* *
12+
* REST is distributed in the hope that it will be useful, *
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15+
* GNU General Public License for more details. *
16+
* *
17+
* You should have a copy of the GNU General Public License along with *
18+
* REST in $REST_PATH/LICENSE. *
19+
* If not, see http://www.gnu.org/licenses/. *
20+
* For the list of contributors see $REST_PATH/CREDITS. *
21+
*************************************************************************/
22+
23+
//////////////////////////////////////////////////////////////////////////
24+
/// TRestGeant4Particle is just a container class to store particle properties
425
///
526
///
6-
/// RESTSoft : Software for Rare Event Searches with TPCs
27+
///--------------------------------------------------------------------------
728
///
8-
/// TRestGeant4Particle.cxx
29+
/// RESTsoft - Software for Rare Event Searches with TPCs
930
///
10-
/// Base class from which to inherit all other event classes in REST
31+
/// History of developments:
32+
///
33+
/// 2015-July: First concept and implementation
34+
/// \author Javier Galan
35+
///
36+
/// \class TRestGeant4Particle
37+
///
38+
/// <hr>
1139
///
12-
/// jul 2015: First concept
13-
/// Created as part of the conceptualization of existing REST
14-
/// software.
15-
/// J. Galan
16-
///_______________________________________________________________________________
17-
1840
#include "TRestGeant4Particle.h"
1941

2042
using namespace std;
@@ -28,3 +50,30 @@ TRestGeant4Particle::TRestGeant4Particle() {
2850
TRestGeant4Particle::~TRestGeant4Particle() {
2951
// TRestGeant4Particle destructor
3052
}
53+
54+
///////////////////////////////////////////////
55+
/// \brief A copy method
56+
///
57+
void TRestGeant4Particle::SetParticle(TRestGeant4Particle particle) {
58+
fExcitationLevel = particle.GetExcitationLevel();
59+
fParticleName = particle.GetParticleName();
60+
fEnergy = particle.GetEnergy();
61+
fDirection = particle.GetMomentumDirection();
62+
fOrigin = particle.fOrigin;
63+
}
64+
65+
///////////////////////////////////////////////
66+
/// \brief Prints on screen the details about the Geant4 simulation
67+
/// conditions, stored in TRestGeant4Metadata.
68+
///
69+
void TRestGeant4Particle::Print() const {
70+
std::cout << "Particle name : " << GetParticleName() << std::endl;
71+
std::cout << "Charge : " << GetParticleCharge() << std::endl;
72+
std::cout << "Energy : " << GetEnergy() << " keV" << std::endl;
73+
std::cout << "Excitation level : " << GetExcitationLevel() << std::endl;
74+
std::cout << "X : " << GetOrigin().X() << "mm Y : " << GetOrigin().Y() << "mm Z : " << GetOrigin().Z()
75+
<< "mm" << std::endl;
76+
std::cout << "Px : " << GetMomentumDirection().X() << " Py : " << GetMomentumDirection().Y()
77+
<< " Pz : " << GetMomentumDirection().Z() << std::endl;
78+
std::cout << " ---------------------- " << std::endl;
79+
}

src/TRestGeant4ParticleSource.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ TRestGeant4ParticleSource::TRestGeant4ParticleSource() = default;
3232

3333
TRestGeant4ParticleSource::~TRestGeant4ParticleSource() = default;
3434

35-
void TRestGeant4ParticleSource::PrintParticleSource() {
35+
void TRestGeant4ParticleSource::PrintMetadata() {
3636
RESTMetadata << " " << RESTendl;
3737
if (GetParticleName() != "" && GetParticleName() != "NO_SUCH_PARA")
3838
RESTMetadata << "Particle Source Name: " << GetParticleName() << RESTendl;
@@ -97,8 +97,8 @@ TRestGeant4ParticleSource* TRestGeant4ParticleSource::instantiate(std::string mo
9797
} else {
9898
// use specific generator
9999
// naming convention: TRestGeant4ParticleSourceXXX
100-
// currently supported generator: decay0
101-
// in future we may add wrapper of generators: cry(for muon), pythia(for HEP), etc.
100+
// currently supported generators: decay0, source
101+
// in future we may add wrapper of generators: pythia(for HEP), etc.
102102
model[0] = *REST_StringHelper::ToUpper(std::string(&model[0], 1)).c_str();
103103
TClass* c = TClass::GetClass(("TRestGeant4ParticleSource" + model).c_str());
104104
if (c) // this means we have the package installed

0 commit comments

Comments
 (0)