NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
NAGASH::HistTool Class Reference

provide tools for manipulating ROOT histograms More...

#include "NAGASH/HistTool.h"

Inheritance diagram for NAGASH::HistTool:
NAGASH::Tool

Public Member Functions

 HistTool (std::shared_ptr< MSGTool > MSG)
 
void Asymmetry (TH1 *A, TH1 *B, TH1 *Asy)
 Calculate the asymmetry between two histograms.
 
void Chi2 (TH1 *A, TH1 *B, TH1 *C)
 Calculate the \(\chi^2\) between two histograms.
 
double Chi2 (TH1D *A, TH1D *B, TH2D *CorrA=nullptr, TH2D *CorrB=nullptr)
 Calculate the \(\chi^2\) between two histograms.
 
void ConvertCorrToCov (TH2D *corr, TH1D *h, TH2D *cov)
 Convert correlation matrix to covariance matrix.
 
void ConvertCovToCorr (TH2D *covar, TH2D *corr)
 Convert covariance matrix to correlation matrix.
 
void ConvertCovToError (TH2D *hcov, TH1D *herr)
 Convert covariance matrix to error histogram.
 
void ConvertMatrixToTH2D (const TMatrixD &mat, TH2D *h2d)
 Convert a matrix to a 2D histogram.
 
std::vector< double > ConvertTH1DErrorToVector (TH1D *h1d)
 Convert the errors of a 1D histogram to a vector.
 
std::vector< double > ConvertTH1DToVector (TH1D *h1d)
 Convert the contents of a 1D histogram to a vector.
 
std::vector< std::vector< double > > ConvertTH2DErrorToVector (TH2D *h2d, const TString &priority="XY")
 Convert the errors of a 2D histogram to a vector.
 
TMatrixD ConvertTH2DToMatrix (TH2D *h2d)
 Convert a 2D histogram to a matrix.
 
std::vector< std::vector< double > > ConvertTH2DToVector (TH2D *h2d, const TString &priority="XY")
 Convert the contents of a 2D histogram to a vector.
 
void ConvertTH2DToVectorTH1D (TH2D *h2d, const std::vector< TH1D * > &vh1d, const TString &priority="XY")
 Convert a 2D histogram into a vector of 1D histograms.
 
std::vector< std::vector< std::vector< double > > > ConvertTH3DErrorToVector (TH3D *h3d, const TString &priority="XYZ")
 Convert the errors of a 3D histogram to a vector.
 
std::vector< std::vector< std::vector< double > > > ConvertTH3DToVector (TH3D *h3d, const TString &priority="XYZ")
 Convert the contents 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 ConvertVectorTH1DToTH1D (const std::vector< TH1D * > &vh1d, TH1D *targeth1d)
 Fuse a vector of 1D histograms into one 1D histogram.
 
void ConvertVectorToTH1D (TH1D *h1, const std::vector< double > &v1, const std::vector< double > &v1err=std::vector< double >())
 Convert vectors to a 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.
 
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.
 
void Delta (TH1 *A, TH1 *B, TH1 *D, bool dosep=false)
 Calculate the difference between two histograms.
 
void ProcessHistLink (const TString &type, const std::vector< TH1 * > &input, TH1 *res)
 constructor
 
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)
 Create a new histogram based on the input histograms.
 
void ProcessHistLink (std::function< void(const std::vector< TH1 * > &, TH1 *)>, const std::vector< TH1 * > &input, TH1 *res)
 Create a new histogram based on the input histograms.
 
void Pull (TH1 *A, TH1 *B, TH1 *P)
 Calculate the pull between two histograms.
 
void Ratio (TH1 *A, TH1 *B, TH1 *R, bool dosep=false)
 Calculate the ratio between two histograms.
 

Static Public Member Functions

template<typename T >
static std::vector< T > ConvertVector2DToVector1D (const std::vector< std::vector< T > > &v2d)
 Flatten 2D vector to a 1D vector.
 
template<typename T >
static std::vector< T > ConvertVector2DToVector1D (std::vector< std::vector< T > > &&v2d)
 Flatten 2D vector to a 1D vector.
 

Protected Attributes

Uncertainty unc
 

Additional Inherited Members

