BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BinSpecification.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 "BinSpecification.hh"
20#include "RBDSException.hh"
21
22#include <string>
23#include <vector>
24
25ClassImp(BinSpecification)
26
28 low(0),
29 high(1),
30 n(1),
31 edges(nullptr),
32 isLogSpaced(false)
33{;}
34
36 double highIn,
37 int nIn):
38 low(lowIn),
39 high(highIn),
40 n(nIn),
41 edges(nullptr),
42 isLogSpaced(false)
43{
44 if (high <= low)
45 {throw RBDSException("high end of binning <= low end -> must be >");}
46 if (n < 1)
47 {throw RBDSException("n bins < 1 -> must be >= 1");}
48}
49
50BinSpecification::BinSpecification(const std::vector<double>& edgesIn):
51 low(0),
52 high(1),
53 n(1),
54 edges(new std::vector<double>(edgesIn)),
55 isLogSpaced(false)
56{
57 if (edges->size() < 2)
58 {throw RBDSException("too few bin edges -> must be at least 2 edges to define 1 bin");}
59 n = (int)edges->size() - 1;
60 low = (*edges)[0];
61 high = edges->back();
62}
63
65 low(other.low),
66 high(other.high),
67 n(other.n),
68 edges(nullptr),
69 isLogSpaced(other.isLogSpaced),
70 edgesFileName(other.edgesFileName)
71{
72 edges = other.edges ? new std::vector<double>(*other.edges) : nullptr;
73}
74
76 low(other.low),
77 high(other.high),
78 n(other.n),
79 edges(other.edges),
80 isLogSpaced(other.isLogSpaced),
81 edgesFileName(other.edgesFileName)
82{
83 other.low = 0;
84 other.high = 1;
85 other.n = 1;
86 other.edges = nullptr;
87 other.isLogSpaced = false;
88 other.edgesFileName.clear();
89}
90
91BinSpecification::~BinSpecification()
92{
93 delete edges;
94}
95
97{
98 if (!edgesFileName.empty())
99 {return edgesFileName;}
100 else
101 {return std::to_string(low) + ":" + std::to_string(high);}
102}
Binning specification for a single dimension.
std::string GetBinString() const
Return the filename or the binning.
BinSpecification()
Default constructor.
General exception with possible name of object and message.