BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
Compare.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 COMPCOMPARE_H
19#define COMPCOMPARE_H
20
21#include <vector>
22
23#include "ResultEvent.hh"
24
25#include "BDSOutputROOTEventSampler.hh"
26
27class Result;
28
29class TDirectory;
30class TFile;
31class TH1;
32class TTree;
33
39namespace Compare
40{
41 const static double Chi2Tolerance = 40;
42 const static double TreeTolerance = 0.05;
43 const static double OpticsSimgaTolerance = 10;
44 const static double EventTreeTolerance = 1e-10;
45
47 std::vector<Result*> Files(TFile* f1, TFile* f2);
48
52 void Directories(TDirectory* d1,
53 TDirectory* d2,
54 std::vector<Result*>& results);
55
57 void Histograms(TH1* h1, TH1* h2, std::vector<Result*>& results);
58
60 void Trees(TTree* t1, TTree* t2, std::vector<Result*>& results);
61
64 void Optics(TTree* t1, TTree* t2, std::vector<Result*>& results);
65
66 void EventTree(TTree* t1, TTree* t2, std::vector<Result*>& results,
67 const std::vector<std::string>& samplerNames,
68 const std::vector<std::string>& samplerCNames,
69 const std::vector<std::string>& samplerSNames);
70
71#ifdef __ROOTDOUBLE__
72 void Sampler(BDSOutputROOTEventSampler<double>* e1,
74 ResultEvent* results);
75#else
76 void Sampler(BDSOutputROOTEventSampler<float>* e1,
78 ResultEvent* results);
79#endif
80
82 template <typename T>
83 bool Diff(const std::vector<T>& v1, std::vector<T>& v2, int i) {return std::abs(v1[i] - v2[i]) > (T)EventTreeTolerance;}
84 template <>
85 bool Diff(const std::vector<bool>& v1, std::vector<bool>& v2, int i) {return v1[i] != v2[i];}
86
87 template <typename T>
88 bool Diff(T v1, T v2) {return std::abs(v1 - v2) > (T)Compare::EventTreeTolerance;}
89 template <>
90 bool Diff(bool v1, bool v2) {return v1 != v2;}
91
94 void PrintNoMatching(std::string className, std::string objectName);
95
97 bool Summarise(const std::vector<Result*>& results);
98
100 bool StringStartsWith(std::string aString, std::string prefix);
101
102 bool IsInVector(std::string key, const std::vector<std::string>& vec);
103
104 inline bool NanOrInf(const double& val) {return std::isnan(val) || std::isinf(val);}
105
106 inline bool GTEZero(const double& val) {return val >= 0;}
107 inline bool LTZero(const double& val) {return val < 0;}
108
111}
112
113#endif
Information stored per sampler per event.
Result of comparison of single entry of an Event tree in BDSIM output.
Base class of a result.
Definition Result.hh:36
Comparison utility functions.
Definition Compare.hh:40
std::vector< Result * > Files(TFile *f1, TFile *f2)
Compare two files.
Definition Compare.cc:52
void Trees(TTree *t1, TTree *t2, std::vector< Result * > &results)
Compare two TTrees.
Definition Compare.cc:182
bool Summarise(const std::vector< Result * > &results)
Loop over results and print any failed ones. Returns true if all passed.
bool Diff(const std::vector< T > &v1, std::vector< T > &v2, int i)
Return true if they're different.
Definition Compare.hh:83
bool hasPrimaries
Bool for checking if primaries were written to file.
Definition Compare.hh:110
void PrintNoMatching(std::string className, std::string objectName)
Definition Compare.cc:575
void Histograms(TH1 *h1, TH1 *h2, std::vector< Result * > &results)
Compare two histogams.
Definition Compare.cc:133
void Directories(TDirectory *d1, TDirectory *d2, std::vector< Result * > &results)
Definition Compare.cc:60
void Optics(TTree *t1, TTree *t2, std::vector< Result * > &results)
Definition Compare.cc:264
bool StringStartsWith(std::string aString, std::string prefix)
Check whether a string is prefixed with another string.
Definition Compare.cc:580