StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
writePlotCode.C
1 #include <stdio.h>
2 #include <string.h>
3 
4 void writePlotCode(char *fileName, char *tag, char **pNames, double *chisq, double *params, double *errors, int nCent, int nParams ) {
5  FILE *fOut = fopen(fileName,"w");
6 
7  fprintf(fOut,"{\n");
8  // plot for chi^2.
9  fprintf(fOut," if (ChiSquares_position > 0) {\n");
10  fprintf(fOut," double %sChiSquareX[] = {",tag);
11  for (int ic=0;ic<nCent;ic++) {
12  fprintf(fOut,"%i",ic);
13  if (ic < nCent-1) {
14  fprintf(fOut,",");
15  } else {
16  fprintf(fOut,"};\n");
17  }
18  }
19  fprintf(fOut," double %sChiSquares[] = {",tag);
20  for (int ic=0;ic<nCent;ic++) {
21  fprintf(fOut,"%7.2f",chisq[ic]);
22  if (ic < nCent-1) {
23  fprintf(fOut,",");
24  } else {
25  fprintf(fOut,"};\n");
26  }
27  }
28  fprintf(fOut," TGraph *g%sChiSquares = new TGraph(%i,%sChiSquareX,%sChiSquares);\n\n",tag,nCent,tag,tag);
29  fprintf(fOut," TAxis *x = g%sChiSquares->GetXaxis();\n",tag);
30  fprintf(fOut," TAxis *y = g%sChiSquares->GetYaxis();\n",tag);
31  fprintf(fOut," x->SetLimits(0,%i);\n",nCent-1);
32  fprintf(fOut," x->SetTitle(\"centrality bin\");\n");
33  fprintf(fOut," x->SetTitleSize(0.05);\n");
34  fprintf(fOut," x->SetTitleOffset(0.6);\n");
35  fprintf(fOut," y->SetTitle(\"ChiSquares\");\n");
36  fprintf(fOut," y->SetTitleSize(0.05);\n");
37  fprintf(fOut," y->SetTitleOffset(0.6);\n");
38  fprintf(fOut," y->SetNdivisions(505);\n");
39  fprintf(fOut," g%sChiSquares->SetLineColor(%s_color);\n",tag,tag);
40  fprintf(fOut," g%sChiSquares->SetMarkerStyle(%s_style);\n",tag,tag);
41  fprintf(fOut," g%sChiSquares->SetMarkerColor(%s_color);\n",tag,tag);
42  fprintf(fOut," g%sChiSquares->SetMarkerSize(0.75);\n",tag);
43  fprintf(fOut," c1->cd(ChiSquares_position);\n");
44  fprintf(fOut," gPad->SetFillColor(0);\n");
45  fprintf(fOut," gPad->SetLeftMargin(ChiSquares_margin);\n");
46  fprintf(fOut," g%sChiSquares->SetMinimum(ChiSquares_min);\n",tag);
47  fprintf(fOut," g%sChiSquares->SetMaximum(ChiSquares_max);\n",tag);
48  fprintf(fOut," g%sChiSquares->Draw(%s_mode);\n",tag,tag);
49  fprintf(fOut," }\n");
50 
51  // One plot for each parameter.
52  for (int ip=0;ip<nParams;ip++) {
53  fprintf(fOut," if (%s_position > 0) {\n",pNames[ip]);
54  fprintf(fOut," double %s%s[] = {",tag,pNames[ip]);
55  int isign = 1;
56  if (1 == ip) {
57  isign = -1;
58  }
59  for (int ic=0;ic<nCent;ic++) {
60  fprintf(fOut,"%7.4f",isign*params[ic*nParams+ip]);
61  if (ic < nCent-1) {
62  fprintf(fOut,",");
63  } else {
64  fprintf(fOut,"};\n");
65  }
66  }
67  fprintf(fOut," double e%s%s[] = {",tag,pNames[ip]);
68  for (int ic=0;ic<nCent;ic++) {
69  fprintf(fOut,"%7.4f",errors[ic*nParams+ip]);
70  if (ic < nCent-1) {
71  fprintf(fOut," ,");
72  } else {
73  fprintf(fOut,"};\n");
74  }
75  }
76  if (!strcmp(pNames[ip],"cos2Phi")) {
77  fprintf(fOut," TGraph *g%s%s = new TGraphErrors(%i,%sBbyB0,%s%s,e%sxpos,e%s%s);\n",tag,pNames[ip],nCent,tag,tag,pNames[ip],tag,tag,pNames[ip]);
78  fprintf(fOut," TAxis *x = g%s%s->GetXaxis();\n",tag,pNames[ip]);
79  fprintf(fOut," TAxis *y = g%s%s->GetYaxis();\n",tag,pNames[ip]);
80  fprintf(fOut," x->SetLimits(0.0,1.0);\n");
81  fprintf(fOut," x->SetTitle(\"1-b/b_0\");\n");
82  } else {
83  fprintf(fOut," TGraph *g%s%s = new TGraphErrors(%i,%sxpos,%s%s,e%sxpos,e%s%s);\n",tag,pNames[ip],nCent,tag,tag,pNames[ip],tag,tag,pNames[ip]);
84  fprintf(fOut," TAxis *x = g%s%s->GetXaxis();\n",tag,pNames[ip]);
85  fprintf(fOut," TAxis *y = g%s%s->GetYaxis();\n",tag,pNames[ip]);
86  fprintf(fOut," x->SetLimits(1,6.5);\n");
87  fprintf(fOut," x->SetTitle(\"#nu\");\n");
88  }
89  fprintf(fOut," x->SetTitleSize(0.05);\n");
90  fprintf(fOut," x->SetTitleOffset(0.6);\n");
91  fprintf(fOut," y->SetTitle(\"%s\");\n",pNames[ip]);
92  fprintf(fOut," y->SetTitleSize(0.05);\n");
93  fprintf(fOut," y->SetTitleOffset(0.6);\n");
94  fprintf(fOut," y->SetNdivisions(505);\n");
95  fprintf(fOut," g%s%s->SetLineColor(%s_color);\n",tag,pNames[ip],tag);
96  fprintf(fOut," g%s%s->SetMarkerStyle(%s_style);\n",tag,pNames[ip],tag);
97  fprintf(fOut," g%s%s->SetMarkerColor(%s_color);\n",tag,pNames[ip],tag);
98  fprintf(fOut," g%s%s->SetMarkerSize(0.75);\n",tag,pNames[ip]);
99  fprintf(fOut," c1->cd(%s_position);\n",pNames[ip]);
100  fprintf(fOut," gPad->SetFillColor(0);\n");
101  fprintf(fOut," gPad->SetLeftMargin(%s_margin);\n",pNames[ip]);
102  fprintf(fOut," g%s%s->SetMinimum(%s_min);\n",tag,pNames[ip],pNames[ip]);
103  fprintf(fOut," g%s%s->SetMaximum(%s_max);\n",tag,pNames[ip],pNames[ip]);
104  fprintf(fOut," g%s%s->Draw(%s_mode);\n",tag,pNames[ip],tag);
105  fprintf(fOut," }\n\n\n");
106  }
107 
108 
109  // plot ratio of minijet amplitude to cos(phi) amplitude.
110  fprintf(fOut," if (jetOvercosphi_position > 0) {\n");
111  fprintf(fOut," double %sjetOvercosphi[] = {",tag);
112  for (int ic=0;ic<nCent;ic++) {
113  double rat = -params[ic*nParams+3]/params[ic*nParams+1];
114  fprintf(fOut,"%7.4f",rat);
115  if (ic < nCent-1) {
116  fprintf(fOut,",");
117  } else {
118  fprintf(fOut,"};\n");
119  }
120  }
121  fprintf(fOut," double e%sjetOvercosphi[] = {",tag);
122  for (int ic=0;ic<nCent;ic++) {
123  double rat = -params[ic*nParams+3]/params[ic*nParams+1];
124  double erat = rat * sqrt( pow(errors[ic*nParams+1]/params[ic*nParams+1],2) + pow(errors[ic*nParams+3]/params[ic*nParams+3],2));
125  fprintf(fOut,"%7.4f",erat);
126  if (ic < nCent-1) {
127  fprintf(fOut," ,");
128  } else {
129  fprintf(fOut,"};\n");
130  }
131  }
132  fprintf(fOut," TGraph *g%sjetOvercosphi = new TGraphErrors(%i,%sxpos,%sjetOvercosphi,e%sxpos,e%sjetOvercosphi);\n\n",tag,nCent,tag,tag,tag,tag);
133  fprintf(fOut," TAxis *x = g%sjetOvercosphi->GetXaxis();\n",tag);
134  fprintf(fOut," TAxis *y = g%sjetOvercosphi->GetYaxis();\n",tag);
135  fprintf(fOut," x->SetLimits(1,6.5);\n");
136  fprintf(fOut," x->SetTitle(\"#nu\");\n");
137  fprintf(fOut," x->SetTitleSize(0.05);\n");
138  fprintf(fOut," x->SetTitleOffset(0.6);\n");
139  fprintf(fOut," y->SetTitle(\"jetOvercosphi\");\n");
140  fprintf(fOut," y->SetTitleSize(0.05);\n");
141  fprintf(fOut," y->SetTitleOffset(0.6);\n");
142  fprintf(fOut," y->SetNdivisions(505);\n");
143  fprintf(fOut," g%sjetOvercosphi->SetLineColor(%s_color);\n",tag,tag);
144  fprintf(fOut," g%sjetOvercosphi->SetMarkerStyle(%s_style);\n",tag,tag);
145  fprintf(fOut," g%sjetOvercosphi->SetMarkerColor(%s_color);\n",tag,tag);
146  fprintf(fOut," g%sjetOvercosphi->SetMarkerSize(0.75);\n",tag);
147  fprintf(fOut," c1->cd(jetOvercosphi_position);\n");
148  fprintf(fOut," gPad->SetFillColor(0);\n");
149  fprintf(fOut," gPad->SetLeftMargin(jetOvercosphi_margin);\n");
150  fprintf(fOut," g%sjetOvercosphi->SetMinimum(jetOvercosphi_min);\n",tag);
151  fprintf(fOut," g%sjetOvercosphi->SetMaximum(jetOvercosphi_max);\n",tag);
152  fprintf(fOut," g%sjetOvercosphi->Draw(%s_mode);\n",tag,tag);
153  fprintf(fOut," }\n");
154  fprintf(fOut,"}\n");
155 
156  fclose(fOut);
157 }