00001 TFile *outH;
00002 const int mxR=3;
00003 const int mxC=16;
00004 char *cutL[mxC]={"All", "Pt1", "Pt2", "Pt3", "Pt4", "Pt5", "Pt6", "PtL", "PtM", "PtH", "EtaBB", "EtaBc", "EtaFc", "EtaFF", "Qpos", "Qneg"};
00005
00006 const int mxAmp=9;
00007 char *ampL[mxAmp]={"a1:P", "-b1:Q", "c0:PQ", "c2:PQ", "a0", "a2", "b0", "b2", "c1"};
00008
00009 const int mxGr=200;
00010 TGraphErrors * grL[mxGr];
00011 int nGr=0;
00012
00013
00014 float minPol=0.07;
00015 float minPol2=0.01;
00016
00017
00018 addFills( TString outPath="defaultB-H/") {
00019 TString inpDir="/star/data04/sim/balewski/LcpRun2/maxEta1.0/";
00020
00021 char *fillL=" F2258 F2266 F2161 ";
00022
00023
00024 fillL=" F2053 F2075 F2076 F2083 F2095 F2102 F2105 F2110 F2116 F2127 F2132 F2134 F2135 F2136 F2147 F2153 F2161 F2162 F2175 F2178 F2181 F2185 F2187 F2192 F2193 F2196 F2201 F2207 F2208 F2212 F2216 F2222 F2235 F2246 F2251 F2257 F2258 F2266 F2269 F2275 F2277 F2281 F2289 F2290 F2301 F2303 F2304";
00025
00026 gStyle->SetPalette(1,0);
00027 gStyle->SetOptStat(1111);
00028 gROOT->LoadMacro("getPol.C");
00029
00030 createHistTgr("final/"+outPath+"asyVer1.hist.root");
00031
00032 char *fill=strtok(fillL," ");
00033 int nFill=0;
00034 do {
00035
00036 TString fname=inpDir+outPath+"r"+fill+".hist.root";
00037 TFile * inpH=new TFile(fname);
00038 assert(inpH->IsOpen());
00039 if(!inpH->IsOpen()) {
00040 printf("#fail %s does not open, skip\n",fname.Data());
00041 continue;
00042 }
00043
00044 nFill++;
00045
00046 int xFill=atoi(fill+1);
00047 assert(xFill);
00048 sortCoef(inpH,xFill);
00049
00050 }while(fill=strtok(0," "));
00051
00052
00053
00054
00055 int icut;
00056 for(icut=0;icut<mxC;icut++) {
00057 char *cut=cutL[icut];
00058 plotTG(cut,3,"final/"+outPath);
00059 }
00060
00061
00062 outH->cd();
00063 int i;
00064 for(i=0;i<nGr;i++) {
00065 if(outH->Get(grL[i]->GetName())) continue;
00066 grL[i]->Write();
00067 }
00068
00069
00070 outH->Write();
00071 return;
00072 }
00073
00074
00075
00076
00077 TGraphErrors * fetchTG(TString name) {
00078
00079 TGraphErrors *gr=0;
00080 int i;
00081 for(i=0;i<nGr && gr==0;i++) {
00082 if(!name.Contains(grL[i]->GetName())) continue;
00083 gr=grL[i];
00084 }
00085 assert(gr);
00086 return gr;
00087 }
00088
00089
00090
00091
00092 void sortCoef(TFile *inp, int xFill){
00093 assert(inp->IsOpen());
00094
00095 float P,Q,eP,eQ;
00096 getPol(xFill,P,Q,eP,eQ);
00097 float PQ, ePQ;
00098 PQ=P*Q;
00099 ePQ=PQ*sqrt(eP*eP/P/P +eQ*eQ/Q/Q);
00100
00101
00102 int cLum=true, cP=true, cQ=true,cPQ=true;
00103 if(xFill<2189) cLum=false;
00104 if(P<minPol) cP=false;
00105 if(Q<minPol) cQ=false;
00106 if(PQ<minPol2) cPQ=false;
00107 printf(" logic cL=%d cP=%d cQ=%d cPQ=%d\n",cLum,cP,cQ,cPQ);
00108
00109
00110 int icut;
00111 for(icut=0;icut<mxC;icut++) {
00112
00113 char *cut=cutL[icut];
00114
00115 TH1F * h[mxR];
00116 int k;
00117 for(k=0;k<mxR;k++) {
00118 char name[100];
00119 sprintf(name,"r%d*%s",k+1,cut);
00120
00121 h[k]=(TH1F *)inp->Get(name);
00122
00123 }
00124
00125
00126 int ir;
00127 for(ir=0;ir<mxR;ir++) {
00128 if( h[ir]==0) continue;
00129 TF1 *ff=h[ir]->GetFunction("fCos012");
00130 assert(ff);
00131
00132 const int mxPar=3;
00133 int ip;
00134 for(ip=0;ip<mxPar;ip++) {
00135 TString grName;
00136 float pol=1, ePol=0;
00137
00138
00139
00140 if(ir==0 && ip==0 ) { grName="a0";
00141 } else if (ir==0 && ip==1 && cP ) { grName="a1:P";
00142 pol=P;
00143 ePol=eP;
00144 } else if (ir==0 && ip==2 ) { grName="a2";
00145 } else if (ir==1 && ip==0 ) { grName="b0";
00146 } else if (ir==1 && ip==1 && cQ ) { grName="-b1:Q";
00147 pol=-Q;
00148 ePol=eQ;
00149 } else if (ir==1 && ip==2 ) { grName="b2";
00150 } else if (ir==2 && ip==0 && cPQ && cLum) { grName="c0:PQ";
00151 pol=PQ;
00152 ePol=ePQ;
00153 } else if (ir==2 && ip==1 ) { grName="c1";
00154 } else if (ir==2 && ip==2 & cPQ ) { grName="c2:PQ";
00155 pol=PQ;
00156 ePol=ePQ;
00157 } else {
00158 continue;
00159 }
00160
00161
00162 grName+="*";
00163 grName+=cut;
00164 TGraphErrors * gr=fetchTG(grName);
00165
00166 double val=ff->GetParameter(ip);
00167 double err=ff->GetParError(ip);
00168 storeVal(gr,xFill, val,err,pol,ePol);
00169
00170 }
00171
00172
00173 double chi2=ff->GetChisquare();
00174 double ndf=ff->GetNDF();
00175
00176 char name[100];
00177 sprintf(name,"chi2R%d*%s",ir+1,cut);
00178 TH1F *ho=(TH1F*)fetchTG(name);
00179 assert(ho);
00180 ho->Fill(chi2/ndf);
00181 }
00182 }
00183
00184 }
00185
00186
00187
00188
00189 void createHistTgr(TString fname) {
00190 outH=new TFile(fname,"RECREATE");
00191 assert(outH->IsOpen());
00192 printf("save outH -->%s\n", fname.Data());
00193
00194
00195
00196 char *ampTit[mxAmp]={"An, ~ cos(#phi), Blue","An, ~ cos(#phi), Yellow","A#Sigma, no #phi ","A#Delta, ~ cos(2#phi)",
00197 "a0 -instrumental", "a2 -instrumental",
00198 "b0 -instrumental", "b2 -instrumental",
00199 "c1 -instrumental"};
00200
00201 int ampCol[mxAmp]={kBlue,kYellow,kGreen,kMagenta,kBlack,
00202 kBlack,kBlack,kBlack,kBlack};
00203 int ic,iam=0;
00204 for (ic=0;ic<mxC;ic++) {
00205 for (iam=0;iam<mxAmp;iam++) {
00206 char name[100];
00207 sprintf(name,"%s*%s",ampL[iam],cutL[ic]);
00208
00209 TGraphErrors *gr =new TGraphErrors;
00210 gr->SetName(name);
00211 gr->SetTitle(ampTit[iam]);
00212 gr->SetMarkerColor(ampCol[iam]);
00213 gr->SetMarkerSize(0.8);
00214 gr->SetMarkerStyle(21);
00215 assert(nGr<mxGr);
00216 grL[nGr++]=gr;
00217 }
00218 int ir=0;
00219 for(ir=0;ir<mxR;ir++) {
00220 char name[100], tit[200];
00221 sprintf(name,"chi2R%d*%s",ir+1,cutL[ic]);
00222 sprintf(tit,"chi2 for R%d(#Phi), LCP cut=%s",ir+1,cutL[ic]);
00223
00224 TH1F *h=new TH1F(name, tit,20,0,4);
00225 assert(nGr<mxGr);
00226 grL[nGr++]=(TGraphErrors*)h;
00227 }
00228 }
00229
00230 }
00231
00232
00233
00234 void plotTG(char *cut, int flag=0, TString plotDir="./") {
00235 printf("plot cut -->%s\n",cut);
00236
00237 c=new TCanvas(cut,cut,900,700);
00238 c->Divide(4,3);
00239 int ampPan[mxAmp]={2,6,9,11,1,3,5,7,10};
00240 int chi2Pan[mxR]={4,8,12};
00241
00242 int iam=0;
00243 for (iam=0;iam<mxAmp;iam++) {
00244 char name[100];
00245 sprintf(name,"%s*%s",ampL[iam],cut);
00246 TGraphErrors * gr=fetchTG(name);
00247 int n=gr->GetN();
00248 printf("\niam=%d name='%s', N=%d\n",iam,name,n);
00249
00250 if(n<=0) continue;
00251 c->cd(ampPan[iam]);
00252 gr->Draw("AP");
00253 gr->Fit("pol0");
00254
00255
00256 TF1 *ff=gr->GetFunction("pol0");
00257 assert(ff);
00258 float val=ff->GetParameter(0);
00259 float err=ff->GetParError(0);
00260
00261 float chi2ndf=0;
00262 if (ff->GetNDF()>0)
00263 chi2ndf=ff->GetChisquare()/ff->GetNDF();
00264
00265 drawFitError(gr);
00266 c->Update();
00267 modifyLabels();
00268
00269 float xSig=fabs(val)/err;
00270 char cKey='N';
00271 if(xSig>2) cKey='Y';
00272
00273 printf("#ampl= %s , cut= %s , nFill= %d , <y>= %f , sig<y>= %f , xSig= %.1f , nonZero= %c\n",
00274 ampL[iam], cut,gr->GetN(), val,err, xSig,cKey);
00275 printf("## , %s , %s , %f , %f , %f\n",
00276 ampL[iam], cut, val,err, chi2ndf);
00277 }
00278
00279 int ir=0;
00280 for(ir=0;ir<mxR;ir++) {
00281 char name[100];
00282 sprintf(name,"chi2R%d*%s",ir+1,cut);
00283 TH1F *ho=(TH1F*)fetchTG(name);
00284 assert(ho);
00285 c->cd(chi2Pan[ir]);
00286 ho->Draw();
00287 printf("%s nE=%d\n",ho->GetName(),ho->GetEntries());
00288 c->Update();
00289 modifyLabels();
00290 }
00291
00292 if(flag<=0) return;
00293 TString outFig=plotDir+"asy";
00294 outFig+=cut;
00295 if(flag&1) c->Print(outFig+".ps");
00296 if(flag&2) c->Print(outFig+".gif");
00297
00298
00299 }
00300
00301
00302
00303
00304 void storeVal(TGraphErrors *gr, float x, float y,float ey,float fac, float efac=0){
00305 assert(gr);
00306
00307 int n=gr->GetN();
00308 double val=y/fac;
00309
00310 double e1=ey/y;
00311 double e2=efac/fac;
00312 double err=fabs(val)*sqrt(e1*e1+e2*e2);
00313
00314 gr->SetPoint(n,x,val);
00315 gr->SetPointError(n,.0,err);
00316
00317
00318 }
00319
00320
00321
00322
00323 void nicePlot(){
00324
00325 c=new TCanvas();
00326
00327 TGraphErrors * gr=fetchTG("a1:P*All");
00328
00329 int n=gr->GetN();
00330 printf("\n name='%s', N=%d\n",gr->GetName(),n);
00331 assert(n>0);
00332
00333 gr->Draw("AP");
00334 gr->Fit("pol0");
00335
00336 drawFitError(gr);
00337
00338 return;
00339 c->Update();
00340 TPaveStats *st1 =( TPaveStats *)gPad->GetPrimitive("stats");
00341 st1->SetX1NDC(0.4);
00342 st1->SetX2NDC(1.);
00343 st1->SetY1NDC(.7);
00344 st1 =( TPaveStats *)gPad->GetPrimitive("title");
00345 st1->SetX2NDC(.4);
00346 st1->SetY1NDC(.8);
00347 c->Update();
00348
00349 }
00350
00351
00352
00353
00354 void drawFitError( TGraphErrors * gr) {
00355 int col=kRed;
00356 TF1 *ff=gr->GetFunction("pol0");
00357 assert(ff);
00358
00359 ff->SetLineColor(col);
00360 ff->SetParName(0,"avr");
00361
00362 float val=ff->GetParameter(0);
00363 float err=ff->GetParError(0);
00364 float upY=val+err, dwY=val-err;
00365
00366 TAxis *ax=gr->GetXaxis();
00367 float x1=ax->GetXmin();
00368 float x2=ax->GetXmax();
00369 ax->SetTitle("RHIC FILL \#");
00370
00371
00372 TLine *ln0=new TLine(x1,0.,x2,0.);
00373 x1+=2;
00374 x2-=2;
00375 TLine *upL=new TLine(x1,upY,x2,upY);
00376 TLine *dwL=new TLine(x1,dwY,x2,dwY);
00377 upL->SetLineStyle(3);
00378 dwL->SetLineStyle(3);
00379
00380 upL->SetLineColor(col);
00381 dwL->SetLineColor(col);
00382
00383 upL->Draw();
00384 dwL->Draw();
00385 ln0->Draw();
00386
00387 float xSig=fabs(val)/err;
00388 char cKey='N';
00389 if(xSig>2) cKey='Y';
00390 printf(" nData= %d , <y>= %f , sig<y>= %f , xSig= %.1f , nonZero= %c\n",
00391 gr->GetN(), val,err, xSig,cKey);
00392
00393 }
00394
00395
00396
00397
00398
00399 void modifyLabels(){
00400 TPaveStats *st1 =( TPaveStats *)gPad->GetPrimitive("stats");
00401 st1->SetX1NDC(0.3);
00402 st1->SetX2NDC(1.);
00403 st1->SetY1NDC(.8);
00404 return;
00405 st1 =( TPaveStats *)gPad->GetPrimitive("title");
00406 st1->SetX1NDC(.6);
00407 st1->SetX2NDC(1.0);
00408 st1->SetY1NDC(.1);
00409 st1->SetY1NDC(.3);
00410
00411
00412 }
00413
00414
00415