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