BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSTrajectoryPoint.hh
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#ifndef BDSTRAJECTORYPOINT_H
19#define BDSTRAJECTORYPOINT_H
20#include "BDSTrajectoryPointIon.hh"
21#include "BDSTrajectoryPointLocal.hh"
22#include "BDSTrajectoryPointLink.hh"
23
24#include "globals.hh" // geant4 types / globals
25#include "G4Allocator.hh"
26#include "G4TrajectoryPoint.hh"
27
28#include <ostream>
29
30class G4Material;
31class G4Step;
32class G4Track;
33
35class BDSBeamline;
36
43class BDSTrajectoryPoint: public G4TrajectoryPoint
44{
45public:
48
51 BDSTrajectoryPoint(const G4Step* step,
52 G4bool storeExtrasLocalIn,
53 G4bool storeExtrasLinkIn,
54 G4bool storeExtrasIonIn);
55
58 BDSTrajectoryPoint(const G4Track* track,
59 G4bool storeExtrasLocalIn,
60 G4bool storeExtrasLinkIn,
61 G4bool storeExtrasIonIn);
62
65
66 virtual ~BDSTrajectoryPoint();
67
68 inline void *operator new(size_t);
69 inline void operator delete(void *aTrajectoryPoint);
70 inline int operator==(const BDSTrajectoryPoint& right) const {return (this==&right);};
71
72 inline void DeleteExtraLocal() {delete extraLocal; extraLocal = nullptr;}
73 inline void DeleteExtraLinks() {delete extraLink; extraLink = nullptr;}
74 inline void DeleteExtraIon() {delete extraIon; extraIon = nullptr;}
75
81 G4bool IsScatteringPoint() const;
82
84 G4bool NotTransportationLimitedStep() const;
85
87 static G4bool IsScatteringPoint(const G4Step* step);
88 static G4bool IsScatteringPoint(G4int postProcessType,
90 G4double totalEnergyDeposit);
92
94 inline G4int GetPreProcessType() const {return preProcessType;}
95 inline G4int GetPreProcessSubType() const {return preProcessSubType;}
96 inline G4int GetPostProcessType() const {return postProcessType;}
97 inline G4int GetPostProcessSubType() const {return postProcessSubType;}
98 inline G4double GetPreWeight() const {return preWeight;}
99 inline G4double GetPostWeight() const {return postWeight;}
100 inline G4double GetPreEnergy() const {return preEnergy;}
101 inline G4double GetPostEnergy() const {return postEnergy;}
102 inline G4double GetEnergyDeposit() const {return energyDeposit;}
103 inline G4ThreeVector GetPreMomentum() const {return preMomentum;}
104 inline G4ThreeVector GetPostMomentum() const {return postMomentum;}
105 inline G4double GetPreS() const {return preS;}
106 inline G4double GetPostS() const {return postS;}
107 inline G4double GetPreGlobalTime() const {return preGlobalTime;}
108 inline G4double GetPostGlobalTime() const {return postGlobalTime;}
109 inline G4int GetBeamLineIndex() const {return beamlineIndex;}
110 inline BDSBeamline* GetBeamLine() const {return beamline;}
111 inline G4ThreeVector GetPrePosLocal() const {return prePosLocal;}
112 inline G4ThreeVector GetPostPosLocal() const {return postPosLocal;}
113 inline G4Material* GetMaterial() const {return material;}
114
117 inline void SetMaterial(G4Material* materialIn) {material = materialIn;}
118
120 inline G4ThreeVector GetPositionLocal() const {return extraLocal ? extraLocal->positionLocal : G4ThreeVector();}
121 inline G4ThreeVector GetMomentumLocal() const {return extraLocal ? extraLocal->momentumLocal : G4ThreeVector();}
123
125 inline G4int GetCharge() const {return extraLink ? extraLink->charge : 0;}
126 inline G4double GetKineticEnergy() const {return preEnergy;}
127 inline G4int GetTurnsTaken() const {return extraLink ? extraLink->turnsTaken : 0;}
128 inline G4double GetMass() const {return extraLink ? extraLink->mass : 0;}
129 inline G4double GetRigidity() const {return extraLink ? extraLink->rigidity : 0;}
131
133 inline G4bool GetIsIon() const {return extraIon ? extraIon->isIon : false;}
134 inline G4int GetIonA() const {return extraIon ? extraIon->ionA : 0;}
135 inline G4int GetIonZ() const {return extraIon ? extraIon->ionZ : 0;}
136 inline G4int GetNElectrons() const {return extraIon ? extraIon->nElectrons : 0;}
138
140 G4double PrePosR() const;
141 G4double PostPosR() const;
143
145 friend std::ostream& operator<< (std::ostream &out, BDSTrajectoryPoint const &p);
146
147 // logic taken from BDSExtent - implement only one operator; rest come for free
149 inline G4bool operator< (const BDSTrajectoryPoint& other) const;
150 inline G4bool operator> (const BDSTrajectoryPoint& other) const {return other < (*this);}
151 inline G4bool operator<=(const BDSTrajectoryPoint& other) const {return !((*this) > other);}
152 inline G4bool operator>=(const BDSTrajectoryPoint& other) const {return !((*this) < other);}
154
155 BDSTrajectoryPointLocal* extraLocal;
156 BDSTrajectoryPointLink* extraLink;
157 BDSTrajectoryPointIon* extraIon;
158
164
165private:
168 void InitialiseVariables();
169
171 void StoreExtrasLink(const G4Track* track);
172
174 void StoreExtrasIon(const G4Track* track);
175
180
181 G4double preWeight;
182 G4double postWeight;
183 G4double preEnergy;
184 G4double postEnergy;
185 G4ThreeVector preMomentum;
186 G4ThreeVector postMomentum;
187 G4double energyDeposit;
188 G4double preS;
189 G4double postS;
190 G4double preGlobalTime;
191 G4double postGlobalTime;
194 G4ThreeVector prePosLocal;
195 G4ThreeVector postPosLocal;
196 G4Material* material;
197
201};
202
203extern G4Allocator<BDSTrajectoryPoint> bdsTrajectoryPointAllocator;
204
205inline void* BDSTrajectoryPoint::operator new(size_t)
206{
207 void *aTrajectoryPoint;
208 aTrajectoryPoint = (void *) bdsTrajectoryPointAllocator.MallocSingle();
209 return aTrajectoryPoint;
210}
211
212inline void BDSTrajectoryPoint::operator delete(void *aTrajectoryPoint)
213{
214 bdsTrajectoryPointAllocator.FreeSingle((BDSTrajectoryPoint *) aTrajectoryPoint);
215}
216
217inline G4bool BDSTrajectoryPoint::operator< (const BDSTrajectoryPoint& other) const
218{
219 // can't test position without knowledge of beam line direction etc - too difficult / inaccurate
220 // for now, this is simplistic
221 // TODO deal with multiple beam lines and s coordinate change at join point
222 return (preS < other.preS) && (preGlobalTime < other.preGlobalTime);
223}
224
225#endif
Extra G4Navigator to get coordinate transforms.
A vector of BDSBeamlineElement instances - a beamline.
Extra information recorded for a single piece of energy deposition.
Extra information recorded for a single piece of energy deposition.
A Point in a trajectory with extra information.
G4double preS
Global curvilinear S coordinate of pre-step point.
G4double GetKineticEnergy() const
Accessor for the extra information links.
G4double GetPreEnergy() const
Accessor.
G4double GetPostS() const
Accessor.
G4int GetCharge() const
Accessor for the extra information links.
G4ThreeVector postMomentum
Momentum of post-step point.
BDSBeamline * beamline
Beam line (if any) point belongs to (always mass world).
BDSBeamline * GetBeamLine() const
Accessor.
void StoreExtrasIon(const G4Track *track)
Utility function to prepare and fill extra ion variables.
G4int beamlineIndex
Index to beam line element in the mass world beam line.
G4double GetPreGlobalTime() const
Accessor.
G4bool operator>=(const BDSTrajectoryPoint &other) const
Comparison operator.
friend std::ostream & operator<<(std::ostream &out, BDSTrajectoryPoint const &p)
Output stream.
G4int GetPostProcessType() const
Accessor.
G4bool operator<(const BDSTrajectoryPoint &other) const
Comparison operator.
G4ThreeVector GetMomentumLocal() const
Accessor.
void SetMaterial(G4Material *materialIn)
G4int GetPreProcessSubType() const
Accessor.
G4bool GetIsIon() const
Accessor for the extra information ions.
G4double PostPosR() const
Return the transverse local radius in x,y.
G4ThreeVector GetPostPosLocal() const
Accessor.
G4double GetPreWeight() const
Accessor.
G4double postGlobalTime
Time since event started of post-step point.
G4double GetRigidity() const
Accessor for the extra information links.
G4double postEnergy
Kinetic energy of post step point.
G4int GetTurnsTaken() const
Accessor for the extra information links.
G4double PrePosR() const
Return the transverse local radius in x,y.
G4double GetEnergyDeposit() const
Accessor.
G4bool operator<=(const BDSTrajectoryPoint &other) const
Comparison operator.
void StoreExtrasLink(const G4Track *track)
Utility function to prepare and fill extra link variables.
G4double GetMass() const
Accessor for the extra information links.
static BDSAuxiliaryNavigator * auxNavigator
G4double GetPreS() const
Accessor.
G4Material * material
Material point for pre-step point.
G4bool operator>(const BDSTrajectoryPoint &other) const
Comparison operator.
BDSTrajectoryPoint()
Default constructor.
G4double postWeight
Weight associated with post step point.
G4int GetPreProcessType() const
Accessor.
G4ThreeVector prePosLocal
Local coordinates of pre-step point.
G4int GetIonZ() const
Accessor for the extra information ions.
G4ThreeVector GetPositionLocal() const
Accessor for the extra information local.
G4int postProcessSubType
Process sub type of post step point.
G4ThreeVector postPosLocal
Local coordinates of post-step point.
G4double GetPostEnergy() const
Accessor.
G4double GetPostWeight() const
Accessor.
G4int GetPostProcessSubType() const
Accessor.
G4bool NotTransportationLimitedStep() const
Return true if step isn't defined by transportation processes.
G4ThreeVector GetPostMomentum() const
Accessor.
G4int preProcessType
Process type of pre-step point.
G4double energyDeposit
Total energy deposited during step.
G4bool IsScatteringPoint() const
G4int GetBeamLineIndex() const
Accessor.
G4double preWeight
Weight associated with pre-step point.
G4int GetNElectrons() const
Accessor for the extra information ions.
G4int GetIonA() const
Accessor for the extra information ions.
G4double GetPostGlobalTime() const
Accessor.
G4ThreeVector preMomentum
Momentum of pre-step point.
G4Material * GetMaterial() const
Accessor.
G4int preProcessSubType
Process sub type of pre-step point.
G4double preGlobalTime
Time since event started of pre-step point.
G4ThreeVector GetPreMomentum() const
Accessor.
G4ThreeVector GetPrePosLocal() const
Accessor.
G4double preEnergy
Kinetic energy of pre-step point.
G4double postS
Global curvilinear S coordinate of post step point.
G4int postProcessType
Process type of post step point.
static G4double dEThresholdForScattering