BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
AnalysisUtilities.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 "AnalysisUtilities.hh"
20#include "BinGeneration.hh"
21#include "RBDSException.hh"
22
23#include "Rtypes.h" // for classdef
24
25#include "TH1D.h"
26
27#include <algorithm>
28#include <string>
29#include <vector>
30#include <iostream>
31
32ClassImp(AnalysisUtilities)
33
34AnalysisUtilities::AnalysisUtilities()
35{;}
36
37AnalysisUtilities::~AnalysisUtilities()
38{;}
39
40std::vector<double> AnalysisUtilities::LogSpace(double start,
41 double stop,
42 int nBins,
43 double base,
44 bool includeLastPoint)
45{
46 return RBDS::LogSpace(start, stop, nBins, base, includeLastPoint);
47}
48
49std::vector<double> AnalysisUtilities::LinSpace(double start,
50 double stop,
51 int nBins,
52 bool includeLastPoint)
53{
54 return RBDS::LinSpace(start, stop, nBins, includeLastPoint);
55}
56
58 const std::vector<float>& values,
59 const std::vector<float>& weights)
60{
61 for (int i=0; i < (int)values.size(); i++)
62 {h1d.Fill(values[i],weights[i]);}
63}
64
65std::string RBDS::DefaultOutputName(const std::string& inputFilePath,
66 const std::string& suffix)
67{
68 std::string result = inputFilePath;
69 // protect against globbing
70 std::replace(result.begin(), result.end(), '*', '_');
71 // get only the filename - ie just write the file to the cwd
72 auto foundSlash = result.rfind('/'); // find the last '/'
73 if (foundSlash != std::string::npos)
74 {result = result.substr(foundSlash + 1);} // the rest
75 std::string key = ".root";
76 auto found = result.rfind(key);
77 if (found != std::string::npos)
78 {result.replace(found, key.length(), suffix + ".root");}
79 else
80 {result += ".root";}
81 return result;
82}
Simple class to hold all unbound functions for ROOT.
void FillTH1D(TH1D &h1d, const std::vector< float > &values, const std::vector< float > &weights)
Fill a vector of entries and weights into a TH1 histogram.
std::vector< double > LinSpace(double start, double stop, int nBins, bool includeLastPoint=true)
Linear range of values.
std::vector< double > LinSpace(double start, double stop, int nBins, bool includeLastPoint=true)
Linear range of values.
std::string DefaultOutputName(const std::string &inputFilePath, const std::string &suffix)