- Protected Member Functions inherited from NAGASH::Tool
 Tool ()=delete
 
 Tool (const Tool &tool)=delete
 
 Tool (std::shared_ptr< MSGTool > MSG)
 Constructor.
 
 Tool (Tool &&tool)=delete
 
virtual ~Tool ()=default
 
std::shared_ptr< MSGToolMSGUser ()
 return the MSGTool inside.
 
Tooloperator= (const Tool &tool)=delete
 
Tooloperator= (Tool &&tool)=delete
 

Detailed Description

provide tools for manipulating ROOT histograms

Definition at line 16 of file HistTool.h.

Constructor & Destructor Documentation

◆ HistTool()

NAGASH::HistTool::HistTool ( std::shared_ptr< MSGTool MSG)
inline

Definition at line 19 of file HistTool.h.

Member Function Documentation

◆ Asymmetry()

void HistTool::Asymmetry ( TH1 *  A,
TH1 *  B,
TH1 *  Asy 
)

Calculate the asymmetry between two histograms.

Parameters
[in]Ahistogram A.
[in]Bhistogram B.
[out]Asythe asymmetry histogram \((A+B)/(A-B)\).

Definition at line 143 of file HistTool.cxx.

◆ Chi2() [1/2]

void HistTool::Chi2 ( TH1 *  A,
TH1 *  B,
TH1 *  C 
)

Calculate the \(\chi^2\) between two histograms.

Parameters
[in]Ahistogram A.
[in]Bhistogram B.
[out]C\((A-B)^2/(\sigma^2(A)+\sigma^2(B))\).

Definition at line 331 of file HistTool.cxx.

◆ Chi2() [2/2]

double HistTool::Chi2 ( TH1D *  A,
TH1D *  B,
TH2D *  CorrA = nullptr,
TH2D *  CorrB = nullptr 
)

Calculate the \(\chi^2\) between two histograms.

Parameters
Ahistogram A.
Bhistogram B.
CorrAcovariance matrix of A.
CorrBcovariance matrix of B.
Returns
\(\chi^2\) value.

Definition at line 442 of file HistTool.cxx.

◆ ConvertCorrToCov()

void HistTool::ConvertCorrToCov ( TH2D *  corr,
TH1D *  h,
TH2D *  cov 
)

Convert correlation matrix to covariance matrix.

Parameters
[in]corrInput correlation matrix.
[in]hthe histogram whose error would be used to calculate the covariance matrix.
[out]covthe output covariance matrix.

Definition at line 603 of file HistTool.cxx.

◆ ConvertCovToCorr()

void HistTool::ConvertCovToCorr ( TH2D *  covar,
TH2D *  corr 
)

Convert covariance matrix to correlation matrix.

Parameters
[in]covarinput covariance matrix.
[out]corroutput correlation matrix.

Definition at line 524 of file HistTool.cxx.

◆ ConvertCovToError()

void HistTool::ConvertCovToError ( TH2D *  hcov,
TH1D *  herr 
)

Convert covariance matrix to error histogram.

Parameters
[in]hcovthe input covariance matrix.
[out]herrthe output error.

Definition at line 566 of file HistTool.cxx.

◆ ConvertMatrixToTH2D()

void HistTool::ConvertMatrixToTH2D ( const TMatrixD &  mat,
TH2D *  h2d 
)

Convert a matrix to a 2D histogram.

Parameters
matthe input matrix.
h2dthe output 2D histogram.

Definition at line 1321 of file HistTool.cxx.

◆ ConvertTH1DErrorToVector()

std::vector< double > HistTool::ConvertTH1DErrorToVector ( TH1D *  h1d)

Convert the errors of a 1D histogram to a vector.

Parameters
h1dthe input histogram.
Returns
the vector of the errors of the histogram.

Definition at line 830 of file HistTool.cxx.

◆ ConvertTH1DToVector()

std::vector< double > HistTool::ConvertTH1DToVector ( TH1D *  h1d)

Convert the contents of a 1D histogram to a vector.

Parameters
h1dthe input histogram.
Returns
the vector of the contents of the histogram.

Definition at line 809 of file HistTool.cxx.

◆ ConvertTH2DErrorToVector()

