Skip to content

Commit 85052c5

Browse files
authored
Add an option to activate Geant4 command-line scoring (#79)
dded an option to activate Geant4 command-line scoring - The activation should be done via calling 'TG4RunConfiguration::SetUseOfG4Scoring()' in user g4Config.C - The scoring (mesh, scorers etc.) can be then defined via Geant UI commands defined in '/score' directory in g4config.in - The scoring data are then automatically saved for each mesh in a 'mesh_name.txt' file at the end of run
1 parent 2411c78 commit 85052c5

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

source/run/include/TG4RunConfiguration.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class TG4RunConfiguration
102102
void SetMTApplication(Bool_t mtApplication);
103103
void SetParameter(const TString& name, Double_t value);
104104
void SetSpecialCutsOld();
105+
void SetUseOfG4Scoring();
105106

106107
// get methods
107108
TString GetUserGeometry() const;
@@ -110,6 +111,7 @@ class TG4RunConfiguration
110111
Bool_t IsSpecialControls() const;
111112
Bool_t IsSpecialCuts() const;
112113
Bool_t IsSpecialCutsOld() const;
114+
Bool_t IsUseOfG4Scoring() const;
113115
Bool_t IsMTApplication() const;
114116

115117
protected:
@@ -122,6 +124,7 @@ class TG4RunConfiguration
122124
Bool_t fSpecialControls; ///< option for special controls
123125
Bool_t fSpecialCuts; ///< option for special cuts
124126
Bool_t fSpecialCutsOld; ///< option for special cuts old
127+
Bool_t fUseOfG4Scoring; ///< option to activate G4 commmand-line scoring
125128
G4UImessenger* fAGDDMessenger; //!< XML messenger
126129
G4UImessenger* fGDMLMessenger; //!< XML messenger
127130

@@ -141,10 +144,21 @@ class TG4RunConfiguration
141144

142145
// inline functions
143146

147+
/// Activate G4 commmand-line scoring
148+
inline void TG4RunConfiguration::SetUseOfG4Scoring()
149+
{
150+
fUseOfG4Scoring = true;
151+
}
152+
144153
/// Return physics list selection
145154
inline TString TG4RunConfiguration::GetPhysicsListSelection() const
146155
{
147156
return fPhysicsListSelection;
148157
}
149158

159+
inline Bool_t TG4RunConfiguration::IsUseOfG4Scoring() const
160+
{
161+
return fUseOfG4Scoring;
162+
}
163+
150164
#endif // TG4V_RUN_CONFIGURATION_H

source/run/src/TG4RunConfiguration.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ TG4RunConfiguration::TG4RunConfiguration(const TString& userGeometry,
4949
fSpecialControls(false),
5050
fSpecialCuts(false),
5151
fSpecialCutsOld(false),
52+
fUseOfG4Scoring(false),
5253
fAGDDMessenger(0),
5354
fGDMLMessenger(0),
5455
fParameters()

source/run/src/TG4RunManager.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@
4545
#include <G4RunManager.hh>
4646
#endif
4747

48+
#include <G4ScoringManager.hh>
49+
#include <G4VScoringMesh.hh>
50+
4851
#include <G4UIExecutive.hh>
4952
#include <G4UImanager.hh>
5053
#include <G4UIsession.hh>
5154
#include <G4Version.hh>
5255
#include <Randomize.hh>
5356

57+
5458
#ifdef USE_G4ROOT
5559
#include <TG4RootNavMgr.h>
5660
#endif
@@ -131,6 +135,11 @@ TG4RunManager::TG4RunManager(
131135

132136
// create and configure G4 run manager
133137
ConfigureRunManager();
138+
139+
if (runConfiguration->IsUseOfG4Scoring()) {
140+
// activate G4 command-line scoring
141+
G4ScoringManager::GetScoringManager();
142+
}
134143
}
135144
else {
136145
// Get G4 worker run manager
@@ -601,6 +610,16 @@ Bool_t TG4RunManager::FinishRun()
601610
G4bool result = !TG4SDServices::Instance()->GetIsStopRun();
602611
TG4SDServices::Instance()->SetIsStopRun(false);
603612

613+
if (fRunConfiguration->IsUseOfG4Scoring()) {
614+
// Dump all scoring meshes in file
615+
auto g4ScoringManager = G4ScoringManager::GetScoringManager();
616+
for (std::size_t i = 0; i < g4ScoringManager->GetNumberOfMesh(); ++i) {
617+
auto meshName = g4ScoringManager->GetMesh(i)->GetWorldName();
618+
auto fileName = meshName + ".txt";
619+
g4ScoringManager->DumpAllQuantitiesToFile(meshName, fileName);
620+
}
621+
}
622+
604623
return result;
605624
}
606625

0 commit comments

Comments
 (0)