BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchType.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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 "BDSBunchType.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh"
25#include "G4String.hh"
26
27#include <map>
28#include <string>
29
30// dictionary for BDSBunchType
31template<>
32std::map<BDSBunchType, std::string>* BDSBunchType::dictionary =
33 new std::map<BDSBunchType, std::string> ({
34 {BDSBunchType::reference, "reference"},
35 {BDSBunchType::gaussmatrix, "gaussmatrix"},
36 {BDSBunchType::gauss, "gauss"},
37 {BDSBunchType::gausstwiss, "gausstwiss"},
38 {BDSBunchType::gaussmatrixslowext, "gaussmatrixslowext"},
39 {BDSBunchType::gaussslowext, "gaussslowext"},
40 {BDSBunchType::gausstwissslowext, "gausstwissslowext"},
41 {BDSBunchType::circle, "circle"},
42 {BDSBunchType::square, "square"},
43 {BDSBunchType::ring, "ring"},
44 {BDSBunchType::eshell, "eshell"},
45 {BDSBunchType::halo, "halo"},
46 {BDSBunchType::composite, "composite"},
47 {BDSBunchType::userfile, "userfile"},
48 {BDSBunchType::ptc, "ptc"},
49 {BDSBunchType::sixtrack, "sixtrack"},
50 {BDSBunchType::eventgeneratorfile, "eventgeneratorfile"},
51 {BDSBunchType::sphere, "sphere"},
52 {BDSBunchType::compositesde,"compositespacedirectionenergy"},
53 {BDSBunchType::box, "box"},
54 {BDSBunchType::halosigma, "halosigma"},
55 {BDSBunchType::bdsimsampler,"bdsimsampler"},
56 {BDSBunchType::hdf5, "hdf5"},
57 {BDSBunchType::slowext, "slowext"},
58});
59
61{
62 std::map<G4String, BDSBunchType> types;
63
64 types["reference"] = BDSBunchType::reference;
65 types["gaussmatrix"] = BDSBunchType::gaussmatrix;
66 types["gauss-matrix"] = BDSBunchType::gaussmatrix;
67 types["gauss"] = BDSBunchType::gauss;
68 types["gausstwiss"] = BDSBunchType::gausstwiss;
69 types["gauss-twiss"] = BDSBunchType::gausstwiss;
70 types["gaussmatrixslowext"] = BDSBunchType::gaussmatrixslowext;
71 types["gauss-matrix-slow-ext"] = BDSBunchType::gaussmatrixslowext;
72 types["gaussslowext"] = BDSBunchType::gaussslowext;
73 types["gauss-slow-ext"] = BDSBunchType::gaussslowext;
74 types["gausstwissslowext"] = BDSBunchType::gausstwissslowext;
75 types["gauss-twiss-slow-ext"] = BDSBunchType::gausstwissslowext;
76 types["circle"] = BDSBunchType::circle;
77 types["square"] = BDSBunchType::square;
78 types["ring"] = BDSBunchType::ring;
79 types["eshell"] = BDSBunchType::eshell;
80 types["halo"] = BDSBunchType::halo;
81 types["composite"] = BDSBunchType::composite;
82 types["userfile"] = BDSBunchType::userfile;
83 types["user-file"] = BDSBunchType::userfile;
84 types["ptc"] = BDSBunchType::ptc;
85 types["sixtrack"] = BDSBunchType::sixtrack;
86 types["eventgeneratorfile"] = BDSBunchType::eventgeneratorfile;
87 types["event-generator-file"] = BDSBunchType::eventgeneratorfile;
88 types["sphere"] = BDSBunchType::sphere;
89 types["compositespacedirectionenergy"] = BDSBunchType::compositesde;
90 types["composite-space-direction-energy"] = BDSBunchType::compositesde;
91 types["compositesde"] = BDSBunchType::compositesde;
92 types["box"] = BDSBunchType::box;
93 types["halosigma"] = BDSBunchType::halosigma;
94 types["halo-sigma"] = BDSBunchType::halosigma;
95 types["bdsimsampler"] = BDSBunchType::bdsimsampler;
96 types["bdsim-sampler"] = BDSBunchType::bdsimsampler;
97 types["hdf5"] = BDSBunchType::hdf5;
98 types["slowext"] = BDSBunchType::slowext;
99 types["slow-ext"] = BDSBunchType::slowext;
100
101 distrType = BDS::LowerCase(distrType);
102
103 auto result = types.find(distrType);
104 if (result == types.end())
105 {// it's not a valid key
106 G4String message = "\"" + distrType + "\" is not a valid distribution\n";
107 message += "Available distributions are:\n";
108 for (const auto& it : types)
109 {message += it.first + "\n";}
110 throw BDSException(__METHOD_NAME__, message);
111 }
112
113#ifdef BDSDEBUG
114 G4cout << __METHOD_NAME__ << "determined distribution to be " << result->second << G4endl;
115#endif
116 return result->second;
117}
General exception with possible name of object and message.
Improve type-safety of native enum data type in C++.
static std::map< BDSTypeSafeEnum< def, inner >, std::string > * dictionary
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
BDSBunchType DetermineBunchType(G4String distrType)
Function that gives corresponding enum value for string (case-insensitive).