BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
physicsbiasing.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 "physicsbiasing.h"
19
20#include <iomanip>
21#include <iostream>
22#include <sstream>
23
24#include "array.h"
25
26using namespace GMAD;
27
31
33{
37 publish("processList", &PhysicsBiasing::processList);
40}
41
43{
44 name = "";
45 particle = "";
46 process = "";
47 processList.clear();
48 factor.clear();
49 flag.clear();
50}
51
53{
54 std::cout << "physicsbiasing: " << std::endl
55 << "name " << name << " " << std::endl
56 << "particle " << particle << " " << std::endl
57 << "process " << process << " " << std::endl
58 << "factor ";
59 for (const auto& i : factor) std::cout << i << " ";
60 std::cout << std::endl << "flag ";
61 for (const auto& i : flag) std::cout << static_cast<int>(i) << " ";
62 std::cout << std::endl;
63}
64
65void PhysicsBiasing::set_value(const std::string& property, double value, bool bExit)
66{
67#ifdef BDSDEBUG
68 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << value << std::endl;
69#endif
70
71 if (property=="flag") {flag.push_back(static_cast<PhysicsBiasingType>((int)value)); return;}
72 if (property=="xsecfact") {factor.push_back(value); return;}
73
74 std::cerr << "Error: parser> unknown physicsbiasing option \"" << property << "\" with value " << value << std::endl;
75 if(bExit)
76 exit(1);
77 else
78 std::rethrow_exception(std::current_exception());
79}
80
81void PhysicsBiasing::set_value(const std::string& property, Array* value, bool bExit)
82{
83 if (property=="flag")
84 {
85 for (const auto& i : value->GetData())
86 {flag.push_back(static_cast<PhysicsBiasingType>((int)i));}
87 }
88 else if (property=="xsecfact")
89 {value->set_vector(factor);}
90 else if (property=="factor")
91 {value->set_vector(factor);}
92 else if (property=="processList")
93 {value->set_vector(processList);}
94 else
95 {
96 std::cerr << "Error: parser> unknown physicsbiasing option \"" << property << "\" with value ";
97 for (const auto& i : value->GetData())
98 {std::cout << i << " ";}
99
100 std::cout << std::endl;
101 if(bExit)
102 exit(1);
103 else
104 std::rethrow_exception(std::current_exception());
105 }
106}
107
108void PhysicsBiasing::set_value(const std::string& property, std::string value, bool bExit)
109{
110#ifdef BDSDEBUG
111 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << value << std::endl;
112#endif
113
114 if (property=="name")
115 {name = value;}
116 else if (property=="particle")
117 {particle = value;}
118 else if ((property=="proc") || (property=="process"))
119 {
120 process = value;
121 std::stringstream ss(process);
122 std::string tok;
123 while(ss >> tok)
124 {processList.push_back(tok);}
125 return;
126 }
127 else
128 {
129 std::cerr << "Error: parser> unknown physicsbiasing option \"" << property
130 << "\" with value " << value << std::endl;
131 if(bExit)
132 exit(1);
133 else
134 std::rethrow_exception(std::current_exception());
135 }
136}
137
138#if __cplusplus >= 201703L
139std::list<std::variant<bool, int, double, std::string>> PhysicsBiasing::get_value_array(const std::string & property) {
140 std::list<std::variant<bool, int, double, std::string>> retval;
141
142 if(property=="processList")
143 {
144 retval.resize(processList.size());
145 std::copy(processList.begin(),processList.end(), retval.begin());
146 }
147 else if(property=="factor")
148 {
149 retval.resize(factor.size());
150 std::copy(factor.begin(),factor.end(), retval.begin());
151 }
152 else if(property=="flag")
153 {
154 //retval.resize(factor.size());
155 for(auto e : flag) {
156 retval.push_back((int)e);
157 }
158 }
159 else
160 {
161 std::cerr << "Error: parser> unknown PhysicsBiasing property \"" << property << "\", or doesn't expect vector type" << std::endl;
162 }
163
164 return retval;
165}
166#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
std::vector< double > factor
factors corresponding to process
void set_value(const std::string &property, double value, bool bExit=true)
set methods by property name, numeric values
PhysicsBiasing()
constructor
void print() const
print some properties
std::vector< PhysicsBiasingType > flag
flag which particles are biased
std::string particle
particle name
void PublishMembers()
publish members
std::list< std::variant< bool, int, double, std::string > > get_value_array(const std::string &)
Get method for lists.
std::string process
geant4 process: single string, but can have multiple processes separated with a space
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
Parser namespace for GMAD language. Combination of Geant4 and MAD.