// $Id: Example1.C,v 1.3 2010/07/18 20:35:54 videbaek Exp $ // // This simple example divides a canvas into 2 pad (nx*ny) // illustrates how to detup the offsets, and draw text with a given size. // { // The package must how been compiled with the makescript // gSystem->Load("../.libs/libGrUtils.so"); gROOT->ProcessLine("using namespace GraphUtils"); gROOT->LoadMacro("../BasePlot.C+"); // Define some histogram and functions to be used in plotpanels. // TH1F* h1 = new TH1F("h1","spec1",40,0,4.0); int i(3); for(double x=0.25;x<4.0;x+=0.1){ double f = TMath::Exp(-x*5.0)*1000; double df= TMath::Sqrt(f); f = gRandom->Gaus(f,df); h1->SetBinContent(i,f); h1->SetBinError(i,df); i++; } TH1F* h2 = new TH1F("h2","spec2",40,0,4.0); i=3; for(double x=0.25;x<4.0;x+=0.1){ double f = TMath::Exp(-x*6.0)*1000; double df= TMath::Sqrt(f); f = gRandom->Gaus(f,df); h2->SetBinContent(i,f); h2->SetBinError(i,df); i++; } TH1F* h3 = new TH1F("h3","spec4",40,0,4.0); i=3; for(double x=0.25;x<4.0;x+=0.1){ double f = TMath::Exp(-x*6.0)*1000; double df= TMath::Sqrt(f); f = gRandom->Gaus(f,df); h3->SetBinContent(i,f); h3->SetBinError(i,df); i++; } TH1F* h4 = new TH1F("h4","spec4",40,0,4.0); i=3; for(double x=0.25;x<4.0;x+=0.1){ double f = TMath::Exp(-x*6.0)*1000; double df= TMath::Sqrt(f); f = gRandom->Gaus(f,df); h4->SetBinContent(i,f); h4->SetBinError(i,df); i++; } TF1* f1 = new TF1("f1","1000.0*exp(-5*x)",0.3,2.5); // Setup BasePlot package // // Define the page size as 4.5" * 3.0" SetupPage(4.5*2.54, 3.0*2.54); SetupCanvas("TestPlot","Test Plot 2 frames"); // fractional margins bottomMargin=0.12; leftMinorMargin=0.0; bottomMinorMargin=0.00; rightMinorMargin=0.00; rightMargin=0.005; // Justify axis labels. leftJustify=1; botJustify=1; // Title offsets in cm. titleYOffset=1.0; titleXOffset=0.45; // have a black line around legends. fLegendLineColor=1; // Create a figure with 2*1 panels // the active range of the plot i.e. with the frames with have // precisely the same size, the labes and tic mark will be the same in // both pads. // int nx(2), ny(1); InitPads(nx,ny); // // The package is by can bet setup to change markerstyle, color when // adding multiple histograms or graphs to one panel. The initial value // is set here. // SetMarkerStyle(21); SetMarkerColor(kRed); SetLineColor(kRed); // use style,color increment useScaling = kTRUE; // each histogram is scaled by the factors // note: This modifies the histogram, so if the macro uses the // histogram byuer beware. useIncrement=kTRUE; scaleFactor=0.1; // Define the frames (axis ) layout for the two pads. Float_t frameMax = 1000.; Float_t nDec = 7; Float_t frameMin = frameMax*TMath::Power(10.,-nDec); xTitle = "p_{T} (GeV/c)"; yTitle = "#frac{1}{2#pi p_{T}} #frac{d^{2}N}{dp_{T}dy} (GeV/c)^{-2}"; xNDiv = 1003; yNDiv = 510; CreateFrames(0.000, 2.9999, frameMin, frameMax, 0, 1); // setup for a legenbox in each pad. // Padnumber (ix, iy) start point (xmin, ymin) (box size (xb,yb) as well // as text size (0.3) is in cm. SetupLegend(0, 0, 3.0, 3.6, 1.0, 1.0, 0.3); SetupLegend(1, 0, 3.0, 3.6, 1.0, 1.0, 0.3); // Add two histogram to pad 0 scale by 10 AddHistogram(0, h1,"#pi h1","e"); AddHistogram(0, h2,"#pi h2","e"); // reset colors, scales,.. SetMarkerColor(kBlue); SetLineColor(kBlue); SetMarkerStyle(21); currentScale = 1; // Add two histogram to pad 1 scale by 10 AddHistogram(1, h3,"#pi^{-} h3","e"); AddHistogram(1, h4,"#pi^{-} h4","e"); // Add a functions to the second pad (1) AddFunction(0,f1,"f1","l"); // Draw pads DrawPads(); // You can now add text to a pad (0,0) TLatex* text = PlotText(0, 0, 1.0, 5.0,"AuAu 200 GeV", 0.3); text->SetTextColor(kOrange); // reuest to save the figure as both a .pdf and png file // If saved as pdf, and you use pdflatex including the figures // with a picture size of the setup page the figure text etc will // have the correct sizes for publication, fullfilling e.g. PRC requirements // for minimum text size. // savePNG=1; savePDF=1; // save as Example1.pdf and Example1.png SaveFigure("Example1"); }