Skip to content

Commit e02b603

Browse files
authored
Merge pull request #12 from rest-for-physics/revise_generators
Revise generators
2 parents 6af33c7 + 47745c6 commit e02b603

File tree

4 files changed

+442
-430
lines changed

4 files changed

+442
-430
lines changed

.gitlab-ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: lobis/root-geant4-garfieldpp:cxx14_ROOTv6-25-01_Geant4v10.4.3
1+
image: nkx1231/root6-geant4-garfield:0.8
22

33
stages:
44
- build
@@ -16,7 +16,7 @@ before_script:
1616
- apt update && apt install -y wget
1717

1818
# This is the one we use to run validations tests. We save the installation as an artifact.
19-
build_root_6.22_Geant4_10.4.2:
19+
build:
2020
type: build
2121
script:
2222
- echo "**${CI_PROJECT_DIR}**"
@@ -26,7 +26,9 @@ build_root_6.22_Geant4_10.4.2:
2626
- git submodule init source/libraries/geant4
2727
- git submodule update source/libraries/geant4
2828
- cd source/libraries/geant4/
29-
- git checkout master
29+
# We attempt to pull a branch from geant4lib named as the one at restG4.
30+
# If not it will pull master by default
31+
- ../../../scripts/checkoutRemoteBranch.sh ${CI_COMMIT_BRANCH}
3032
- cd ../../../
3133
- git submodule init source/packages/restG4
3234
- git submodule update source/packages/restG4

include/PrimaryGeneratorAction.hh

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
#ifndef PrimaryGeneratorAction_h
33
#define PrimaryGeneratorAction_h 1
44

5+
#include <TF3.h>
56
#include <TH1D.h>
67

8+
#include <fstream>
9+
#include <iostream>
10+
711
#include <G4IonTable.hh>
812
#include <G4ParticleGun.hh>
913
#include <G4VUserPrimaryGeneratorAction.hh>
10-
#include <fstream>
1114
#include <globals.hh>
12-
#include <iostream>
1315

1416
#include "DetectorConstruction.hh"
17+
#include "TRestGeant4Particle.h"
1518

1619
using namespace std;
1720

@@ -28,54 +31,21 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
2831
virtual void GeneratePrimaries(G4Event*);
2932
G4ParticleGun* GetParticleGun() { return fParticleGun; };
3033

31-
void SetSpectrum(TH1D* spt, double eMin = 0, double eMax = 0) {
32-
TString xLabel = (TString)spt->GetXaxis()->GetTitle();
33-
34-
if (xLabel.Contains("MeV")) {
35-
energyFactor = 1.e3;
36-
} else if (xLabel.Contains("GeV")) {
37-
energyFactor = 1.e6;
38-
} else {
39-
energyFactor = 1.;
40-
}
41-
42-
fSpectrum = spt;
43-
fSpectrumIntegral = fSpectrum->Integral();
44-
45-
startEnergyBin = 1;
46-
endEnergyBin = fSpectrum->GetNbinsX();
47-
48-
if (eMin > 0) {
49-
for (int i = startEnergyBin; i <= endEnergyBin; i++) {
50-
if (fSpectrum->GetBinCenter(i) > eMin) {
51-
startEnergyBin = i;
52-
break;
53-
}
54-
}
55-
}
56-
57-
if (eMax > 0) {
58-
for (int i = startEnergyBin; i <= endEnergyBin; i++) {
59-
if (fSpectrum->GetBinCenter(i) > eMax) {
60-
endEnergyBin = i;
61-
break;
62-
}
63-
}
64-
}
65-
66-
fSpectrumIntegral = fSpectrum->Integral(startEnergyBin, endEnergyBin);
67-
}
34+
void SetSpectrum(TH1D* spt, double eMin = 0, double eMax = 0);
35+
void SetGeneratorSpatialDensity(TString str);
6836

6937
void SetAngularDistribution(TH1D* ang) { fAngularDistribution = ang; }
7038

7139
private:
40+
vector<TRestGeant4Particle> fTempParticles;
41+
7242
G4ParticleGun* fParticleGun;
7343
DetectorConstruction* fDetector;
74-
7544
G4ParticleDefinition* fParticle = nullptr;
7645

7746
TH1D* fSpectrum;
7847
TH1D* fAngularDistribution;
48+
TF3* fGeneratorSpatialDensityFunction;
7949

8050
Int_t startEnergyBin;
8151
Int_t endEnergyBin;
@@ -88,15 +58,26 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
8858
Double_t lastEnergy;
8959

9060
void SetParticlePosition();
91-
void SetParticlePosition(int n);
92-
G4ParticleDefinition* SetParticleDefinition(int n);
93-
void SetParticleEnergy(int n);
94-
void SetParticleDirection(int n);
61+
G4ParticleDefinition* SetParticleDefinition(Int_t particlesourceindex, TRestGeant4Particle p);
62+
void SetParticleEnergy(Int_t particlesourceindex, TRestGeant4Particle p);
63+
void SetParticleDirection(Int_t particlesourceindex, TRestGeant4Particle p);
9564

9665
G4ThreeVector GetIsotropicVector();
9766
Double_t GetAngle(G4ThreeVector x, G4ThreeVector y);
9867
Double_t GetCosineLowRandomThetaAngle();
9968

