BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSParticleCoords.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 "BDSParticleCoords.hh"
19
20#include "G4ThreeVector.hh"
21#include "G4Transform3D.hh"
22
23#include "CLHEP/Geometry/Point3D.h"
24
25#include <ostream>
26
27BDSParticleCoords::BDSParticleCoords():
28 x(0),
29 y(0),
30 z(0),
31 xp(0),
32 yp(0),
33 zp(0),
34 T(0)
35{;}
36
37BDSParticleCoords::BDSParticleCoords(G4double xIn,
38 G4double yIn,
39 G4double zIn,
40 G4double xpIn,
41 G4double ypIn,
42 G4double zpIn,
43 G4double tIn):
44 x(xIn),
45 y(yIn),
46 z(zIn),
47 xp(xpIn),
48 yp(ypIn),
49 zp(zpIn),
50 T(tIn)
51{;}
52
53BDSParticleCoords::BDSParticleCoords(G4ThreeVector pos,
54 G4ThreeVector mom,
55 G4double tIn):
56 x(pos.x()),
57 y(pos.y()),
58 z(pos.z()),
59 xp(mom.x()),
60 yp(mom.y()),
61 zp(mom.z()),
62 T(tIn)
63{;}
64
65BDSParticleCoords BDSParticleCoords::ApplyTransform(const G4Transform3D& transform) const
66{
67 // if no transform, return copy of self
68 if (transform == G4Transform3D::Identity)
69 {return BDSParticleCoords(*this);}
70
71 G4ThreeVector originalPos = G4ThreeVector(x,y,z);
72 G4ThreeVector newPos = transform * (HepGeom::Point3D<G4double>)originalPos;
73 G4ThreeVector originalMom = G4ThreeVector(xp,yp,zp);
74 G4ThreeVector newMom = transform * (HepGeom::Vector3D<G4double>)originalMom;
75 return BDSParticleCoords(newPos.x(), newPos.y(), newPos.z(),
76 newMom.x(), newMom.y(), newMom.z(),
77 T);
78}
79
80BDSParticleCoords BDSParticleCoords::ApplyOffset(const G4ThreeVector& offset) const
81{
82 return BDSParticleCoords(x + offset.x(),
83 y + offset.y(),
84 z + offset.z(),
85 xp, yp, zp, T);
86}
87
88void BDSParticleCoords::AddOffset(const G4ThreeVector& offset,
89 G4double offsetT)
90{
91 x += offset.x();
92 y += offset.y();
93 z += offset.z();
94 T += offsetT;
95}
96
97std::ostream& operator<< (std::ostream& out, BDSParticleCoords const& p)
98{
99 p.Print(out);
100 return out;
101}
102
103void BDSParticleCoords::Print(std::ostream& out) const
104{
105 out << "Position: (" << x << ", " << y << ", " << z << ")";
106 out << ", Momentum: (" << xp << ", " << yp << ", " << zp << ")";
107 out << ", t: " << T << G4endl;
108}
A set of particle coordinates.
virtual void Print(std::ostream &out) const
Actual print out method so it can be called from a derived class.
void AddOffset(const G4ThreeVector &offset, G4double offsetT=0)
Apply an offset to the spatial and T coordinates only - assignment.
BDSParticleCoords ApplyTransform(const G4Transform3D &transform) const
Apply a transform to the coordinates and return a copy of them transformed.
BDSParticleCoords ApplyOffset(const G4ThreeVector &offset) const
Apply an offset to the spatial coordinates only and return a copy.