std::vector< std::vector< double > > HistTool::ConvertTH2DErrorToVector ( TH2D *  h2d,
const TString &  priority = "XY" 
)

Convert the errors of a 2D histogram to a vector.

Parameters
h2dthe input histogram.
prioritythe priority of the axis to be converted, can be either "XY" or "YX".
Returns
the errors of the histogram.

Definition at line 900 of file HistTool.cxx.

◆ ConvertTH2DToMatrix()

TMatrixD HistTool::ConvertTH2DToMatrix ( TH2D *  h2d)

Convert a 2D histogram to a matrix.

Parameters
h2dthe input 2D histogram.
Returns
the output matrix.

Definition at line 1301 of file HistTool.cxx.

◆ ConvertTH2DToVector()

std::vector< std::vector< double > > HistTool::ConvertTH2DToVector ( TH2D *  h2d,
const TString &  priority = "XY" 
)

Convert the contents of a 2D histogram to a vector.

Parameters
h2dthe input histogram.
prioritythe priority of the axis to be converted, can be either "XY" or "YX".
Returns
the contents of the histogram.

Definition at line 852 of file HistTool.cxx.

◆ ConvertTH2DToVectorTH1D()

void HistTool::ConvertTH2DToVectorTH1D ( TH2D *  h2d,
const std::vector< TH1D * > &  vh1d,
const TString &  priority = "XY" 
)

Convert a 2D histogram into a vector of 1D histograms.

Parameters
[in]h2dthe input 2D histogram.
[out]vh1dthe output vector of 1D histograms.
[in]prioritythe priority of the axis to be converted, can be either "XY" or "YX".

Definition at line 1227 of file HistTool.cxx.

◆ ConvertTH3DErrorToVector()

std::vector< std::vector< std::vector< double > > > HistTool::ConvertTH3DErrorToVector ( TH3D *  h3d,
const TString &  priority = "XYZ" 
)

Convert the errors of a 3D histogram to a vector.

Parameters
h3dthe input histogram.
prioritythe priority of the axis to be converted, can be either "XYZ", XZY", "ZXY", "ZYX", "YZX" or "YXZ".
Returns
the errors of the histogram.

Definition at line 1074 of file HistTool.cxx.

◆ ConvertTH3DToVector()

std::vector< std::vector< std::vector< double > > > HistTool::ConvertTH3DToVector ( TH3D *  h3d,
const TString &  priority = "XYZ" 
)

Convert the contents of a 3D histogram to a vector.

Parameters
h3dthe input histogram.
prioritythe priority of the axis to be converted, can be either "XYZ", XZY", "ZXY", "ZYX", "YZX" or "YXZ".
Returns
the contents of the histogram.

Definition at line 948 of file HistTool.cxx.

◆ ConvertTH3DToVectorTH1D()

void HistTool::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.

Parameters
[in]h3dthe input 3D histogram.
[out]vh1dthe output 2D vector of 1D histograms.
[in]prioritythe priority of the axis to be converted, can be either "XYZ", "XZY", "ZXY", "ZYX", "YZX", or "YXZ".

Definition at line 1260 of file HistTool.cxx.

◆ ConvertVector2DToVector1D() [1/2]

template<typename T >
std::vector< T > NAGASH::HistTool::ConvertVector2DToVector1D ( const std::vector< std::vector< T > > &  v2d)
inlinestatic

Flatten 2D vector to a 1D vector.

Template Parameters
Ttype of the vector.
Parameters
v2dinput 2D vector with const reference.
Returns
flattened 1D vector.

Definition at line 70 of file HistTool.h.

◆ ConvertVector2DToVector1D() [2/2]

template<typename T >
std::vector< T > NAGASH::HistTool::ConvertVector2DToVector1D ( std::vector< std::vector< T > > &&  v2d)
inlinestatic

Flatten 2D vector to a 1D vector.

Template Parameters
Ttype of the vector.
Parameters
v2dinput 2D vector with right value reference.
Returns
flattened 1D vector.

Definition at line 85 of file HistTool.h.

◆ ConvertVectorTH1DToTH1D()

void HistTool::ConvertVectorTH1DToTH1D ( const std::vector< TH1D * > &  vh1d,
TH1D *  targeth1d 
)

