BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
samplerplacement.h
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 SAMPLERPLACEMENT_H
19#define SAMPLERPLACEMENT_H
20
21#include <iomanip>
22#include <iostream>
23#include <list>
24#include <string>
25#if __cplusplus >= 201703L
26#include <variant>
27#endif
28
29#include "published.h"
30
31namespace GMAD
32{
38 class SamplerPlacement : public Published<SamplerPlacement>
39 {
40 public:
41 std::string name;
42 std::string samplerType;
43 std::string referenceElement;
45 double s;
46 double x;
47 double y;
48 double z;
50 double phi;
51 double theta;
52 double psi;
55 double axisX;
56 double axisY;
57 double axisZ;
58 double angle;
60 bool axisAngle;
61
62 std::string apertureModel;
63 std::string shape;
64 double aper1;
65 double aper2;
66 double aper3;
67 double aper4;
68
69 double startAnglePhi;
70 double sweepAnglePhi;
71 double startAngleTheta;
72 double sweepAngleTheta;
73
74 // This should be std::list<int> but the parser only supports double for numerical types in a list.
76 std::list<double> partID;
78
82 void clear();
84 void print()const;
86 template <typename T>
87 void set_value(std::string property, T value, bool bExit = true);
89 void set_value(const std::string& property, Array* value, bool bExit = true);
91#if __cplusplus >= 201703L
92 std::list<std::variant<bool, int, double, std::string>> get_value_array(const std::string &);
93#endif
94 private:
96 void PublishMembers();
97 };
98
99 template <typename T>
100 void SamplerPlacement::set_value(std::string property, T value, bool bExit)
101 {
102#ifdef BDSDEBUG
103 std::cout << "samplerplacement> Setting value " << std::setw(25) << std::left
104 << property << value << std::endl;
105#endif
106 // member method can throw runtime_error, catch and exit gracefully
107 try
108 {
109 set(this, property, value);
110 }
111 catch (const std::runtime_error &)
112 {
113 std::cerr << "Error: samplerplacement> unknown option \"" << property
114 << "\" with value \"" << value << "\"" << std::endl;
115 if (property == "partID")
116 {
117 std::cerr << "Note \"partID\" should be a list {int,int...}" << std::endl;
118 if (bExit)
119 {exit(1);}
120 else
121 {std::rethrow_exception(std::current_exception());} // to be caught by python
122 }
123 }
124 }
125}
126
127#endif
Representation of arrays used in tokens.
Definition array.h:39
Class that provides introspection to its members.
Definition published.h:48
void set(SamplerPlacement *instance, const std::string &name, double value)
Definition published.h:100
Sampler placement class for parser.
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.