NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
HistTool.h
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#pragma once
7
8#include "NAGASH/Global.h"
10
11namespace NAGASH
12{
16 class HistTool : public Tool
17 {
18 public:
19 HistTool(std::shared_ptr<MSGTool> MSG) : Tool(MSG), unc(MSG){};
20 // Hist Link
21 // use TH1 To make it possible for TH1D TH2D TH3D etc.
22 void ProcessHistLink(const TString &type, const std::vector<TH1 *> &input, TH1 *res);
23 void ProcessHistLink(std::function<double(const std::vector<double> &)>, std::function<double(const std::vector<double> &, const std::vector<double> &)>, const std::vector<TH1 *> &input, TH1 *res);
24 void ProcessHistLink(std::function<void(const std::vector<TH1 *> &, TH1 *)>, const std::vector<TH1 *> &input, TH1 *res);
25 void Asymmetry(TH1 *A, TH1 *B, TH1 *Asy);
26 void Delta(TH1 *A, TH1 *B, TH1 *D, bool dosep = false);
27 void Ratio(TH1 *A, TH1 *B, TH1 *R, bool dosep = false);
28 void Chi2(TH1 *A, TH1 *B, TH1 *C);
29 void Pull(TH1 *A, TH1 *B, TH1 *P);
30 double Chi2(TH1D *A, TH1D *B, TH2D *CorrA = nullptr, TH2D *CorrB = nullptr);
31 void ConvertCovToCorr(TH2D *covar, TH2D *corr);
32 void ConvertCorrToCov(TH2D *corr, TH1D *h, TH2D *cov);
33 void ConvertCovToError(TH2D *hcov, TH1D *herr);
34
35 // vector hist convertion
36 // maybe write a version of Rvalue references for better performance
37 void ConvertVectorToTH1D(TH1D *h1, const std::vector<double> &v1, const std::vector<double> &v1err = std::vector<double>());
38 void ConvertVectorToTH2D(TH2D *h2, const std::vector<std::vector<double>> &v2, const std::vector<std::vector<double>> &v2err = std::vector<std::vector<double>>());
39 void ConvertVectorToTH3D(TH3D *h3, const std::vector<std::vector<std::vector<double>>> &v3, const std::vector<std::vector<std::vector<double>>> &v3err = std::vector<std::vector<std::vector<double>>>());
40 std::vector<double> ConvertTH1DToVector(TH1D *h1d);
41 std::vector<double> ConvertTH1DErrorToVector(TH1D *h1d);
42 std::vector<std::vector<double>> ConvertTH2DToVector(TH2D *h2d, const TString &priority = "XY");
43 std::vector<std::vector<double>> ConvertTH2DErrorToVector(TH2D *h2d, const TString &priority = "XY");
44 std::vector<std::vector<std::vector<double>>> ConvertTH3DToVector(TH3D *h3d, const TString &priority = "XYZ");
45 std::vector<std::vector<std::vector<double>>> ConvertTH3DErrorToVector(TH3D *h3d, const TString &priority = "XYZ");
46
47 // dimension change
48 void ConvertVectorTH1DToTH1D(const std::vector<TH1D *> &vh1d, TH1D *targeth1d);
49 void ConvertTH2DToVectorTH1D(TH2D *h2d, const std::vector<TH1D *> &vh1d, const TString &priority = "XY");
50 void ConvertTH3DToVectorTH1D(TH3D *h3d, const std::vector<std::vector<TH1D *>> &vh1d, const TString &priority = "XYZ");
51
52 // convert To matrix
53 TMatrixD ConvertTH2DToMatrix(TH2D *h2d);
54 void ConvertMatrixToTH2D(const TMatrixD &mat, TH2D *h2d);
55
56 template <typename T>
57 static std::vector<T> ConvertVector2DToVector1D(const std::vector<std::vector<T>> &v2d);
58 template <typename T>
59 static std::vector<T> ConvertVector2DToVector1D(std::vector<std::vector<T>> &&v2d);
60
61 protected:
63 };
64
69 template <typename T>
70 inline std::vector<T> HistTool::ConvertVector2DToVector1D(const std::vector<std::vector<T>> &v2d)
71 {
72 std::vector<T> returnv1d;
73 for (auto &v1d : v2d)
74 for (auto &content : v1d)
75 returnv1d.emplace_back(content);
76
77 return returnv1d;
78 }
79
84 template <typename T>
85 inline std::vector<T> HistTool::ConvertVector2DToVector1D(std::vector<std::vector<T>> &&v2d)
86 {
87 std::vector<T> returnv1d;
88 for (auto &v1d : v2d)
89 for (auto &content : v1d)
90 returnv1d.emplace_back(content);
91
92 return returnv1d;
93 }
94
95} // namespace NAGASH
Some global definitions.
provide tools for manipulating ROOT histograms
Definition HistTool.h:17
void ConvertCorrToCov(TH2D *corr, TH1D *h, TH2D *cov)
Convert correlation matrix to covariance matrix.
Definition HistTool.cxx:603
HistTool(std::shared_ptr< MSGTool > MSG)
Definition HistTool.h:19
void ConvertCovToError(TH2D *hcov, TH1D *herr)
Convert covariance matrix to error histogram.
Definition HistTool.cxx:566
std::vector< std::vector< double > > ConvertTH2DToVector(TH2D *h2d, const TString &priority="XY")
Convert the contents of a 2D histogram to a vector.
Definition HistTool.cxx:852
void ConvertVectorToTH3D(TH3D *h3, const std::vector< std::vector< std::vector< double > > > &v3, const std::vector< std::vector< std::vector< double > > > &v3err=std::vector< std::vector< std::vector< double > > >())
Convert vectors to a 3D histogram.
Definition HistTool.cxx:738
static std::vector< T > ConvertVector2DToVector1D(const std::vector< std::vector< T > > &v2d)
Flatten 2D vector to a 1D vector.
Definition HistTool.h:70
void Chi2(TH1 *A, TH1 *B, TH1 *C)
Calculate the between two histograms.
Definition HistTool.cxx:331
void Asymmetry(TH1 *A, TH1 *B, TH1 *Asy)
Calculate the asymmetry between two histograms.
Definition HistTool.cxx:143
void ConvertCovToCorr(TH2D *covar, TH2D *corr)
Convert covariance matrix to correlation matrix.
Definition HistTool.cxx:524
std::vector< double > ConvertTH1DToVector(TH1D *h1d)
Convert the contents of a 1D histogram to a vector.
Definition HistTool.cxx:809
void Ratio(TH1 *A, TH1 *B, TH1 *R, bool dosep=false)
Calculate the ratio between two histograms.
Definition HistTool.cxx:253
std::vector< double > ConvertTH1DErrorToVector(TH1D *h1d)
Convert the errors of a 1D histogram to a vector.
Definition HistTool.cxx:830
std::vector< std::vector< std::vector< double > > > ConvertTH3DErrorToVector(TH3D *h3d, const TString &priority="XYZ")
Convert the errors of a 3D histogram to a vector.
void ConvertTH3DToVectorTH1D(TH3D *h3d, const std::vector< std::vector< TH1D * > > &vh1d, const TString &priority="XYZ")
Convert a 3D histogram into a 2D vector of 1D histograms.
void Pull(TH1 *A, TH1 *B, TH1 *P)
Calculate the pull between two histograms.
Definition HistTool.cxx:386
Uncertainty unc
Definition HistTool.h:62
void ConvertVectorTH1DToTH1D(const std::vector< TH1D * > &vh1d, TH1D *targeth1d)
Fuse a vector of 1D histograms into one 1D histogram.
void ConvertVectorToTH2D(TH2D *h2, const std::vector< std::vector< double > > &v2, const std::vector< std::vector< double > > &v2err=std::vector< std::vector< double > >())
Convert vectors to a 2D histogram.
Definition HistTool.cxx:685
void ConvertMatrixToTH2D(const TMatrixD &mat, TH2D *h2d)
Convert a matrix to a 2D histogram.
TMatrixD ConvertTH2DToMatrix(TH2D *h2d)
Convert a 2D histogram to a matrix.
void ConvertTH2DToVectorTH1D(TH2D *h2d, const std::vector< TH1D * > &vh1d, const TString &priority="XY")
Convert a 2D histogram into a vector of 1D histograms.
void Delta(TH1 *A, TH1 *B, TH1 *D, bool dosep=false)
Calculate the difference between two histograms.
Definition HistTool.cxx:197
void ConvertVectorToTH1D(TH1D *h1, const std::vector< double > &v1, const std::vector< double > &v1err=std::vector< double >())
Convert vectors to a histogram.
Definition HistTool.cxx:648
std::vector< std::vector< double > > ConvertTH2DErrorToVector(TH2D *h2d, const TString &priority="XY")
Convert the errors of a 2D histogram to a vector.
Definition HistTool.cxx:900
std::vector< std::vector< std::vector< double > > > ConvertTH3DToVector(TH3D *h3d, const TString &priority="XYZ")
Convert the contents of a 3D histogram to a vector.
Definition HistTool.cxx:948
void ProcessHistLink(const TString &type, const std::vector< TH1 * > &input, TH1 *res)
constructor
Definition HistTool.cxx:15
Provide interface for all tools in NAGASH.
Definition Tool.h:72
Provide static functions for calculating uncertainties.
Definition Uncertainty.h:17