FeldmanCousins.C: Example macro of using the TFeldmanCousins class in root. | Math tutorials | Legendre.C: Example of first few Legendre Polynomials |
// Example showing the usage of the major special math functions (gamma, beta, erf) in ROOT // To execute the macro type in: // // root[0]: .x GammaFun.C // // It will create one canvas with the representation //of the tgamma, lgamma, beta, erf and erfc functions // // Author: Magdalena Slawinska #include "TMath.h" #include "TF1.h" #include "TF2.h" #include "TSystem.h" #include "TCanvas.h" #include "TStyle.h" #include "TPaveLabel.h" #include "TAxis.h" #include "TH1.h" void GammaFun() { gSystem->Load("libMathCore"); gStyle->SetPalette(1); gStyle->SetOptStat(0); TF1 *f1a = new TF1("Gamma(x)","ROOT::Math::tgamma(x)",-2,5); TF1 *f2a = new TF1("f2a","ROOT::Math::lgamma(x)",0,10); TF2 *f3a = new TF2("Beta(x)","ROOT::Math::beta(x, y)",0,0.1, 0, 0.1); TF1 *f4a = new TF1("erf(x)","ROOT::Math::erf(x)",0,5); TF1 *f4b = new TF1("erfc(x)","ROOT::Math::erfc(x)",0,5); TCanvas *c1 = new TCanvas("c1", "Gamma and related functions",1000,750); c1->SetFillColor(17); c1->Divide(2,2); c1->cd(1); gPad->SetGrid(); gPad->SetFrameFillColor(19); //setting the title in a label style TPaveLabel *p1 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::tgamma(x)", "NDC"); p1->SetFillColor(0); p1->SetTextFont(22); p1->SetTextColor(kBlack); //setting graph // draw axis first (use TH1 to draw the frame) TH1F * h = new TH1F("htmp","",500,-2,5); h->SetMinimum(-20); h->SetMaximum(20); h->GetXaxis()->SetTitleSize(0.06); h->GetXaxis()->SetTitleOffset(.7); h->GetXaxis()->SetTitle("x"); h->Draw(); // draw the funcitions 3 times in the separate ranges to avoid singularities f1a->SetLineWidth(2); f1a->SetLineColor(kBlue); f1a->SetRange(-2,-1); f1a->DrawCopy("same"); f1a->SetRange(-1,0); f1a->DrawCopy("same"); f1a->SetRange(0,5); f1a->DrawCopy("same"); p1->Draw(); c1->cd(2); gPad->SetGrid(); gPad->SetFrameFillColor(19); TPaveLabel *p2 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::lgamma(x)", "NDC"); p2->SetFillColor(0); p2->SetTextFont(22); p2->SetTextColor(kBlack); f2a->SetLineColor(kBlue); f2a->SetLineWidth(2); f2a->GetXaxis()->SetTitle("x"); f2a->GetXaxis()->SetTitleSize(0.06); f2a->GetXaxis()->SetTitleOffset(.7); f2a->SetTitle(""); f2a->Draw(); p2->Draw(); c1->cd(3); gPad->SetGrid(); gPad->SetFrameFillColor(19); TPaveLabel *p3 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"ROOT::Math::beta(x, y)", "NDC"); p3->SetFillColor(0); p3->SetTextFont(22); p3->SetTextColor(kBlack); f3a->SetLineWidth(2); f3a->GetXaxis()->SetTitle("x"); f3a->GetXaxis()->SetTitleOffset(1.2); f3a->GetXaxis()->SetTitleSize(0.06); f3a->GetYaxis()->SetTitle("y"); f3a->GetYaxis()->SetTitleSize(0.06); f3a->GetYaxis()->SetTitleOffset(1.5); f3a->SetTitle(""); f3a->Draw("surf1");//option for a 3-dim plot p3->Draw(); c1->cd(4); gPad->SetGrid(); gPad->SetFrameFillColor(19); TPaveLabel *p4 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,"erf(x) and erfc(x)", "NDC"); p4->SetFillColor(0); p4->SetTextFont(22); p4->SetTextColor(kBlack); f4a->SetTitle("erf(x) and erfc(x)"); f4a->SetLineWidth(2); f4b->SetLineWidth(2); f4a->SetLineColor(kBlue); f4b->SetLineColor(kRed); f4a->GetXaxis()->SetTitleSize(.06); f4a->GetXaxis()->SetTitleOffset(.7); f4a->GetXaxis()->SetTitle("x"); f4a->Draw(); f4b->Draw("same");//option for a multiple graph plot f4a->SetTitle(""); p4->Draw(); c1->Update(); c1->cd(); } GammaFun.C:1 GammaFun.C:2 GammaFun.C:3 GammaFun.C:4 GammaFun.C:5 GammaFun.C:6 GammaFun.C:7 GammaFun.C:8 GammaFun.C:9 GammaFun.C:10 GammaFun.C:11 GammaFun.C:12 GammaFun.C:13 GammaFun.C:14 GammaFun.C:15 GammaFun.C:16 GammaFun.C:17 GammaFun.C:18 GammaFun.C:19 GammaFun.C:20 GammaFun.C:21 GammaFun.C:22 GammaFun.C:23 GammaFun.C:24 GammaFun.C:25 GammaFun.C:26 GammaFun.C:27 GammaFun.C:28 GammaFun.C:29 GammaFun.C:30 GammaFun.C:31 GammaFun.C:32 GammaFun.C:33 GammaFun.C:34 GammaFun.C:35 GammaFun.C:36 GammaFun.C:37 GammaFun.C:38 GammaFun.C:39 GammaFun.C:40 GammaFun.C:41 GammaFun.C:42 GammaFun.C:43 GammaFun.C:44 GammaFun.C:45 GammaFun.C:46 GammaFun.C:47 GammaFun.C:48 GammaFun.C:49 GammaFun.C:50 GammaFun.C:51 GammaFun.C:52 GammaFun.C:53 GammaFun.C:54 GammaFun.C:55 GammaFun.C:56 GammaFun.C:57 GammaFun.C:58 GammaFun.C:59 GammaFun.C:60 GammaFun.C:61 GammaFun.C:62 GammaFun.C:63 GammaFun.C:64 GammaFun.C:65 GammaFun.C:66 GammaFun.C:67 GammaFun.C:68 GammaFun.C:69 GammaFun.C:70 GammaFun.C:71 GammaFun.C:72 GammaFun.C:73 GammaFun.C:74 GammaFun.C:75 GammaFun.C:76 GammaFun.C:77 GammaFun.C:78 GammaFun.C:79 GammaFun.C:80 GammaFun.C:81 GammaFun.C:82 GammaFun.C:83 GammaFun.C:84 GammaFun.C:85 GammaFun.C:86 GammaFun.C:87 GammaFun.C:88 GammaFun.C:89 GammaFun.C:90 GammaFun.C:91 GammaFun.C:92 GammaFun.C:93 GammaFun.C:94 GammaFun.C:95 GammaFun.C:96 GammaFun.C:97 GammaFun.C:98 GammaFun.C:99 GammaFun.C:100 GammaFun.C:101 GammaFun.C:102 GammaFun.C:103 GammaFun.C:104 GammaFun.C:105 GammaFun.C:106 GammaFun.C:107 GammaFun.C:108 GammaFun.C:109 GammaFun.C:110 GammaFun.C:111 GammaFun.C:112 GammaFun.C:113 GammaFun.C:114 GammaFun.C:115 GammaFun.C:116 GammaFun.C:117 GammaFun.C:118 GammaFun.C:119 GammaFun.C:120 GammaFun.C:121 GammaFun.C:122 GammaFun.C:123 GammaFun.C:124 GammaFun.C:125 GammaFun.C:126 GammaFun.C:127 GammaFun.C:128 GammaFun.C:129 GammaFun.C:130 GammaFun.C:131 GammaFun.C:132 GammaFun.C:133 GammaFun.C:134 GammaFun.C:135 GammaFun.C:136 GammaFun.C:137 GammaFun.C:138 GammaFun.C:139 |
|