Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
pdf009_Bessel.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_pdf
3/// \notebook
4/// Show the different kinds of Bessel functions available in ROOT
5/// To execute the macro type in:
6///
7/// ~~~{.cpp}
8/// root[0] .x Bessel.C
9/// ~~~
10///
11/// It will create one canvas with the representation
12/// of the cylindrical and spherical Bessel functions
13/// regular and modified
14///
15/// \macro_image
16/// \macro_code
17///
18/// \author Magdalena Slawinska
19
20#include "TMath.h"
21#include "TF1.h"
22#include "TCanvas.h"
23
24#include "TLegend.h"
25#include "TLegendEntry.h"
26
27#include "Math/IFunction.h"
28#include <cmath>
29#include "TSystem.h"
30#include "TAxis.h"
31#include "TPaveLabel.h"
32
33void pdf009_Bessel()
34{
35 TCanvas *DistCanvas = new TCanvas("DistCanvas", "Bessel functions example", 10, 10, 800, 600);
36 DistCanvas->SetFillColor(17);
37 DistCanvas->Divide(2, 2);
38 DistCanvas->cd(1);
39 gPad->SetGrid();
40 gPad->SetFrameFillColor(19);
41 TLegend *leg = new TLegend(0.75, 0.7, 0.89, 0.89);
42
43 int n = 5; //number of functions in each pad
44 //drawing the set of Bessel J functions
45 TF1* JBessel[5];
46 for(int nu = 0; nu < n; nu++)
47 {
48 JBessel[nu]= new TF1("J_0", "ROOT::Math::cyl_bessel_j([0],x)", 0, 10);
49 JBessel[nu]->SetParameters(nu, 0.0);
50 JBessel[nu]->SetTitle(""); //Bessel J functions");
51 JBessel[nu]->SetLineStyle(kSolid);
52 JBessel[nu]->SetLineWidth(3);
53 JBessel[nu]->SetLineColor(nu+1);
54 }
55 JBessel[0]->TF1::GetXaxis()->SetTitle("x");
56 JBessel[0]->GetXaxis()->SetTitleSize(0.06);
57 JBessel[0]->GetXaxis()->SetTitleOffset(.7);
58
59 //setting the title in a label style
60 TPaveLabel *p1 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) , "Bessel J functions", "NDC");
61 p1->SetFillColor(0);
62 p1->SetTextFont(22);
63 p1->SetTextColor(kBlack);
64
65 //setting the legend
66 leg->AddEntry(JBessel[0]->DrawCopy(), " J_0(x)", "l");
67 leg->AddEntry(JBessel[1]->DrawCopy("same"), " J_1(x)", "l");
68 leg->AddEntry(JBessel[2]->DrawCopy("same"), " J_2(x)", "l");
69 leg->AddEntry(JBessel[3]->DrawCopy("same"), " J_3(x)", "l");
70 leg->AddEntry(JBessel[4]->DrawCopy("same"), " J_4(x)", "l");
71
72 leg->Draw();
73 p1->Draw();
74
75 //------------------------------------------------
76 DistCanvas->cd(2);
77 gPad->SetGrid();
78 gPad->SetFrameFillColor(19);
79
80 TLegend *leg2 = new TLegend(0.75, 0.7, 0.89, 0.89);
81 //------------------------------------------------
82 //Drawing Bessel k
83 TF1* KBessel[5];
84 for(int nu = 0; nu < n; nu++){
85 KBessel[nu]= new TF1("J_0", "ROOT::Math::cyl_bessel_k([0],x)", 0, 10);
86 KBessel[nu]->SetParameters(nu, 0.0);
87 KBessel[nu]->SetTitle("Bessel K functions");
88 KBessel[nu]->SetLineStyle(kSolid);
89 KBessel[nu]->SetLineWidth(3);
90 KBessel[nu]->SetLineColor(nu+1);
91 }
92 KBessel[0]->GetXaxis()->SetTitle("x");
93 KBessel[0]->GetXaxis()->SetTitleSize(0.06);
94 KBessel[0]->GetXaxis()->SetTitleOffset(.7);
95
96 //setting title
97 TPaveLabel *p2 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) , "Bessel K functions", "NDC");
98 p2->SetFillColor(0);
99 p2->SetTextFont(22);
100 p2->SetTextColor(kBlack);
101
102 //setting legend
103 leg2->AddEntry(KBessel[0]->DrawCopy(), " K_0(x)", "l");
104 leg2->AddEntry(KBessel[1]->DrawCopy("same"), " K_1(x)", "l");
105 leg2->AddEntry(KBessel[2]->DrawCopy("same"), " K_2(x)", "l");
106 leg2->AddEntry(KBessel[3]->DrawCopy("same"), " K_3(x)", "l");
107 leg2->AddEntry(KBessel[4]->DrawCopy("same"), " K_4(x)", "l");
108 leg2->Draw();
109 p2->Draw();
110 //------------------------------------------------
111 DistCanvas->cd(3);
112 gPad->SetGrid();
113 gPad->SetFrameFillColor(19);
114 TLegend *leg3 = new TLegend(0.75, 0.7, 0.89, 0.89);
115 //------------------------------------------------
116 //Drawing Bessel i
117 TF1* iBessel[5];
118 for(int nu = 0; nu <= 4; nu++){
119 iBessel[nu]= new TF1("J_0", "ROOT::Math::cyl_bessel_i([0],x)", 0, 10);
120 iBessel[nu]->SetParameters(nu, 0.0);
121 iBessel[nu]->SetTitle("Bessel I functions");
122 iBessel[nu]->SetLineStyle(kSolid);
123 iBessel[nu]->SetLineWidth(3);
124 iBessel[nu]->SetLineColor(nu+1);
125 }
126
127 iBessel[0]->GetXaxis()->SetTitle("x");
128 iBessel[0]->GetXaxis()->SetTitleSize(0.06);
129 iBessel[0]->GetXaxis()->SetTitleOffset(.7);
130
131 //setting title
132 TPaveLabel *p3 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,"Bessel I functions", "NDC");
133 p3->SetFillColor(0);
134 p3->SetTextFont(22);
135 p3->SetTextColor(kBlack);
136
137 //setting legend
138 leg3->AddEntry(iBessel[0]->DrawCopy(), " I_0", "l");
139 leg3->AddEntry(iBessel[1]->DrawCopy("same"), " I_1(x)", "l");
140 leg3->AddEntry(iBessel[2]->DrawCopy("same"), " I_2(x)", "l");
141 leg3->AddEntry(iBessel[3]->DrawCopy("same"), " I_3(x)", "l");
142 leg3->AddEntry(iBessel[4]->DrawCopy("same"), " I_4(x)", "l");
143 leg3->Draw();
144 p3->Draw();
145 //------------------------------------------------
146 DistCanvas->cd(4);
147 gPad->SetGrid();
148 gPad->SetFrameFillColor(19);
149 TLegend *leg4 = new TLegend(0.75, 0.7, 0.89, 0.89);
150 //------------------------------------------------
151 //Drawing sph_bessel
152 TF1* jBessel[5];
153 for(int nu = 0; nu <= 4; nu++){
154 jBessel[nu]= new TF1("J_0", "ROOT::Math::sph_bessel([0],x)", 0, 10);
155 jBessel[nu]->SetParameters(nu, 0.0);
156 jBessel[nu]->SetTitle("Bessel j functions");
157 jBessel[nu]->SetLineStyle(kSolid);
158 jBessel[nu]->SetLineWidth(3);
159 jBessel[nu]->SetLineColor(nu+1);
160 }
161 jBessel[0]->GetXaxis()->SetTitle("x");
162 jBessel[0]->GetXaxis()->SetTitleSize(0.06);
163 jBessel[0]->GetXaxis()->SetTitleOffset(.7);
164
165 //setting title
166 TPaveLabel *p4 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,"Bessel j functions", "NDC");
167 p4->SetFillColor(0);
168 p4->SetTextFont(22);
169 p4->SetTextColor(kBlack);
170
171 //setting legend
172
173 leg4->AddEntry(jBessel[0]->DrawCopy(), " j_0(x)", "l");
174 leg4->AddEntry(jBessel[1]->DrawCopy("same"), " j_1(x)", "l");
175 leg4->AddEntry(jBessel[2]->DrawCopy("same"), " j_2(x)", "l");
176 leg4->AddEntry(jBessel[3]->DrawCopy("same"), " j_3(x)", "l");
177 leg4->AddEntry(jBessel[4]->DrawCopy("same"), " j_4(x)", "l");
178
179 leg4->Draw();
180 p4->Draw();
181
182 DistCanvas->cd();
183}
@ kBlack
Definition Rtypes.h:65
@ kSolid
Definition TAttLine.h:54
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gPad
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:182
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
const Int_t n
Definition legend1.C:16
leg
Definition legend1.C:34