Fuse a vector of 1D histograms into one 1D histogram.

Parameters
[in]vh1dthe input vector of 1D histograms.
[out]targeth1dthe output 1D histogram.

Definition at line 1199 of file HistTool.cxx.

◆ ConvertVectorToTH1D()

void HistTool::ConvertVectorToTH1D ( TH1D *  h1,
const std::vector< double > &  v1,
const std::vector< double > &  v1err = std::vector<double>() 
)

Convert vectors to a histogram.

Parameters
[out]h1output histogram.
[in]v1vector of the contents of the histogram.
[in]v1errvector of the errors of the histogram.

Definition at line 648 of file HistTool.cxx.

◆ ConvertVectorToTH2D()

void HistTool::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.

Parameters
[out]h2output histogram.
[in]v2the contents of the histogram.
[in]v2errthe errors of the histogram.

Definition at line 685 of file HistTool.cxx.

◆ ConvertVectorToTH3D()

void HistTool::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.

Parameters
[out]h3output histogram.
[in]v3the contents of the histogram.
[in]v3errthe errors of the histogram.

Definition at line 738 of file HistTool.cxx.

◆ Delta()

void HistTool::Delta ( TH1 *  A,
TH1 *  B,
TH1 *  D,
bool  dosep = false 
)

Calculate the difference between two histograms.

Parameters
[in]Ahistogram A.
[in]Bhistogram B.
[out]Dthe difference histogram \((A-B)\).
[in]dosepseperate the error or not, if do seperate, ignore A's error.

Definition at line 197 of file HistTool.cxx.

◆ ProcessHistLink() [1/3]

void HistTool::ProcessHistLink ( const TString &  type,
const std::vector< TH1 * > &  input,
TH1 *  res 
)

constructor

Create a new histogram based on the input histograms.

Parameters
[in]typethe kind of the histogram you want to create. Possible values are: Asymmetry, Delta, Ratio, Chi2 and Pull.
[in]inputthe input set of histograms.
[out]resoutput histogram.

Definition at line 15 of file HistTool.cxx.

◆ ProcessHistLink() [2/3]

void HistTool::ProcessHistLink ( std::function< double(const std::vector< double > &)>  contentfunction,
std::function< double(const std::vector< double > &, const std::vector< double > &)>  errorfunction,
const std::vector< TH1 * > &  input,
TH1 *  res 
)

Create a new histogram based on the input histograms.

Parameters
[in]contentfunctionthe function to calculate the new histogram content.
[in]errorfunctionthe function to calculate the new histogram error.
[in]inputthe input set of histograms.
[out]resthe output histogram.

Definition at line 72 of file HistTool.cxx.

◆ ProcessHistLink() [3/3]

void HistTool::ProcessHistLink ( std::function< void(const std::vector< TH1 * > &, TH1 *)>  func,
const std::vector< TH1 * > &  input,
TH1 *  res 
)

Create a new histogram based on the input histograms.

Parameters
[in]functhe function to calculate the new histogram.
[in]inputthe input set of histograms.
[out]resthe output histogram.

Definition at line 119 of file HistTool.cxx.

◆ Pull()

void HistTool::Pull ( TH1 *  A,
TH1 *  B,
TH1 *  P 
)

Calculate the pull between two histograms.

Parameters
[in]Ahistogram A.
[in]Bhistogram B.
[out]Ppull histogram \((A-B)/\sqrt{\sigma^2(A)+\sigma^2(B)}\).

Definition at line 386 of file HistTool.cxx.

◆ Ratio()

void HistTool::Ratio ( TH1 *  A,
TH1 *  B,
TH1 *  R,
bool  dosep = false 
)

Calculate the ratio between two histograms.

Parameters
[in]Ahistogram A.
[in]Bhistogram B.
[out]Rthe ratio histogram \((A/B)\).
[in]dosepseperate the error or not, if do seperate, ignore A's error.

Definition at line 253 of file HistTool.cxx.

Member Data Documentation

◆ unc

Uncertainty NAGASH::HistTool::unc
protected

Definition at line 62 of file HistTool.h.


The documentation for this class was generated from the following files: