BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
samplerplacement.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 "samplerplacement.h"
19
20using namespace GMAD;
21
27
29{
30 name = "";
31 samplerType = "plane";
34 s = 0;
35 x = 0;
36 y = 0;
37 z = 0;
38 phi = 0;
39 theta = 0;
40 psi = 0;
41 axisX = 0;
42 axisY = 0;
43 axisZ = 0;
44 angle = 0;
45 axisAngle = false;
46 apertureModel = "";
47 shape = "circular";
48 aper1 = 0;
49 aper2 = 0;
50 aper3 = 0;
51 aper4 = 0;
52 startAnglePhi = 0;
53 sweepAnglePhi = -1; // -1 to flag we should use 2pi later when we have units
54 startAngleTheta = 0;
55 sweepAngleTheta = -1; // -1 to flag we should use 2pi later when we have units
56 partID.clear();
57 partIDSetID = -1;
58}
59
61{
64 publish("referenceElement", &SamplerPlacement::referenceElement);
65 publish("referenceElementNumber", &SamplerPlacement::referenceElementNumber);
78 publish("apertureModel", &SamplerPlacement::apertureModel);
79 publish("shape", &SamplerPlacement::shape);
80 publish("apertureType", &SamplerPlacement::shape);
81 publish("aper1", &SamplerPlacement::aper1);
82 publish("aper2", &SamplerPlacement::aper2);
83 publish("aper3", &SamplerPlacement::aper3);
84 publish("aper4", &SamplerPlacement::aper4);
85 publish("startAnglePhi", &SamplerPlacement::startAnglePhi);
86 publish("sweepAnglePhi", &SamplerPlacement::sweepAnglePhi);
87 publish("startAngleTheta", &SamplerPlacement::startAngleTheta);
88 publish("sweepAngleTheta", &SamplerPlacement::sweepAngleTheta);
90 // partIDSetID is for internal use only - not published
91}
92
94{
95 std::cout << "SamplerPlacement: "
96 << "name " << name << std::endl
97 << "samplerType " << samplerType << std::endl
98 << "referenceElement" << referenceElement << std::endl
99 << "referenceElementNumber" << referenceElementNumber << std::endl
100 << "s" << s << std::endl
101 << "x " << x << std::endl
102 << "y " << y << std::endl
103 << "z " << z << std::endl
104 << "phi " << phi << std::endl
105 << "theta " << theta << std::endl
106 << "psi " << psi << std::endl
107 << "axisX " << axisX << std::endl
108 << "axisY " << axisY << std::endl
109 << "axisZ " << axisZ << std::endl
110 << "angle " << angle << std::endl
111 << "axisAngle " << axisAngle << std::endl
112 << "apertureMode " << apertureModel << std::endl
113 << "shape " << shape << std::endl
114 << "aper1 " << aper1 << std::endl
115 << "aper2 " << aper2 << std::endl
116 << "aper3 " << aper3 << std::endl
117 << "aper4 " << aper4 << std::endl
118 << "startAnglePhi " << startAnglePhi << std::endl
119 << "sweepAnglePhi " << sweepAnglePhi << std::endl
120 << "startAngleTheta " << startAngleTheta << std::endl
121 << "sweepAngleTheta " << sweepAngleTheta << std::endl
122 << "partID list {";
123 for (auto v : partID)
124 {std::cout << v << ", ";}
125 std::cout << "}" << std::endl
126 << "partIDSet ID " << partIDSetID << std::endl;
127}
128
129void SamplerPlacement::set_value(const std::string& property, Array* value, bool bExit)
130{
131#ifdef BDSDEBUG
132 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << std::endl;
133#endif
134 if(property=="partID")
135 {
136 value->set_vector(partID);
137 }
138 else
139 {
140 std::cerr << "Error: parser> unknown material option \"" << property << "\", or doesn't expect vector type" << std::endl;
141 if(bExit)
142 {exit(1);}
143 else
144 {std::rethrow_exception(std::current_exception());} // to be caught by python
145 }
146}
147
148#if __cplusplus >= 201703L
149std::list<std::variant<bool, int, double, std::string>> SamplerPlacement::get_value_array(const std::string & property) {
150 std::list<std::variant<bool, int, double, std::string>> retval;
151
152 if(property=="partID")
153 {
154 retval.resize(partID.size());
155 std::copy(partID.begin(),partID.end(), retval.begin());
156 }
157
158 else
159 {
160 std::cerr << "Error: parser> unknown material option \"" << property << "\", or doesn't expect vector type" << std::endl;
161 }
162
163 return retval;
164}
165#endif
Representation of arrays used in tokens.
Definition array.h:39
void set_vector(Container< std::string, std::allocator< std::string > > &dst) const
Copy symbols into STL string containers.
Definition array.h:101
void publish(const std::string &name, T C::*mp)
Make pointer to member from class C and type T with accessible with a name.
Definition published.h:93
std::list< std::variant< bool, int, double, std::string > > get_value_array(const std::string &)
Get method for lists.
int referenceElementNumber
Index of repetition of element if there are multiple uses.
double phi
Euler angle for rotation.
std::string name
Name of this samplerplacement.
std::string referenceElement
Name of reference element w.r.t. to place to.
void PublishMembers()
publish members
std::string samplerType
Plane, Cylinder, Sphere.
std::list< double > partID
List of PDG IDs of which particles to record for - default is empty, so all particles.
void print() const
print some properties
double theta
Euler angle for rotation.
double s
Curvilinear s position to place w.r.t..
double psi
Euler angle for rotation.
void set_value(std::string property, T value, bool bExit=true)
set methods by property name and value
bool axisAngle
Flag to use the axis angle construction of rotation.
double x
Offset in x.
int partIDSetID
The unique ID of the particle set given by the parser.
double y
Offset in y.
Parser namespace for GMAD language. Combination of Geant4 and MAD.