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) Royal Holloway,
3University of London 2001 - 2023.
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#include "physicsbiasing.h"
20
21#include <iomanip>
22#include <iostream>
23#include <sstream>
24
25#include "array.h"
26
27using namespace GMAD;
28
30
32{
33 name = "";
34 particle = "";
35 process = "";
36 processList.clear();
37 factor.clear();
38 flag.clear();
39}
40
42{
43 std::cout << "physicsbiasing: " << std::endl
44 << "name " << name << " " << std::endl
45 << "particle " << particle << " " << std::endl
46 << "process " << process << " " << std::endl
47 << "factor ";
48 for (const auto& i : factor) std::cout << i << " ";
49 std::cout << std::endl << "flag ";
50 for (const auto& i : flag) std::cout << static_cast<int>(i) << " ";
51 std::cout << std::endl;
52}
53
54void PhysicsBiasing::set_value(const std::string& property, double value )
55{
56#ifdef BDSDEBUG
57 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << value << std::endl;
58#endif
59
60 if (property=="flag") {flag.push_back(static_cast<PhysicsBiasingType>((int)value)); return;}
61 if (property=="xsecfact") {factor.push_back(value); return;}
62
63 std::cerr << "Error: parser> unknown physicsbiasing option \"" << property << "\" with value " << value << std::endl;
64 exit(1);
65}
66
67void PhysicsBiasing::set_value(const std::string& property, Array* value)
68{
69 if (property=="flag")
70 {
71 for (const auto& i : value->GetData())
72 {flag.push_back(static_cast<PhysicsBiasingType>((int)i));}
73 }
74 else if (property=="xsecfact")
75 {value->set_vector(factor);}
76 else
77 {
78 std::cerr << "Error: parser> unknown physicsbiasing option \"" << property << "\" with value ";
79 for (const auto& i : value->GetData())
80 {std::cout << i << " ";}
81 std::cout << std::endl;
82 exit(1);
83 }
84}
85
86void PhysicsBiasing::set_value(const std::string& property, std::string value)
87{
88#ifdef BDSDEBUG
89 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << value << std::endl;
90#endif
91
92 if (property=="name")
93 {name = value;}
94 else if (property=="particle")
95 {particle = value;}
96 else if ((property=="proc") || (property=="process"))
97 {
98 process = value;
99 std::stringstream ss(process);
100 std::string tok;
101 while(ss >> tok)
102 {processList.push_back(tok);}
103 return;
104 }
105 else
106 {
107 std::cerr << "Error: parser> unknown physicsbiasing option \"" << property
108 << "\" with value " << value << std::endl;
109 exit(1);
110 }
111}
Representation of arrays used in tokens.
Definition: array.h:40
void set_vector(Container< std::string, std::allocator< std::string > > &dst) const
Copy symbols into STL string containers.
Definition: array.h:102
std::vector< double > factor
factors corresponding to process
void set_value(const std::string &property, double value)
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
std::string process
geant4 process: single string, but can have multiple processes separated with a space
Parser namespace for GMAD language. Combination of Geant4 and MAD.