scanEff( char *conf="D") { // const int mxH=10; // TH1F *hEff[mxH]; int nh=0; gStyle->SetPalette(1,0); TString inpP="out"; inpP+=conf;inpP+="/"; TString outF="scan";outF+=conf; outF+=".hist.root"; hf=new TFile(outF,"recreate"); printf("\n Histo saved -->%s<\n",outF.Data()); c=new TCanvas("aa","aa",600,600); c->Divide(2,2); char *core="elePt"; char *zver="Zm30"; int jpt; int jz; int tq=1; for(tq=0;tq<2;tq++ ) for(jz=0;jz<3;jz++ ) { TH2F *h2d=0; if(jz==0) zver="Zm30"; if(jz==1) zver="Z0"; if(jz==2) zver="Zp30"; for(jpt=1;jpt<=10 ;jpt++) { int PT=5*jpt; char name[100]; sprintf(name,"%s%d%s",core,PT,zver); printf("name=%s=\n",name); fd=new TFile(inpP+name+".hist.root"); TH1F *h=doEff(fd,nh,tq); assert(h); //c->cd(nh+1); h->Draw(); TString tit=h->GetTitle(); tit=" "+tit; tit=name+tit; h->SetTitle(tit); TString tit0=zver; if(tq==0) { tit="Track eff,"; tit0="trEff_"+tit0; } else { tit="Charge eff_"; tit0="qEff_"+tit0; } tit+=zver; ax=h->GetXaxis(); if(h2d==0) { h2d=new TH2F(tit0,tit+" vs. eta & pt; gen #eta; gen PT (GeV)", ax->GetNbins(),ax->GetXmin(),ax->GetXmax(), 20,1.25,51.25 ); } int ib; for(ib=1;ib<=ax->GetNbins();ib++) { h2d->SetBinContent(ib,jpt*2,h->GetBinContent(ib)); } // assert(nhcd(4); c=new TCanvas("aa","aa",400,450); h2d->Draw("colz"); gStyle->SetOptStat(0); } hf->cd(); h2d->Write(); } } //=============================== TH1F *doEff(TFile *fd, int xx, int type=0){ // c=new TCanvas("aa","aa",700,800); // c=new TCanvas("aa2","aa2",400,500); // c->Divide(1,2); char *name1="gEtaG"; char *name2="mEta"; if(type!=0)name2="mqEta"; TH1F* h1=(TH1F*)fd->Get(name1); assert(h1); TH1F* h2=(TH1F*)fd->Get(name2); assert(h2); // c->cd(1); h1->Draw(); // h2->Draw("same"); h2->SetLineColor(kRed); TH1F* hef=(TH1F*) h1->Clone(); hef->SetTitle("efficiency vs. #eta; generated #eta; eff "); hef->Reset(); TString tt2="aaa"; tt2+=xx; hef->SetName(tt2); int nb=hef->GetNbinsX(); printf("------- nh=%d\n",xx); int ib; for(ib=1;ib<=nb;ib++) { // loop over all histo bins, starts from 1 - how silly! float x=h1->GetBinCenter(ib); float y1=h1->GetBinContent(ib); float y2=h2->GetBinContent(ib); if(y1<=0.) continue; float eff=y2/y1; float effEr=sqrt(y2*(y1-y2)/y1)/y1; printf("bin=%d x=%.2f y1=%.0f y2=%.0f eff=%.2f +/-%.2f\n",ib,x,y1,y2,eff,effEr); hef->SetBinContent(ib,eff); hef->SetBinError(ib,effEr); } // c->cd(2); hef->Draw(); return hef; }