void LatexMaker::writeCorrMatrix( ofstream& file, TMatrixDSym mat, RooArgList *observables, vector<TString> labels ) { file << "\\begin{tabular}{ l |"; for ( int i=0; i < mat.GetNcols(); i++) file << "c"; file << "}" << endl; file << "\\hline" << endl; file << "\\hline" << endl; file << Form("%-15s",""); for ( int i=0; i < mat.GetNcols(); i++) { TString title = observables->at(i)->GetTitle(); title.ReplaceAll("#","\\"); if ( i < labels.size() ) title = labels[i]; file << Form(" & %s",title.Data()); } file << "\\\\" << endl; file << "\\hline" << endl; for ( int i=0; i < mat.GetNrows(); i++) { TString title = observables->at(i)->GetTitle(); title.ReplaceAll("#","\\"); if ( i < labels.size() ) title = labels[i]; file << Form("%-15s",title.Data()); for (int j=0; j < mat.GetNcols(); j++) { if ( mat[i][j] < 0 ) { file << Form(" & %4.2f",mat[i][j]); } else if ( TMath::Abs(mat[i][j]-1) < 1.e-6 ) { file << " & 1"; } else if ( mat[i][j] > 0 ) { file << Form(" & %4.2f",mat[i][j]); } else { file << " & 0"; } } file << " \\\\" << endl; } file << "\\hline" << endl; file << "\\hline" << endl; file << "\\end{tabular}" << endl; }
void MultiGaus(const TVectorD& parMeans, const TMatrixDSym& covMatrix, TVectorD& genPars) { TRandom3 rnd(0); int nPars = parMeans.GetNrows(); if(nPars <= 0) { Error("MultiGaus", "Must have >0 pars"); return; } if(covMatrix.GetNrows() != nPars) { Error("MultiGaus", "parMeans.GetNrows() != covMatrix.GetNrows()"); return; } // Check that covMatrix is symmetric for(int iRow = 0; iRow < nPars; iRow++) { for(int iCol = iRow; iCol < nPars; iCol++) { if(covMatrix(iRow, iCol) != covMatrix(iCol, iRow)) { Error("MultiGaus", "malformed cov matrix at row %d, col %d", iRow, iCol); return; } } } genPars.ResizeTo(nPars); TMatrixDSymEigen eigenvariances(covMatrix); TMatrixD V = eigenvariances.GetEigenVectors(); TVectorD rotParMeans = V * parMeans; for(int iPar = 0; iPar < nPars; iPar++) { double variance = eigenvariances.GetEigenValues()[iPar]; // check for positive-definiteness of covMatrix if(variance < 0) { Error("MultiGaus", "Got a negative eigenvariance (%f) on iPar = %d", variance, iPar); } genPars[iPar] = rnd.Gaus(rotParMeans[iPar], sqrt(variance)); } V.Invert(); genPars = V * genPars; }