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) 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 "BinSpecification.hh"
19#include "RBDSException.hh"
20
21#include <string>
22#include <vector>
23
24ClassImp(BinSpecification)
25
27 low(0),
28 high(1),
29 n(1),
30 edges(nullptr),
31 isLogSpaced(false)
32{;}
33
35 double highIn,
36 int nIn):
37 low(lowIn),
38 high(highIn),
39 n(nIn),
40 edges(nullptr),
41 isLogSpaced(false)
42{
43 if (high <= low)
44 {throw RBDSException("high end of binning <= low end -> must be >");}
45 if (n < 1)
46 {throw RBDSException("n bins < 1 -> must be >= 1");}
47}
48
49BinSpecification::BinSpecification(const std::vector<double>& edgesIn):
50 low(0),
51 high(1),
52 n(1),
53 edges(new std::vector<double>(edgesIn)),
54 isLogSpaced(false)
55{
56 if (edges->size() < 2)
57 {throw RBDSException("too few bin edges -> must be at least 2 edges to define 1 bin");}
58 n = (int)edges->size() - 1;
59 low = (*edges)[0];
60 high = edges->back();
61}
62
64 low(other.low),
65 high(other.high),
66 n(other.n),
67 edges(nullptr),
68 isLogSpaced(other.isLogSpaced),
69 edgesFileName(other.edgesFileName)
70{
71 edges = other.edges ? new std::vector<double>(*other.edges) : nullptr;
72}
73
75 low(other.low),
76 high(other.high),
77 n(other.n),
78 edges(other.edges),
79 isLogSpaced(other.isLogSpaced),
80 edgesFileName(other.edgesFileName)
81{
82 other.low = 0;
83 other.high = 1;
84 other.n = 1;
85 other.edges = nullptr;
86 other.isLogSpaced = false;
87 other.edgesFileName.clear();
88}
89
90BinSpecification::~BinSpecification()
91{
92 delete edges;
93}
94
96{
97 if (!edgesFileName.empty())
98 {return edgesFileName;}
99 else
100 {return std::to_string(low) + ":" + std::to_string(high);}
101}
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.
STL namespace.