GammaFun.C

Go to the documentation of this file.
00001 // Example showing the usage of the major special math functions  (gamma, beta, erf)  in ROOT
00002 // To execute the macro type in:
00003 //
00004 // root[0]: .x GammaFun.C 
00005 //
00006 // It will create one canvas with the representation 
00007 //of the tgamma, lgamma, beta, erf and erfc functions
00008 
00009 //
00010 //  Author: Magdalena Slawinska
00011 
00012 #include "TMath.h"
00013 #include "TF1.h"
00014 #include "TF2.h"
00015 #include "TSystem.h"
00016 #include "TCanvas.h"
00017 #include "TStyle.h"
00018 #include "TPaveLabel.h"
00019 #include "TAxis.h"
00020 #include "TH1.h" 
00021 
00022 void GammaFun() {
00023 
00024 gSystem->Load("libMathCore");
00025 
00026 gStyle->SetPalette(1);
00027 gStyle->SetOptStat(0);
00028 
00029 
00030 TF1 *f1a = new TF1("Gamma(x)","ROOT::Math::tgamma(x)",-2,5);
00031 TF1 *f2a = new TF1("f2a","ROOT::Math::lgamma(x)",0,10);
00032 TF2 *f3a = new TF2("Beta(x)","ROOT::Math::beta(x, y)",0,0.1, 0, 0.1);
00033 TF1 *f4a = new TF1("erf(x)","ROOT::Math::erf(x)",0,5);
00034 TF1 *f4b = new TF1("erfc(x)","ROOT::Math::erfc(x)",0,5);
00035 
00036 TCanvas *c1 = new TCanvas("c1", "Gamma and related functions",1000,750);
00037 
00038 c1->SetFillColor(17);
00039 c1->Divide(2,2);
00040 
00041 
00042 c1->cd(1);
00043 gPad->SetGrid();
00044 gPad->SetFrameFillColor(19);
00045  
00046 //setting the title in a label style
00047 TPaveLabel *p1 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::tgamma(x)", "NDC");
00048 p1->SetFillColor(0);
00049 p1->SetTextFont(22);
00050 p1->SetTextColor(kBlack);
00051 
00052 //setting graph 
00053 // draw axis first (use TH1 to draw the frame)
00054 TH1F * h = new TH1F("htmp","",500,-2,5);
00055 h->SetMinimum(-20);
00056 h->SetMaximum(20);
00057 h->GetXaxis()->SetTitleSize(0.06);
00058 h->GetXaxis()->SetTitleOffset(.7);
00059 h->GetXaxis()->SetTitle("x");
00060 
00061 h->Draw(); 
00062 
00063 // draw the functions 3 times in the separate ranges to avoid singularities 
00064 f1a->SetLineWidth(2);
00065 f1a->SetLineColor(kBlue);
00066 
00067 f1a->SetRange(-2,-1);
00068 f1a->DrawCopy("same");
00069 
00070 f1a->SetRange(-1,0);
00071 f1a->DrawCopy("same");
00072 
00073 f1a->SetRange(0,5);
00074 f1a->DrawCopy("same");
00075 
00076 
00077 p1->Draw();
00078 
00079 c1->cd(2);
00080 gPad->SetGrid();
00081 gPad->SetFrameFillColor(19);
00082 TPaveLabel *p2 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::lgamma(x)", "NDC");
00083    p2->SetFillColor(0);
00084    p2->SetTextFont(22);
00085    p2->SetTextColor(kBlack);
00086 f2a->SetLineColor(kBlue);
00087 f2a->SetLineWidth(2);
00088 f2a->GetXaxis()->SetTitle("x");
00089 f2a->GetXaxis()->SetTitleSize(0.06);
00090 f2a->GetXaxis()->SetTitleOffset(.7);
00091 f2a->SetTitle("");
00092 f2a->Draw();
00093  p2->Draw();
00094 
00095 c1->cd(3);
00096 gPad->SetGrid();
00097 gPad->SetFrameFillColor(19);
00098 
00099 TPaveLabel *p3 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::beta(x, y)", "NDC");
00100    p3->SetFillColor(0);
00101    p3->SetTextFont(22);
00102    p3->SetTextColor(kBlack);
00103 f3a->SetLineWidth(2);
00104 f3a->GetXaxis()->SetTitle("x");
00105 f3a->GetXaxis()->SetTitleOffset(1.2);
00106 f3a->GetXaxis()->SetTitleSize(0.06);
00107 f3a->GetYaxis()->SetTitle("y");
00108 f3a->GetYaxis()->SetTitleSize(0.06);
00109 f3a->GetYaxis()->SetTitleOffset(1.5);
00110 f3a->SetTitle("");
00111  f3a->Draw("surf1");//option for a 3-dim plot
00112 p3->Draw();
00113 
00114 c1->cd(4);
00115 gPad->SetGrid();
00116 gPad->SetFrameFillColor(19);
00117 TPaveLabel *p4 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"erf(x) and erfc(x)", "NDC");
00118    p4->SetFillColor(0);
00119    p4->SetTextFont(22);
00120    p4->SetTextColor(kBlack);
00121 f4a->SetTitle("erf(x) and erfc(x)");
00122 f4a->SetLineWidth(2);
00123 f4b->SetLineWidth(2);
00124 f4a->SetLineColor(kBlue);
00125 f4b->SetLineColor(kRed);
00126 f4a->GetXaxis()->SetTitleSize(.06);
00127 f4a->GetXaxis()->SetTitleOffset(.7);
00128 f4a->GetXaxis()->SetTitle("x");
00129 f4a->Draw();
00130  f4b->Draw("same");//option for a multiple graph plot
00131 f4a->SetTitle("");
00132 p4->Draw();
00133 
00134 c1->Update();
00135  c1->cd();
00136 
00137 
00138 }

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