BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSSDVolumeExit.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 "BDSHitEnergyDepositionGlobal.hh"
21#include "BDSSDVolumeExit.hh"
22
23#include "globals.hh"
24#include "G4SDManager.hh"
25#include "G4StepPoint.hh"
26#include "G4StepStatus.hh"
27#include "G4Track.hh"
28
29BDSSDVolumeExit::BDSSDVolumeExit(G4String name,
30 G4bool worldExitIn):
31 G4VSensitiveDetector("volume_exit/" + name),
32 colName(name),
33 HCIDve(-1),
34 hits(nullptr)
35{
36 collectionName.insert(name);
37
38 statusToMatch = worldExitIn ? G4StepStatus::fWorldBoundary : fGeomBoundary;
39}
40
41void BDSSDVolumeExit::Initialize(G4HCofThisEvent* HCE)
42{
44 if (HCIDve < 0)
45 {HCIDve = G4SDManager::GetSDMpointer()->GetCollectionID(hits);}
46 HCE->AddHitsCollection(HCIDve, hits);
47
48#ifdef BDSDEBUG
49 G4cout << __METHOD_NAME__ << "Hits Collection ID: " << HCIDve << G4endl;
50#endif
51}
52
53G4bool BDSSDVolumeExit::ProcessHits(G4Step* aStep,
54 G4TouchableHistory* /*th*/)
55{
56 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
57
58 if (postStepPoint->GetStepStatus() == statusToMatch)
59 {
60 G4double totalEnergy = postStepPoint->GetTotalEnergy();
61 G4double preStepKineticEnergy = aStep->GetPreStepPoint()->GetKineticEnergy();
62 G4double postStepKineticEnergy = postStepPoint->GetKineticEnergy();
63 G4double stepLength = aStep->GetStepLength();
64 G4ThreeVector position = postStepPoint->GetPosition();
65 G4double T = postStepPoint->GetGlobalTime();
66 G4Track* track = aStep->GetTrack();
67 G4int pdgID = track->GetDefinition()->GetPDGEncoding();
68 G4int trackID = track->GetTrackID();
69 G4int parentID = track->GetParentID();
70 G4double weight = track->GetWeight();
71 G4int turnsTaken = BDSGlobalConstants::Instance()->TurnsTaken();
72
74 preStepKineticEnergy,
75 postStepKineticEnergy,
76 stepLength,
77 position.x(),
78 position.y(),
79 position.z(),
80 T,
81 pdgID,
82 trackID,
83 parentID,
84 weight,
85 turnsTaken);
86 hits->insert(hit);
87 return true;
88 }
89 else
90 {return false;}
91}
static BDSGlobalConstants * Instance()
Access method.
Information recorded for a step leaving a volume.
G4int HCIDve
Hits collection ID for volume exit.
G4String colName
Name prepared for collection.
G4StepStatus statusToMatch
World or volume exit status cache.
BDSHitsCollectionEnergyDepositionGlobal * hits
Hits collection.
const char * GetName(int)
Name of element.
Definition parserROOT.cc:37