BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSColourScaleMagma.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 "BDSColourScaleMagma.hh"
20
21#include "G4Colour.hh"
22#include "G4Types.hh"
23
24#include <algorithm>
25#include <array>
26#include <cmath>
27#include <vector>
28
29std::vector<std::array<G4double, 3>> BDSColourScaleMagma::data = {
30 {1.46200e-03, 4.66000e-04, 1.38660e-02},
31 {1.37080e-02, 1.17710e-02, 6.86670e-02},
32 {3.96080e-02, 3.10900e-02, 1.33515e-01},
33 {7.42570e-02, 5.20170e-02, 2.02660e-01},
34 {1.13094e-01, 6.54920e-02, 2.76784e-01},
35 {1.59018e-01, 6.83540e-02, 3.52688e-01},
36 {2.11718e-01, 6.19920e-02, 4.18647e-01},
37 {2.65447e-01, 6.02370e-02, 4.61840e-01},
38 {3.16654e-01, 7.16900e-02, 4.85380e-01},
39 {3.66012e-01, 9.03140e-02, 4.97960e-01},
40 {4.14709e-01, 1.10431e-01, 5.04662e-01},
41 {4.63508e-01, 1.29893e-01, 5.07652e-01},
42 {5.12831e-01, 1.48179e-01, 5.07648e-01},
43 {5.62866e-01, 1.65368e-01, 5.04692e-01},
44 {6.13617e-01, 1.81811e-01, 4.98536e-01},
45 {6.64915e-01, 1.98075e-01, 4.88836e-01},
46 {7.16387e-01, 2.14982e-01, 4.75290e-01},
47 {7.67398e-01, 2.33705e-01, 4.57755e-01},
48 {8.16914e-01, 2.55895e-01, 4.36461e-01},
49 {8.63320e-01, 2.83729e-01, 4.12403e-01},
50 {9.04281e-01, 3.19610e-01, 3.88137e-01},
51 {9.37221e-01, 3.64929e-01, 3.68567e-01},
52 {9.60949e-01, 4.18323e-01, 3.59630e-01},
53 {9.76690e-01, 4.76226e-01, 3.64466e-01},
54 {9.86700e-01, 5.35582e-01, 3.82210e-01},
55 {9.92785e-01, 5.94891e-01, 4.10283e-01},
56 {9.96096e-01, 6.53659e-01, 4.46213e-01},
57 {9.97325e-01, 7.11848e-01, 4.88154e-01},
58 {9.96898e-01, 7.69591e-01, 5.34892e-01},
59 {9.95131e-01, 8.27052e-01, 5.85701e-01},
60 {9.92440e-01, 8.84330e-01, 6.40099e-01},
61 {9.89434e-01, 9.41470e-01, 6.97519e-01}
62};
63
64
65BDSColourScaleMagma::BDSColourScaleMagma():
66 dataStep(1.0 / (G4double)(data.size()-1))
67{;}
68
69BDSColourScaleMagma::~BDSColourScaleMagma()
70{;}
71
72G4Colour BDSColourScaleMagma::GetValue(G4double numberFromZeroToOne) const
73{
74 numberFromZeroToOne = std::min(numberFromZeroToOne, 1.0); // ensure <= 1
75 numberFromZeroToOne = std::max(0.0, numberFromZeroToOne); // ensure >= 0
76 // (x - xMin) / xStep
77 // xMin is 0 by definition
78 G4double arrayCoords = numberFromZeroToOne / dataStep;
79 G4int arrayIndex = (G4int) std::floor(arrayCoords);
80
81 const auto& value = data.at(arrayIndex);
82 return G4Colour(value[0], value[1], value[2]);
83}