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