69+
void GenPositionOnGDMLVolume(double& x, double& y, double& z);
70+
void GenPositionOnGDMLSurface(double& x, double& y, double& z);
71+
void GenPositionOnBoxVolume(double& x, double& y, double& z);
72+
void GenPositionOnBoxSurface(double& x, double& y, double& z);
73+
void GenPositionOnSphereVolume(double& x, double& y, double& z);
74+
void GenPositionOnSphereSurface(double& x, double& y, double& z);
75+
void GenPositionOnCylinderVolume(double& x, double& y, double& z);
76+
void GenPositionOnCylinderSurface(double& x, double& y, double& z);
77+
void GenPositionOnPoint(double& x, double& y, double& z);
78+
void GenPositionOnWall(double& x, double& y, double& z);
79+
void GenPositionOnPlate(double& x, double& y, double& z);
80+
10081
G4String fParType;
10182
G4String fGenType;
10283
G4double fParEnergy;

restG4.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ int main(int argc, char** argv) {
182182
// set user action classes
183183
PrimaryGeneratorAction* prim = new PrimaryGeneratorAction(det);
184184

185-
if (restG4Metadata->GetParticleSource(0).GetEnergyDistType() == "TH1D") {
186-
TString fileFullPath = (TString)restG4Metadata->GetParticleSource(0).GetSpectrumFilename();
185+
if (restG4Metadata->GetParticleSource(0)->GetEnergyDistType() == "TH1D") {
186+
TString fileFullPath = (TString)restG4Metadata->GetParticleSource(0)->GetSpectrumFilename();
187187

188188
TFile fin(fileFullPath);
189189

190-
TString sptName = restG4Metadata->GetParticleSource(0).GetSpectrumName();
190+
TString sptName = restG4Metadata->GetParticleSource(0)->GetSpectrumName();
191191

192192
TH1D* h = (TH1D*)fin.Get(sptName);
193193
;
@@ -200,22 +200,22 @@ int main(int argc, char** argv) {
200200

201201
initialEnergySpectrum = *h;
202202

203-
Double_t minEnergy = restG4Metadata->GetParticleSource(0).GetMinEnergy();
203+
Double_t minEnergy = restG4Metadata->GetParticleSource(0)->GetMinEnergy();
204204
if (minEnergy < 0) minEnergy = 0;
205205

206-
Double_t maxEnergy = restG4Metadata->GetParticleSource(0).GetMaxEnergy();
206+
Double_t maxEnergy = restG4Metadata->GetParticleSource(0)->GetMaxEnergy();
207207
if (maxEnergy < 0) maxEnergy = 0;
208208

209209
// We set the initial spectrum energy provided from TH1D
210210
prim->SetSpectrum(&initialEnergySpectrum, minEnergy, maxEnergy);
211211
}
212212

213-
if (restG4Metadata->GetParticleSource(0).GetAngularDistType() == "TH1D") {
214-
TString fileFullPath = (TString)restG4Metadata->GetParticleSource(0).GetAngularFilename();
213+
if (restG4Metadata->GetParticleSource(0)->GetAngularDistType() == "TH1D") {
214+
TString fileFullPath = (TString)restG4Metadata->GetParticleSource(0)->GetAngularFilename();
215215

216216
TFile fin(fileFullPath);
217217

218-
TString sptName = restG4Metadata->GetParticleSource(0).GetAngularName();
218+
TString sptName = restG4Metadata->GetParticleSource(0)->GetAngularName();
219219
TH1D* h = (TH1D*)fin.Get(sptName);
220220
;
221221
if (h == NULL) {
@@ -311,13 +311,13 @@ int main(int argc, char** argv) {
311311
while (biasing) {
312312
// Definning isotropic gammas using the spectrum and angular distribution
313313
// previously obtained
314-
restG4Metadata->RemoveSources();
314+
restG4Metadata->RemoveParticleSources();
315315

316-
TRestGeant4ParticleSource src;
317-
src.SetParticleName("gamma");
318-
src.SetEnergyDistType("TH1D");
319-
src.SetAngularDistType("TH1D");
320-
restG4Metadata->AddSource(src);
316+
TRestGeant4ParticleSource* src = new TRestGeant4ParticleSource();
317+
src->SetParticleName("gamma");
318+
src->SetEnergyDistType("TH1D");
319+
src->SetAngularDistType("TH1D");
320+
restG4Metadata->AddParticleSource(src);
321321

322322
// We set the spectrum from previous biasing volume inside the primary
323323
// generator
@@ -331,8 +331,8 @@ int main(int argc, char** argv) {
331331
// the biasing volume
332332
restG4Metadata->SetGeneratorType(
333333
restG4Metadata->GetBiasingVolume(biasing).GetBiasingVolumeType());
334-
restG4Metadata->SetGeneratorSize(
335-
restG4Metadata->GetBiasingVolume(biasing).GetBiasingVolumeSize());
334+
double size = restG4Metadata->GetBiasingVolume(biasing).GetBiasingVolumeSize();
335+
restG4Metadata->SetGeneratorSize(TVector3(size,size,size));
336336
// restG4Metadata->GetBiasingVolume( biasing-1 ).PrintBiasingVolume();
337337

338338
// Definning biasing the number of event to be re-launched

0 commit comments

Comments
 (0)