BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSSDTerminator.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 "BDSDebug.hh"
19#include "BDSGlobalConstants.hh"
20#include "BDSSDTerminator.hh"
21
22#include "G4ios.hh"
23#include "G4TouchableHistory.hh"
24#include "G4VTouchable.hh"
25#include "G4Step.hh"
26
27#include <iomanip>
28
30
31
32BDSSDTerminator::BDSSDTerminator(G4String name)
33 :G4VSensitiveDetector(name)
34{
35 moduloEvents = BDSGlobalConstants::Instance()->PrintModuloEvents();
36 moduloTurns = BDSGlobalConstants::Instance()->PrintModuloTurns();
37}
38
39BDSSDTerminator::~BDSSDTerminator()
40{
41 eventNumber = 0;
42}
43
44void BDSSDTerminator::Initialize(G4HCofThisEvent* /*HCE*/)
45{
47 //we don't actually use HCE here as we don't need to log any of the particle info
48}
49
50G4bool BDSSDTerminator::ProcessHits(G4Step* aStep, G4TouchableHistory*)
51{
52 G4Track* theTrack = aStep->GetTrack();
53 G4int parentID = theTrack->GetParentID();
54 G4double trackLength = theTrack->GetTrackLength();
55#ifdef BDSDEBUG
56 G4cout << __METHOD_NAME__ << "parentID: " << parentID << G4endl;
57 G4cout << __METHOD_NAME__ << "track lenth (mm): " << trackLength << G4endl;
58#endif
59
60 if ((parentID == 0) && (trackLength > 1000) && aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary)
61 {
62 // parentID == 0 -> primary particle - should only increment turn number for primaries
63 // trackLength > 1000 (mm) -> not due to initial coordinate offset (at least 1 turn)
64 // pre step point status is on a geometry boundary -> particle just entering volume
65 // and not starting in middle
66#ifdef BDSDEBUG
67 G4cout << __METHOD_NAME__ << "Incrementing turn number " << G4endl;
68 G4cout << __METHOD_NAME__ << "Primary particle - incrementing turn number" << G4endl;
69 G4cout << __METHOD_NAME__ << "Track length is : " << trackLength << " m" << G4endl;
70 G4cout << __METHOD_NAME__ << "Turn number is : " << BDSGlobalConstants::Instance()->TurnsTaken() << G4endl;
71#endif
72 if (eventNumber % moduloEvents == 0)
73 {// feedback on this event
74 G4int turnstaken = BDSGlobalConstants::Instance()->TurnsTaken();
75 if (turnstaken % moduloTurns == 0)
76 {
77 std::ios_base::fmtflags ff = G4cout.flags();// save flags since they are changed
78 G4cout << "Turn: " << std::right << std::setw(4) << std::fixed
79 << turnstaken << " / " << std::left
80 << BDSGlobalConstants::Instance()->TurnsToTake() << G4endl;
81
82 G4cout.flags(ff);// reset flags
83 }
84 }
85
87
88#ifdef BDSDEBUG
89 G4cout << __METHOD_NAME__ << "New turn number : " << BDSGlobalConstants::Instance()->TurnsTaken() << G4endl;
90#endif
91 }
92#ifdef BDSDEBUG
93 else
94 {G4cout << __METHOD_NAME__ << "not incrementing turn number" << G4endl;}
95#endif
96 return true;
97}
98
99
100void BDSSDTerminator::EndOfEvent(G4HCofThisEvent* /*HCE*/)
101{
103}
void IncrementTurnNumber()
Setter.
static BDSGlobalConstants * Instance()
Access method.
void ResetTurnNumber()
Setter.
G4int moduloTurns
Cache of print turn number on these turns.
static G4int eventNumber
Externally accessible counter for event number. Set in BeginOfEventAction.
G4int moduloEvents
Cache of print turn number on these events.