BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BinSpecification.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
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 <vector>
23
24ClassImp(BinSpecification)
25
27 low(0),
28 high(1),
29 n(1),
30 edges(nullptr)
31{;}
32
34 double highIn,
35 int nIn):
36 low(lowIn),
37 high(highIn),
38 n(nIn),
39 edges(nullptr)
40{
41 if (high <= low)
42 {throw RBDSException("high end of binning <= low end -> must be >");}
43 if (n < 1)
44 {throw RBDSException("n bins < 1 -> must be >= 1");}
45}
46
47BinSpecification::BinSpecification(const std::vector<double>& edgesIn):
48 low(0),
49 high(1),
50 n(1),
51 edges(new std::vector<double>(edgesIn))
52{
53 if (edges->size() < 2)
54 {throw RBDSException("too few bin edges -> must be at least 2 edges to define 1 bin");}
55 n = (int)edges->size() - 1;
56 low = (*edges)[0];
57 high = edges->back();
58}
59
61 low(other.low),
62 high(other.high),
63 n(other.n),
64 edges(nullptr)
65{
66 edges = other.edges ? new std::vector<double>(*other.edges) : nullptr;
67}
68
70 low(other.low),
71 high(other.high),
72 n(other.n),
73 edges(other.edges)
74{
75 other.low = 0;
76 other.high = 1;
77 other.n = 1;
78 other.edges = nullptr;
79}
80
81BinSpecification::~BinSpecification()
82{
83 delete edges;
84}
Binning specification for a single dimension.
BinSpecification()
Default constructor.
General exception with possible name of object and message.