BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSOutputROOTEventAperture.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 "BDSOutputROOTEventAperture.hh"
19#include "BDSOutputROOTParticleData.hh"
20
21#ifndef __ROOTBUILD__
22#include "CLHEP/Units/SystemOfUnits.h"
23#include "BDSHitApertureImpact.hh"
24#endif
25
27
28BDSOutputROOTParticleData* BDSOutputROOTEventAperture::particleTable = nullptr;
29
30BDSOutputROOTEventAperture::BDSOutputROOTEventAperture()
31{
32 FlushLocal();
33}
34
35BDSOutputROOTEventAperture::~BDSOutputROOTEventAperture()
36{;}
37
38#ifndef __ROOTBUILD__
39void BDSOutputROOTEventAperture::Fill(const BDSHitApertureImpact* hit,
40 G4bool isPrimaryFirstImpact)
41{
42 n++;
43 energy.push_back((float)hit->totalEnergy / CLHEP::GeV);
44 S.push_back((double)hit->S / CLHEP::m);
45 weight.push_back((float)hit->weight);
46 isPrimary.push_back(hit->parentID == 0);
47 firstPrimaryImpact.push_back(isPrimaryFirstImpact);
48 partID.push_back((int)hit->partID);
49 turn.push_back((int)hit->turnsTaken);
50 x.push_back((float)hit->x / CLHEP::m);
51 y.push_back((float)hit->y / CLHEP::m);
52 xp.push_back((float)hit->xp / CLHEP::rad);
53 yp.push_back((float)hit->yp / CLHEP::rad);
54 T.push_back((float)hit->globalTime / CLHEP::ns);
55 kineticEnergy.push_back((float)hit->preStepKineticEnergy / CLHEP::GeV);
56 G4int pid = hit->partID;
57
58 G4bool isIonL = false; // 'L' for local variable
59 if (particleTable)
60 {isIonL = particleTable->IsIon(pid);}
61 if (particleTable && isIonL) // avoid nested ifs with duplicated setting of variables by doing it this way
62 {
63 auto& ionInfo = particleTable->GetIonInfo(pid);
64 isIon.push_back(true);
65 ionA.push_back((int)ionInfo.a);
66 ionZ.push_back((int)ionInfo.z);
67 nElectrons.push_back(0);
68 }
69 else
70 {
71 G4bool isIonAgain = hit->nElectrons > 0;
72 isIon.push_back(isIonAgain);
73 ionA.push_back(0);
74 ionZ.push_back(0);
75 nElectrons.push_back(hit->nElectrons);
76 }
77
78 trackID.push_back((int)hit->trackID);
79 parentID.push_back((int)hit->parentID);
80 modelID.push_back((int)hit->beamlineIndex);
81}
82
83#endif
84
85void BDSOutputROOTEventAperture::Fill(const BDSOutputROOTEventAperture* other)
86{
87 if (!other)
88 {return;}
89 n = other->n;
90 energy = other->energy;
91 S = other->S;
92 weight = other->weight;
93 isPrimary = other->isPrimary;
95 partID = other->partID;
96 turn = other->turn;
97 x = other->x;
98 y = other->y;
99 xp = other->xp;
100 yp = other->yp;
101 T = other->T;
103 isIon = other->isIon;
104 ionA = other->ionA;
105 ionZ = other->ionZ;
106 nElectrons = other->nElectrons;
107 trackID = other->trackID;
108 parentID = other->parentID;
109 modelID = other->modelID;
110}
111
113{
114 n = 0;
115 energy.clear();
116 S.clear();
117 weight.clear();
118 isPrimary.clear();
119 firstPrimaryImpact.clear();
120 partID.clear();
121 turn.clear();
122 x.clear();
123 y.clear();
124 xp.clear();
125 yp.clear();
126 T.clear();
127 kineticEnergy.clear();
128 isIon.clear();
129 ionA.clear();
130 ionZ.clear();
131 nElectrons.clear();
132 trackID.clear();
133 parentID.clear();
134 modelID.clear();
135}
Snapshot of information for particle passing through a collimator.
Data stored for energy deposition hits per event.
std::vector< float > kineticEnergy
Kinetic energy in GeV at pre step point.
std::vector< int > parentID
ParentID that created the deposit.
std::vector< int > turn
Turn number.
std::vector< float > energy
Total energy of particle.
std::vector< int > trackID
TrackID that created the deposit.
std::vector< bool > firstPrimaryImpact
Whether the first time the primary is passing through.
std::vector< int > modelID
Geometry model index.
std::vector< float > weight
Weight associated with loss.
std::vector< float > T
Global time (time since beginning of event).
std::vector< double > S
Global curvilinear S coordinate.
std::vector< int > partID
ParticleID that create the deposit.
Geant4 particle data for particles used in simulation.
bool IsIon(const int &pdgID) const
This doesn't count a proton (even with electrons) as an ion.