/// /// Build a full correlation matrix by /// filling diagonal elements with unity /// and symmetrizing. /// void Utils::buildCorMatrix(TMatrixDSym &cor) { // fill diagonals for ( int i=0; i<cor.GetNcols(); i++ ) { cor[i][i] = 1.; } // symmetrize for ( int i=0; i<cor.GetNcols(); i++ ) for ( int j=0; j<cor.GetNcols(); j++ ) { if ( cor[i][j]!=0.0 && cor[j][i]==0.0 ) cor[j][i] = cor[i][j]; if ( cor[i][j]==0.0 && cor[j][i]!=0.0 ) cor[i][j] = cor[j][i]; } }
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; }
/// /// Return a submatrix of a given input matrix, defined by the rows /// and columns provided. /// /// \param source - the input matrix /// \param target - the output matrix /// \param indices - vector of the row/column indices that should make up the submatrix /// void PDF_Abs::getSubMatrix(TMatrixDSym& target, TMatrixDSym& source, vector<int>& indices) { if ( indices.size()==0 ){ cout << "PDF_Abs::getSubMatrix() : vector 'indices' can't be empty" << endl; exit(1); } if ( target.GetNcols() != indices.size() ){ cout << "PDF_Abs::getSubMatrix() : 'target' matrix doesn't have size of 'indices' vector" << endl; exit(1); } for ( int i=0; i<indices.size(); i++ ){ // check requested index if ( indices[i]<0 || indices[i]>=source.GetNcols() ){ cout << "PDF_Abs::getSubMatrix() : ERROR : requested index for submatrix is out of range of parent matrix" << endl; exit(1); } // copy over row and column for ( int j=0; j<indices.size(); j++ ){ target[i][j] = source[indices[i]][indices[j]]; target[j][i] = source[indices[j]][indices[i]]; } } }
/// /// Set an external systematic correlation matrix. /// After modifying, call buildCov() and buildPdf(); /// void PDF_Abs::setSystCorrelation(TMatrixDSym &corSystMatrix) { assert(corSystMatrix.GetNcols()==nObs); this->corSystMatrix = corSystMatrix; corSource = corSource + " (syst. cor. set manually)"; }