1 #include "TRestGeant4ParticleSourceCry.h"
7 TRestGeant4ParticleSourceCry::TRestGeant4ParticleSourceCry() {}
15 RESTMetadata <<
"Return Neutrons : " << fReturnNeutrons << RESTendl;
16 RESTMetadata <<
"Return Protons : " << fReturnProtons << RESTendl;
17 RESTMetadata <<
"Return Gammas : " << fReturnGammas << RESTendl;
18 RESTMetadata <<
"Return Electrons : " << fReturnElectrons << RESTendl;
19 RESTMetadata <<
"Return Pions : " << fReturnPions << RESTendl;
20 RESTMetadata <<
"Return Kaons : " << fReturnKaons << RESTendl;
21 RESTMetadata <<
"Return Muons : " << fReturnMuons << RESTendl;
22 RESTMetadata <<
" ======= " << RESTendl;
24 RESTMetadata <<
"N particles min : " << fNParticlesMin << RESTendl;
25 RESTMetadata <<
"N particles max : " << fNParticlesMax << RESTendl;
26 RESTMetadata <<
" ======= " << RESTendl;
28 RESTMetadata <<
"X-offset : " << fXOffset <<
"m" << RESTendl;
29 RESTMetadata <<
"Y-offset : " << fYOffset <<
"m" << RESTendl;
30 RESTMetadata <<
"Z-offset : " << fZOffset <<
"m" << RESTendl;
31 RESTMetadata <<
"SubBoxLength : " << fSubBoxLength <<
"m" << RESTendl;
32 RESTMetadata <<
" ======= " << RESTendl;
34 RESTMetadata <<
"Date : " << fDate << RESTendl;
35 RESTMetadata <<
"Latitude : " << fLatitude << RESTendl;
36 RESTMetadata <<
"Altitude : " << fAltitude << RESTendl;
37 RESTMetadata <<
"----------------------" << RESTendl;
47 fReturnElectrons =
StringToInteger(GetParameter(
"returnElectrons",
"1"));
53 fNParticlesMax =
StringToInteger(GetParameter(
"nParticlesMax",
"1000000"));
58 fSubBoxLength =
StringToDouble(GetParameter(
"subBoxLength",
"100.0"));
60 fDate = GetParameter(
"date",
"7\\1\\2012");
67 std::string setupString =
"";
81 setupString +=
" date " + fDate;
89 CRYSetup* setup =
new CRYSetup(setupString, CRY_DATA_PATH);
90 fCRYGenerator =
new CRYGenerator(setup);
103 std::vector<CRYParticle*>* ev =
new std::vector<CRYParticle*>;
105 fCRYGenerator->genEvent(ev);
110 for (
const auto& cryParticle : *ev) {
120 particle.SetParticleCharge(cryParticle->charge());
121 particle.SetExcitationLevel(0);
124 TVector3 position(cryParticle->x(), cryParticle->y(), cryParticle->z());
125 particle.SetOrigin(1000. * position);
128 TVector3 momDirection(cryParticle->u(), cryParticle->v(), cryParticle->w());
129 momDirection = momDirection.Unit();
130 particle.SetDirection(momDirection);
133 particle.SetEnergy(1000. * cryParticle->ke());
145 int id = cryParticle->id();
146 if (
id == 0) particle.SetParticleName(
"neutron");
147 if (
id == 1) particle.SetParticleName(
"proton");
149 if (cryParticle->charge() > 0)
150 particle.SetParticleName(
"pi+");
151 else if (cryParticle->charge() == 0)
152 particle.SetParticleName(
"pi0");
153 else if (cryParticle->charge() < 0)
154 particle.SetParticleName(
"pi-");
157 if (cryParticle->charge() > 0)
158 particle.SetParticleName(
"kaon+");
159 else if (cryParticle->charge() == 0)
160 particle.SetParticleName(
"kaon0");
161 else if (cryParticle->charge() < 0)
162 particle.SetParticleName(
"kaon-");
165 if (cryParticle->charge() > 0)
166 particle.SetParticleName(
"mu+");
167 else if (cryParticle->charge() < 0)
168 particle.SetParticleName(
"mu-");
171 if (cryParticle->charge() > 0)
172 particle.SetParticleName(
"e+");
173 else if (cryParticle->charge() < 0)
174 particle.SetParticleName(
"e-");
176 if (
id == 6) particle.SetParticleName(
"gamma");
178 AddParticle(particle);
182 cout <<
"TRestGeant4ParticleSourceCry - ERROR: Geant4lib was not linked to CRY libraries" << endl;
184 cout <<
"Please, compile REST using `cmake -DREST_CRY_PATH=/path/to/cry/installation/directory" << endl;
187 <<
"By default CRY libraries will generate just the static library, but REST needs the shared library"
189 cout <<
"In order to generate the SHARED object from the STATIC libCRY.a object, execute the following "
192 cout <<
"inside the CRY lib directory" << endl;
194 cout <<
"```" << endl;
195 cout <<
"gcc -shared -o libCRY.so -Wl,--whole-archive libCRY.a -Wl,--no-whole-archive" << endl;
196 cout <<
"```" << endl;
void PrintMetadata() override
It will print on screen the settings used for the CRY generator setup.
void Update() override
It is used by restG4 PrimaryGeneratorAction to update the particle source.
void InitFromConfigFile() override
Initialization of TRestGeant4ParticleSourceCry members through a RML file.
virtual void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
A class used to store particle properties.
std::string IntegerToString(Int_t n, std::string format="%d")
Gets a string from an integer.
Double_t StringToDouble(std::string in)
Gets a double from a string.
Int_t StringToInteger(std::string in)
Gets an integer from a string.
std::string DoubleToString(Double_t d, std::string format="%8.6e")
Gets a string from a double.
std::string Replace(std::string in, std::string thisString, std::string byThisString, size_t fromPosition=0, Int_t N=0)
Replace any occurences of thisSring by byThisString inside string in.