Dear all,
I’m a beginner and I started recently to use Geant4. I’m writing to ask help about the adoption of the user hooks (G4UserTrackingAction, G4UserSteppingAction, …). In particular, I want to print information of the particle through UserSteppingAction into an output file.
What I did at the beginning in UserSteppingAction(const G4Step * theStep)
is the printing in the output of the information in the following way:
void NewSteppingAction::UserSteppingAction(const G4Step * theStep) { ... G4StepPoint* pointIn=theStep->GetPreStepPoint(); G4StepPoint* pointOut=theStep->GetPostStepPoint(); ... G4ThreeVector posIn=pointIn->GetPosition(); G4ThreeVector posOut=pointOut->GetPosition(); extFile << posIn/cm<< " " << posOut/cm << G4endl; ... }
where the extFile has been opened at the beginning of the file NewSteppingAction.cc file:
std::ofstream extFile(“ext_file.txt”);
The problem is that,in this way, the simulation keeps opening the file at each Step with an unuseful lose of the simulation time.
For this reason, I tried to save all the data in an array, declared at the beginning of the Run, and store the information in the output file only at the end of the run.
Indeed, UserSteppingAction allows to access to the information of G4Step and I thought to do the same by including NewG4Run, a new class inherited from G4Run with the definition of the dynamic vector std::vector<G4ThreeVector> vector;
in the class. So, I implemented NewSteppingAction with the variable theRun declared with NewG4Run:
void NewSteppingAction::UserSteppingAction(const G4Step * theStep, NewG4Run* theRun)
I tried to do the same with NewG4RunAction (inherited from G4RunAction), without success: in both cases (with NewG4RunAction and NewG4Run), the simulation is not able to print any tipe of information (empty file).
Any suggestion, please? Also an explanation regarding how Geant4 works in order to pass the variables between Run, Step, Event and Track would be really appreciated!
Thank you in advance for your time!
Regards,
Christian