96 TString msg =
"All histograms must have equal dimension.\n";
97 msg += Form(
" Found: dim(bdat)=%i\n", bdat->GetNbinsX() );
98 msg += Form(
" Found: dim(bini)=%i\n", bini->GetNbinsX() );
99 msg += Form(
" Found: dim(xini)=%i\n", xini->GetNbinsX() );
100 msg += Form(
" Found: dim(Adet)=%i,%i\n", Adet->GetNbinsX(), Adet->GetNbinsY() );
101 msg +=
"Please start again!";
103 Fatal(
"Init", msg,
"%s" );
108 for(
int i=1; i<=fBdat->GetNbinsX(); i++){
109 fBcov->SetBinContent(i, i,
fBdat->GetBinError(i)*
fBdat->GetBinError(i));
110 for(
int j=1; j<=
fBdat->GetNbinsX(); j++){
112 fBcov->SetBinContent(i,j,0.);
151 TString msg =
"All histograms must have equal dimension.\n";
152 msg += Form(
" Found: dim(bdat)=%i\n", bdat->GetNbinsX() );
153 msg += Form(
" Found: dim(Bcov)=%i,%i\n", Bcov->GetNbinsX(), Bcov->GetNbinsY() );
154 msg += Form(
" Found: dim(bini)=%i\n", bini->GetNbinsX() );
155 msg += Form(
" Found: dim(xini)=%i\n", xini->GetNbinsX() );
156 msg += Form(
" Found: dim(Adet)=%i,%i\n", Adet->GetNbinsX(), Adet->GetNbinsY() );
157 msg +=
"Please start again!";
159 Fatal(
"Init", msg,
"%s" );
270 for (
Int_t i=0; i<
fNdim; i++) CSVM(i,i) = 1/CSV(i);
273 TMatrixD mCinv = (CVort*CSVM)*CUort;
282 for(
int i=0; i<
fNdim; i++){
289 for(
int i=0; i<
fNdim; i++){
290 for(
int j=0; j<
fNdim; j++){
292 vbtmp(i) += QT(i,j)*vb(j)/BSV(i);
296 mAtmp(i,j) += QT(i,
m)*mA(
m,j)/BSV(i);
332 if (ASV(i)<ASV(0)*eps) sreg = ASV(0)*eps;
334 vdz(i) = sreg/(sreg*sreg + ASV(k)*ASV(k));
335 Z(i,i) = vdz(i)*vdz(i);
341 TMatrixD W = mCinv*Vort*Z*VortT*mCinv;
349 Xtau(i,j) = vxini(i) * vxini(j) * W(i,j);
353 a += mA(
m,i)*mA(
m,j);
355 if(vxini(i) && vxini(j))
356 Xinv(i,j) =
a/vxini(i)/vxini(j);
370 Xtau *= 1./scale/scale;
382 Info(
"Unfold",
"Unfolding param: %i",k+1 );
383 Info(
"Unfold",
"Curvature of weight distribution: %f",
GetCurvature( vw, mCurv ) );
387 for(
int i=1; i<=
fNdim; i++){
388 h->SetBinContent(i,0.);
389 h->SetBinError(i,0.);
407 TH1D* unfres =
nullptr;
409 unfcov->
SetTitle(
"Toy covariance matrix");
410 for(
int i=1; i<=
fNdim; i++)
411 for(
int j=1; j<=
fNdim; j++)
424 if (L(iPar,iPar) > 0.0) L(iPar,iPar) =
TMath::Sqrt(L(iPar,iPar));
425 else L(iPar,iPar) = 0.0;
430 for (
Int_t k=0; k<iPar; k++) L(iPar,jPar) -= L(k,iPar)*L(k,jPar);
431 if (L(iPar,iPar)!=0.) L(iPar,jPar) /= L(iPar,iPar);
432 else L(iPar,jPar) = 0;
445 for (
int i=1; i<=ntoys; i++) {
455 for (
int j=1; j<=
fNdim; j++) {
473 for (
int i=1; i<=ntoys; i++) {
483 for (
int j=1; j<=
fNdim; j++) {
513 TH1D* unfres =
nullptr;
515 unfcov->
SetTitle(
"Toy covariance matrix");
516 for(
int i=1; i<=
fNdim; i++)
517 for(
int j=1; j<=
fNdim; j++)
527 for (
int i=1; i<=ntoys; i++) {
530 if (
fAdet->GetBinContent(k,
m)) {
548 for (
int i=1; i<=ntoys; i++) {
551 if (
fAdet->GetBinContent(k,
m))
577 for (
int i=1; i<=
fDHist->GetNbinsX(); i++) {
671 if (vec2(i) != 0) quot(i) = vec1(i) / vec2(i);
673 if (zero) quot(i) = 0;
674 else quot(i) = vec1(i);
688 if (
vec(i) != 0) quotmat(i,j) = mat(i,j) /
vec(i);
690 if (zero) quotmat(i,j) = 0;
691 else quotmat(i,j) = mat(i,j);
704 for (
Int_t i=0; i<vec1.
GetNrows(); i++) res(i) = vec1(i) * vec2(i);
728 if (
fDdim == 0)
for (
Int_t i=0; i<ndim; i++) tC(i,i) = 1;
729 else if (
fDdim == 1) {
730 for (
Int_t i=0; i<ndim; i++) {
731 if (i < ndim-1) tC(i,i+1) = 1.0;
735 else if (
fDdim == 2) {
736 for (
Int_t i=0; i<ndim; i++) {
737 if (i > 0) tC(i,i-1) = 1.0;
738 if (i < ndim-1) tC(i,i+1) = 1.0;
742 tC(ndim-1,ndim-1) = -1.0;
744 else if (
fDdim == 3) {
745 for (
Int_t i=1; i<ndim-2; i++) {
753 for (
Int_t i=0; i<ndim; i++) {
754 if (i > 0) tC(i,i-1) = -4.0;
755 if (i < ndim-1) tC(i,i+1) = -4.0;
756 if (i > 1) tC(i,i-2) = 1.0;
757 if (i < ndim-2) tC(i,i+2) = 1.0;
761 tC(ndim-1,ndim-1) = 2.0;
763 tC(ndim-2,ndim-1) = -3.0;
765 tC(ndim-1,ndim-2) = -3.0;
767 tC(ndim-2,ndim-2) = 6.0;
769 else if (
fDdim == 5) {
770 for (
Int_t i=2; i < ndim-3; i++) {
779 else if (
fDdim == 6) {
780 for (
Int_t i = 3; i < ndim - 3; i++) {
792 for (
Int_t i=0; i<ndim; i++) tC(i,i) = tC(i,i) + eps;
795 for (
Int_t i=0; i<ndim; i++) {
796 for (
Int_t j=0; j<ndim; j++) {
797 for (
Int_t k=0; k<ndim; k++) {
798 tCurv(i,j) = tCurv(i,j) + tC(k,i)*tC(k,j);
815 fXtau->SetTitle(
"Regularized covariance matrix");
819 fXinv->SetTitle(
"Inverse covariance matrix");
847 for (
UInt_t in=0; in<nn; in++)
for (
UInt_t jn=0; jn<nn; jn++) matwork(in,jn) = 0;
850 for (
UInt_t in=0; in<nn; in++) {
852 matwork[in][in] = mat[ipos[in]][ipos[in]];
853 for (
UInt_t jn=in+1; jn<nn; jn++) {
854 matwork[in][jn] = mat[ipos[in]][ipos[jn]];
855 matwork[jn][in] = matwork[in][jn];
863 for (
UInt_t i=0; i<
n; i++)
for (
UInt_t j=0; j<
n; j++) mat[i][j] = 0;
866 for (
UInt_t in=0; in<nn; in++) {
867 mat[ipos[in]][ipos[in]] = matwork[in][in];
868 for (
UInt_t jn=in+1; jn<nn; jn++) {
869 mat[ipos[in]][ipos[jn]] = matwork[in][jn];
870 mat[ipos[jn]][ipos[in]] = mat[ipos[in]][ipos[jn]];
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
double Double_t
Double 8 bytes.
TMatrixTSym< Double_t > TMatrixDSym
TMatrixT< Double_t > TMatrixD
TVectorT< Double_t > TVectorD
Single Value Decomposition class.
const TVectorD & GetSig()
1-D histogram with a double per channel (see TH1 documentation)
void SetTitle(const char *title) override
Change/set the title.
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
virtual Int_t GetNbinsX() const
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
2-D histogram with a double per channel (see TH1 documentation)
void SetBinContent(Int_t bin, Double_t content) override
Set bin content.
Double_t GetBinContent(Int_t binx, Int_t biny) const override
TMatrixTSym< Element > & Invert(Double_t *det=nullptr)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
TMatrixT< Element > & Transpose(const TMatrixT< Element > &source)
Transpose matrix source.
TObject()
TObject constructor.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Random number generator class based on M.
void SetSeed(ULong_t seed=0) override
Set the random generator sequence.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
virtual ULong64_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
TH1D * GetSV() const
Returns singular values vector.
TH2D * GetBCov() const
Returns the covariance matrix.
TH1D * fSVHist
! Distribution of singular values
TH2D * GetXtau() const
Returns the computed regularized covariance matrix corresponding to total uncertainties on measured s...
Bool_t fToyMode
! Internal switch for covariance matrix propagation
static void V2H(const TVectorD &vec, TH1D &histo)
Fill vector into 1D histogram.
static void H2M(const TH2D *histo, TMatrixD &mat)
Fill 2D histogram into matrix.
static void RegularisedSymMatInvert(TMatrixDSym &mat, Double_t eps=1e-3)
naive regularised inversion cuts off small elements
static TVectorD CompProd(const TVectorD &vec1, const TVectorD &vec2)
Multiply entries of two vectors.
static void M2H(const TMatrixD &mat, TH2D &histo)
Fill 2D histogram into matrix.
Bool_t fMatToyMode
! Internal switch for evaluation of statistical uncertainties from response matrix
TSVDUnfold(const TH1D *bdat, const TH1D *bini, const TH1D *xini, const TH2D *Adet)
Alternative constructor User provides data and MC test spectra, as well as detector response matrix,...
Bool_t fNormalize
! Normalize unfolded spectrum to 1
const TH1D * fBini
Reconstructed distribution (MC).
TH1D * Unfold(Int_t kreg)
Perform the unfolding with regularisation parameter kreg.
Double_t ComputeChiSquared(const TH1D &truspec, const TH1D &unfspec)
Helper routine to compute chi-squared between distributions using the computed inverse of the covaria...
TH2D * fToymat
! Toy MC detector response matrix
static Double_t GetCurvature(const TVectorD &vec, const TMatrixD &curv)
Compute curvature of vector.
const TH1D * fBdat
Measured distribution (data).
~TSVDUnfold() override
Destructor.
static TMatrixD MatDivVec(const TMatrixD &mat, const TVectorD &vec, Int_t zero=0)
Divide matrix entries by vector.
TH2D * fXinv
! Computed inverse of covariance matrix
static TVectorD VecDiv(const TVectorD &vec1, const TVectorD &vec2, Int_t zero=0)
Divide entries of two vectors.
void FillCurvatureMatrix(TMatrixD &tCurv, TMatrixD &tC) const
TH1D * GetD() const
Returns d vector (for choosing appropriate regularisation).
TH2D * fXtau
! Computed regularized covariance matrix
TH1D * fDHist
! Distribution of d (for checking regularization)
static void H2Verr(const TH1D *histo, TVectorD &vec)
Fill 1D histogram errors into vector.
Int_t fDdim
! Derivative for curvature matrix
TH2D * GetUnfoldCovMatrix(const TH2D *cov, Int_t ntoys, Int_t seed=1)
Determine for given input error matrix covariance matrix of unfolded spectrum from toy simulation giv...
TH2D * GetAdetCovMatrix(Int_t ntoys, Int_t seed=1)
Determine covariance matrix of unfolded spectrum from finite statistics in response matrix using pseu...
const TH2D * fAdet
Detector response matrix.
TH2D * GetXinv() const
Returns the computed inverse of the covariance matrix.
static void H2V(const TH1D *histo, TVectorD &vec)
Fill 1D histogram into vector.
Int_t fKReg
! Regularisation parameter
TH1D * fToyhisto
! Toy MC histogram
TH2D * fBcov
Covariance matrix of measured distribution (data).
const TH1D * fXini
Truth distribution (MC).
Int_t fNdim
! Truth and reconstructed dimensions
Element Sum() const
Compute sum of elements.
Double_t Sqrt(Double_t x)
Returns the square root of x.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.