BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSOutputROOTEventLoss.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 "BDSOutputROOTEventLoss.hh"
19
20#ifndef __ROOTBUILD__
21#include "CLHEP/Units/SystemOfUnits.h"
22#include "BDSHitEnergyDeposition.hh"
23#include "BDSTrajectoryPoint.hh"
24#include "BDSTrajectoryPointHit.hh"
25#endif
26
28
29BDSOutputROOTEventLoss::BDSOutputROOTEventLoss():
30n(0)
31#ifndef __ROOTBUILD__
32,
33 storeTurn(false),
34 storeLinks(false),
35 storeModelID(false),
36 storeLocal(false),
37 storeGlobal(false),
38 storeTime(false),
39 storeStepLength(false),
40 storePhysicsProcesses(false)
41#endif
42{
43 Flush();
44}
45
46#ifndef __ROOTBUILD__
47BDSOutputROOTEventLoss::BDSOutputROOTEventLoss(bool storeTurnIn,
48 bool storeLinksIn,
49 bool storeModelIDIn,
50 bool storeLocalIn,
51 bool storeGlobalIn,
52 bool storeTimeIn,
53 bool storeStepLengthIn,
54 bool storePreStepKineticEnergyIn,
55 bool storePhysicsProcessesIn):
56 n(0),
57 storeTurn(storeTurnIn),
58 storeLinks(storeLinksIn),
59 storeModelID(storeModelIDIn),
60 storeLocal(storeLocalIn),
61 storeGlobal(storeGlobalIn),
62 storeTime(storeTimeIn),
63 storeStepLength(storeStepLengthIn),
64 storePreStepKineticEnergy(storePreStepKineticEnergyIn),
65 storePhysicsProcesses(storePhysicsProcessesIn)
66{
67 Flush();
68}
69#endif
70
71BDSOutputROOTEventLoss::~BDSOutputROOTEventLoss()
72{;}
73
74#ifndef __ROOTBUILD__
75
77{
78 n++;
79 energy.push_back( (float) (hit->point->GetEnergyDeposit() / CLHEP::GeV));
80 S.push_back ( (float) (hit->point->GetPostS() / CLHEP::m));
81 weight.push_back( (float) hit->point->GetPostWeight());
82 partID.push_back( (int) hit->pdgID);
83 trackID.push_back( (int) hit->trackID);
84 if (hit->parentID !=0) // general but don't fill for primaries as obvious -> reduce data size
85 {parentID.push_back((int) hit->parentID);}
86 modelID.push_back( (int) hit->point->GetBeamLineIndex());
87
88 if (storeTurn)
89 {turn.push_back((int) hit->point->GetTurnsTaken());}
90
91 if (storeLocal)
92 {
93 const G4ThreeVector& pos = hit->point->GetPostPosLocal();
94 x.push_back( (float) (pos.x() / CLHEP::m));
95 y.push_back( (float) (pos.y() / CLHEP::m));
96 z.push_back( (float) (pos.z() / CLHEP::m));
97 }
98
99 if (storeGlobal)
100 {
101 const G4ThreeVector& pos = hit->point->GetPosition();
102 X.push_back( (float) (pos.x() / CLHEP::m));
103 Y.push_back( (float) (pos.y() / CLHEP::m));
104 Z.push_back( (float) (pos.z() / CLHEP::m));
105 }
106
107 if (storeTime)
108 {T.push_back( (float) (hit->point->GetPostGlobalTime() / CLHEP::ns));}
109
110 // no step length for a point
111
113 {preStepKineticEnergy.push_back( (float) (hit->point->GetKineticEnergy() / CLHEP::GeV));}
114
115 if (storePhysicsProcesses)
116 {
117 postStepProcessType.push_back( (int) (hit->point->GetPostProcessType()));
118 postStepProcessSubType.push_back( (int) (hit->point->GetPostProcessSubType()));
119 }
120}
121
123{
124 n++;
125 energy.push_back( (float) (hit->GetEnergy() / CLHEP::GeV));
126 S.push_back ( (float) (hit->GetSHit() / CLHEP::m));
127 weight.push_back( (float) hit->GetWeight());
128
129 if (storeTurn)
130 {turn.push_back( hit->GetTurnsTaken());}
131
132 if (storeLinks)
133 {
134 partID.push_back(hit->GetPartID());
135 trackID.push_back(hit->GetTrackID());
136 parentID.push_back(hit->GetParentID());
137 }
138
139 if (storeModelID)
140 {modelID.push_back(hit->GetBeamlineIndex());}
141
142 if (storeLocal)
143 {
144 x.push_back( (float) (hit->Getx() / CLHEP::m));
145 y.push_back( (float) (hit->Gety() / CLHEP::m));
146 z.push_back( (float) (hit->Getz() / CLHEP::m));
147 }
148
149 if(storeGlobal)
150 {
151 X.push_back( (float) (hit->GetX() / CLHEP::m));
152 Y.push_back( (float) (hit->GetY() / CLHEP::m));
153 Z.push_back( (float) (hit->GetZ() / CLHEP::m));
154 }
155
156 if (storeTime)
157 {T.push_back( (float) (hit->GetGlobalTime() / CLHEP::ns));}
158
159 if (storeStepLength)
160 {stepLength.push_back( (float) (hit->GetStepLength() / CLHEP::m));}
161
163 {preStepKineticEnergy.push_back( (float) (hit->GetPreStepKineticEnergy() / CLHEP::GeV));}
164
165 if (storePhysicsProcesses)
166 {
167 postStepProcessType.push_back( (int) hit->GetPostStepProcessType());
168 postStepProcessSubType.push_back( (int) hit->GetPostStepProcessSubType());
169 }
170}
171#endif
172
174{
175 if (!other)
176 {return;}
177 n = other->n;
178 energy = other->energy;
179 S = other->S;
180 weight = other->weight;
181 partID = other->partID;
182 trackID = other->trackID;
183 parentID = other->parentID;
184 modelID = other->modelID;
185 turn = other->turn;
186 x = other->x;
187 y = other->y;
188 z = other->z;
189 X = other->X;
190 Y = other->Y;
191 Z = other->Z;
192 T = other->T;
193 stepLength = other->stepLength;
195 postStepProcessType = other->postStepProcessType;
196 postStepProcessSubType = other->postStepProcessSubType;
197}
198
199void BDSOutputROOTEventLoss::Flush()
200{FlushLocal();}
201
203{
204 n = 0;
205 energy.clear();
206 S.clear();
207 weight.clear();
208 partID.clear();
209 trackID.clear();
210 parentID.clear();
211 modelID.clear();
212 turn.clear();
213 x.clear();
214 y.clear();
215 z.clear();
216 X.clear();
217 Y.clear();
218 Z.clear();
219 T.clear();
220 stepLength.clear();
221 preStepKineticEnergy.clear();
222 postStepProcessType.clear();
223 postStepProcessSubType.clear();
224}
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.
void FlushLocal()
Non-virtual function for initialising / clearing variables.
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.