BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BinGeneration.hh
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#ifndef BINGENERATION_H
20#define BINGENERATION_H
21
22#include <vector>
23
24namespace RBDS
25{
26
27 /* @brief Class to generate logarithmic points.
28 *
29 * Based on solution on StackOverFlow:
30 * https://stackoverflow.com/a/21429452
31 */
32 template<typename T>
34 {
35 public:
36 Logspace(T first, T baseIn) : curValue(first), base(baseIn) {;}
37
38 T operator()()
39 {
40 T retval = curValue;
41 curValue *= base;
42 return retval;
43 }
44
45 private:
46 T curValue;
47 T base;
48 };
49
50 /* @brief Method to generate evenly spaced points on a log scale.
51 *
52 * Based on solution on StackOverFlow:
53 * https://stackoverflow.com/a/21429452
54 */
55 std::vector<double> LogSpace(double start,
56 double stop,
57 int nBins,
58 double base = 10,
59 bool includeLastPoint = true);
60
62 std::vector<double> LinSpace(double start,
63 double stop,
64 int nBins,
65 bool includeLastPoint = true);
66}
67
68#endif
Utility functions for data files.
std::vector< double > LinSpace(double start, double stop, int nBins, bool includeLastPoint=true)
Linear range of values.