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