StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
endPlot.C
1 TFile *outH, *inpH;
2 
3 const int totC=4;
4 char *tCutL[totC]={ "Pt16", "PtLMH", "EtaBF", "Qpn"};
5 
6 const int mxAmp=4;
7 char *ampL[mxAmp]={"a1:P", "-b1:Q", "c0:PQ", "c2:PQ"};
8 
9 const int mxGr=200;
10 TGraphErrors * grL[mxGr];
11 int nGr=0;
12 TString wrkDir="final/fixMe/";
13 
14 endPlot(char *path="") {
15  wrkDir="final/";
16  wrkDir+=path;
17  //wrkDir="final/default-H/";
18  //wrkDir="final/maxEta1.4-H/";
19  //wrkDir="final/nPrim5_20-H/";
20  //wrkDir="final/zVert50-H/";
21  //wrkDir="final/highPol-H/";
22 
23 
24 //wrkDir="final/swapPatt-H/";
25  // wrkDir="final/shiftPatt-H/";
26  //wrkDir="final/pT1_3-H/";
27 
28  //wrkDir="final/posCharge-H/";
29 
30 
31  gStyle->SetOptStat(1111);
32 
33  createTgr(wrkDir+"endVer1.hist.root");
34 
35  //.................. access TGraphs with averages
36  TString fname=wrkDir+"asyVer1.hist.root";
37  inpH=new TFile(fname);
38  assert(inpH->IsOpen());
39  //inpH->ls();
40 
41  const int mxC2=6, mxC3=3, mxC4=4, mxC5=2;
42  char *cut2L[mxC2]={ "Pt1", "Pt2", "Pt3", "Pt4", "Pt5", "Pt6"};
43  float cut2XM[mxC2]={ 0.7,1.5,2.5,3.5,4.5,5.5};
44  float cut2XH[mxC2]={ 0.3,.5,.5,.5,.5,.5};
45  sortCoef(cut2L, mxC2,"Pt16", cut2XM, cut2XH );
46 
47  char *cut3L[mxC3]={ "PtL", "PtM", "PtH"};
48  float cut3XM[mxC3]={ 0.55, 0.85, 2.};
49  float cut3XH[mxC3]={ 0.15, 0.15, 1.};
50  sortCoef(cut3L, mxC3,"PtLMH", cut3XM, cut3XH );
51 
52  char *cut4L[mxC4]={ "EtaBB", "EtaBc", "EtaFc", "EtaFF" };
53  float cut4XM[mxC4]={ -.75, -.25, .25, .75};
54  float cut4XH[mxC4]={ .25,.25,.25.,.25};
55  // float cut4XM[mxC4]={ -.95, -.25, .25, .95}; // maxEta=1.4
56  //float cut4XH[mxC4]={ .45,.25,.25.,.45}; // maxEta=1.4
57  sortCoef(cut4L, mxC4,"EtaBF", cut4XM, cut4XH );
58 
59  char *cut5L[mxC5]={ "Qneg", "Qpos"};
60  float cut5XM[mxC5]={ -1, 1};
61  float cut5XH[mxC5]={ 0., 0.};
62  sortCoef(cut5L, mxC5,"Qpn", cut5XM, cut5XH );
63 
64  // add for blue & yellow
65  TGraphErrors *gr;
66  gr=appendTG("a1:P*Pt16","-b1:Q*Pt16"); gr->SetName("A_n*Pt16");
67  gr=appendTG("a1:P*PtLMH","-b1:Q*PtLMH");gr->SetName("A_n*PtLMH");
68  gr=appendTG("a1:P*Qpn","-b1:Q*Qpn");gr->SetName("A_n*Qpn");
69  gr=appendTG("a1:P*EtaBF","-b1:Q*EtaBF");gr->SetName("A_n*EtaBF");
70 
71 
72  fetchTG("c0:PQ*Pt16")->SetName("A_s*Pt16");
73  fetchTG("c0:PQ*PtLMH")->SetName("A_s*PtLMH");
74  fetchTG("c0:PQ*Qpn")->SetName("A_s*Qpn");
75  takeModuleEta("c0:PQ*EtaBF","A_s*EtaBF");
76 
77  fetchTG("c2:PQ*Pt16")->SetName("A_d*Pt16");
78  fetchTG("c2:PQ*PtLMH")->SetName("A_d*PtLMH");
79  fetchTG("c2:PQ*Qpn")->SetName("A_d*Qpn");
80  takeModuleEta("c2:PQ*EtaBF","A_d*EtaBF");
81 
82  int pl=3;
83  plotObs("A_n",pl);
84  plotObs("A_s",pl);
85  plotObs("A_d",pl);
86 
87  // save histo+TGraph's
88  outH->cd();
89  int i;
90  for(i=0;i<nGr;i++) {// add TGrpahs only
91  if(outH->Get(grL[i]->GetName())) continue;
92  grL[i]->Write();
93  }
94 
95 
96 
97  // outH->ls();
98  outH->Write();
99 
100  return;
101 }
102 
103 
104 //==========================================
105 //==========================================
106 TGraphErrors * fetchTG(TString name) {
107  // printf("fetch-->'%s'\n",name.Data());
108  TGraphErrors *gr=0;
109  int i;
110  for(i=0;i<nGr && gr==0;i++) {
111  if(!name.Contains(grL[i]->GetName())) continue;
112  gr=grL[i];
113  }
114  assert(gr);
115  return gr;
116 }
117 
118 
119 //==========================================
120 //==========================================
121 void createTgr(TString fname) {
122  outH=new TFile(fname,"RECREATE");
123  assert(outH->IsOpen());
124  printf("save outH -->%s\n", fname.Data());
125 
126  char *ampTit[mxAmp]={"An", "AnYell", "A#Sigma", "A#Delta"};
127  int ampCol[mxAmp]={kBlue, kYellow, kGreen, kMagenta};
128 
129  int ic,iam;
130  for (ic=0;ic<totC;ic++) {
131  for (iam=0;iam<mxAmp;iam++) {
132  char name[100];
133  sprintf(name,"%s*%s",ampL[iam],tCutL[ic]);
134  //printf("ic=%d iam=%d name=%s=\n",ic,iam,name);
135  TGraphErrors *gr =new TGraphErrors;
136  gr->SetName(name);
137  gr->SetTitle(ampTit[iam]);
138  gr->SetMarkerColor(ampCol[iam]);
139  gr->SetMarkerSize(0.8);
140  gr->SetMarkerStyle(21);
141  assert(nGr<mxGr);
142  grL[nGr++]=gr;
143  }
144  }
145 }
146 
147 
148 //==========================================
149 //==========================================
150 TGraphErrors * appendTG(char *basket, char *apple, float eps=0.){
151 
152  TGraphErrors *gr1=fetchTG(basket);
153  TGraphErrors *gr2=fetchTG(apple);
154  int i;
155  for(i=0;i<gr2->GetN();i++) {
156  double erX=gr2->GetErrorX(i);
157  double erY=gr2->GetErrorY(i);
158  double x,y;
159  gr2->GetPoint(i,x,y);
160 
161  int n=gr1->GetN();
162  gr1->SetPoint(n,x+eps,y);
163  gr1->SetPointError(n,erX,erY);
164  }
165  //gr1->Print();
166  return gr1;
167 }
168 
169 //==========================================
170 //==========================================
171 takeModuleEta(char *inp, char *out) {
172  TGraphErrors *gr= (TGraphErrors *)fetchTG(inp)->Clone();
173  gr->SetName(out);
174  int i;
175  // gr->Print();
176  //printf(" do reflection\n");
177  for(i=0;i<gr->GetN();i++) {
178  double x,y;
179  gr->GetPoint(i,x,y);
180  if(x>0) continue;
181  gr->SetPoint(i,-x,y);
182  }
183  // gr->Print();
184 
185  assert(nGr<mxGr);
186  grL[nGr++]=gr;
187 
188 }
189 
190 //==========================================
191 //==========================================
192 void sortCoef(char **cutL, int nC, char *tCut, float *xMean, float *xErr){
193 
194  printf("sortCoef(%s)\n",tCut);
195  int iam=0;
196 
197  for(iam=0;iam<mxAmp;iam++) {
198  TString outG=ampL[iam];
199  outG+="*";
200  outG+=tCut;
201  TGraphErrors * grOut=fetchTG(outG);
202 
203  int ic;
204  for(ic=0;ic<nC;ic++){
205  TString inpG=ampL[iam];
206  inpG+="*";
207  inpG+=cutL[ic];
208  printf("%d '%s' -->%s xM=%f xEr=%f\n",ic,cutL[ic],inpG.Data(),xMean[ic], xErr[ic]);
209  TGraphErrors * gr=(TGraphErrors *)inpH->Get(inpG);
210  assert(gr);
211  TF1 *ff=gr->GetFunction("pol0");
212  if(ff==0) continue; // no fit was made
213  float val=ff->GetParameter(0);
214  float err=ff->GetParError(0);
215  int n=grOut->GetN();
216  float x=xMean[ic];
217  if(strstr(inpG.Data(),"-b1:Q*Eta")) x=-x;
218  grOut->SetPoint(n,x,val);
219  grOut->SetPointError(n,xErr[ic],err);
220  }
221  }
222 }
223 
224 
225 //==========================================
226 //==========================================
227 void plotObs(char *obs="c0:PQ", int flag=0) {
228  printf("plot Obs -->%s\n",obs);
229  char *tCutX[totC]={"pT (GeV/c), 1 GeV/c bins", " pT (GeV/c), rebinned","pseudorapidity", "charge"};
230 
231  c=new TCanvas(obs,obs,600,500);
232  c->Divide(2,2);
233 
234  int it;
235  for (it=0;it<totC;it++) {
236  char name[100];
237  sprintf(name,"%s*%s",obs,tCutL[it]);
238  TGraphErrors * gr=fetchTG(name);
239  int n=gr->GetN();
240  printf("\nit=%d name='%s', N=%d\n",it,name,n);
241  // gr->Print();
242  if(n<=0) continue;
243  c->cd(1+it);
244  gr->Draw("AP");
245  gr->Fit("pol0");
246 
247  TAxis *ax=gr->GetXaxis();
248  ax->SetTitle(tCutX[it]);
249 
250  drawFitError(gr); // draw +/- sigma of the fit
251  c->Update();
252  modifyLabels();
253  c->Update();
254 
255  // draw +/- sigma of the fit
256  TF1 *ff=gr->GetFunction("pol0");
257  assert(ff);
258  TString aaa="avr"; aaa+=name;
259  ff->SetName(aaa);
260 
261  if(strstr(obs,"A_n")) {// draw also yellow An
262  sprintf(name,"%s*%s","-b1:Q",tCutL[it]);
263  TGraphErrors * gr=fetchTG(name);
264  if(gr->GetN()<=0) continue;
265  gr->Draw("P");
266  } else if(strstr(tCutL[it],"EtaBF")) {// draw once more positive eta for A_s & A_d
267  if(strstr(obs,"A_s")) sprintf(name,"c0:PQ*EtaBF");
268  if(strstr(obs,"A_d")) sprintf(name,"c2:PQ*EtaBF");
269  TGraphErrors * gr=fetchTG(name);
270  if(gr->GetN()<=0) continue;
271  gr->Draw("P");
272  gr->SetMarkerColor(kBlack);
273  gr->SetMarkerStyle(25);
274  }
275 
276  // junk
277  float val=ff->GetParameter(0);
278  float err=ff->GetParError(0);
279 
280  float chi2ndf=0;
281  if (ff->GetNDF()>0)
282  chi2ndf=ff->GetChisquare()/ff->GetNDF();
283 
284  float xSig=fabs(val)/err;
285  char cKey='N';
286  if(xSig>2) cKey='Y';
287 
288  printf("## , %s , %s , %f , %f , %f %s\n",
289  tCutL[it], obs, val,err, chi2ndf,ff->GetName());
290  }
291 
292  if(flag<=0) return;
293  TString outFig=wrkDir+obs;
294  if(flag&1) c->Print(outFig+".ps");
295  if(flag&2) c->Print(outFig+".gif");
296 
297 }
298 
299 //==========================================
300 //==========================================
301 void modifyLabels(){
302  TPaveStats *st1 =( TPaveStats *)gPad->GetPrimitive("stats");
303  st1->SetX1NDC(0.4);
304 
305  st1 =( TPaveStats *)gPad->GetPrimitive("title");
306  st1->SetX2NDC(0.2);
307  st1->SetY1NDC(.8);
308 
309 }
310 
311 //==========================================
312 //==========================================
313 void drawFitError( TGraphErrors * gr) {
314 
315  int col=kRed;
316  TF1 *ff=gr->GetFunction("pol0");
317  assert(ff);
318 
319  ff->SetLineColor(col);
320  ff->SetParName(0,"avr");
321 
322  float val=ff->GetParameter(0);
323  float err=ff->GetParError(0);
324  float upY=val+err, dwY=val-err;
325 
326  TAxis *ax=gr->GetXaxis();
327  float x1=ax->GetXmin();
328  float x2=ax->GetXmax();
329 
330  TLine *ln0=new TLine(x1,0.,x2,0.);
331  float xlen=x2-x1;
332  x1+=0.1*xlen;
333  x2-=0.1*xlen;
334  TLine *upL=new TLine(x1,upY,x2,upY);
335  TLine *dwL=new TLine(x1,dwY,x2,dwY);
336  upL->SetLineStyle(3);
337  dwL->SetLineStyle(3);
338 
339  upL->SetLineColor(col);
340  dwL->SetLineColor(col);
341 
342  upL->Draw();
343  dwL->Draw();
344  ln0->Draw();
345 }
346 
347 
348 
349 
350