00001
00002 void plCalcZeffic(char* iPath="/star/u/stevens4/wAnalysis/efficXsec/outEmb/gainUp2/"){
00003
00004 system("mkdir -p plots/");
00005
00006 char* core0;
00007 core0="Ze+e-Interf";
00008
00009
00010
00011 gStyle->SetPalette(1);
00012
00013
00014 TString fullInpName=iPath; fullInpName+=core0;
00015 fullInpName+=".wana.hist.root";
00016 fd=new TFile(fullInpName);
00017 if(!fd->IsOpen()) {
00018 printf("ERROR: input histo file not found, quit\n",fullInpName.Data());
00019 return;
00020 } else {
00021 printf("Opened: %s\n",fullInpName.Data());
00022 }
00023
00024
00025 int massRebin=4;
00026 int zdcRebin=5;
00027
00028
00029 float massPlot[5]={1.0,1.0,1.0,1.0,1.0};
00030 float massPlotErr[5]={1.0,1.0,1.0,1.0,1.0};
00031
00032
00033 TH1F *hTrigMass=doEfficiency(fd,"MCzMassAll","MCzMassTrig",Form("Z trigger efficiency"),massRebin,massPlot[0],massPlotErr[0]);
00034 TH1F *hTrigZDC=doEfficiency(fd,"MCzZdcAll","MCzZdcTrig",Form("Z trigger efficiency"),zdcRebin,0);
00035
00036 TH1F *hVertMass=doEfficiency(fd,"MCzMassTrig","MCzMassVert",Form("Z vertex efficiency"),massRebin,massPlot[1],massPlotErr[1]);
00037 TH1F *hVertZDC=doEfficiency(fd,"MCzZdcTrig","MCzZdcVert",Form("Z vertex efficiency"),zdcRebin,0);
00038
00039 TH1F *hTrackMass=doEfficiency(fd,"MCzMassVert","MCzMassTrack",Form("Z tracking efficiency"),massRebin,massPlot[2],massPlotErr[2]);
00040 TH1F *hTrackZDC=doEfficiency(fd,"MCzZdcVert","MCzZdcTrack",Form("Z tracking efficiency"),zdcRebin,0);
00041
00042 TH1F *hRecoMass=doEfficiency(fd,"MCzMassTrack","MCzMassReco",Form("Z algo efficiency"),massRebin,massPlot[3],massPlotErr[3]);
00043 TH1F *hRecoZDC=doEfficiency(fd,"MCzZdcTrack","MCzZdcReco",Form("Z algo efficiency"),zdcRebin,0);
00044
00045
00046 TH1F *hTotMass=doEfficiency(fd,"MCzMassAll","MCzMassReco",Form("Z total efficiency"),massRebin,massPlot[4],massPlotErr[4]);
00047 cout<<"Total Efficiency = "<<massPlot[4]<<" $\\pm$ "<<massPlotErr[4]<<endl;
00048 TH1F *hTotZDC=doEfficiency(fd,"MCzZdcAll","MCzZdcReco",Form("Z total efficiency"),zdcRebin,0);
00049 hTotZDC->Draw();
00050
00051
00052 cV=new TCanvas(Form("Z vertex and trig effic"),"vertex and effic",800,600);
00053 cV->Divide(2,2);
00054 cV->cd(3);
00055 hVertMass->Draw();
00056 cV->cd(4);
00057 hVertZDC->Draw();
00058 cV->cd(1);
00059 hTrigMass->Draw();
00060 cV->cd(2);
00061 hTrigZDC->Draw();
00062 cV->Print("plots/ZVert-TrigEffic.eps");
00063 cV->Print("plots/ZVert-TrigEffic.png");
00064
00065
00066 cA=new TCanvas(Form("Z algo and track effic"),"algo and track effic",800,600);
00067 cA->Divide(2,2);
00068 cA->cd(3);
00069 hRecoMass->Draw();
00070 cA->cd(4);
00071 hRecoZDC->Draw();
00072 cA->cd(1);
00073 hTrackMass->Draw();
00074 cA->cd(2);
00075 hTrackZDC->Draw();
00076 cA->Print("plots/ZAlgo-TrkEffic.eps");
00077 cA->Print("plots/ZAlgo-TrkEffic.png");
00078
00079 return;
00080 }
00081
00082
00083 TH1F* doEfficiency(TFile *fd,char* name0, char* name1, char *tit, int reb=1, float &etplot, float &etplotErr=0){
00084
00085 TH1F * h0=(TH1F * )fd->Get(name0); assert(h0);
00086 TH1F * h1=(TH1F * )fd->Get(name1); assert(h1);
00087
00088 ha=(TH1F*) h0->Clone(); assert(ha);
00089 hb=(TH1F*) h1->Clone(); assert(hb);
00090
00091 ha->Rebin(reb);
00092 hb->Rebin(reb);
00093
00094 hc=(TH1F*) hb->Clone(); assert(hc);
00095 hc->SetTitle(tit);
00096 hc->Reset();
00097
00098 float num=0; float den=0;
00099 float matchErr2=0; float thrownErr2=0;
00100 int nb=hb->GetNbinsX();
00101 int startBin=hb->GetXaxis()->FindBin(70.);
00102 int endBin=hb->GetXaxis()->FindBin(109.9);
00103
00104
00105 assert(nb==ha->GetNbinsX());
00106 for(int i=1; i<=nb; i++) {
00107 float n0=ha->GetBinContent(i);
00108 float n1=hb->GetBinContent(i);
00109 float e0=ha->GetBinError(i);
00110 float e1=hb->GetBinError(i);
00111 if(n0==0) continue;
00112 float eff=(float) n1/n0;
00113
00114
00115
00116
00117
00118
00119 float errEff=0;
00120
00121 if(n1==n0) {
00122
00123 errEff=1./n0;
00124 }
00125 else errEff=sqrt(e1*e1*(n0-n1)*(n0-n1)+(e0-e1)*(e0-e1)*n1*n1)/n0/n0;
00126
00127
00128 hc->SetBinContent(i,eff);
00129 hc->SetBinError(i,errEff);
00130 if(i>=startBin && i<=endBin){
00131 num+=n1;
00132 den+=n0;
00133 matchErr2+=e1*e1;
00134 thrownErr2+=e0*e0;
00135 }
00136
00137 }
00138
00139 if(etplot==1.0){
00140
00141
00142
00143
00144 cout<<name1<<"="<< num/den <<" $\\pm$ "<< sqrt(matchErr2*(den-num)*(den-num) + (thrownErr2-matchErr2)*num*num)/den/den <<endl;
00145 etplot=num/den;
00146 etplotErr=sqrt(matchErr2*(den-num)*(den-num) + (thrownErr2-matchErr2)*num*num)/den/den;
00147 }
00148 hc->SetMinimum(0.0);
00149 hc->SetMaximum(1.2);
00150
00151 return hc;
00152 }