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

Support Latest Geant4 Versions #35

Merged
merged 22 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
54e74d1
restG4/src - replaced `NULL` by `nullptr`
lobis Mar 26, 2022
664ce98
PhysicsList.cxx - removed deprecated `G4EmProcessOptions` header and …
lobis Mar 26, 2022
80a8ca0
restG4/src - simplified checks for pointer nullness
lobis Mar 26, 2022
be8113c
PhysicsList.cxx - updated `G4RadioactiveDecay` to new API (or so I th…
lobis Mar 26, 2022
d806eea
restG4/src - minor format changes, should not have any effect
lobis Mar 26, 2022
12b64bc
TrackingAction.cxx - `G4String.contains` is now deprecated, now using…
lobis Mar 26, 2022
3f5d030
Removed fix for backwards compatibility with Geant4 version older tha…
lobis Mar 26, 2022
45939cd
removed `using namespace std;` from headers and made corresponding ad…
lobis Mar 26, 2022
0908183
CMakeLists.txt - using `add_compile_definitions` for compile definiti…
lobis Mar 26, 2022
f81ae27
Added backwards compatibility fix for `G4RadioactiveDecay`
lobis Mar 26, 2022
64fd7e4
.gitlab-ci.yml - minor formatting
lobis Mar 26, 2022
64bce4e
TrackingAction.cxx - backwards compatibility support for old `G4Strin…
lobis Mar 26, 2022
0cb2782
restG4.cxx - minor formatting changes
lobis Mar 26, 2022
7f8dd4a
.gitlab-ci.yml - placed standalone install in different directory
lobis Mar 26, 2022
986afb4
.gitlab-ci.yml - fix typo
lobis Mar 26, 2022
43af7a5
Merge remote-tracking branch 'origin/master' into lobis-support-lates…
lobis Mar 28, 2022
499741e
fix merge errors
lobis Mar 28, 2022
801a48a
PhysicsList - renamed `G4EmConfigurator` to `fEmConfig`
lobis Mar 28, 2022
5e09c3c
PhysicsList.cxx - added braces around `if`s and `for`
lobis Mar 28, 2022
146294a
PhysicsList.cxx - modernized for loop
lobis Mar 28, 2022
fd0e477
PhysicsList.cxx - added removed EM commands
lobis Mar 28, 2022
ca4bfef
PhysicsList.cxx - added braces to statements, used range based for loop
lobis Mar 28, 2022
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
44 changes: 9 additions & 35 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ before_script:
- apt update && apt install -y wget

# This is the one we use to run validations tests. We save the installation as an artifact.
build:
Build and Install:
type: build
script:
- echo "**${CI_PROJECT_DIR}**"
- git clone https://github.com/rest-for-physics/framework.git framework
- cd framework
- ./scripts/checkoutRemoteBranch.sh ${CI_COMMIT_BRANCH}
- if [ -d ${CI_PROJECT_DIR}/install ]; then rm -rf ${CI_PROJECT_DIR}/install; fi
- rm -rf ${CI_PROJECT_DIR}/install
- git submodule init source/libraries/geant4
- git submodule update source/libraries/geant4
- cd source/libraries/geant4/
Expand All @@ -38,7 +38,7 @@ build:
- cd source/packages/restG4/
- git checkout ${CI_COMMIT_BRANCH}
- cd ../../../
- if [ -d build ]; then rm -rf build; fi
- rm -rf build
- mkdir build
- cd build
- cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install
Expand All @@ -50,45 +50,21 @@ build:
- ${CI_PROJECT_DIR}/framework/build
expire_in: 1 day

build-standalone:
Build Standalone:
type: build-standalone
script:
- echo "**${CI_PROJECT_DIR}**"
- cd ${CI_PROJECT_DIR}/
- if [ -d build ]; then rm -rf build; fi
- rm -rf build
- mkdir build
- cd build
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cmake ../ -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install
- cmake ../ -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install-standalone
- make -j2 install
- ${CI_PROJECT_DIR}/install/bin/restG4 --help
- ${CI_PROJECT_DIR}/install-standalone/bin/restG4 --help
- rm -rf ${CI_PROJECT_DIR}/install-standalone

### We make sure the build and install directories are different
##build_root_6.25_Geant4_10.7.1:
## image: lobis/root-geant4-garfieldpp:cxx14_ROOTv6-25-01_Geant4v10.7.1
## type: build
## script:
## - echo "**${CI_PROJECT_DIR}**"
## - git clone --single-branch --branch development https://github.com/rest-for-physics/framework.git framework
## - cd framework
## - if [ -d ${CI_PROJECT_DIR}/install2 ]; then rm -rf ${CI_PROJECT_DIR}/install2; fi
## - git submodule init source/libraries/geant4
## - git submodule update source/libraries/geant4
## - cd source/libraries/geant4/
## - git checkout master
## - cd ../../../
## - git submodule init source/packages/restG4
## - git submodule update source/packages/restG4
## - cd source/packages/restG4/
## - git checkout ${CI_COMMIT_BRANCH}
## - cd ../../../
## - if [ -d build2 ]; then rm -rf build2; fi
## - mkdir build2
## - cd build2
## - cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install2
## - make install -j2

loadRESTLibs:
Load REST Libraries:
type: loadRESTLibs
script:
- . ${CI_PROJECT_DIR}/install/thisREST.sh
Expand Down Expand Up @@ -174,7 +150,6 @@ loadRESTLibs:
- restManager --c plots.rml --f "data/*g4Ana*root" --batch
- restRoot -b -q Validate.C


09_Pb210_Shielding:
type: examples
script:
Expand All @@ -183,7 +158,6 @@ loadRESTLibs:
- restG4 Pb210.rml
- restRoot -b -q Validate.C'("Run00001_Pb210_Shielding.root")'


10_Geometries:
type: examples
script:
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ find_package(Geant4 REQUIRED ui_all vis_all)
include(${Geant4_USE_FILE})
message("-- Found Geant4 version: ${Geant4_VERSION}")

if (${Geant4_VERSION} VERSION_GREATER "10.2.9")
add_definitions(-DG4104)
# Fix for older Geant4 versions
if (${Geant4_VERSION} VERSION_LESS 11.0.0)
add_compile_definitions(GEANT4_VERSION_LESS_11_0_0)
endif ()

# Fix to allow compatibility with older Geant4 versions that don't have G4RunManagerFactory
if (NOT EXISTS "${Geant4_INCLUDE_DIRS}/G4RunManagerFactory.hh")
add_definitions(-DWITHOUT_G4RunManagerFactory)
add_compile_definitions(GEANT4_WITHOUT_G4RunManagerFactory)
endif ()

if (NOT DEFINED CMAKE_INSTALL_PREFIX)
Expand Down
2 changes: 1 addition & 1 deletion include/PhysicsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PhysicsList : public G4VModularPhysicsList {
virtual void SetCuts();

private:
G4EmConfigurator em_config;
G4EmConfigurator fEmConfig;

G4VPhysicsConstructor* fEmPhysicsList;
G4VPhysicsConstructor* fDecPhysicsList;
Expand Down
15 changes: 3 additions & 12 deletions include/SteppingAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class SteppingAction : public G4UserSteppingAction {
SteppingAction();
~SteppingAction();

void SetBiasingVolume(TRestGeant4BiasingVolume biasVol) { restBiasingVolume = biasVol; }
void SetBiasingVolume(const TRestGeant4BiasingVolume& biasVol) { restBiasingVolume = biasVol; }
void SetBiasingSpectrum(TH1D* bSpectrum) { fBiasingSpectrum = bSpectrum; }
void SetAngularDistribution(TH1D* aDist) { fAngularDistribution = aDist; }
void SetSpatialDistribution(TH2D* sDist) { fSpatialDistribution = sDist; }
void UserSteppingAction(const G4Step*);
void UserSteppingAction(const G4Step*) override;

TRestGeant4BiasingVolume GetBiasingVolume() { return restBiasingVolume; }
TH1D* GetBiasingSpectrum() { return fBiasingSpectrum; }
Expand All @@ -37,22 +37,13 @@ class SteppingAction : public G4UserSteppingAction {
TH1D* fAngularDistribution;
TH2D* fSpatialDistribution;

Double_t absDouble(Double_t x) {
static Double_t absDouble(Double_t x) {
if (x < 0) return -x;
return x;
}

TRestGeant4BiasingVolume restBiasingVolume;

G4ThreeVector previousDirection;

/*
G4ThreeVector momentum;
G4double x, y, z;
G4int step;


void WriteDefaultInt();
*/
};
#endif
14 changes: 7 additions & 7 deletions restG4.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ int main(int argc, char** argv) {

biasing = restG4Metadata->GetNumberOfBiasingVolumes();
for (int i = 0; i < biasing; i++) {
TString spctName = "Bias_Spectrum_" + TString(Form("%d", i));
TString spectrumName = "Bias_Spectrum_" + TString(Form("%d", i));
TString angDistName = "Bias_Angular_Distribution_" + TString(Form("%d", i));
TString spatialDistName = "Bias_Spatial_Distribution_" + TString(Form("%d", i));

Double_t maxEnergy = restG4Metadata->GetBiasingVolume(i).GetMaxEnergy();
Double_t minEnergy = restG4Metadata->GetBiasingVolume(i).GetMinEnergy();
Int_t nbins = (Int_t)(maxEnergy - minEnergy);
auto nBins = (Int_t)(maxEnergy - minEnergy);

Double_t biasSize = restG4Metadata->GetBiasingVolume(i).GetBiasingVolumeSize();
TString biasType = restG4Metadata->GetBiasingVolume(i).GetBiasingVolumeType();

cout << "Initializing biasing histogram : " << spctName << endl;
biasingSpectrum[i] = new TH1D(spctName, "Biasing gamma spectrum", nbins, minEnergy, maxEnergy);
cout << "Initializing biasing histogram : " << spectrumName << endl;
biasingSpectrum[i] = new TH1D(spectrumName, "Biasing gamma spectrum", nBins, minEnergy, maxEnergy);
angularDistribution[i] = new TH1D(angDistName, "Biasing angular distribution", 150, 0, M_PI / 2);

if (biasType == "virtualSphere")
Expand Down Expand Up @@ -414,13 +414,13 @@ int main(int argc, char** argv) {
sleep(5);

// Then we just add the geometry
TFile* f1 = new TFile(Filename, "update");
auto file = new TFile(Filename, "update");
TGeoManager* geo2 = gdml->CreateGeoM();

f1->cd();
file->cd();
geo2->SetName("Geometry");
geo2->Write();
f1->Close();
file->Close();
exit(0);
}
// father process
Expand Down
5 changes: 2 additions & 3 deletions src/CommandLineSetup.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CommandLineParameters CommandLineSetup::ProcessParameters(int argc, char** argv)
// TODO: implement this in the simulation
// Multithreading mode
parameters.serialMode = false;
parameters.nThreads = std::stoi(optarg);
parameters.nThreads = stoi(optarg);
if (parameters.nThreads < 1) {
cout << "CommandLineParameters::ProcessParameters - Number of threads must be > 0"
<< endl;
Expand Down Expand Up @@ -113,7 +113,6 @@ void CommandLineSetup::Print(const CommandLineParameters& parameters) {
<< (!parameters.geometryFile.IsNull() ? "\t- Geometry file: " + parameters.geometryFile + "\n" : "")
<< (parameters.interactive ? "\t- Interactive: True\n" : "") //
<< "\t- Execution mode: "
<< (parameters.serialMode ? "serial"
: "multithreading (N = " + std::to_string(parameters.nThreads) + ")")
<< (parameters.serialMode ? "serial" : "multithreading (N = " + to_string(parameters.nThreads) + ")")
<< endl;
}
6 changes: 3 additions & 3 deletions src/DetectorConstruction.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "DetectorConstruction.h"

#include <TRestGeant4GeometryInfo.h>

#include <G4FieldManager.hh>
#include <G4IonTable.hh>
#include <G4Isotope.hh>
Expand All @@ -10,8 +12,6 @@
#include <G4UniformMagField.hh>
#include <G4UserLimits.hh>

#include "TRestGeant4GeometryInfo.h"

using namespace std;

extern TRestGeant4Event* restG4Event;
Expand Down Expand Up @@ -204,7 +204,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct() {
G4VPhysicalVolume* DetectorConstruction::GetPhysicalVolume(const G4String& physVolName) {
G4PhysicalVolumeStore* physVolStore = G4PhysicalVolumeStore::GetInstance();

std::vector<G4VPhysicalVolume*>::const_iterator physVol;
vector<G4VPhysicalVolume*>::const_iterator physVol;
for (physVol = physVolStore->begin(); physVol != physVolStore->end(); physVol++) {
auto name = (*physVol)->GetName();
auto alternativeName =
Expand Down
12 changes: 6 additions & 6 deletions src/EventAction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void EventAction::EndOfEventAction(const G4Event* geant4_event) {

// fill analysis tree
TRestAnalysisTree* analysis_tree = restRun->GetAnalysisTree();
if (analysis_tree != nullptr) {
if (analysis_tree) {
analysis_tree->SetEventInfo(subRestG4Event);
analysis_tree->Fill();
} else {
Expand All @@ -121,7 +121,7 @@ void EventAction::EndOfEventAction(const G4Event* geant4_event) {
}
// fill event tree
TTree* event_tree = restRun->GetEventTree();
if (event_tree != nullptr) {
if (event_tree) {
event_tree->Fill();
} else {
// event tree is not found (nullptr)
Expand Down Expand Up @@ -164,7 +164,7 @@ void EventAction::FillSubEvent(Int_t subId) {
subRestG4Event->SetRunOrigin(restRun->GetRunNumber());
subRestG4Event->SetSubRunOrigin(0);

time_t systime = time(NULL);
time_t systime = time(nullptr);
subRestG4Event->SetTimeStamp((Double_t)systime);

subRestG4Event->SetPrimaryEventOrigin(restG4Event->GetPrimaryEventOrigin());
Expand Down Expand Up @@ -201,7 +201,7 @@ void EventAction::FillSubEvent(Int_t subId) {
void EventAction::ReOrderTrackIds(Int_t subId) {
// We define as event timestamp the system time.
// We will be always able to extract the global simulation time from Geant4 tracks.
time_t systime = time(NULL);
time_t systime = time(nullptr);
subRestG4Event->SetTimeStamp(systime);

if (subId > 0) {
Expand Down Expand Up @@ -253,7 +253,7 @@ int EventAction::SetTrackSubEventIDs() {
Double_t timeDelay = restG4Metadata->GetSubEventTimeDelay(); // in unit us

// reorder tracks
std::map<int, TRestGeant4Track*> tracks;
map<int, TRestGeant4Track*> tracks;
for (int n = 0; n < nTracks; n++) {
TRestGeant4Track* track = restG4Event->GetTrack(n);
tracks[track->GetTrackID()] = track;
Expand All @@ -271,7 +271,7 @@ int EventAction::SetTrackSubEventIDs() {
int parentid = track->GetParentID();
TRestGeant4Track* ptrack = tracks[parentid];
while (1) {
if (ptrack != NULL) {
if (ptrack) {
tadd += ptrack->GetTrackTimeLength();
if (tadd > timeDelay) {
int subid = ptrack->GetSubEventID() + 1;
Expand Down
Loading