00001
00002
00003
00004
00005
00006
00007 const int mx=4;
00008 const int mt=1;
00009 TFile *fd[mx];
00010 TCanvas *c1=0;
00011 FILE* fout=fopen("yield.txt","w");assert(fout);
00012 FILE* fmass=fopen("mass.txt","w");assert(fout);
00013 TF1* f1[7];
00014
00015 FitPt2Mass(){
00016 fprintf(fout,"ss pt_mean totpi realpi background\n");
00017 float fptmin[7]={4.0,5.0,6.0,7.0,8.0,9.0,10.0};
00018 float fptmax[7]={5.0,6.0,7.0,8.0,9.0,10.0,25.0};
00019 float ffit_x1[7]={0.03,0.03,0.03,0.05,0.05,0.05,0.07};
00020 float ffit_x2=0.4;
00021 float fpar0[7]={8.0,7.8,7.2,6.4,5.6,4.9,4.9};
00022 float fpar1[7]={-8.33,-6.82,-5.15,-4.14,-3.52,-3.0,-2.9};
00023 float fpar2[7]={3000,3000,2000,1000,500,400,400};
00024 float fpar3[7]={0.1308,0.1356,0.136,0.137,0.138,0.1375,0.1385};
00025 float fpar4[7]={0.0208,0.02166,0.0231,0.025,0.027,0.027,0.029};
00026 f1[0]=new TF1("ffit","exp([0]-8.262*x)+[1]*exp(-0.5*((x-0.1305)/(0.02073*(1.+6.11*(x-0.1305))))**2)",ffit_x1[0],ffit_x2);
00027 f1[1]=new TF1("ffit","exp([0]-6.752*x)+[1]*exp(-0.5*((x-0.1353)/(0.02164*(1.+6.11*(x-0.1353))))**2)",ffit_x1[1],ffit_x2);
00028 f1[2]=new TF1("ffit","exp([0]-5.095*x)+[1]*exp(-0.5*((x-0.1359)/(0.02307*(1.+6.11*(x-0.1359))))**2)",ffit_x1[2],ffit_x2);
00029 f1[3]=new TF1("ffit","exp([0]-4.041*x)+[1]*exp(-0.5*((x-0.1375)/(0.02498*(1.+6.11*(x-0.1375))))**2)",ffit_x1[3],ffit_x2);
00030 f1[4]=new TF1("ffit","exp([0]-3.37*x)+[1]*exp(-0.5*((x-0.1374)/(0.02666*(1.+6.11*(x-0.1374))))**2)",ffit_x1[4],ffit_x2);
00031 f1[5]=new TF1("ffit","exp([0]-2.942*x)+[1]*exp(-0.5*((x-0.137)/(0.0266*(1.+6.11*(x-0.137))))**2)",ffit_x1[5],ffit_x2);
00032 f1[6]=new TF1("ffit","exp([0]-2.668*x)+[1]*exp(-0.5*((x-0.1392)/(0.02792*(1.+6.11*(x-0.1392))))**2)",ffit_x1[6],ffit_x2);
00033 for(int i=0;i<7;i++){
00034 if(i<3){
00035 const int fnend=int(ffit_x1[i]*100)+1;
00036 }
00037 else{
00038 const int fnend=int(ffit_x1[i]*100);
00039 }
00040 const int fnstart=int(ffit_x2*100);
00041 cout<<"i="<<i<<" nend="<<fnend<<" nstart="<<fnstart<<endl;
00042
00043 FitPtMass(i, fptmin[i], fptmax[i], ffit_x1[i], ffit_x2, fpar0[i], fpar1[i], fpar2[i], fnend, fnstart);
00044 }
00045 }
00046
00047 void FitPtMass(int key, float ptmin, float ptmax, float fit_x1, float fit_x2, float par0, float par1, float par2, int nend, int nstart) {
00048
00049 int Realpi=0,backpi=0,totpi=0;
00050
00051
00052
00053
00054
00055
00056 char *PlotName[mx]={"hMassPtUU","hMassPtUD","hMassPtDU","hMassPtDD"};
00057 char *fName[mt]={"allfill.hist"};
00058 TString inPath="";
00059
00060 gStyle->SetPalette(1,0);
00061 int i;
00062 for(i=0;i<mt;i++) {
00063 TString hFile=inPath+fName[i];
00064 hFile+=".root";
00065 fd0=new TFile(hFile); assert(fd0->IsOpen());
00066 fd[i]=fd0;
00067 }
00068
00069 int channel_yield[mx][40];
00070 int channel_pi_yield[mx][40];
00071 int channel_bg_yield[mx][40];
00072 for(int cmx=0;cmx<mx;cmx++)
00073 {
00074 for(int i=0;i<40;i++)
00075 {
00076 channel_yield[cmx][i]=0;
00077 channel_pi_yield[cmx][i]=0;
00078 channel_bg_yield[cmx][i]=0;
00079 }
00080 }
00081 for(int ploti=0;ploti<mx;ploti++)
00082 {
00083 if(c1) delete c1;
00084 c1=new TCanvas("c1","c1",500,500);
00085 c1->Divide(1,1);
00086 c1->cd(1);
00087
00088
00089 int minbin,maxbin;
00090 TH1F* h1= new TH1F("hMassAny","diphoton invariant mass",120,0.,1.2 );
00091 TH1F* h2= new TH1F("hMassAny","diphoton invariant mass",120,0.,1.2 );
00092 TH1F* hResidual= new TH1F("hMassAny","diphoton invariant mass",120,0.,1.2 );
00093 TString hname=PlotName[ploti];
00094 printf("i= %d =%s=\n",ploti,hname.Data());
00095 h0=(TH2F*)fd[0]->Get(hname); assert(h0);
00096 minbin=h0->GetYaxis()->FindBin(ptmin);
00097 maxbin=h0->GetYaxis()->FindBin(ptmax)-1;
00098 h1->Add(h0->ProjectionX("htemp",minbin,maxbin,""));
00099 int ent=h1->Integral();
00100 cout<<"entry="<<ent<<endl;
00101 h1->SetEntries(ent);
00102 int ccount=0;
00103 float sum=0;
00104 float tpt=ptmin;
00105 for(int i=minbin;i<=maxbin;i++){
00106 ccount+=h0->ProjectionX("",i,i,"")->Integral();
00107 sum+=(h0->ProjectionX("",i,i,"")->Integral())*tpt;
00108 tpt+=(ptmax-ptmin)/(maxbin+1-minbin);
00109 }
00110 float ptmean=sum/ccount;
00111 cout<<"raw="<<int(h1->Integral(11,19))<<" ptmean="<<ptmean<<endl;
00112 h1->Draw();
00113 h1->SetMinimum(-ent/100);
00114
00115 f1[key]->SetParameters(par0,par2);
00116 h1->Fit(f1[key],"R+","",fit_x1,fit_x2);
00117 int nx=h1->GetNbinsX();
00118 cout<<"nx="<<nx<<endl;
00119 float sumx=0,sum2;
00120 for(int ix=1;ix<=40;ix++)
00121 {
00122 channel_yield[ploti][ix-1]+=h1->GetBinContent(ix);
00123
00124 sumx+=h1->GetBinContent(ix);
00125 }
00126
00127 TF1* f2=new TF1("fit2","expo",0.,1.2);
00128
00129 h2->Add(h1);
00130 hResidual->Add(h1);
00131 hResidual->Add(f1[key],-1);
00132 for (int ix= 1; ix <= nend; ix++) {
00133 hResidual->SetBinContent(ix, 0);
00134 }
00135 for (int ix= nstart; ix <= nx; ix++) {
00136 hResidual->SetBinContent(ix, 0);
00137 }
00138 hResidual->SetLineColor(11);
00139 hResidual->Draw("same");
00140 f2->SetParameters(f1[key]->GetParameter(0),par1);
00141 h2->Add(f2,-1);
00142 for (int ix= 1; ix <= 8; ix++) {
00143
00144 h2->SetBinContent(ix, 0);
00145 }
00146
00147
00148
00149 h2->SetLineColor(kBlue);
00150 TF1* f3=new TF1("f3","expo(0)",fit_x1,fit_x2);
00151 f3->SetParameters(f1[key]->GetParameter(0),par1);
00152 cout<<"p0="<<f1[key]->GetParameter(0)<<endl;
00153
00154 Realpi=h2->Integral(11,19);
00155 backpi=h1->Integral(11,19)-h2->Integral(11,19);
00156 totpi=h1->Integral(11,19);
00157
00158 for(int ix=1;ix<=40;ix++)
00159 {
00160 channel_pi_yield[ploti][ix-1]+=h2->Integral(ix,ix);
00161
00162 channel_bg_yield[ploti][ix-1]+=h1->Integral(ix,ix)-h2->Integral(ix,ix);
00163
00164 }
00165
00166 cout<<"total pi="<<totpi<<" Real Pi0 integral="<<Realpi<<" backpi="<<backpi<<endl;
00167
00168 fprintf(fout,"%d %6f %d %d %d\n",ploti,ptmean,totpi,Realpi,backpi);
00169 h2->Draw("same");
00170 f3->SetLineColor(6);
00171 f3->Draw("same");
00172
00173 l1=new TLine(0.135,0.,0.135,7000);
00174 l1->SetLineColor(kRed);
00175 l1->Draw();
00176 l2=new TLine(0.18,0.,0.18,7000);
00177 l2->SetLineColor(kGreen);
00178 l2->Draw();
00179 l3=new TLine(0.1,0.,0.1,7000);
00180 l3->SetLineColor(kGreen);
00181 l3->Draw();
00182
00183 TString hMassAny="mass";
00184 hMassAny+=key;
00185 hMassAny+=ploti;
00186 c1->Print(hMassAny+".gif");
00187
00188 }
00189 if(key==5)
00190 {
00191 for(int j=0;j<40;j++)
00192 {
00193 int ySame=channel_yield[0][j]+channel_yield[3][j];
00194 int yAnti=channel_yield[1][j]+channel_yield[2][j];
00195 float ypi=channel_pi_yield[0][j]+channel_pi_yield[1][j]+channel_pi_yield[2][j]+channel_pi_yield[3][j];
00196 if(ypi<0.0) ypi=0.0;
00197 float ybg=channel_bg_yield[0][j]+channel_bg_yield[1][j]+channel_bg_yield[2][j]+channel_bg_yield[3][j];
00198 float ratio=0.0;
00199 if(ybg==0)
00200 {
00201 ratio=0;
00202 }
00203 else{
00204 ratio=ypi/ybg;
00205 }
00206 fprintf(fmass,"%d %d %d %f\n",j+1,ySame,yAnti,ratio);
00207 }
00208 }
00209 return;
00210
00211 }
00212