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