00001 TFile *outH, *inpH;
00002 const int mxR=3;
00003
00004
00005 doRatio(TString fill="F2201x", TString wrkDir="./") {
00006
00007
00008
00009 gStyle->SetPalette(1,0);
00010 gStyle->SetOptStat(0);
00011
00012 TString fname=wrkDir+"/"+fill+".hist.root";
00013
00014 inpH=new TFile(fname);
00015
00016 if(!inpH->IsOpen()) {
00017 printf(" %s not exits \n",fname.Data());
00018 return;
00019 }
00020 printf(" %s opened \n",fname.Data());
00021
00022
00023
00024
00025 fname.ReplaceAll("F","rF");
00026 outH=new TFile(fname,"recreate");
00027 if(outH->IsZombie()==kTRUE) {
00028 printf("WARN file %s not created\n",fname.Data());
00029 return;
00030 }
00031
00032
00033 double PI=3.141592654;
00034 TF1 *ff;
00035 ff = new TF1("fCos012",Cos012,-PI ,PI,3);
00036 ff->SetParameters(0,0,0); ff->SetParNames("a0","a1","a2");
00037
00038
00039
00040
00041 ff->SetLineColor(kGreen);
00042
00043 char *cut="xxx";
00044 TH1F *hr[mxR];
00045 char *cutL="All Pt1 Pt2 Pt3 Pt4 Pt5 Pt6 PtL PtM PtH EtaBB EtaBc EtaFc EtaFF Qpos Qneg";
00046
00047
00048
00049 char *cut=strtok(cutL," ");
00050
00051 do {
00052 int err=calcRatio(cut,hr);
00053 if(err) continue;
00054 fitRatio(hr);
00055 plotRatio(fill,hr);
00056 } while(cut=strtok(0," "));
00057 outH->Write();
00058 outH->ls();
00059
00060 }
00061
00062
00063
00064
00065 void plotRatio(TString fill1, TH1F **hr){
00066 c=new TCanvas(fill1,fill1);
00067 c->Divide(2,2);
00068 int k;
00069
00070 TLine *ln1=new TLine(-3.14,0.,3.14,0.);
00071
00072 TGraphErrors *gr=new TGraphErrors;
00073
00074 for(k=0;k<mxR;k++) {
00075 c->cd(k+1);
00076 hr[k]-> Draw();
00077 ln1->Draw();
00078
00079 TF1 *ff=hr[k]->GetFunction("fCos012");
00080 int i;
00081 int npar=3;
00082 for(i=0;i<npar;i++) {
00083 double val=ff->GetParameter(i);
00084 double err=ff->GetParError(i);
00085 int n=gr->GetN();
00086 gr->SetPoint(n,i+1+5*k,val);
00087 gr->SetPointError(n,.0,err);
00088 }
00089 }
00090
00091 c->cd(4);
00092 gr->Draw("AP");
00093
00094 gr->SetMarkerSize(1.3);
00095 gr->SetMarkerColor(4);
00096 gr->SetMarkerStyle(21);
00097 gr->SetTitle("Fit params: #2=Ay*P #7=-Ay*Q #11=A#Sigma*P*Q #13=A#Delta*P*Q");
00098
00099 TAxis *ax;
00100 ax=gr->GetXaxis();
00101 float x1=0,x2=15;
00102 ax->SetLimits(x1,x2);
00103 TLine *ln0=new TLine(x1,0.,x2,0.);
00104 ln0->SetLineColor(kBlue);
00105 ln0->Draw();
00106
00107 gr->Print();
00108
00109
00110 }
00111
00112
00113
00114
00115 void fitRatio( TH1F **hr){
00116 c=new TCanvas("aa","aa",50,100);
00117
00118 int k;
00119 for(k=0;k<mxR;k++) {
00120 hr[k]-> Fit("fCos012");
00121 TF1 *ff=hr[k]->GetFunction("fCos012");
00122 assert(ff);
00123 if(k==0) ff->SetParNames("a0","a1","a2");
00124 if(k==1) ff->SetParNames("b0","b1","b2");
00125 if(k==2) ff->SetParNames("c0","c1","c2");
00126 }
00127 }
00128
00129
00130
00131
00132 int calcRatio( char *cut, TH1F **hr){
00133 int minContent=4;
00134 printf("doRatio for cut='%s'\n",cut);
00135
00136 const int mxPol=4;
00137 char *cpolBY[mxPol]={"B+Y+","B+Y-","B-Y+","B-Y-"};
00138
00139 TH1F * h[mxPol];
00140
00141
00142 int k;
00143 double sum1=0;
00144 double min=10000;
00145 for(k=0;k<mxPol;k++) {
00146 char name[100];
00147 sprintf(name,"Phi%2s%s",cpolBY[k],cut);
00148 h[k]=(TH1F *)inpH->Get(name);
00149 assert(h[k]);
00150 sum1+=h[k]->Integral();
00151 printf("%s int=%f min=%f\n",name,h[k]->Integral(),h[k]->GetMinimum());
00152 if(h[k]->GetMinimum()<minContent) return -1;
00153 }
00154
00155 TAxis *phiAx=h[0]->GetXaxis();
00156
00157
00158 outH->cd();
00159 int k;
00160
00161 for(k=0;k<mxR;k++) {
00162 char name[100];
00163 sprintf(name,"r%d*%s",k+1,cut);
00164 char tit2[100]={"aaa bbb"};
00165 sprintf(tit2,"R%d(#phi), LCP cut=%s, Neve=%.0f",k+1,cut,sum1);
00166 hr[k]=new TH1F(name,tit2,phiAx->GetNbins(),phiAx->GetXmin(), phiAx->GetXmax());
00167 hr[k]->Sumw2();
00168 }
00169
00170
00171 double sum=0;
00172 int iph;
00173 for(iph=1;iph<=phiAx->GetNbins();iph++) {
00174 float m[mxPol], v[mxPol];
00175
00176
00177 for(k=0;k<mxPol;k++){
00178 m[k]=h[k]->GetBinContent(iph);
00179 v[k]=h[k]->GetBinError(iph);
00180 v[k]*=v[k];
00181 }
00182
00183 for(int ir=0;ir<mxR;ir++) {
00184 TH1F * h3=hr[ir];
00185 assert(h3);
00186 double s,s1,s2,r=900.,vs1,vs2;
00187 switch(ir) {
00188 case 0:
00189 s1 =m[0]+m[2]; s2=m[1]+m[3];
00190 vs1=v[0]+v[2]; vs2=v[1]+v[3];
00191 break;
00192 case 1:
00193 s1 =m[0]+m[1]; s2=m[2]+m[3];
00194 vs1=v[0]+v[1]; vs2=v[2]+v[3];
00195 break;
00196 case 2:
00197 s1 =m[0]+m[3]; s2=m[1]+m[2];
00198 vs1=v[0]+v[3]; vs2=v[1]+v[2];
00199 break;
00200 default:
00201 printf("wrong ir=%d\n",ir); assert(1==2);
00202 }
00203
00204 s=s1+s2;
00205 if(s1<=0 || s2<=0) {
00206 printf("iph=%d s1=%f s2=%f s=%f \n",iph,s1,s2,s);
00207 assert(2==3);
00208 }
00209
00210 r=(s1-s2)/s;
00211
00212 double vr = 4*( s2*s2*vs1 + s1*s1*vs2 )/s/s/s/s;
00213
00214 h3->SetBinContent(iph,r);
00215 h3->SetBinError(iph,sqrt(vr));
00216 if(ir==0) sum+=s;
00217 }
00218 }
00219
00220 printf("sum=%f sum1=%f r=%f\n",sum,sum1,sum/sum1);
00221
00222 return 0;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 Double_t Cos012(Double_t *x, Double_t *par)
00236 {
00237 float PI=3.141592654;
00238
00239 Float_t phi =x[0];
00240 Float_t A0=par[0];
00241 Float_t A1=par[1];
00242 Float_t A2=par[2];
00243 Float_t phi0=0;
00244
00245 Double_t f =A0 +A1*cos(phi-phi0) + A2*cos(2*(phi-phi0));
00246 return f;
00247 }
00248
00249