BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSSteppingAction.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSSteppingAction.hh"
19#include "BDSUtilities.hh"
20
21#include "globals.hh"
22#include "G4Event.hh"
23#include "G4EventManager.hh"
24#include "G4LogicalVolume.hh"
25#include "G4ThreeVector.hh"
26#include "G4Track.hh"
27#include "G4VPhysicalVolume.hh"
28#include "G4VProcess.hh"
29
30
31BDSSteppingAction::BDSSteppingAction():
32 verboseStep(false),
33 verboseEventStart(false),
34 verboseEventStop(false)
35{;}
36
37BDSSteppingAction::BDSSteppingAction(G4bool verboseStepIn,
38 G4int verboseEventStartIn,
39 G4int verboseEventStopIn):
40 verboseStep(verboseStepIn),
41 verboseEventStart(verboseEventStartIn),
42 verboseEventStop(verboseEventStopIn)
43{;}
44
45BDSSteppingAction::~BDSSteppingAction()
46{;}
47
49{
50 if (!verboseStep)
51 {return;}
52 G4int eventID = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID();
53 if (BDS::VerboseThisEvent(eventID, verboseEventStart, verboseEventStop) || verboseStep)
55}
56
58{
59 //output in case of verbose step
60 G4Track* track = step->GetTrack();
61 int trackID = track->GetTrackID();
62 G4VPhysicalVolume* pv = track->GetVolume();
63 G4LogicalVolume* lv = pv->GetLogicalVolume();
64 G4ThreeVector pos = track->GetPosition();
65 G4ThreeVector mom = track->GetMomentum() / CLHEP::GeV;
66 G4String materialName = track->GetMaterial()->GetName();
67
68 int G4precision = G4cout.precision();
69 G4cout.precision(10);
70 G4cout << "pv: " << pv->GetName() << " lv: " << lv->GetName() << G4endl;
71 G4cout << "trackID: " << trackID
72 << " pdgID: " << track->GetDefinition()->GetParticleName()
73 << " Energy: " << track->GetTotalEnergy()/CLHEP::GeV
74 << " position: " << pos << "mm "
75 << " momentum: " << mom
76 << " material: " << materialName
77 << G4endl;
78
79 auto preProcess = step->GetPreStepPoint()->GetProcessDefinedStep();
80 auto postProcess = step->GetPostStepPoint()->GetProcessDefinedStep();
81
82 if (preProcess)
83 {G4cout << "Pre-step process: " << preProcess->GetProcessName() << G4endl;}
84 if (postProcess)
85 {G4cout << "Post-step process: " << postProcess->GetProcessName() << G4endl;}
86
87 // set precision back
88 G4cout.precision(G4precision);
89}
void VerboseSteppingAction(const G4Step *step)
The implementation of the print out.
virtual void UserSteppingAction(const G4Step *step)
G4bool VerboseThisEvent(G4int eventIndex, G4int eventStart, G4int eventStop)
Logic of whether this event should be verbose or not. Code here so it's not duplicated.