+//______________________________________________________________________________
+void AliAlignObj::GetCovMatrix(Double_t *cmat) const
+{
+ // Fills the cmat argument with the coefficients of the external cov matrix (21 elements)
+ // calculating them from the correlation matrix data member
+ //
+
+ for(Int_t i=0; i<6; ++i) {
+ // Off diagonal elements
+ for(Int_t j=0; j<i; ++j) {
+ cmat[i*(i+1)/2+j] = (fDiag[j] >= 0. && fDiag[i] >= 0.) ? fODia[(i-1)*i/2+j]*fDiag[j]*fDiag[i]: -999.;
+ }
+
+ // Diagonal elements
+ cmat[i*(i+1)/2+i] = (fDiag[i] >= 0.) ? fDiag[i]*fDiag[i] : -999.;
+ }
+}
+
+//______________________________________________________________________________
+void AliAlignObj::SetCorrMatrix(Double_t *cmat)
+{
+ // Sets the correlation matrix data member from the coefficients of the external covariance
+ // matrix (21 elements passed as argument).
+ //
+ if(cmat) {
+
+ // Diagonal elements first
+ for(Int_t i=0; i<6; ++i) {
+ fDiag[i] = (cmat[i*(i+1)/2+i] >= 0.) ? TMath::Sqrt(cmat[i*(i+1)/2+i]) : -999.;
+ }
+
+ // ... then the ones off diagonal
+ for(Int_t i=0; i<6; ++i)
+ // Off diagonal elements
+ for(Int_t j=0; j<i; ++j) {
+ fODia[(i-1)*i/2+j] = (fDiag[i] > 0. && fDiag[j] > 0.) ? cmat[i*(i+1)/2+j]/(fDiag[j]*fDiag[i]) : 0.; // check for division by zero (due to diagonal element of 0) and for fDiag != -999. (due to negative input diagonal element).
+ if (fODia[(i-1)*i/2+j]>1.) fODia[(i-1)*i/2+j] = 1.; // check upper boundary
+ if (fODia[(i-1)*i/2+j]<-1.) fODia[(i-1)*i/2+j] = -1.; // check lower boundary
+ }
+ } else {
+ for(Int_t i=0; i< 6; ++i) fDiag[i]=-999.;
+ for(Int_t i=0; i< 6*(6-1)/2; ++i) fODia[i]=0.;
+ }
+
+ return;
+}
+