Bessel.C

Go to the documentation of this file.
00001 // Show the different kinds of Bessel functions available in ROOT 
00002 // To execute the macro type in:
00003 //
00004 // root[0]: .x Bessel.C 
00005 //
00006 // It will create one canvas with the representation 
00007 // of the  cylindrical and spherical Bessel functions
00008 // regular and modified
00009 
00010 //
00011 //  Author: Magdalena Slawinska
00012 
00013 #include "TMath.h"
00014 #include "TF1.h"
00015 #include "TCanvas.h"
00016 
00017 #include <Riostream.h>
00018 #include "TLegend.h"
00019 #include "TLegendEntry.h"
00020 
00021 #include "Math/IFunction.h"
00022 #include <cmath>
00023 #include "TSystem.h"
00024 #include "TAxis.h"
00025 #include "TPaveLabel.h"
00026 
00027 void Bessel()
00028 {
00029   gSystem->Load("libMathMore");
00030 
00031   TCanvas *DistCanvas = new TCanvas("DistCanvas", 
00032      "Bessel functions example", 10, 10, 1000, 800);  
00033   DistCanvas->SetFillColor(17);
00034   DistCanvas->Divide(2, 2);
00035   DistCanvas->cd(1);
00036   gPad->SetGrid();
00037   gPad->SetFrameFillColor(19);
00038   TLegend *leg = new TLegend(0.75, 0.7, 0.89, 0.89); 
00039 
00040   int n = 5;//number of functions in each pad
00041 //drawing the set of Bessel J functions   
00042   TF1* JBessel[5];
00043   for(int nu = 0; nu < n; nu++)
00044   {
00045       JBessel[nu]= new TF1("J_0", "ROOT::Math::cyl_bessel_j([0],x)", 0, 10);
00046       JBessel[nu]->SetParameters(nu, 0.0);
00047       JBessel[nu]->SetTitle("");//Bessel J functions");  
00048       JBessel[nu]->SetLineStyle(1);
00049       JBessel[nu]->SetLineWidth(3);
00050       JBessel[nu]->SetLineColor(nu+1);
00051   }
00052   JBessel[0]->TF1::GetXaxis()->SetTitle("x");
00053   JBessel[0]->GetXaxis()->SetTitleSize(0.06);
00054   JBessel[0]->GetXaxis()->SetTitleOffset(.7);
00055 
00056   //setting the title in a label style
00057   TPaveLabel *p1 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,
00058      "Bessel J functions", "NDC");
00059 p1->SetFillColor(0);
00060 p1->SetTextFont(22);
00061 p1->SetTextColor(kBlack);
00062 
00063 //setting the legend
00064   leg->AddEntry(JBessel[0]->DrawCopy(), " J_0(x)", "l");
00065   leg->AddEntry(JBessel[1]->DrawCopy("same"), " J_1(x)", "l");
00066   leg->AddEntry(JBessel[2]->DrawCopy("same"), " J_2(x)", "l");
00067   leg->AddEntry(JBessel[3]->DrawCopy("same"), " J_3(x)", "l");
00068   leg->AddEntry(JBessel[4]->DrawCopy("same"), " J_4(x)", "l");
00069 
00070   leg->Draw();
00071   p1->Draw();
00072 
00073 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00074    DistCanvas->cd(2);
00075    gPad->SetGrid();
00076    gPad->SetFrameFillColor(19);
00077 
00078    TLegend *leg2 = new TLegend(0.75, 0.7, 0.89, 0.89); 
00079 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00080 //Drawing Bessel k  
00081    TF1* KBessel[5];
00082    for(int nu = 0; nu < n; nu++)
00083     {
00084       KBessel[nu]= new TF1("J_0", "ROOT::Math::cyl_bessel_k([0],x)", 0, 10);
00085       KBessel[nu]->SetParameters(nu, 0.0);
00086       KBessel[nu]->SetTitle("Bessel K functions");  
00087       KBessel[nu]->SetLineStyle(1);
00088       KBessel[nu]->SetLineWidth(3);
00089       KBessel[nu]->SetLineColor(nu+1);
00090     }
00091     KBessel[0]->GetXaxis()->SetTitle("x");
00092     KBessel[0]->GetXaxis()->SetTitleSize(0.06);
00093     KBessel[0]->GetXaxis()->SetTitleOffset(.7);
00094 
00095     //setting title
00096     TPaveLabel *p2 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,
00097        "Bessel K functions", "NDC");
00098     p2->SetFillColor(0);
00099     p2->SetTextFont(22);
00100     p2->SetTextColor(kBlack);
00101 
00102     //setting legend
00103     leg2->AddEntry(KBessel[0]->DrawCopy(), " K_0(x)", "l");
00104     leg2->AddEntry(KBessel[1]->DrawCopy("same"), " K_1(x)", "l");
00105     leg2->AddEntry(KBessel[2]->DrawCopy("same"), " K_2(x)", "l");
00106     leg2->AddEntry(KBessel[3]->DrawCopy("same"), " K_3(x)", "l");
00107     leg2->AddEntry(KBessel[4]->DrawCopy("same"), " K_4(x)", "l");
00108 //   for(int nu = 1; nu <= 4; nu++)
00109 //   leg->AddEntry(JBessel[0]->DrawCopy("lsame"), "", "l");
00110   
00111 
00112     leg2->Draw();
00113     p2->Draw();
00114 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00115    DistCanvas->cd(3);
00116    gPad->SetGrid();
00117    gPad->SetFrameFillColor(19);
00118    TLegend *leg3 = new TLegend(0.75, 0.7, 0.89, 0.89); 
00119 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00120  //Drawing Bessel i     
00121    TF1* iBessel[5];
00122    for(int nu = 0; nu <= 4; nu++)
00123     {
00124       iBessel[nu]= new TF1("J_0", "ROOT::Math::cyl_bessel_i([0],x)", 0, 10);
00125       iBessel[nu]->SetParameters(nu, 0.0);
00126       iBessel[nu]->SetTitle("Bessel I functions");  
00127       iBessel[nu]->SetLineStyle(1);
00128       iBessel[nu]->SetLineWidth(3);
00129       iBessel[nu]->SetLineColor(nu+1);
00130     }
00131 
00132     iBessel[0]->GetXaxis()->SetTitle("x");   
00133     iBessel[0]->GetXaxis()->SetTitleSize(0.06);
00134     iBessel[0]->GetXaxis()->SetTitleOffset(.7);
00135 
00136     //setting title
00137     TPaveLabel *p3 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,
00138        "Bessel I functions", "NDC");
00139     p3->SetFillColor(0);
00140     p3->SetTextFont(22);
00141     p3->SetTextColor(kBlack);
00142 
00143     //setting legend
00144     leg3->AddEntry(iBessel[0]->DrawCopy(), " I_0", "l");
00145     leg3->AddEntry(iBessel[1]->DrawCopy("same"), " I_1(x)", "l");
00146     leg3->AddEntry(iBessel[2]->DrawCopy("same"), " I_2(x)", "l");
00147     leg3->AddEntry(iBessel[3]->DrawCopy("same"), " I_3(x)", "l");
00148     leg3->AddEntry(iBessel[4]->DrawCopy("same"), " I_4(x)", "l");
00149 //   for(int nu = 1; nu <= 4; nu++)
00150 //   leg->AddEntry(JBessel[0]->DrawCopy("lsame"), "", "l");
00151   
00152     //iBessel[0]->Draw();
00153     leg3->Draw();
00154     p3->Draw();
00155  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00156 
00157    DistCanvas->cd(4);
00158    gPad->SetGrid();
00159    gPad->SetFrameFillColor(19);
00160    TLegend *leg4 = new TLegend(0.75, 0.7, 0.89, 0.89); 
00161 
00162   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00163    //drawing sph_bessel
00164    TF1* jBessel[5];
00165    for(int nu = 0; nu <= 4; nu++)
00166    {
00167       jBessel[nu]= new TF1("J_0", "ROOT::Math::sph_bessel([0],x)", 0, 10);
00168       jBessel[nu]->SetParameters(nu, 0.0);
00169       jBessel[nu]->SetTitle("Bessel j functions");  
00170       jBessel[nu]->SetLineStyle(1);
00171       jBessel[nu]->SetLineWidth(3);
00172       jBessel[nu]->SetLineColor(nu+1);
00173    }
00174     jBessel[0]->GetXaxis()->SetTitle("x");   
00175     jBessel[0]->GetXaxis()->SetTitleSize(0.06);
00176     jBessel[0]->GetXaxis()->SetTitleOffset(.7);
00177 
00178     //setting title
00179     TPaveLabel *p4 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,
00180        "Bessel j functions", "NDC");
00181     p4->SetFillColor(0);
00182     p4->SetTextFont(22);
00183     p4->SetTextColor(kBlack);
00184 
00185     //setting legend
00186 
00187     leg4->AddEntry(jBessel[0]->DrawCopy(), " j_0(x)", "l");
00188     leg4->AddEntry(jBessel[1]->DrawCopy("same"), " j_1(x)", "l");
00189     leg4->AddEntry(jBessel[2]->DrawCopy("same"), " j_2(x)", "l");
00190     leg4->AddEntry(jBessel[3]->DrawCopy("same"), " j_3(x)", "l");
00191     leg4->AddEntry(jBessel[4]->DrawCopy("same"), " j_4(x)", "l");
00192 
00193     leg4->Draw();
00194     p4->Draw();
00195  
00196     DistCanvas->cd();
00197 }
00198 
00199 

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