void pion_pres(void) { gROOT->Reset(); TColor::CreateColorWheel(); TFile *f = new TFile("hd_res_charged.root"); TH2D *dE_over_E_vs_p_vs_theta = (TH2D*)gROOT->FindObject("dp_over_p_vs_p_vs_theta"); TCanvas *c1 = new TCanvas("c1"); c1->SetTicks(); c1->SetGridy(); TH2D *axes = new TH2D("axes","Reconstructed photon energy resolution vs E_{#gamma}", 100, 0.0, 130.0, 100, 0.0, 0.2); axes->SetStats(0); axes->SetYTitle("#sigma(#deltap/p)"); axes->SetXTitle("#theta (degrees)"); axes->Draw(); TLegend *leg = new TLegend(0.3, 0.5, 0.80, 0.80); int colors[] = {kRed, kBlue, kGreen, kMagenta}; double moms[] = {0.8, 1.5, 2.5, 3.5}; int Nmoms=4; for(int i=0; iGetYaxis()->FindBin(moms[i]); dp_over_p_vs_p_vs_theta->ProjectionX(hname, bin, bin); TH1D *h = (TH1D*)gROOT->FindObject(hname); // Get rid of bins with really large error bars for(int bin=1; bin<=h->GetNbinsX(); bin++){ if(h->GetBinError(bin)>0.04){ h->SetBinContent(bin, 0.0); h->SetBinError(bin, 0.0); } } h->SetXTitle("Polar Angle #theta (degrees)"); h->SetYTitle("Relative momentum resolution"); h->SetTitle("#pi^{+} momentum resolution vs #theta"); h->SetStats(0); h->SetLineColor(colors[i]); h->SetLineWidth(2.0); h->Draw("same"); char str[256]; sprintf(str,"p=%02d GeV/c ", moms[i]); leg->AddEntry(h, str); } leg->Draw(); AddStandardLabels(axes); c1->SaveAs("pion_pres.gif"); c1->SaveAs("pion_pres.pdf"); } //---------------- // AddStandardLabels //---------------- void AddStandardLabels(TH2D *axes=NULL) { // This will draw a label or two on the // current plot using the NDC coordinates. // It is put here to make sure all plots have // a consistent labeling. // Date, Author TLatex *lab = new TLatex(0.7, 0.7, "Feb. 17, 2009 DL"); ConvertFromNDC(lab, axes); lab->SetTextSize(0.03); lab->SetTextAlign(33); lab->Draw(); // SVN Revision lab = new TLatex(0.7, 0.645, "svn revision: 4865"); ConvertFromNDC(lab, axes); lab->SetTextSize(0.02); lab->SetTextAlign(31); lab->Draw(); // Event type lab = new TLatex(0.45, 0.61, "Single #pi^{+} ; Wire-based tracks from THROWN"); ConvertFromNDC(lab, axes); lab->SetTextSize(0.03); lab->SetTextAlign(31); lab->Draw(); } //---------------- // ConvertFromNDC //---------------- void ConvertFromNDC(TLatex *obj, TH2D *h=NULL) { // Bugs in ROOT make it hard to plot labels consistently. // For 1D plots, the histogram axes define the coordinate // system. For 2D plots, we seem to be forced to use the // NDC. There does not seem to be an obvious way to tell // which we're using so we pass the information in in the // form of the "axes" histogram. If it is not NULL, then // we use it to define the limits. Otherwise, we do nothing. if(h==NULL)return; TAxis *xaxis = h->GetXaxis(); int Nbinsx = xaxis->GetNbins(); double xmin = xaxis->GetBinLowEdge(1); double xmax = xmin + xaxis->GetBinLowEdge(Nbinsx); TAxis *yaxis = h->GetYaxis(); int Nbinsy = yaxis->GetNbins(); double ymin = yaxis->GetBinLowEdge(1); double ymax = ymin + yaxis->GetBinLowEdge(Nbinsy); double x = obj->GetX(); double y = obj->GetY(); cout<<" in: x="<