BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSLinkRunAction.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 "BDSAuxiliaryNavigator.hh"
19#include "BDSHitSamplerLink.hh"
20#include "BDSLinkEventAction.hh"
21#include "BDSLinkRunAction.hh"
22
23BDSLinkRunAction::BDSLinkRunAction():
24 allHits(nullptr),
25 nSecondariesToReturn(0),
26 nPrimariesToReturn(0),
27 maximumExternalParticleID(0)
28{;}
29
30BDSLinkRunAction::~BDSLinkRunAction()
31{
32 delete allHits;
33}
34
35void BDSLinkRunAction::BeginOfRunAction(const G4Run* /*aRun*/)
36{
37 nSecondariesToReturn = 0;
38 nPrimariesToReturn = 0;
39 BDSAuxiliaryNavigator::ResetNavigatorStates();
40 allHits = new BDSHitsCollectionSamplerLink();
41 //output->InitialiseGeometryDependent();
42 //output->NewFile();
43 // Write options now file open.
44 //const GMAD::OptionsBase* ob = BDSParser::Instance()->GetOptionsBase();
45 //output->FillOptions(ob);
46 // Write beam
47 //const GMAD::BeamBase* bb = BDSParser::Instance()->GetBeamBase();
48 //output->FillBeam(bb);
49 // Write model now file open.
50 //output->FillModel();
51 // Write out geant4 data including particle tables.
52 //output->FillGeant4Data(usingIons);
53}
54
55void BDSLinkRunAction::EndOfRunAction(const G4Run* /*aRun*/)
56{;}
57
58void BDSLinkRunAction::AppendHits(G4int currentEventIndex,
59 G4int externalParticleID,
60 G4int externalParentID,
62{
63 if (!hits)
64 {return;}
65 for (G4int i = 0; i < (G4int)hits->entries(); i++)
66 {
67 auto hit = new BDSHitSamplerLink(*(*hits)[i]);
68 hit->eventID = currentEventIndex;
69 if (hit->parentID == 0)
70 {// use same ones from event which are the original ones for this primary
71 hit->externalParticleID = externalParticleID;
72 hit->externalParentID = externalParentID;
73 nPrimariesToReturn++;
74 }
75 else
76 {// new secondary - give it a new index (caching that), and new parentID
77 maximumExternalParticleID++;
78 hit->externalParticleID = maximumExternalParticleID;
79 hit->externalParentID = externalParticleID;
80 nSecondariesToReturn++;
81 }
82 allHits->insert(hit);
83 }
84}