BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSOutputROOTEventLoss.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
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 "BDSOutputROOTEventLoss.hh"
20
21#ifndef __ROOTBUILD__
22#include "CLHEP/Units/SystemOfUnits.h"
23#include "BDSHitEnergyDeposition.hh"
24#include "BDSTrajectoryPoint.hh"
25#include "BDSTrajectoryPointHit.hh"
26#endif
27
29
30BDSOutputROOTEventLoss::BDSOutputROOTEventLoss():
31n(0)
32#ifndef __ROOTBUILD__
33,
34 storeTurn(false),
35 storeLinks(false),
36 storeModelID(false),
37 storeLocal(false),
38 storeGlobal(false),
39 storeTime(false),
40 storeStepLength(false),
41 storePhysicsProcesses(false)
42#endif
43{
44 Flush();
45}
46
47#ifndef __ROOTBUILD__
48BDSOutputROOTEventLoss::BDSOutputROOTEventLoss(bool storeTurnIn,
49 bool storeLinksIn,
50 bool storeModelIDIn,
51 bool storeLocalIn,
52 bool storeGlobalIn,
53 bool storeTimeIn,
54 bool storeStepLengthIn,
55 bool storePreStepKineticEnergyIn,
56 bool storePhysicsProcessesIn):
57 n(0),
58 storeTurn(storeTurnIn),
59 storeLinks(storeLinksIn),
60 storeModelID(storeModelIDIn),
61 storeLocal(storeLocalIn),
62 storeGlobal(storeGlobalIn),
63 storeTime(storeTimeIn),
64 storeStepLength(storeStepLengthIn),
65 storePreStepKineticEnergy(storePreStepKineticEnergyIn),
66 storePhysicsProcesses(storePhysicsProcessesIn)
67{
68 Flush();
69}
70#endif
71
72BDSOutputROOTEventLoss::~BDSOutputROOTEventLoss()
73{;}
74
75#ifndef __ROOTBUILD__
76
78{
79 n++;
80 energy.push_back( (float) (hit->point->GetEnergyDeposit() / CLHEP::GeV));
81 S.push_back ( (float) (hit->point->GetPostS() / CLHEP::m));
82 weight.push_back( (float) hit->point->GetPostWeight());
83 partID.push_back( (int) hit->pdgID);
84 trackID.push_back( (int) hit->trackID);
85 if (hit->parentID !=0) // general but don't fill for primaries as obvious -> reduce data size
86 {parentID.push_back((int) hit->parentID);}
87 modelID.push_back( (int) hit->point->GetBeamLineIndex());
88
89 if (storeTurn)
90 {turn.push_back((int) hit->point->GetTurnsTaken());}
91
92 if (storeLocal)
93 {
94 const G4ThreeVector& pos = hit->point->GetPostPosLocal();
95 x.push_back( (float) (pos.x() / CLHEP::m));
96 y.push_back( (float) (pos.y() / CLHEP::m));
97 z.push_back( (float) (pos.z() / CLHEP::m));
98 }
99
100 if (storeGlobal)
101 {
102 const G4ThreeVector& pos = hit->point->GetPosition();
103 X.push_back( (float) (pos.x() / CLHEP::m));
104 Y.push_back( (float) (pos.y() / CLHEP::m));
105 Z.push_back( (float) (pos.z() / CLHEP::m));
106 }
107
108 if (storeTime)
109 {T.push_back( (float) (hit->point->GetPostGlobalTime() / CLHEP::ns));}
110
111 // no step length for a point
112
114 {preStepKineticEnergy.push_back( (float) (hit->point->GetKineticEnergy() / CLHEP::GeV));}
115
116 if (storePhysicsProcesses)
117 {
118 postStepProcessType.push_back( (int) (hit->point->GetPostProcessType()));
119 postStepProcessSubType.push_back( (int) (hit->point->GetPostProcessSubType()));
120 }
121}
122
124{
125 n++;
126 energy.push_back( (float) (hit->GetEnergy() / CLHEP::GeV));
127 S.push_back ( (float) (hit->GetSHit() / CLHEP::m));
128 weight.push_back( (float) hit->GetWeight());
129
130 if (storeTurn)
131 {turn.push_back( hit->GetTurnsTaken());}
132
133 if (storeLinks)
134 {
135 partID.push_back(hit->GetPartID());
136 trackID.push_back(hit->GetTrackID());
137 parentID.push_back(hit->GetParentID());
138 }
139
140 if (storeModelID)
141 {modelID.push_back(hit->GetBeamlineIndex());}
142
143 if (storeLocal)
144 {
145 x.push_back( (float) (hit->Getx() / CLHEP::m));
146 y.push_back( (float) (hit->Gety() / CLHEP::m));
147 z.push_back( (float) (hit->Getz() / CLHEP::m));
148 }
149
150 if(storeGlobal)
151 {
152 X.push_back( (float) (hit->GetX() / CLHEP::m));
153 Y.push_back( (float) (hit->GetY() / CLHEP::m));
154 Z.push_back( (float) (hit->GetZ() / CLHEP::m));
155 }
156
157 if (storeTime)
158 {T.push_back( (float) (hit->GetGlobalTime() / CLHEP::ns));}
159
160 if (storeStepLength)
161 {stepLength.push_back( (float) (hit->GetStepLength() / CLHEP::m));}
162
164 {preStepKineticEnergy.push_back( (float) (hit->GetPreStepKineticEnergy() / CLHEP::GeV));}
165
166 if (storePhysicsProcesses)
167 {
168 postStepProcessType.push_back( (int) hit->GetPostStepProcessType());
169 postStepProcessSubType.push_back( (int) hit->GetPostStepProcessSubType());
170 }
171}
172#endif
173
175{
176 if (!other)
177 {return;}
178 n = other->n;
179 energy = other->energy;
180 S = other->S;
181 weight = other->weight;
182 partID = other->partID;
183 trackID = other->trackID;
184 parentID = other->parentID;
185 modelID = other->modelID;
186 turn = other->turn;
187 x = other->x;
188 y = other->y;
189 z = other->z;
190 X = other->X;
191 Y = other->Y;
192 Z = other->Z;
193 T = other->T;
194 stepLength = other->stepLength;
196 postStepProcessType = other->postStepProcessType;
197 postStepProcessSubType = other->postStepProcessSubType;
198}
199
200void BDSOutputROOTEventLoss::Flush()
201{
202 n = 0;
203 energy.clear();
204 S.clear();
205 weight.clear();
206 partID.clear();
207 trackID.clear();
208 parentID.clear();
209 modelID.clear();
210 turn.clear();
211 x.clear();
212 y.clear();
213 z.clear();
214 X.clear();
215 Y.clear();
216 Z.clear();
217 T.clear();
218 stepLength.clear();
219 preStepKineticEnergy.clear();
220 postStepProcessType.clear();
221 postStepProcessSubType.clear();
222}
Information recorded for a single piece of energy deposition.
G4double GetZ() const
Accessor for extra piece of information.
G4int GetTurnsTaken() const
Accessor for extra piece of information.
G4int GetPartID() const
Accessor for extra piece of information.
G4int GetTrackID() const
Accessor for extra piece of information.
G4double GetY() const
Accessor for extra piece of information.
G4int GetBeamlineIndex() const
Accessor for extra piece of information.
G4double GetPreStepKineticEnergy() const
Accessor for extra piece of information.
G4int GetParentID() const
Accessor for extra piece of information.
G4double Getz() const
Accessor for extra piece of information.
G4double GetX() const
Accessor for extra piece of information.
G4double Getx() const
Accessor for extra piece of information.
G4double Gety() const
Accessor for extra piece of information.
G4int GetPostStepProcessType() const
Accessor for extra piece of information.
G4double GetGlobalTime() const
Accessor for extra piece of information.
G4int GetPostStepProcessSubType() const
Accessor for extra piece of information.
G4double GetStepLength() const
Accessor for extra piece of information.
Data stored for energy deposition hits per event.
bool storePreStepKineticEnergy
Whether to store pre step kinetic energy.
std::vector< float > y
Local coordinate.
bool storeLinks
Whether to store links between Eloss and model and trajectors.
std::vector< float > preStepKineticEnergy
Kinetic energy in GeV at pre step point.
bool storeLocal
Whether to store local coordinates.
bool storeGlobal
Whether to store global coordinates.
bool storeTurn
Store turn number.
std::vector< int > modelID
Geometry model index.
std::vector< float > weight
Weight associated with loss.
bool storeTime
Whether to store global time.
std::vector< int > trackID
TrackID that created the deposit.
std::vector< int > parentID
ParentID that created the deposit.
std::vector< float > z
Local coordinate.
std::vector< float > x
Local coordinate.
std::vector< int > turn
Turn number.
std::vector< float > stepLength
Step length taken for hit.
bool storeModelID
Whether to store the beam line index.
void Fill(const BDSOutputROOTEventLoss *other)
Fill from another instance.
std::vector< float > energy
Energy deposited in step.
bool storeStepLength
Whether to store step length.
std::vector< int > partID
ParticleID that create the deposit.
std::vector< float > S
Global curvilinear S coordinate.
std::vector< float > T
Global time (time since beginning of event).
A summary trajectory object of a loss point.
G4double GetKineticEnergy() const
Accessor for the extra information links.
G4double GetPostS() const
Accessor.
G4int GetPostProcessType() const
Accessor.
G4ThreeVector GetPostPosLocal() const
Accessor.
G4int GetTurnsTaken() const
Accessor for the extra information links.
G4double GetEnergyDeposit() const
Accessor.
G4double GetPostWeight() const
Accessor.
G4int GetPostProcessSubType() const
Accessor.
G4int GetBeamLineIndex() const
Accessor.
G4double GetPostGlobalTime() const
Accessor.