diff --git a/CODE/stepping.cc b/CODE/stepping.cc new file mode 100644 index 0000000000000000000000000000000000000000..35587eb90f74a05947d8830ab77213aa31fc1768 --- /dev/null +++ b/CODE/stepping.cc @@ -0,0 +1,42 @@ +#include "stepping.hh" +//#include "G4UserSteppingAction.hh" +#include "G4ThreeVector.hh" +#include "G4Step.hh" +#include "G4ParticleDefinition.hh" +#include "G4Track.hh" +#include "G4SystemOfUnits.hh" +#include <fstream> + +MySteppingAction::MySteppingAction() +{} + +MySteppingAction::~MySteppingAction() +{} + +void MySteppingAction :: UserSteppingAction(const G4Step* step) + { + + G4ThreeVector position = step->GetPreStepPoint()->GetPosition(); + + G4double distanceThreshold = 1200.*m; + + // Verifica si la distancia recorrida supera el umbral + if (position.z() == distanceThreshold) + { + const G4Track* track = step->GetTrack(); + G4ThreeVector momentum = track->GetMomentum(); + + G4String particleName = track->GetDynamicParticle()->GetDefinition()->GetParticleName(); + + std::ofstream outfile; + outfile.open("datos.dat", std::ios_base::app); + + // Escribir la información en el archivo + outfile << particleName << " " << position.x() << " " << position.y() << " " << position.z() << " " << momentum.x() << " " << momentum.y() << " " << momentum.z() << std::endl; + + // Cerrar el archivo + outfile.close(); + } + } + +