void draw_R2m(void) { const double er[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; double ccnt[9]; double eccnt[9]; double dcnt[9]; TGraphErrors *gr; TGraphErrors *grd; TH1D *hst; TH1D *hstd; double effUp, effDown, C, shift, size; double eeffUp, eeffDown, eC, eshift, esize; double fmin, fedm, errdef; int npari, nparx; int i, irc; char str[1024]; TF1 *fR2; TVirtualPad *pd; gStyle->SetOptStat(0); gStyle->SetOptFit(0); MyMinuit = new TMinuit(5); MyMinuit->SetFCN(chi2fun); MyMinuit->DefineParameter(0, "Const", 1000, 10, 0, 1E10); MyMinuit->DefineParameter(1, "EffUp", 1, 0.1, 0.5, 1.5); MyMinuit->DefineParameter(2, "EffDown", 1, 0.1, 0.5, 1.5); MyMinuit->DefineParameter(3, "Shift", 0, 0.1, -10, 10); MyMinuit->DefineParameter(4, "Size", 3, 1, 0, 10); MyMinuit->FixParameter(3); MyMinuit->FixParameter(4); MyMinuit->Migrad(); MyMinuit->GetParameter(0, C, eC); MyMinuit->GetParameter(1, effUp, eeffUp); MyMinuit->GetParameter(2, effDown, eeffDown); MyMinuit->GetParameter(3, shift, eshift); MyMinuit->GetParameter(4, size, esize); MyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, irc); // Renorm top and bottom sections to the middle for (i=0; i<3; i++) { ccnt[i] = DataArray.cnt[i] / effUp; ccnt[i+3] = DataArray.cnt[i+3]; ccnt[i+6] = DataArray.cnt[i+6] / effDown; eccnt[i] = DataArray.ecnt[i] / effUp; eccnt[i+3] = DataArray.ecnt[i+3]; eccnt[i+6] = DataArray.ecnt[i+6] / effDown; } // for (i=0; i<9; i++) printf("L = %8.3f CNT = %6.1f +- %4.1f\n", r[i], cnt[i], ecnt[i]); gr = new TGraphErrors(9, DataArray.r, ccnt, er, eccnt); gr->SetLineColor(kBlue); gr->SetLineWidth(4); gr->SetMarkerStyle(20); gr->SetMarkerColor(kBlue); gr->SetMarkerSize(2); fR2 = new TF1("fR2", "[0] / ((x - [1]) * (x - [1]) - [2] * [2] / 4.0)", 1, 100); fR2->SetParameter(0, C); fR2->SetParameter(1, shift); fR2->SetParameter(2, size); fR2->SetLineColor(kRed); fR2->SetLineWidth(3); hst = new TH1D("H", ";Distance to reactor core center, m;Events per day", 35, 10, 13.5); hst->SetMinimum(DataArray.cnt[4] * 0.5); hst->SetMaximum(DataArray.cnt[4] * 1.5); hst->GetXaxis()->SetLabelSize(0.06); hst->GetYaxis()->SetLabelSize(0.06); hst->GetXaxis()->SetTitleSize(0.06); hst->GetYaxis()->SetTitleSize(0.06); hst->GetYaxis()->SetTitleOffset(1.25); hstd = new TH1D("H", ";Distance to reactor core center, m;Events per day", 35, 10, 13.5); hstd->SetMinimum(-40); hstd->SetMaximum(40); hstd->GetXaxis()->SetLabelSize(0.06); hstd->GetYaxis()->SetLabelSize(0.06); hstd->GetXaxis()->SetTitleSize(0.06); hstd->GetYaxis()->SetTitleSize(0.06); hstd->GetYaxis()->SetTitleOffset(1.25); TCanvas *cv = new TCanvas("CV", "R2", 800, 1200); cv->Divide(1, 2); // Do common fit and draw pd = cv->cd(1); pd->SetLeftMargin(0.15); pd->SetBottomMargin(0.15); pd->SetTopMargin(0.03); hst->Draw(); gr->Draw("p"); fR2->Draw("same"); TLatex txt; txt.SetTextSize(0.07); sprintf(str, "#chi^{2}/n.d.f. = %6.2f/5", fmin); txt.DrawLatex(11.3, DataArray.cnt[4] * 1.3, str); // Draw difference for (i=0; i<9; i++) dcnt[i] = ccnt[i] - fR2->Eval(DataArray.r[i]); grd = new TGraphErrors(9, DataArray.r, dcnt, er, eccnt); grd->SetLineColor(kBlue); grd->SetLineWidth(4); grd->SetMarkerStyle(20); grd->SetMarkerColor(kBlue); grd->SetMarkerSize(2); pd = cv->cd(2); pd->SetLeftMargin(0.15); pd->SetBottomMargin(0.15); pd->SetTopMargin(0.03); hstd->Draw(); grd->Draw("p"); }
/// /// Plot the evolution of best fit nuisance paramters /// along the 1-CL curve. /// /// By changing the code at the beginning of the function /// one can chose whether all scan results are plotted, or /// only those comprising the 1-CL curve. /// void ParameterEvolutionPlotter::plotParEvolution() { vector<RooSlimFitResult*> results = allResults; // vector<RooSlimFitResult*> results = curveResults; cout << "ParameterEvolutionPlotter::plotParEvolution() : plotting ..." << endl; selectNewCanvas(title+" 1"); // get all parameters, loop over them TIterator* it = w->set(parsName)->createIterator(); while ( RooRealVar* p = (RooRealVar*)it->Next() ) { if ( p->isConstant() && p->GetName()!=scanVar1 ) continue; if ( arg->debug ) cout << "ParameterEvolutionPlotter::plotParEvolution() : var = " << p->GetName() << endl; TVirtualPad *pad = selectNewPad(); pad->SetLeftMargin(0.25); pad->SetTopMargin(0.10); // create a graph of the nominal evolution of one parameter TGraph *g = makeEvolutionGraph(curveResults, p->GetName()); g->SetTitle(p->GetTitle()); g->GetXaxis()->SetTitle(scanVar1); g->GetXaxis()->SetTitleSize(0.08); g->GetXaxis()->SetLabelSize(0.06); g->GetXaxis()->SetNdivisions(-406); g->GetYaxis()->SetTitleSize(0.08); g->GetYaxis()->SetLabelSize(0.06); g->GetYaxis()->SetTitleOffset(1.4); g->GetYaxis()->SetTitle(p->GetName()); g->SetLineColor(kBlue); g->SetLineWidth(2); TGaxis::SetMaxDigits(3); // forces scienfific notation g->Draw("al"); // add error bands TGraphErrors *g2 = makeEvolutionGraphErrors(curveResults, p->GetName()); g2->SetFillColorAlpha(kBlue,0.15); g2->Draw("3"); // create a graph of the full evolution of one parameter if ( arg->isQuickhack(16) ){ TGraph *g3 = makeEvolutionGraph(allResults, p->GetName()); g3->Draw("p"); } updateCurrentCanvas(); // plot a red line at minimum drawLinesAtMinima(pad); } // plot the chi2 to the last pad TVirtualPad *pad = selectNewPad(); pad->SetLeftMargin(0.25); TGraph *g = makeChi2Graph(curveResults); g->SetLineWidth(2); g->SetTitle("chi2"); g->GetXaxis()->SetTitle(scanVar1); g->GetXaxis()->SetTitleSize(0.08); g->GetXaxis()->SetLabelSize(0.06); g->GetXaxis()->SetNdivisions(-406); g->GetYaxis()->SetTitleSize(0.08); g->GetYaxis()->SetLabelSize(0.06); g->GetYaxis()->SetTitleOffset(1.4); g->GetYaxis()->SetTitle("#chi^{2}"); g->Draw("al"); drawLinesAtMinima(pad); updateCurrentCanvas(); // save plots saveEvolutionPlots(); }
void plot(char* v, int run, int cut, TCanvas* cvs, int fit=0, int bin1=-1, int bin2=-1, float ymax=0.0, int rebin=0){ int bin0=1; char c[100]; char c2[100]; readfile(OPT,run); gStyle->SetOptStat(0); gStyle->SetOptFit(0); gStyle->SetOptTitle(0); cvs->Clear(); int b1=bin1, b2=bin1+1, b3=bin2, b4=b3; if(bin1<0) {cvs->Divide(kNPtBin-bin0,kNPtBin-bin0); b1=bin0; b2=kNPtBin; b3=bin0;} float ptcut[kNPtBin+1]={0.5,1.0,1.5,2.0,2.5,3.0,10.0}; memset(PAR,0,sizeof(PAR)); TText* t; for(int i=b1; i<b2; i++){ if(bin1<0) b4=i; for(int j=b3; j<=b4; j++){ int cc=cut; if(cut==99 && (v=="m1" || v=="m2")) cc=0; if(cut==99 && v=="dphi") cc=1; TH1F *h,*h2,*h3,*h4; TH2F *h2d; //get normalizations float norm0=1.0; float norm1=1.0; float norm2=1.0; float norm3=1.0; if(v=="m0" || v=="phi0"){} else{ sprintf(c,"m0_%1d_c%d",i,cc); TH1F* h0 = (TH1F*)mTFile->Get(c); norm0 = h0->GetEntries(); sprintf(c,"m2_%1d%1d_c%d",i,j,cc); TH1F* h1 = (TH1F*)mTFile->Get(c); norm1 = h1->GetEntries(); printf("n0=%d n1=%d\n",norm0,norm1); norm2=norm1/norm0; norm3=norm2/ZggCut; } int opt=1, log=0; if(v=="mix"){ h3=mix(run,cc,i,j,0,1,h,h2); h1->SetLineColor(1); h2->SetLineColor(6); }else if(v=="corr"){ h = mix(run,cc,i,j,0,1); if(rebin>0) h->Rebin(rebin); if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0); int nbin = h->GetNbinsX(); h->Sumw2(); if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);} else {h->Scale(1.0/norm0*nbin/2.0/PI);} }else if(v=="norm"){ sprintf(c,"dphi_%1d%1d_c%d",i,j,cc); h = (TH1F*)mTFile->Get(c); if(rebin>0) h->Rebin(rebin); if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0); int nbin = h->GetNbinsX(); h->Sumw2(); if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);} else {h->Scale(1.0/norm0*nbin/2.0/PI);} }else if(v=="mall"){ sprintf(c,"m0_%1d_c%d",i,0); sprintf(c2,"m0_%1d%1d_c%d",i,j,0); h4 = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); float norm4 = h4->Integral(h4->GetXaxis()->FindBin(MassCut0),h4->GetXaxis()->FindBin(MassCut1)); h4->Scale(norm1/norm4); h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); sprintf(c,"m0_%1d_c%d",i,cc); sprintf(c2,"m0_%1d%1d_c%d",i,j,cc); h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); h->SetLineColor(6); h->Scale(norm2); sprintf(c,"m1_%1d%1d_c%d",i,j,cc); h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(2); sprintf(c,"m2_%1d%1d_c%d",i,j,cc); h3 = (TH1F*)mTFile->Get(c); h3->SetLineColor(4); }else if(v=="z12"){ sprintf(c,"z1_%1d%1d_c%d",i,j,cc); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); sprintf(c,"z2_%1d%1d_c%d",i,j,cc); h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(4); }else if(v=="m0" || v=="phi0"){ sprintf(c,"%s_%1d_c%d",v,i,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else if(v=="bbce"){ opt=1; log=1; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); h->SetMinimum(0.1); }else if(v=="phi1" || v=="phi2"){ opt=1; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else if(v=="phi1dphi"){ opt=2; sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); }else{ sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc); printf("%s\n",c); h = (TH1F*)mTFile->Get(c); } if(bin1<0){ TVirtualPad *pad = cvs->cd((i-bin0)*(kNPtBin-bin0)+(j-bin0)+1); pad->SetRightMargin(0.01); pad->SetLeftMargin(0); pad->SetTopMargin(0); pad->SetBottomMargin(0.01); pad->Draw(); } h->SetMinimum(0.0); if(ymax>0.0) h->SetMaximum(ymax); if(opt==0) h->Draw("e"); if(opt==1) h->Draw(); if(opt==2) h->Draw("colz"); if(v=="mall"){ h4->Draw("same"); h2->Draw("same"); h3->Draw("same"); } if(v=="z12" || v=="mix") h2->Draw("same"); TF1* f; if((v=="norm" || v=="corr") && fit==1){ f=new TF1("oneGaus",oneGaus,+PI/2.0,+PI*3.0/2.0,3); f->SetParameters(norm3/10.0,norm3/2.0,0.3); f->SetParNames("Const","IntFar","SigFar"); f->SetParLimits(0,0.0,1.0); f->SetParLimits(1,0.0,1.0); f->SetParLimits(2,0.0,3.0); f->SetLineColor(2); f->SetLineWidth(1); h->Fit("oneGaus","Q"); PAR[i][j][0]=f->GetParameter(0); PAR[i][j][1]=f->GetParameter(1); PAR[i][j][2]=f->GetParameter(2); printf("norm=%8.6f Int=%8.6f IntFar=%8.6 SigFar=%6.3f C=%8.6f\n", norm3,PAR[i][j][1]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][2],PAR[i][j][0]); } if((v=="norm" || v="corr") && fit==2){ f=new TF1("twoGaus",twoGaus,-PI/2.0,+PI*3.0/2.0,5); f->SetParameters(norm3/10.0,norm3/2.0,0.3,norm3/2.0,0.3); f->SetParNames("Const","IntNear","SigNear","IntFar","SigFar"); f->SetParLimits(0,0.0,1.0); f->SetParLimits(1,0.0,1.0); f->SetParLimits(2,0.0,3.0); f->SetParLimits(3,0.0,1.0); f->SetParLimits(4,0.0,3.0); f->SetLineColor(2); f->SetLineWidth(1); h->Fit("twoGaus","Q"); PAR[i][j][0]=f->GetParameter(0); PAR[i][j][1]=f->GetParameter(1); PAR[i][j][2]=f->GetParameter(2); PAR[i][j][3]=f->GetParameter(3); PAR[i][j][4]=f->GetParameter(4); printf("norm=%8.6f Int=%8.6f IntNear=%8.6f IntFar=%8.6f SigNear=%6.3f SigFar=%6.3f C=%8.6f\n", norm3,PAR[i][j][1]+PAR[i][j][3]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][3], PAR[i][j][2],PAR[i][j][4],PAR[i][j][0]); } float xx=0.60, yy=0.85, dy=0.04, size=0.04; if(bin1<0){xx=0.45, yy=0.90, dy=0.08, size=0.08;} if(v=="z12") {xx=0.1; yy=0.35;} t = new TText(xx, yy, Form("pT1=%3.1f-%3.1f",ptcut[i],ptcut[i+1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy, Form("pT2=%3.1f-%3.1f",ptcut[j],ptcut[j+1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); if(norm3>0.0){ t = new TText(xx, yy-dy*2, Form("P=%7.5f",norm3)); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if((v=="norm" || v="corr") && fit==1){ t = new TText(xx, yy-dy*3, Form("PBg=%7.5f", PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*5, Form("Saway=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if((v=="norm" || v="corr") && fit==2){ t = new TText(xx, yy-dy*3, Form("Pnear=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][3])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*5, Form("PBg=%7.5f", PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*6, Form("Snear=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw(); t = new TText(xx, yy-dy*7, Form("Saway=%4.2f",PAR[i][j][4])); t->SetNDC(); t->SetTextSize(size); t->Draw(); } if(cut==88) h->SetLineColor(2); if(cut==99 && (v=="m1"|| v=="m2")){ sprintf(c,"%s_%1d%1d_c%d",v,i,j,1); h = (TH1F*)mTFile->Get(c); h->SetLineColor(4); h->Draw("same"); sprintf(c,"%s_%1d%1d_c%d",v,i,j,2); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); h->Draw("same"); } if(cut==99 && v=="dphi"){ h->SetLineColor(4); sprintf(c,"%s_%1d%1d_c%d",v,i,j,2); h = (TH1F*)mTFile->Get(c); h->SetLineColor(2); h->Draw("same"); } if(bin1>0){ t = new TText(0.1, 0.92,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.07); t->SetTextColor(1); t->Draw(); if (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d_bin%d%d.png",v,cut,i,j);} else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d_bin%d%d.png",v,cut,i,j);} else {sprintf(c,"plot/dipi0_%d_%s_c%d_bin%d%d.png",run,v,cut,i,j);} printf("Saving %s\n",c); cvs->SaveAs(c); } } } if(bin1<0){ cvs->cd(2); t = new TText(0.0, 0.85,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(1); t->Draw(); } if(v=="mall"){ t = new TText(0.05, 0.65,"M1(no mass, scaled)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(1); t->Draw(); t = new TText(0.05, 0.55,"M1(without M2)/P"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(6); t->Draw(); t = new TText(0.05, 0.45,"M1(with M2)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw(); t = new TText(0.05, 0.35,"M2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw(); } if(v=="z12"){ t = new TText(0.05, 0.65,"Zgg1"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw(); t = new TText(0.05, 0.55,"Zgg2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw(); } if(cut==99) { t = new TText(0.0, 0.65, "Inclusive Pair"); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(4); t->Draw(); t = new TText(0.0, 0.45, "Exclusive Pair"); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(2); t->Draw(); } if(bin1<0){ if (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d.png",v,cut);} else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d.png",v,cut);} else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d.png",v,cut);} else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d.png",v,cut);} else {sprintf(c,"plot/dipi0_%d_%s_c%d.png",run,v,cut);} printf("Saving %s\n",c); cvs->SaveAs(c); } }
/** * Draw the Poisson estimate of the occupancy * * @param filename Input file name * @param folder Input folder name in file * * @deprecated Use QATrender instead * @ingroup pwglf_forward_scripts_qa */ void DrawOccupancy(const char* filename="forward.root", const char* folder="ForwardResults") { gStyle->SetPalette(1); gStyle->SetOptFit(0); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetTitleW(.4); gStyle->SetTitleH(.1); gStyle->SetTitleX(.4); // gStyle->SetTitleY(.1); gStyle->SetTitleColor(0); gStyle->SetTitleStyle(0); gStyle->SetTitleBorderSize(0); TFile* file = TFile::Open(filename, "READ"); if (!file) { Error("DrawOccupancy", "failed to open %s", filename); return; } TList* forward = static_cast<TList*>(file->Get(folder)); if (!forward) { Error("DrawOccupancy", "List %s not found in %s", folder, filename); return; } TList* dc = static_cast<TList*>(forward->FindObject("fmdDensityCalculator")); if (!dc) { Error("DrawOccupancy", "List fmdDensityCalculator not found in Forward"); return; } TCanvas* c = new TCanvas("occupancy", "Mean Occupancy", 900, 700); c->SetFillColor(0); c->SetBorderSize(0); c->SetBorderMode(0); c->SetHighLightColor(0); c->SetBottomMargin(.15); c->SetTopMargin(.02); c->SetRightMargin(.02); c->SetLeftMargin(.15); c->Divide(3, 2, 0, 0); Double_t corrs[5]; c->cd(1); corrs[0] = DrawRingOccupancy(dc, 1, 'I'); c->cd(2); corrs[1] = DrawRingOccupancy(dc, 2, 'I'); c->cd(5); corrs[2] = DrawRingOccupancy(dc, 2, 'O'); c->cd(3); corrs[3] = DrawRingOccupancy(dc, 3, 'I'); c->cd(6); corrs[4] = DrawRingOccupancy(dc, 3, 'O'); TVirtualPad* p = c->cd(4); p->SetTopMargin(0.05); p->SetRightMargin(0.10); p->SetLeftMargin(0.15); p->SetBottomMargin(0.15); p->SetFillColor(0); TH1D* hc = new TH1D("occ", "Mean occupancy", 5, .5, 5.5); hc->SetFillColor(kRed+1); hc->SetFillStyle(3001); hc->SetMinimum(0.0); hc->GetXaxis()->SetBinLabel(1,"FMD1i"); hc->SetBinContent(1,corrs[0]); hc->GetXaxis()->SetBinLabel(2,"FMD2i"); hc->SetBinContent(2,corrs[1]); hc->GetXaxis()->SetBinLabel(3,"FMD2o"); hc->SetBinContent(3,corrs[2]); hc->GetXaxis()->SetBinLabel(4,"FMD3i"); hc->SetBinContent(4,corrs[3]); hc->GetXaxis()->SetBinLabel(5,"FMD3o"); hc->SetBinContent(5,corrs[4]); hc->GetXaxis()->SetLabelSize(0.08); hc->GetYaxis()->SetTitle("#bar{occupancy}"); hc->SetMarkerSize(1.5); hc->Draw("text hist"); hc->SetMaximum(hc->GetMaximum()*1.5); // TH2D* highCuts = static_cast<TH2D*>(dc->FindObject("highCuts")); // if (highCuts) highCuts->Draw("colz"); c->cd(); c->SaveAs("occupancy.png"); }
void DrawTwoInPad(TVirtualPad* p, Int_t sub, TH1* h1, TH1* h2, Bool_t ratio, Bool_t logy=false, Bool_t legend=false) { TVirtualPad* pp = p->cd(sub); pp->SetRightMargin(0.02); pp->SetLeftMargin(0.10); TVirtualPad* ppp = pp; if (ratio) { pp->Divide(1,2,0,0); ppp = pp->cd(1); ppp->SetRightMargin(0.02); } if (logy) ppp->SetLogy(); TH1* hs[] = { h1, h2, 0 }; if (h1->GetMaximum() < h2->GetMaximum()) { hs[0] = h2; hs[1] = h1; } TH1** ph = hs; Double_t size = (ratio ? 0.1 : 0.05); Double_t off = (ratio ? 0.6 : 0.5); h1->SetFillStyle(3004); h2->SetFillStyle(3005); while (*ph) { TString opt("hist"); if (ph != hs) opt.Append(" same"); TH1* copy = (*ph)->DrawCopy(opt); copy->GetXaxis()->SetLabelSize(2*size); copy->GetYaxis()->SetLabelSize(size); copy->GetYaxis()->SetTitleSize(size); copy->GetYaxis()->SetTitleOffset(off); copy->SetYTitle(copy->GetTitle()); copy->SetTitle(""); copy->SetDirectory(0); ph++; } TString s1 = h1->GetYaxis()->GetTitle(); TString s2 = h2->GetYaxis()->GetTitle(); if (legend) { TLegend* l = new TLegend(0.6, 0.1, 0.9, 0.9); l->SetBorderSize(0); TLegendEntry* e = l->AddEntry("dummy", s1, "lf"); l->SetFillColor(kWhite); e->SetFillColor(kBlack); e->SetFillStyle(h1->GetFillStyle()); e = l->AddEntry("dummy", s2, "lf"); e->SetFillColor(kBlack); e->SetFillStyle(h2->GetFillStyle()); l->Draw(); } if (!ratio) return; ppp = pp->cd(2); ppp->SetRightMargin(0.02); TH1* r = static_cast<TH1*>(h1->Clone(Form("ratio%s", h1->GetName()))); r->SetDirectory(0); r->SetTitle(""); r->GetXaxis()->SetLabelSize(size); r->GetYaxis()->SetLabelSize(size); r->GetYaxis()->SetTitleSize(0.9*size); r->GetYaxis()->SetTitleOffset(0.9*off); r->SetMarkerStyle(20); r->SetMarkerColor(h1->GetFillColor()+1); r->SetFillStyle(3007); r->SetYTitle(Form("#frac{%s}{%s}", s1.Data(), s2.Data())); // r->Add(h2, -1); // r->Divide(h1); if (!r->IsA()->InheritsFrom(TProfile::Class())) { r->GetSumw2()->Set(0); // r->Sumw2(false); h2->GetSumw2()->Set(0); // h2->Sumw2(false); } r->Divide(h2); Printf("%s", r->GetName()); for (UShort_t bin = 1; bin <= r->GetNbinsX(); bin++) { Printf(" bin # %2d: Diff=%g+/-%g", bin, r->GetBinContent(bin), r->GetBinError(bin)); r->SetBinError(bin, 0); } r->GetSumw2()->Set(0); //r->Sumw2(false); r->SetMarkerSize(4); r->SetMaximum(r->GetMaximum()*1.2); r->SetMinimum(r->GetMinimum()*0.8); r->Draw("hist text30"); p->Modified(); p->Update(); p->cd(); }