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