h1draw.C

Go to the documentation of this file.
00001 // 1-D histogram drawing options
00002 #include "TInterpreter.h"
00003 #include "TCanvas.h"
00004 #include "TSystem.h"
00005 #include "TFile.h"
00006 #include "TH2.h"
00007 #include "TNtuple.h"
00008 #include "TPaveLabel.h"
00009 #include "TPaveText.h"
00010 #include "TFrame.h"
00011 #include "TSystem.h"
00012 #include "TInterpreter.h"
00013    
00014 void h1draw()
00015 {
00016    // We attach (or generate) the ROOT file in $ROOTSYS/tutorials/hsimple.root 
00017    // or $PWD/hsimple.root
00018    // We draw one histogram in different formats
00019    //Author: Rene Brun
00020    
00021    TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00022    dir.ReplaceAll("h1draw.C","../hsimple.C");
00023    dir.ReplaceAll("/./","/");
00024    if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
00025    TFile *example = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
00026    if (!example) return;
00027    
00028    example->ls();
00029    TH1 *hpx = (TH1*)example->Get("hpx");
00030    
00031    TCanvas *c1 = new TCanvas("c1","Histogram Drawing Options",200,10,700,900);
00032    TPad *pad1 = new TPad("pad1",
00033       "The pad with the function",0.03,0.62,0.50,0.92,21);
00034    TPad *pad2 = new TPad("pad2",
00035       "The pad with the histogram",0.51,0.62,0.98,0.92,21);
00036    TPad *pad3 = new TPad("pad3",
00037       "The pad with the histogram",0.03,0.02,0.97,0.57,21);
00038    pad1->Draw();
00039    pad2->Draw();
00040    pad3->Draw();
00041 
00042    // Draw a global picture title
00043    TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98,
00044                     "Drawing options for one dimensional histograms");
00045    title->SetFillColor(16);
00046    title->SetTextFont(52);
00047    title->Draw();
00048 
00049    // Draw histogram hpx in first pad with the default option.
00050    pad1->cd();
00051    pad1->GetFrame()->SetFillColor(18);
00052    hpx->SetFillColor(45);
00053    hpx->DrawCopy();
00054    TPaveLabel *label1 = new TPaveLabel(-3.5,700,-1,800,"Default option");
00055    label1->SetFillColor(42);
00056    label1->Draw();
00057 
00058    // Draw hpx as a lego. Clicking on the lego area will show
00059    // a "transparent cube" to guide you rotating the lego in real time.
00060    pad2->cd();
00061    hpx->DrawCopy("lego1");
00062    TPaveLabel *label2 = new TPaveLabel(-0.72,0.74,-0.22,0.88,"option Lego1");
00063    label2->SetFillColor(42);
00064    label2->Draw();
00065    TPaveLabel *label2a = new TPaveLabel(-0.93,-1.08,0.25,-0.92,
00066       "Click on lego to rotate");
00067    label2a->SetFillColor(42);
00068    label2a->Draw();
00069 
00070    // Draw hpx with its errors and a marker.
00071    pad3->cd();
00072    pad3->SetGridx();
00073    pad3->SetGridy();
00074    pad3->GetFrame()->SetFillColor(18);
00075    hpx->SetMarkerStyle(21);
00076    hpx->Draw("e1p");
00077    TPaveLabel *label3 = new TPaveLabel(2,600,3.5,650,"option e1p");
00078    label3->SetFillColor(42);
00079    label3->Draw();
00080 
00081    // The following illustrates how to add comments using a PaveText.
00082    // Attributes of text/lines/boxes added to a PaveText can be modified.
00083    // The AddText function returns a pointer to the added object.
00084    TPaveText *pave = new TPaveText(-3.78,500,-1.2,750);
00085    pave->SetFillColor(42);
00086    TText *t1=pave->AddText("You can move");
00087    t1->SetTextColor(4);
00088    t1->SetTextSize(0.05);
00089    pave->AddText("Title and Stats pads");
00090    pave->AddText("X and Y axis");
00091    pave->AddText("You can modify bin contents");
00092    pave->Draw();
00093    c1->Update();
00094 }

Generated on Tue Jul 5 15:44:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1