StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
writeCovariance.C
1 #include <stdio.h>
2 
3 void writeCovariance(FILE *fOut, int ibin, int icharge, char **paramNames, double *errors, double *covar, int nCent, int nParams) {
4  const char* binName[]={"all","soft","neck","hard","softHard"};
5  const char* chargeName[] = {"LS", "US", "CD", "CI"};
6  if (fOut) {
7  fprintf(fOut," covariance matrices for %s, %s\n",binName[ibin],chargeName[icharge]);\
8  } else {
9  printf(" covariance matrices for %s, %s\n",binName[ibin],chargeName[icharge]);\
10  }
11 
12  for (int ic=0;ic<nCent;ic++) {
13  if (fOut) {
14  fprintf(fOut," Normalized covariance for centrality %i\n",ic);
15  fprintf(fOut," ");
16  for (int ip=0;ip<nParams;ip++) {
17  fprintf(fOut," %s",paramNames[ip]);
18  }
19  fprintf(fOut,"\n");
20  } else {
21  printf(" Normalized covariance for centrality %i\n",ic);
22  printf(" ");
23  for (int ip=0;ip<nParams;ip++) {
24  printf(" %s",paramNames[ip]);
25  }
26  printf("\n");
27  }
28  int kp = 0;
29  for (int ip=0;ip<nParams;ip++) {
30  if (fOut) {
31  fprintf(fOut,"%s ",paramNames[ip]);
32  } else {
33  printf("%s ",paramNames[ip]);
34  }
35  if (0 < errors[ic*nParams+ip]) {
36  int lp = 0;
37  for (int jp=0;jp<=ip;jp++) {
38  if (0 < errors[ic*nParams+jp]) {
39  double den = sqrt(covar[(ic*nParams+kp)*nParams+kp]*covar[(ic*nParams+lp)*nParams+lp]);
40  if (fOut) {
41  fprintf(fOut," %8.3f",covar[(ic*nParams+kp)*nParams+lp]/den);
42  } else {
43  printf(" %8.3f",covar[(ic*nParams+kp)*nParams+lp]/den);
44  }
45  lp++;
46  } else {
47  if (fOut) {
48  fprintf(fOut," ");
49  } else {
50  printf(" ");
51  }
52  }
53  }
54  kp++;
55  }
56  if (fOut) {
57  fprintf(fOut,"\n");
58  } else {
59  printf("\n");
60  }
61  }
62  }
63 }