289 const
char *
TUnfold::GetTUnfoldVersion(
void)
357 for(
Int_t i=0;i<2;i++) {
454 if(rank !=
GetNx()) {
455 Warning(
"DoUnfold",
"rank of matrix E %d expect %d",rank,
GetNx());
479 epsilonNosparse(A_cols[i],0) += A_data[i];
491 Fatal(
"Unfold",
"epsilon#Eepsilon has dimension %d != 1",
498 y_minus_epsx += (*fY)(iy,0);
501 for(
Int_t ix=0;ix<epsilonNosparse.GetNrows();ix++) {
502 y_minus_epsx -= epsilonNosparse(ix,0) * (*fX)(ix,0);
505 lambda_half=y_minus_epsx*one_over_epsEeps;
510 if(EEpsilon_rows[ix]<EEpsilon_rows[ix+1]) {
511 (*fX)(ix,0) += lambda_half * EEpsilon_data[EEpsilon_rows[ix]];
530 data[i]=one_over_epsEeps;
540 AddMSparse(temp, -one_over_epsEeps, epsilonB);
577 if(VyyinvDy_rows[iy]<VyyinvDy_rows[iy+1]) {
578 fChi2A += VyyinvDy_data[VyyinvDy_rows[iy]]*dy(iy,0);
587 if(LsquaredDx_rows[ix]<LsquaredDx_rows[ix+1]) {
588 fLXsquared += LsquaredDx_data[LsquaredDx_rows[ix]]*dx(ix,0);
603 "epsilon#fDXDtauSquared has dimension %d != 1",
626 (Eepsilon,Eepsilon,0);
651 if(rank !=
GetNx()) {
652 Warning(
"DoUnfold",
"rank of output covariance is %d expect %d",
661 for(
int ik=VxxInv_rows[ix];ik<VxxInv_rows[ix+1];ik++) {
662 if(ix==VxxInv_cols[ik]) {
663 VxxInvDiag(ix)=VxxInv_data[ik];
677 for(
int ik=Vxx_rows[ix];ik<Vxx_rows[ix+1];ik++) {
678 if(ix==Vxx_cols[ik]) {
680 1. - 1. / (VxxInvDiag(ix) * Vxx_data[ik]);
681 if (rho_squared > rho_squared_max)
682 rho_squared_max = rho_squared;
683 if(rho_squared>0.0) {
692 fRhoAvg = (n_rho>0) ? (rho_sum/n_rho) : -1.0;
719 Fatal(
"MultiplyMSparseMSparse",
720 "inconsistent matrix col/ matrix row %d !=%d",
734 if(a_rows[irow+1]>a_rows[irow]) nMax += b->
GetNcols();
736 if((nMax>0)&&(a_cols)&&(b_cols)) {
743 if(a_rows[irow+1]<=a_rows[irow])
continue;
749 for(
Int_t ia=a_rows[irow];ia<a_rows[irow+1];ia++) {
752 for(
Int_t ib=b_rows[k];ib<b_rows[k+1];ib++) {
753 row_data[b_cols[ib]] += a_data[ia]*b_data[ib];
758 if(row_data[icol] != 0.0) {
761 r_data[
n]=row_data[icol];
789 Fatal(
"MultiplyMSparseTranspMSparse",
790 "inconsistent matrix row numbers %d!=%d",
804 typedef std::map<Int_t,Double_t> MMatrixRow_t;
805 typedef std::map<Int_t, MMatrixRow_t > MMatrix_t;
809 for(
Int_t ia=a_rows[iRowAB];ia<a_rows[iRowAB+1];ia++) {
810 for(
Int_t ib=b_rows[iRowAB];ib<b_rows[iRowAB+1];ib++) {
812 MMatrixRow_t &row=matrix[a_cols[ia]];
813 MMatrixRow_t::iterator icol=row.find(b_cols[ib]);
814 if(icol!=row.end()) {
816 (*icol).second += a_data[ia]*b_data[ib];
819 row[b_cols[ib]] = a_data[ia]*b_data[ib];
826 for(MMatrix_t::const_iterator irow=matrix.begin();
827 irow!=matrix.end();irow++) {
828 n += (*irow).second.size();
836 for(MMatrix_t::const_iterator irow=matrix.begin();
837 irow!=matrix.end();irow++) {
838 for(MMatrixRow_t::const_iterator icol=(*irow).second.begin();
839 icol!=(*irow).second.end();icol++) {
840 r_rows[
n]=(*irow).first;
841 r_cols[
n]=(*icol).first;
842 r_data[
n]=(*icol).second;
867 Fatal(
"MultiplyMSparseM",
"inconsistent matrix col /matrix row %d!=%d",
878 if(a_rows[irow+1]-a_rows[irow]>0) nMax += b->
GetNcols();
888 if(a_rows[irow+1]-a_rows[irow]<=0)
continue;
893 for(
Int_t i=a_rows[irow];i<a_rows[irow+1];i++) {
895 r_data[
n] += a_data[i]*(*b)(j,icol);
897 if(r_data[n]!=0.0) n++;
921 Fatal(
"MultiplyMSparseMSparseTranspVector",
922 "matrix cols/vector rows %d!=%d!=%d or vector rows %d!=1\n",
925 Fatal(
"MultiplyMSparseMSparseTranspVector",
934 if(rows_m1[i]<rows_m1[i+1]) num_m1++;
941 if(rows_m2[j]<rows_m2[j+1]) num_m2++;
944 const Int_t *v_rows=0;
950 Int_t num_r=num_m1*num_m2+1;
958 Int_t index_m1=rows_m1[i];
959 Int_t index_m2=rows_m2[j];
960 while((index_m1<rows_m1[i+1])&&(index_m2<rows_m2[j+1])) {
961 Int_t k1=cols_m1[index_m1];
962 Int_t k2=cols_m2[index_m2];
969 Int_t v_index=v_rows[k1];
970 if(v_index<v_rows[k1+1]) {
971 data_r[num_r] += data_m1[index_m1] * data_m2[index_m2]
977 data_r[num_r] += data_m1[index_m1] * data_m2[index_m2]
980 data_r[num_r] += data_m1[index_m1] * data_m2[index_m2];
986 if(data_r[num_r] !=0.0) {
994 num_r,row_r,col_r,data_r);
1015 Fatal(
"AddMSparse",
"inconsistent matrix rows %d!=%d OR cols %d!=%d",
1026 while((i_dest<dest_rows[row+1])||(i_src<src_rows[row+1])) {
1027 Int_t col_dest=(i_dest<dest_rows[row+1]) ?
1028 dest_cols[i_dest] : dest->
GetNcols();
1029 Int_t col_src =(i_src <src_rows[row+1] ) ?
1030 src_cols [i_src] : src->
GetNcols();
1032 if(col_dest<col_src) {
1033 result_cols[
n]=col_dest;
1034 result_data[
n]=dest_data[i_dest++];
1035 }
else if(col_dest>col_src) {
1036 result_cols[
n]=col_src;
1037 result_data[
n]=f*src_data[i_src++];
1039 result_cols[
n]=col_dest;
1040 result_data[
n]=dest_data[i_dest++]+f*src_data[i_src++];
1042 if(result_data[n] !=0.0) {
1044 Fatal(
"AddMSparse",
"Nan detected %d %d %d",
1058 delete[] result_data;
1059 delete[] result_rows;
1060 delete[] result_cols;
1078 Fatal(
"InvertMSparseSymmPos",
"inconsistent matrix row/col %d!=%d",
1095 for(
Int_t indexA=a_rows[iA];indexA<a_rows[iA+1];indexA++) {
1096 Int_t jA=a_cols[indexA];
1098 if(!(a_data[indexA]>=0.0)) nError++;
1099 aII(iA)=a_data[indexA];
1105 Fatal(
"InvertMSparseSymmPos",
1106 "Matrix has %d negative elements on the diagonal", nError);
1121 for(
Int_t iStart=0;iStart<iBlock;iStart++) {
1123 for(
Int_t i=iStart;i<iBlock;i++) {
1127 Int_t tmp=swap[iStart];
1128 swap[iStart]=swap[i];
1134 Int_t iA=swap[iStart];
1135 for(
Int_t indexA=a_rows[iA];indexA<a_rows[iA+1];indexA++) {
1136 Int_t jA=a_cols[indexA];
1145 for(
Int_t i=iStart+1;i<iBlock;) {
1146 if(isZero[swap[i]]) {
1150 Int_t tmp=swap[iBlock];
1151 swap[iBlock]=swap[i];
1163 #ifdef CONDITION_BLOCK_PART
1165 for(
int inc=(nn+1)/2;inc;inc /= 2) {
1166 for(
int i=inc;i<nn;i++) {
1167 int itmp=swap[i+iBlock];
1169 for(j=i;(j>=inc)&&(aII(swap[j-inc+iBlock])<aII(itmp));j -=inc) {
1170 swap[j+iBlock]=swap[j-inc+iBlock];
1172 swap[j+iBlock]=itmp;
1179 swapBack[swap[i]]=i;
1183 std::cout<<
" "<<i<<
" "<<swap[i]<<
" "<<swapBack[i]<<
"\n";
1185 std::cout<<
"after sorting\n";
1187 if(i==iDiagonal) std::cout<<
"iDiagonal="<<i<<
"\n";
1188 if(i==iBlock) std::cout<<
"iBlock="<<i<<
"\n";
1189 std::cout<<
" "<<swap[i]<<
" "<<aII(swap[i])<<
"\n";
1203 for(
Int_t indexA=a_rows[row];indexA<a_rows[row+1];indexA++) {
1204 Int_t j=swapBack[a_cols[indexA]];
1206 else if((i<iDiagonal)||(j<iDiagonal)) nError1++;
1207 else if((i<iBlock)&&(j<iBlock)) nError2++;
1208 else if((i<iBlock)||(j<iBlock)) nBlock++;
1212 if(nError1+nError2>0) {
1213 Fatal(
"InvertMSparseSymmPos",
"sparse matrix analysis failed %d %d %d %d %d",
1214 iDiagonal,iBlock,A->
GetNrows(),nError1,nError2);
1219 Info(
"InvertMSparseSymmPos",
"iDiagonal=%d iBlock=%d nRow=%d",
1279 for(
Int_t i=0;i<iDiagonal;++i) {
1284 rEl_data[rNumEl]=1./aII(iA);
1289 if((!rankPtr)&&(rankD1!=iDiagonal)) {
1290 Fatal(
"InvertMSparseSymmPos",
1291 "diagonal part 1 has rank %d != %d, matrix can not be inverted",
1299 Int_t nD2=iBlock-iDiagonal;
1301 if((rNumEl>=0)&&(nD2>0)) {
1306 for(
Int_t i=0;i<nD2;++i) {
1307 Int_t iA=swap[i+iDiagonal];
1309 D2inv_col[D2invNumEl]=i;
1310 D2inv_row[D2invNumEl]=i;
1311 D2inv_data[D2invNumEl]=1./aII(iA);
1315 if(D2invNumEl==nD2) {
1316 D2inv=CreateSparseMatrix(nD2,nD2,D2invNumEl,D2inv_row,D2inv_col,
1318 }
else if(!rankPtr) {
1319 Fatal(
"InvertMSparseSymmPos",
1320 "diagonal part 2 has rank %d != %d, matrix can not be inverted",
1324 delete [] D2inv_data;
1325 delete [] D2inv_col;
1326 delete [] D2inv_row;
1336 if((rNumEl>=0)&&(nF>0)&&((nD2==0)||D2inv)) {
1345 Int_t nBmax=nF*(nD2+1);
1351 for(
Int_t i=0;i<nF;i++) {
1352 Int_t iA=swap[i+iBlock];
1353 for(
Int_t indexA=a_rows[iA];indexA<a_rows[iA+1];indexA++) {
1354 Int_t jA=a_cols[indexA];
1355 Int_t j0=swapBack[jA];
1360 F_data[FnumEl]=a_data[indexA];
1362 }
else if(j0>=iDiagonal) {
1363 Int_t j=j0-iDiagonal;
1366 B_data[BnumEl]=a_data[indexA];
1373 #ifndef FORCE_EIGENVALUE_DECOMPOSITION
1374 F=CreateSparseMatrix(nF,nF,FnumEl,F_row,F_col,F_data);
1381 B=CreateSparseMatrix(nF,nD2,BnumEl,B_row,B_col,B_data);
1388 minusBD2inv=MultiplyMSparseMSparse(B,D2inv);
1393 for(
Int_t i=0;i<mbd2_nMax;i++) {
1394 mbd2_data[i] = - mbd2_data[i];
1398 if(minusBD2inv && F) {
1400 MultiplyMSparseMSparseTranspVector(minusBD2inv,B,0);
1401 AddMSparse(F,1.,minusBD2invBt);
1402 DeleteMatrix(&minusBD2invBt);
1413 for(
Int_t i=0;i<nF;i++) {
1414 for(
Int_t indexF=f_rows[i];indexF<f_rows[i+1];indexF++) {
1415 if(f_cols[indexF]>=i)
c(f_cols[indexF],i)=f_data[indexF];
1419 for(
Int_t j=0;j<i;j++) {
1430 for(
Int_t j=i+1;j<nF;j++) {
1432 for(
Int_t k=0;k<i;k++) {
1433 c_ji -=
c(i,k)*
c(j,k);
1442 for(
Int_t i=1;i<nF;i++) {
1447 std::cout<<
"dmin,dmax: "<<dmin<<
" "<<dmax<<
"\n";
1449 if(dmin/dmax<epsilonF2*nF) nErrorF=2;
1455 for(
Int_t i=0;i<nF;i++) {
1456 cinv(i,i)=1./
c(i,i);
1458 for(
Int_t i=0;i<nF;i++) {
1459 for(
Int_t j=i+1;j<nF;j++) {
1461 for(
Int_t k=i+1;k<j;k++) {
1462 tmp -= cinv(k,i)*
c(j,k);
1464 cinv(j,i)=tmp*cinv(j,j);
1468 Finv=MultiplyMSparseTranspMSparse
1469 (&cInvSparse,&cInvSparse);
1480 Int_t rankD2Block=0;
1482 if( ((nD2==0)||D2inv) && ((nF==0)||Finv) ) {
1492 if(Finv && minusBD2inv) {
1493 G=MultiplyMSparseMSparse(Finv,minusBD2inv);
1497 if(G && minusBD2inv) {
1499 MultiplyMSparseTranspMSparse(minusBD2inv,G);
1501 AddMSparse(E,1.,minusBD2invTransG);
1502 DeleteMatrix(&minusBD2invTransG);
1504 E=minusBD2invTransG;
1513 Int_t iA=swap[iE+iDiagonal];
1514 for(
Int_t indexE=e_rows[iE];indexE<e_rows[iE+1];++indexE) {
1515 Int_t jE=e_cols[indexE];
1516 Int_t jA=swap[jE+iDiagonal];
1519 rEl_data[rNumEl]=e_data[indexE];
1531 Int_t iA=swap[iG+iBlock];
1532 for(
Int_t indexG=g_rows[iG];indexG<g_rows[iG+1];++indexG) {
1533 Int_t jG=g_cols[indexG];
1534 Int_t jA=swap[jG+iDiagonal];
1538 rEl_data[rNumEl]=g_data[indexG];
1543 rEl_data[rNumEl]=g_data[indexG];
1555 Int_t iA=swap[iF+iBlock];
1556 for(
Int_t indexF=finv_rows[iF];indexF<finv_rows[iF+1];++indexF) {
1557 Int_t jF=finv_cols[indexF];
1558 Int_t jA=swap[jF+iBlock];
1561 rEl_data[rNumEl]=finv_data[indexF];
1567 }
else if(!rankPtr) {
1569 Fatal(
"InvertMSparseSymmPos",
1570 "non-trivial part has rank < %d, matrix can not be inverted",
1577 Info(
"InvertMSparseSymmPos",
1578 "cholesky-decomposition failed, try eigenvalue analysis");
1580 std::cout<<
"nEV="<<nEV<<
" iDiagonal="<<iDiagonal<<
"\n";
1583 for(
Int_t i=0;i<nEV;i++) {
1584 Int_t iA=swap[i+iDiagonal];
1585 for(
Int_t indexA=a_rows[iA];indexA<a_rows[iA+1];indexA++) {
1586 Int_t jA=a_cols[indexA];
1587 Int_t j0=swapBack[jA];
1589 Int_t j=j0-iDiagonal;
1591 if((i<0)||(j<0)||(i>=nEV)||(j>=nEV)) {
1592 std::cout<<
" error "<<nEV<<
" "<<i<<
" "<<j<<
"\n";
1596 Fatal(
"InvertMSparseSymmPos",
1597 "non-finite number detected element %d %d\n",
1600 EV(i,j)=a_data[indexA];
1607 std::cout<<
"Eigenvalues\n";
1617 if(condition<-epsilonEV2) {
1622 Error(
"InvertMSparseSymmPos",
1623 "Largest Eigenvalue is negative %f",
1626 Error(
"InvertMSparseSymmPos",
1627 "Some Eigenvalues are negative (EV%d/EV0=%g epsilon=%g)",
1637 for(
Int_t i=0;i<nEV;i++) {
1640 inverseEV(i,0)=1./
x;
1649 const Int_t *vdvt_rows=VDVt->GetRowIndexArray();
1650 const Int_t *vdvt_cols=VDVt->GetColIndexArray();
1651 const Double_t *vdvt_data=VDVt->GetMatrixArray();
1652 for(
Int_t iVDVt=0;iVDVt<VDVt->GetNrows();iVDVt++) {
1653 Int_t iA=swap[iVDVt+iDiagonal];
1654 for(
Int_t indexVDVt=vdvt_rows[iVDVt];
1655 indexVDVt<vdvt_rows[iVDVt+1];++indexVDVt) {
1656 Int_t jVDVt=vdvt_cols[indexVDVt];
1657 Int_t jA=swap[jVDVt+iDiagonal];
1660 rEl_data[rNumEl]=vdvt_data[indexVDVt];
1664 DeleteMatrix(&VDVt);
1668 *rankPtr=rankD1+rankD2Block;
1672 DeleteMatrix(&D2inv);
1673 DeleteMatrix(&Finv);
1675 DeleteMatrix(&minusBD2inv);
1683 rEl_row,rEl_col,rEl_data) : 0;
1711 std::cout<<
"Ar is not symmetric Ar("<<i<<
","<<j<<
")="<<
ar(i,j)
1712 <<
" Ar("<<j<<
","<<i<<
")="<<
ar(j,i)<<
"\n";
1717 std::cout<<
"ArA is not equal A ArA("<<i<<
","<<j<<
")="<<ara(i,j)
1718 <<
" A("<<i<<
","<<j<<
")="<<
a(i,j)<<
"\n";
1723 std::cout<<
"rAr is not equal r rAr("<<i<<
","<<j<<
")="<<rar(i,j)
1724 <<
" r("<<i<<
","<<j<<
")="<<
R(i,j)<<
"\n";
1728 if(rankPtr) std::cout<<
"rank="<<*rankPtr<<
"\n";
1730 std::cout<<
"Matrix is not positive\n";
1798 for (
Int_t ix = 0; ix < nx0; ix++) {
1803 for (
Int_t iy = 0; iy <
ny; iy++) {
1841 Int_t underflowBin=0,overflowBin=0;
1842 for (
Int_t ix = 0; ix <
nx; ix++) {
1844 if(ibinx<1) underflowBin=1;
1846 if(ibinx>hist_A->
GetNbinsX()) overflowBin=1;
1848 if(ibinx>hist_A->
GetNbinsY()) overflowBin=1;
1853 Int_t ixfirst=-1,ixlast=-1;
1855 int nDisconnected=0;
1856 for (
Int_t ix = 0; ix < nx0; ix++) {
1867 if(((
fHistToX[ix]>=0)&&(ixlast>=0))||
1868 (nprint==nskipped)) {
1869 if(ixlast>ixfirst) {
1876 if(nprint==nskipped) {
1880 if(nskipped==(2-underflowBin-overflowBin)) {
1881 Info(
"TUnfold",
"underflow and overflow bin "
1882 "do not depend on the input data");
1884 Warning(
"TUnfold",
"%d output bins "
1885 "do not depend on the input data %s",nDisconnected,
1886 static_cast<const char *>(binlist));
1897 for (
Int_t iy = 0; iy <
ny; iy++) {
1898 for (
Int_t ix = 0; ix <
nx; ix++) {
1914 if(underflowBin && overflowBin) {
1915 Info(
"TUnfold",
"%d input bins and %d output bins (includes 2 underflow/overflow bins)",ny,nx);
1916 }
else if(underflowBin) {
1917 Info(
"TUnfold",
"%d input bins and %d output bins (includes 1 underflow bin)",ny,nx);
1918 }
else if(overflowBin) {
1919 Info(
"TUnfold",
"%d input bins and %d output bins (includes 1 overflow bin)",ny,nx);
1921 Info(
"TUnfold",
"%d input bins and %d output bins",ny,nx);
1925 Error(
"TUnfold",
"too few (ny=%d) input bins for nx=%d output bins",ny,nx);
1927 Warning(
"TUnfold",
"too few (ny=%d) input bins for nx=%d output bins",ny,nx);
1939 "%d regularisation conditions have been skipped",nError);
1942 "One regularisation condition has been skipped");
2003 return AddRegularisationCondition(nEle,indices,data);
2020 const Int_t *l0_rows=fL->GetRowIndexArray();
2021 const Int_t *l0_cols=fL->GetColIndexArray();
2022 const Double_t *l0_data=fL->GetMatrixArray();
2024 Int_t nF=l0_rows[fL->GetNrows()]+nEle;
2030 for(
Int_t row=0;row<fL->GetNrows();row++) {
2031 for(
Int_t k=l0_rows[row];k<l0_rows[row+1];k++) {
2033 l_col[nF]=l0_cols[k];
2034 l_data[nF]=l0_data[k];
2042 rowMax=fL->GetNrows();
2046 for(
Int_t i=0;i<nEle;i++) {
2047 Int_t col=fHistToX[indices[i]];
2054 l_data[nF]=rowData[i];
2061 fL=CreateSparseMatrix(rowMax+1,GetNx(),nF,l_row,l_col,l_data);
2117 (left_bin,-scale_left,
2118 center_bin,scale_left+scale_right,
2119 right_bin,-scale_right)
2146 Error(
"RegularizeBins",
"regmode = %d is not valid",regmode);
2148 for (
Int_t i = nSkip; i < nbin; i++) {
2164 int step2,
int nbin2,
ERegMode regmode)
2177 for (
Int_t i1 = 0; i1 < nbin1; i1++) {
2178 nError +=
RegularizeBins(start_bin + step1 * i1, step2, nbin2, regmode);
2180 for (
Int_t i2 = 0; i2 < nbin2; i2++) {
2181 nError +=
RegularizeBins(start_bin + step2 * i2, step1, nbin1, regmode);
2210 const TH2 *hist_vyy_inv)
2260 if(oneOverZeroError>0.0) {
2261 dy2 = 1./ ( oneOverZeroError*oneOverZeroError);
2267 rowVyyN[nVyyN] = iy;
2268 colVyyN[nVyyN] = iy;
2269 rowVyy1[nVyy1] = iy;
2271 dataVyyDiag[iy] = dy2;
2273 dataVyyN[nVyyN++] = dy2;
2274 dataVyy1[nVyy1++] = dy2;
2281 if(dataVyyDiag[iy]<=0.0)
continue;
2284 if(iy==jy)
continue;
2286 if(dataVyyDiag[jy]<=0.0)
continue;
2288 rowVyyN[nVyyN] = iy;
2289 colVyyN[nVyyN] = jy;
2291 if(dataVyyN[nVyyN] == 0.0)
continue;
2297 "inverse of input covariance is taken from user input");
2304 rowVyyInv[nVyyInv] = iy;
2305 colVyyInv[nVyyInv] = jy;
2306 dataVyyInv[nVyyInv]= hist_vyy_inv->
GetBinContent(iy+1,jy+1);
2307 if(dataVyyInv[nVyyInv] == 0.0)
continue;
2312 (
GetNy(),
GetNy(),nVyyInv,rowVyyInv,colVyyInv,dataVyyInv);
2313 delete [] rowVyyInv;
2314 delete [] colVyyInv;
2315 delete [] dataVyyInv;
2320 (
GetNy(),
GetNy(),nVyyN,rowVyyN,colVyyN,dataVyyN);
2327 (
GetNy(),1,nVyy1,rowVyy1,colVyy1, dataVyy1);
2351 if(oneOverZeroError !=0.0) {
2353 Warning(
"SetInput",
"%d/%d input bins have zero error,"
2354 " 1/error set to %lf.",nError,
GetNy(),oneOverZeroError);
2356 Warning(
"SetInput",
"One input bin has zero error,"
2357 " 1/error set to %lf.",oneOverZeroError);
2361 Warning(
"SetInput",
"%d/%d input bins have zero error,"
2362 " and are ignored.",nError,
GetNy());
2364 Warning(
"SetInput",
"One input bin has zero error,"
2365 " and is ignored.");
2372 if(oneOverZeroError<=0.0) {
2378 TString binlist(
"no data to constrain output bin ");
2394 Error(
"SetInput",
"%d/%d output bins are not constrained by any data.",
2397 Error(
"SetInput",
"One output bins is not constrained by any data.");
2402 delete[] dataVyyDiag;
2404 return nError+10000*nError2;
2438 typedef std::map<Double_t,std::pair<Double_t,Double_t> > XYtau_t;
2463 if((tauMin<=0)||(tauMax<=0.0)||(tauMin>=tauMax)) {
2473 Error(
"ScanLcurve",
"too few input bins, NDF<=0 %d",
GetNdf());
2478 Info(
"ScanLcurve",
"logtau=-Infinity X=%lf Y=%lf",x0,y0);
2480 Fatal(
"ScanLcurve",
"problem (too few input bins?) X=%f",x0);
2483 Fatal(
"ScanLcurve",
"problem (missing regularisation?) Y=%f",y0);
2492 Fatal(
"ScanLcurve",
"problem (missing regularisation?) X=%f Y=%f",
2496 Info(
"ScanLcurve",
"logtau=%lf X=%lf Y=%lf",
2499 if((*curve.begin()).second.first<x0) {
2511 Fatal(
"ScanLcurve",
"problem (missing regularisation?) X=%f Y=%f",
2515 Info(
"ScanLcurve",
"logtau=%lf X=%lf Y=%lf",
2518 while(((
int)curve.size()<(nPoint-1)/2)&&
2519 ((*curve.begin()).second.first<x0));
2526 while(((
int)curve.size()<nPoint-1)&&
2527 (((*curve.begin()).second.first-x0>0.00432)||
2528 ((*curve.begin()).second.second-y0>0.00432)||
2529 (curve.size()<2))) {
2533 Fatal(
"ScanLcurve",
"problem (missing regularisation?) X=%f Y=%f",
2537 Info(
"ScanLcurve",
"logtau=%lf X=%lf Y=%lf",
2548 Fatal(
"ScanLcurve",
"problem (missing regularisation?) X=%f Y=%f",
2551 Info(
"ScanLcurve",
"logtau=%lf X=%lf Y=%lf",
2558 Fatal(
"ScanLcurve",
"problem (missing regularisation?) X=%f Y=%f",
2561 Info(
"ScanLcurve",
"logtau=%lf X=%lf Y=%lf",
2571 while(
int(curve.size())<nPoint-1) {
2574 XYtau_t::const_iterator i0,i1;
2579 for(i1++;i1!=curve.end();i1++) {
2580 const std::pair<Double_t,Double_t> &xy0=(*i0).second;
2581 const std::pair<Double_t,Double_t> &xy1=(*i1).second;
2587 logTau=0.5*((*i0).first+(*i1).first);
2593 Fatal(
"ScanLcurve",
"problem (missing regularisation?) X=%f Y=%f",
2605 XYtau_t::const_iterator i0,i1;
2610 if( ((
int)curve.size())<nPoint) {
2619 for( XYtau_t::const_iterator i=curve.begin();i!=curve.end();i++) {
2620 lXi[
n]=(*i).second.first;
2621 lYi[
n]=(*i).second.second;
2629 for(
Int_t i=0;i<n-1;i++) {
2631 splineX->
GetCoeff(i,ltau,xy,bi,ci,di);
2632 Double_t tauBar=0.5*(lTi[i]+lTi[i+1]);
2633 Double_t dTau=0.5*(lTi[i+1]-lTi[i]);
2634 Double_t dx1=bi+dTau*(2.*ci+3.*di*dTau);
2636 splineY->
GetCoeff(i,ltau,xy,bi,ci,di);
2637 Double_t dy1=bi+dTau*(2.*ci+3.*di*dTau);
2640 cCi[i]=(dy2*dx1-dy1*dx2)/
TMath::Power(dx1*dx1+dy1*dy1,1.5);
2660 for(
Int_t i=iskip;i<n-2-iskip;i++) {
2683 xx = m_p_half + discr;
2685 xx = m_p_half - discr;
2689 if((xx>0.0)&&(xx<dx)) {
2690 y=splineC->
Eval(x+xx);
2703 if((xx>0.0)&&(xx<dx)) {
2704 y=splineC->
Eval(x+xx);
2723 lcc.
SaveAs(
"splinec.ps");
2732 Fatal(
"ScanLcurve",
"problem (missing regularisation?) X=%f Y=%f",
2735 Info(
"ScanLcurve",
"Result logtau=%lf X=%lf Y=%lf",
2745 Int_t bestChoice=-1;
2746 if(curve.size()>0) {
2751 for( XYtau_t::const_iterator i=curve.begin();i!=curve.end();i++) {
2752 if(logTauFin==(*i).first) {
2755 x[
n]=(*i).second.first;
2756 y[
n]=(*i).second.second;
2761 (*lCurve)=
new TGraph(n,x,y);
2762 (*lCurve)->SetTitle(
"L curve");
2764 if(logTauX) (*logTauX)=
new TSpline3(
"log(chi**2)%log(tau)",logT,x,n);
2765 if(logTauY) (*logTauY)=
new TSpline3(
"log(reg.cond)%log(tau)",logT,y,n);
2838 Int_t destI = binMap ? binMap[i+1] : i+1;
2839 if(destI<0)
continue;
2843 Int_t index_a=rows_A[i];
2844 Int_t index_av=rows_AVxx[i];
2845 while((index_a<rows_A[i+1])&&(index_av<rows_AVxx[i])) {
2846 Int_t j_a=cols_A[index_a];
2847 Int_t j_av=cols_AVxx[index_av];
2850 }
else if(j_a>j_av) {
2853 e2 += data_AVxx[index_av] * data_A[index_a];
2872 for(
Int_t indexA=rows_A[iy];indexA<rows_A[iy+1];indexA++) {
2873 Int_t ix = cols_A[indexA];
2902 Int_t destI=binMap ? binMap[i] : i;
2903 if(destI<0)
continue;
2908 for(
int index=rows_Vyy[i];index<rows_Vyy[i+1];index++) {
2909 if(cols_Vyy[index]==i) {
2928 Warning(
"GetInputInverseEmatrix",
"input covariance matrix has rank %d expect %d",
2932 Error(
"GetInputInverseEmatrix",
"number of parameters %d > %d (rank of input covariance). Problem can not be solved",
GetNpar(),rank);
2933 }
else if(
fNdf==0) {
2934 Warning(
"GetInputInverseEmatrix",
"number of parameters %d = input rank %d. Problem is ill posed",
GetNpar(),rank);
2943 for(
int i=0;i<=out->
GetNbinsX()+1;i++) {
2944 for(
int j=0;j<=out->
GetNbinsY()+1;j++) {
2950 for(
int index=rows_Vyy[i];index<rows_Vyy[i+1];index++) {
2951 Int_t j=cols_Vyy[index];
2969 for (
Int_t cindex = rows[i]; cindex < rows[i+1]; cindex++) {
2970 Int_t j=cols[cindex];
2987 for (
Int_t cindex = rows[row]; cindex < rows[row+1]; cindex++) {
2988 Int_t col=cols[cindex];
3053 std::map<Int_t,Double_t> e2;
3060 for(
Int_t i=0;i<binMapSize;i++) {
3061 Int_t destBinI=binMap ? binMap[i] : i;
3063 if((destBinI>=0)&&(srcBinI>=0)) {
3071 Int_t index_vxx=rows_Vxx[srcBinI];
3073 while((j<binMapSize)&&(index_vxx<rows_Vxx[srcBinI+1])) {
3074 Int_t destBinJ=binMap ? binMap[j] : j;
3075 if(destBinI!=destBinJ) {
3084 if(cols_Vxx[index_vxx]<srcBinJ) {
3087 }
else if(cols_Vxx[index_vxx]>srcBinJ) {
3092 e2[destBinI] += data_Vxx[index_vxx];
3102 for(std::map<Int_t,Double_t>::const_iterator i=e2.begin();
3123 for(
Int_t i=0;i<nbin+2;i++) {
3124 for(
Int_t j=0;j<nbin+2;j++) {
3137 for(
Int_t i=0;i<binMapSize;i++) {
3138 Int_t destBinI=binMap ? binMap[i] : i;
3140 if((destBinI>=0)&&(destBinI<nbin+2)&&(srcBinI>=0)) {
3146 Int_t index_vxx=rows_emat[srcBinI];
3147 while((j<binMapSize)&&(index_vxx<rows_emat[srcBinI+1])) {
3148 Int_t destBinJ=binMap ? binMap[j] : j;
3150 if((destBinJ<0)||(destBinJ>=nbin+2)||(srcBinJ<0)) {
3154 if(cols_emat[index_vxx]<srcBinJ) {
3157 }
else if(cols_emat[index_vxx]>srcBinJ) {
3163 + data_emat[index_vxx];
3201 for(
Int_t i=0;i<nbin+2;i++) {
3204 for(
Int_t i=0;i<nbin+2;i++) {
3205 for(
Int_t j=0;j<nbin+2;j++) {
3206 if((e[i]>0.0)&&(e[j]>0.0)) {
3249 for(
int index_vxx=rows_Vxx[i];index_vxx<rows_Vxx[i+1];index_vxx++) {
3250 if(cols_Vxx[index_vxx]==i) {
3251 e_ii=data_Vxx[index_vxx];
3255 for(
int index_vxxinv=rows_VxxInv[i];index_vxxinv<rows_VxxInv[i+1];
3257 if(cols_VxxInv[index_vxxinv]==i) {
3258 einv_ii=data_VxxInv[index_vxxinv];
3263 if((einv_ii>0.0)&&(e_ii>0.0)) rho=1.-1./(einv_ii*e_ii);
3276 const Int_t *binMap,
TH2 *invEmat)
const
3299 std::map<int,int> histToLocalBin;
3301 for(
Int_t i=0;i<binMapSize;i++) {
3302 Int_t mapped_i=binMap ? binMap[i] : i;
3304 if(histToLocalBin.find(mapped_i)==histToLocalBin.end()) {
3305 histToLocalBin[mapped_i]=nBin;
3315 for(std::map<int,int>::const_iterator i=histToLocalBin.begin();
3316 i!=histToLocalBin.end();i++) {
3317 localBinToHist[(*i).second]=(*i).first;
3334 Int_t destI=binMap ? binMap[origI] : origI;
3335 if(destI<0)
continue;
3336 Int_t ematBinI=histToLocalBin[destI];
3337 for(
int index_eOrig=rows_eOrig[i];index_eOrig<rows_eOrig[i+1];
3340 Int_t j=cols_eOrig[index_eOrig];
3344 Int_t destJ=binMap ? binMap[origJ] : origJ;
3345 if(destJ<0)
continue;
3346 Int_t ematBinJ=histToLocalBin[destJ];
3347 eRemap(ematBinI,ematBinJ) += data_eOrig[index_eOrig];
3355 Warning(
"GetRhoIFormMatrix",
"Covariance matrix has rank %d expect %d",
3366 for(
Int_t index_einv=rows_eInv[i];index_einv<rows_eInv[i+1];
3368 Int_t j=cols_eInv[index_einv];
3370 einv_ii=data_eInv[index_einv];
3374 data_eInv[index_einv]);
3378 if((einv_ii>0.0)&&(e_ii>0.0)) rho=1.-1./(einv_ii*e_ii);
3389 delete [] localBinToHist;
3403 for(
int i=0;i<3;i++) ixyz[i]=0;
3404 while((ixyz[0]<=nxyz[0])&&
3405 (ixyz[1]<=nxyz[1])&&
3406 (ixyz[2]<=nxyz[2])){
3410 for(
Int_t i=0;i<3;i++) {
3412 if(ixyz[i]<=nxyz[i])
break;
const TVectorD & GetEigenValues() const
void SetBias(const TH1 *bias)
static void DeleteMatrix(TMatrixD **m)
TMatrixDSparse * CreateSparseMatrix(Int_t nrow, Int_t ncol, Int_t nele, Int_t *row, Int_t *col, Double_t *data) const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TMatrixDSparse * InvertMSparseSymmPos(const TMatrixDSparse *A, Int_t *rank) const
virtual Int_t ScanLcurve(Int_t nPoint, Double_t tauMin, Double_t tauMax, TGraph **lCurve, TSpline **logTauX=0, TSpline **logTauY=0)
void GetOutput(TH1 *output, const Int_t *binMap=0) const
void Fatal(const char *location, const char *msgfmt,...)
virtual const Element * GetMatrixArray() const
virtual Int_t GetDimension() const
Base class for spline implementation containing the Draw/Paint methods //.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
virtual TString GetOutputBinName(Int_t iBinX) const
virtual TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *="")
Copy array data to matrix .
Short_t Min(Short_t a, Short_t b)
TMatrixDSparse * fDXDtauSquared
Int_t RegularizeBins2D(int start_bin, int step1, int nbin1, int step2, int nbin2, ERegMode regmode)
virtual Int_t GetNbinsX() const
void GetInputInverseEmatrix(TH2 *ematrix)
TMatrixDSparse * fDXDAZ[2]
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
virtual Double_t GetLcurveY(void) const
Int_t GetNpar(void) const
const char * Data() const
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Bool_t AddRegularisationCondition(Int_t i0, Double_t f0, Int_t i1=-1, Double_t f1=0., Int_t i2=-1, Double_t f2=0.)
void GetFoldedOutput(TH1 *folded, const Int_t *binMap=0) const
static void swap(double &a, double &b)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
TMatrixDSparse * MultiplyMSparseM(const TMatrixDSparse *a, const TMatrixD *b) const
TMatrixDSparse * fDXDAM[2]
void ClearHistogram(TH1 *h, Double_t x=0.) const
Double_t Eval(Double_t x) const
Eval this spline at x.
Double_t Log10(Double_t x)
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save Pad contents in a file in one of various formats.
virtual Int_t GetBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
Return Global bin number corresponding to binx,y,z.
void Info(const char *location, const char *msgfmt,...)
Int_t RegularizeCurvature(int left_bin, int center_bin, int right_bin, Double_t scale_left=1.0, Double_t scale_right=1.0)
void GetRhoIJ(TH2 *rhoij, const Int_t *binMap=0) const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Set(Int_t n)
Set size of this array to n ints.
void SetEpsMatrix(Double_t eps)
virtual void SetBinError(Int_t bin, Double_t error)
see convention for numbering bins in TH1::GetBin
void Error(const char *location, const char *msgfmt,...)
TMatrixTSparse< Double_t > TMatrixDSparse
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
void GetEmatrix(TH2 *ematrix, const Int_t *binMap=0) const
TMatrixT< Double_t > TMatrixD
Double_t GetChi2L(void) const
Double_t GetTau(void) const
virtual Int_t SetInput(const TH1 *hist_y, Double_t scaleBias=0.0, Double_t oneOverZeroError=0.0, const TH2 *hist_vyy=0, const TH2 *hist_vyy_inv=0)
Double_t GetRhoI(TH1 *rhoi, const Int_t *binMap=0, TH2 *invEmat=0) const
virtual Double_t DoUnfold(void)
virtual const Int_t * GetRowIndexArray() const
Service class for 2-Dim histogram classes.
ClassImp(TUnfold) const char *TUnfold
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...
void GetLsquared(TH2 *lsquared) const
virtual Int_t GetNbinsZ() const
void GetNormalisationVector(TH1 *s, const Int_t *binMap=0) const
void ErrorMatrixToHist(TH2 *ematrix, const TMatrixDSparse *emat, const Int_t *binMap, Bool_t doClear) const
const Double_t * GetArray() const
TMatrixDSparse * MultiplyMSparseTranspMSparse(const TMatrixDSparse *a, const TMatrixDSparse *b) const
const TMatrixD & GetEigenVectors() const
virtual void ClearResults(void)
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
void SetConstraint(EConstraint constraint)
virtual Double_t GetLcurveX(void) const
Int_t RegularizeBins(int start, int step, int nbin, ERegMode regmode)
virtual const Int_t * GetColIndexArray() const
void GetCoeff(Int_t i, Double_t &x, Double_t &y, Double_t &b, Double_t &c, Double_t &d)
virtual Int_t GetNbinsY() const
void AddMSparse(TMatrixDSparse *dest, Double_t f, const TMatrixDSparse *src) const
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Int_t RegularizeDerivative(int left_bin, int right_bin, Double_t scale=1.0)
TUnfold is used to decompose a measurement y into several sources x given the measurement uncertainti...
TMatrixDSparse * MultiplyMSparseMSparse(const TMatrixDSparse *a, const TMatrixDSparse *b) const
#define dest(otri, vertexptr)
Short_t Max(Short_t a, Short_t b)
A Graph is a graphics object made of two arrays X and Y with npoints each.
TArrow ar(9, 23, 9, 21.6, 0.015,"|>")
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Double_t Sqrt(Double_t x)
static void output(int code)
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
void GetBias(TH1 *bias, const Int_t *binMap=0) const
Double_t GetRhoIFromMatrix(TH1 *rhoi, const TMatrixDSparse *eOrig, const Int_t *binMap, TH2 *invEmat) const
Int_t RegularizeSize(int bin, Double_t scale=1.0)
void Set(Int_t n)
Set size of this array to n doubles.
void GetProbabilityMatrix(TH2 *A, EHistMap histmap) const
void GetInput(TH1 *inputData, const Int_t *binMap=0) const
TMatrixDSparse * MultiplyMSparseMSparseTranspVector(const TMatrixDSparse *m1, const TMatrixDSparse *m2, const TMatrixTBase< Double_t > *v) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.