BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSArrayOperatorIndexFlip.hh
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#ifndef BDSARRAYOPERATORINDEXFLIP_H
20#define BDSARRAYOPERATORINDEXFLIP_H
21#include "BDSArrayOperatorIndex.hh"
22
23#include "G4String.hh"
24#include "G4Types.hh"
25
26#include <array>
27#include <string>
28
36{
37public:
39 BDSArrayOperatorIndex("Flip(None)"),
40 xyzt{1,1,1,1}
41 {;}
42 explicit BDSArrayOperatorIndexFlip(const std::array<G4bool,4>& xyztIn):
44 {
45 operatesOn = xyztIn;
46
47 for (G4int i = 0; i < 4; i++)
48 {xyzt[0] = xyztIn[i] ? -1 : 1;}
49
50 G4String newName = "Flip(";
51 for (const auto& v : xyzt)
52 {newName += std::to_string(v < 0);}
53 newName += ")";
54 name = newName;
55 }
57
58 virtual void Apply(G4int& x,
59 G4int& y,
60 G4int& z,
61 G4int& t) const
62 {
63 x *= xyzt[0];
64 y *= xyzt[1];
65 z *= xyzt[2];
66 t *= xyzt[3];
67 }
68 virtual void ApplyX(G4int& x) const {x *= xyzt[0];}
69 virtual void ApplyY(G4int& y) const {y *= xyzt[1];}
70 virtual void ApplyZ(G4int& z) const {z *= xyzt[2];}
71 virtual void ApplyT(G4int& t) const {t *= xyzt[3];}
72
73 virtual void TransformLimits(G4double& xMin, G4double& xMax,
74 G4double& yMin, G4double& yMax,
75 G4double& zMin, G4double& zMax,
76 G4double& tMin, G4double& tMax) const
77 {
78 if (xyzt[0])
79 {std::swap(xMin, xMax);}
80 if (xyzt[1])
81 {std::swap(yMin, yMax);}
82 if (xyzt[2])
83 {std::swap(zMin, zMax);}
84 if (xyzt[3])
85 {std::swap(tMin, tMax);}
86 }
87
88private:
89 std::array<G4int,4> xyzt;
90};
91
92#endif
1D array for completeness in array system.
virtual void Apply(G4int &x, G4int &y, G4int &z, G4int &t) const
Interface for modifying by reference array indices.