CovarianceTools.cxx
Go to the documentation of this file.
1 //
2 // Created by Adam Lister on 2019-11-19.
3 //
4 
5 #include "CovarianceTools.h"
6 
7 namespace cmf {
8 
10  {
11  TMatrixD fracCovMatrix;
12  fracCovMatrix.ResizeTo(m.GetNrows(),m.GetNcols());
13 
14  for (int i = 0; i < m.GetNrows(); i++){
15  for (int j = 0; j < m.GetNcols(); j++){
16 
17  fracCovMatrix(i,j)=
18  m(i,j)/(spectrum->GetBinContent(i+1) * spectrum->GetBinContent(j+1));
19 
20  std::cout
21  << "i,j: " << i << ", " << j
22  << " pre: " << m(i,j)
23  << " bin i: " << spectrum->GetBinContent(i+1)
24  << " bin j: " << spectrum->GetBinContent(j+1)
25  << " post: " << fracCovMatrix(i,j)
26  << std::endl;
27 
28  if (spectrum->GetBinContent(i+1) == 0 || spectrum->GetBinContent(j+1) == 0)
29  fracCovMatrix(i,j) = 0;
30 
31  }
32  }
33 
34  return fracCovMatrix;
35  }
36 
38  {
40  covMatrix.ResizeTo(m.GetNrows(),m.GetNcols());
41 
42  for (int i = 0; i < m.GetNrows(); i++){
43  for (int j = 0; j < m.GetNcols(); j++){
44 
45  covMatrix(i,j)=
46  m(i,j)*(spectrum->GetBinContent(i+1) * spectrum->GetBinContent(j+1));
47 
48  }
49  }
50 
51  return covMatrix;
52  }
53 
55  {
56  TMatrixD corrMatrix;
57  corrMatrix.ResizeTo(m.GetNrows(),m.GetNcols());
58 
59  for (int i = 0; i < m.GetNrows(); i++){
60  for (int j = 0; j < m.GetNcols(); j++){
61 
62  corrMatrix(i,j)=
63  m(i,j)/(std::sqrt(m(i,i))*std::sqrt(m(j,j)));
64 
65  }
66  }
67 
68  return corrMatrix;
69  }
70 
72  {
74  covMatrix.ResizeTo(m.GetNrows(),m.GetNcols());
75 
76  for (int i = 0; i < m.GetNrows(); i++){
77  for (int j = 0; j < m.GetNcols(); j++){
78 
79  covMatrix(i,j)=
80  m(i,j)*(std::sqrt(m(i,i))*std::sqrt(m(j,j)));
81 
82  }
83  }
84 
85  return covMatrix;
86  }
87 
89  {
90 
91  TMatrixD cov = this->FracCovToCov(m, spectrum);
92  TMatrixD corrMatrix = this->CovToCorr(cov);
93 
94  return corrMatrix;
95  }
96 
98  {
99 
100  TMatrixD cov = this->CorrToCov(m);
101  TMatrixD fracCovMatrix = this->CovToFracCov(cov, spectrum);
102 
103  return fracCovMatrix;
104  }
105 
107  {
108  TH2D* thisTH2 = new TH2D(m);
109 
110  return thisTH2;
111  }
112 
114  {
115  int nbins = h->GetNbinsX();
116 
117  TMatrixD thisMatrix(nbins,
118  nbins);
119 
120  for (int i = 0; i < h->GetNbinsX(); i++){
121  for (int j = 0; j < h->GetNbinsY(); j++){
122  thisMatrix(i,j) = h->GetBinContent(i+1,j+1);
123  }
124  }
125 
126  return thisMatrix;
127 
128  }
129 
130 } // cmf namespace
float covMatrix[xbins][xbins]
Definition: MakePlots.C:95
TMatrixD FracCovToCorr(TMatrixD m, TH1D *spectrum)
T sqrt(T number)
Definition: d0nt_math.hpp:156
TMatrixD CovToFracCov(TMatrixD m, TH1D *spectrum)
const int nbins
Definition: cellShifts.C:15
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6
TH2D * matToTH2D(TMatrixD m)
TMatrixD CorrToCov(TMatrixD m)
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
TMatrixD FracCovToCov(TMatrixD m, TH1D *spectrum)
TMatrixD CovToCorr(TMatrixD m)
TMatrixD TH2ToMat(TH2D *m)
TMatrixD CorrToFracCov(TMatrixD m, TH1D *spectrum)