feat: debug mode; fix: root file name

This commit is contained in:
liuyihui 2023-05-14 20:38:15 +08:00
parent 9a58b5a071
commit c6fab20c6c
13 changed files with 31 additions and 73 deletions

10
include/GeneConst.hh Normal file
View File

@ -0,0 +1,10 @@
#ifndef GeneConst_hh
#define GeneConst_hh 1
#include "globals.hh"
extern G4double innerR;
extern G4double outerR;
extern G4double fBeamEnergy;
#endif

View File

@ -19,9 +19,6 @@ public:
private:
G4LogicalVolume* logicalWorld;
G4VPhysicalVolume* physicalWorld;
G4double innerR = 8.5 * cm;
G4double outerR = 13.0 * cm;
};
#endif

View File

@ -19,7 +19,6 @@ public:
private:
G4ParticleGun* particleGun;
G4double fBeamEnergy;
G4double mass[4];
G4double beta;
G4double gamma;

View File

@ -5,7 +5,6 @@
#include "globals.hh"
class G4String;
class GeneRunActionMessenger;
class GeneRunAction : public G4UserRunAction {
public:
@ -15,9 +14,6 @@ public:
public:
void BeginOfRunAction(const G4Run*);
void EndOfRunAction(const G4Run*);
inline void SetRunNo(G4String val) { RunNo = val; };
G4String RunNo;
GeneRunActionMessenger* pMessenger;
};
#endif

View File

@ -1,25 +0,0 @@
#ifndef GeneRunActionMessenger_hh
#define GeneRunActionMessenger_hh 1
#include "G4UImessenger.hh"
#include "globals.hh"
class GeneRunAction;
class G4UIdirectory;
class G4UIcmdWithAString;
class GeneRunActionMessenger : public G4UImessenger {
public:
GeneRunActionMessenger(GeneRunAction*);
virtual ~GeneRunActionMessenger();
virtual void SetNewValue(G4UIcommand*, G4String);
private:
GeneRunAction* pRunAction;
G4UIdirectory* RunDir;
G4UIcmdWithAString* RunNoCmd;
};
#endif

2
loop.mac Normal file
View File

@ -0,0 +1,2 @@
/Gene/PrimaryGA/SetBeamEnergy {energy} MeV # alpha energy for 22Ne(a,n)25Mg reaction
/run/beamOn 10000

View File

@ -5,12 +5,5 @@
/run/initialize
# energy setting
/Gene/PrimaryGA/SetBeamEnergy 1.0 MeV # alpha energy for 22Ne(a,n)25Mg reaction
# user setting for runNo of output file
/Gene/Run/RunNo 1000keV_i85_o130_10000evts
# gsp particle
/gun/particle neutron
/run/beamOn 10000
/control/loop loop.mac energy 0.1 5 0.1

7
src/GeneConst.cc Normal file
View File

@ -0,0 +1,7 @@
#include "GeneConst.hh"
#include "G4SystemOfUnits.hh"
G4double innerR = 8.5 * cm;
G4double outerR = 13.0 * cm;
G4double fBeamEnergy;

View File

@ -16,6 +16,7 @@
#include "G4ThreeVector.hh"
#include "G4Tubs.hh"
#include "G4VisAttributes.hh"
#include "GeneConst.hh"
#include "GeneHe3detSD.hh"
#include "globals.hh"

View File

@ -8,6 +8,7 @@
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"
#include "GeneAnalysisManager.hh"
#include "GeneConst.hh"
#include "GenePrimaryGeneratorAction.hh"
#include "GenePrimaryGeneratorActionMessenger.hh"
#include "Randomize.hh"

View File

@ -6,14 +6,16 @@
#include "G4VVisManager.hh"
#include "G4ios.hh"
#include "GeneAnalysisManager.hh"
#include "GeneRunActionMessenger.hh"
#include "GeneConst.hh"
GeneRunAction::GeneRunAction() : G4UserRunAction() {
RunNo = "00";
pMessenger = new GeneRunActionMessenger(this);
static G4String RunNo() {
return std::to_string(int(fBeamEnergy * 1000)) + "kev_" + std::to_string(int(innerR)) + "mm_" +
std::to_string(int(outerR)) + "mm";
}
GeneRunAction::~GeneRunAction() { delete pMessenger; }
GeneRunAction::GeneRunAction() : G4UserRunAction() {}
GeneRunAction::~GeneRunAction() {}
void GeneRunAction::BeginOfRunAction(const G4Run*) {
// Prepare the visualization
@ -23,7 +25,7 @@ void GeneRunAction::BeginOfRunAction(const G4Run*) {
}
GeneAnalysisManager* analysisManager = GeneAnalysisManager::GetInstance();
G4String sFileName = "Simulation_RunNo" + RunNo + ".root";
G4String sFileName = "Simulation_RunNo_" + RunNo() + ".root";
analysisManager->SetAnalysisFileName(sFileName);
// Open an output file
analysisManager->book();

View File

@ -1,26 +0,0 @@
#include "GeneRunActionMessenger.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIdirectory.hh"
#include "GeneRunAction.hh"
GeneRunActionMessenger::GeneRunActionMessenger(GeneRunAction* pRun) : pRunAction(pRun) {
RunDir = new G4UIdirectory("/Gene/Run/");
RunDir->SetGuidance("Commands to set RunNo");
RunNoCmd = new G4UIcmdWithAString("/Gene/Run/RunNo", this);
RunNoCmd->SetGuidance("Set RunNo of file");
RunNoCmd->SetParameterName("RunNo", false);
RunNoCmd->AvailableForStates(G4State_PreInit);
}
GeneRunActionMessenger::~GeneRunActionMessenger() {
delete RunNoCmd;
delete RunDir;
}
void GeneRunActionMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
if (command == RunNoCmd) {
pRunAction->SetRunNo(newValue);
}
}

View File

@ -1,5 +1,6 @@
set_project("Neuron Detector")
set_languages("c++17")
add_rules("mode.debug", "mode.release")
add_requires("cmake::Geant4", {
alias = "Geant4",