ROOT
v6-28
Reference Guide
Loading...
Searching...
No Matches
waves.C File Reference
Tutorials
»
Graphs tutorials
Detailed Description
Hint: Spherical waves
#include "
TROOT.h
"
#include "
TCanvas.h
"
#include "
TColor.h
"
#include "
TArc.h
"
#include "
TGraph.h
"
#include "
TF2.h
"
#include "
TLine.h
"
#include "
TLatex.h
"
#include "
TMath.h
"
#include "
TStyle.h
"
//______________________________________________________________
Double_t
interference(
Double_t
*
x
,
Double_t
*par)
{
Double_t
x_p2 =
x
[0] *
x
[0];
Double_t
d_2 = 0.5 * par[2];
Double_t
ym_p2 = (
x
[1] - d_2) * (
x
[1] - d_2);
Double_t
yp_p2 = (
x
[1] + d_2) * (
x
[1] + d_2);
Double_t
tpi_l =
TMath::Pi
() / par[1];
Double_t
amplitude = par[0] * (cos(tpi_l * sqrt(x_p2 + ym_p2))
+ par[3] * cos(tpi_l * sqrt(x_p2 + yp_p2)));
return
amplitude * amplitude;
}
//_____________________________________________________________
Double_t
result
(
Double_t
*
x
,
Double_t
*par)
{
Double_t
xint[2];
Double_t
maxintens = 0, xcur = 14;
Double_t
dlambda = 0.1 * par[1];
for
(
Int_t
i=0; i<10; i++){
xint[0] = xcur;
xint[1] =
x
[1];
Double_t
intens = interference(xint, par);
if
(intens > maxintens) maxintens = intens;
xcur -= dlambda;
}
return
maxintens;
}
//_____________________________________________________________
void
waves(
Double_t
d
= 3,
Double_t
lambda = 1,
Double_t
amp = 10)
{
TCanvas
*
c1
=
new
TCanvas
(
"waves"
,
"A double slit experiment"
, 300, 40, 1004, 759);
c1
->Range(0, -10, 30, 10);
c1
->SetFillColor(0);
TPad
*pad =
new
TPad
(
"pr"
,
"pr"
, 0.5, 0 , 1., 1);
pad->
Range
(0, -10, 15, 10);
pad->
Draw
();
const
Int_t
colNum = 30;
Int_t
palette[colNum];
for
(
Int_t
i=0;i<colNum;i++) {
Float_t
level = 1.*i/colNum;
palette[i] =
TColor::GetColor
((
Float_t
)
TMath::Power
(level,0.3), (
Float_t
)
TMath::Power
(level,0.3), (
Float_t
) 0.5*level);
// palette[i] = 1001+i;
}
gStyle
->
SetPalette
(colNum, palette);
c1
->cd();
TF2
*f0 =
new
TF2
(
"ray_source"
,interference, 0.02, 15, -8, 8, 4);
f0->
SetParameters
(amp, lambda, 0, 0);
f0->
SetNpx
(200);
f0->
SetNpy
(200);
f0->
SetContour
(colNum-2);
f0->
Draw
(
"samecol"
);
TLatex
title;
title.
DrawLatex
(1.6, 8.5,
"A double slit experiment"
);
TGraph
*
graph
=
new
TGraph
(4);
graph
->SetFillColor(0);
graph
->SetFillStyle(1001);
graph
->SetLineWidth(0);
graph
->SetPoint(0, 0., 0.1);
graph
->SetPoint(1, 14.8, 8);
graph
->SetPoint(2, 0, 8);
graph
->SetPoint(3, 0, 0.1);
graph
->Draw(
"F"
);
graph
=
new
TGraph
(4);
graph
->SetFillColor(0);
graph
->SetFillStyle(1001);
graph
->SetLineWidth(0);
graph
->SetPoint(0, 0, -0.1);
graph
->SetPoint(1, 14.8, -8);
graph
->SetPoint(2, 0, -8);
graph
->SetPoint(3, 0, -0.1);
graph
->Draw(
"F"
);
TLine
*
line
=
new
TLine
(15,-10, 15, 0 - 0.5*
d
-0.2);
line
->
SetLineWidth
(10);
line
->
Draw
();
line
=
new
TLine
(15, 0 - 0.5*
d
+0.2 ,15, 0 + 0.5*
d
-0.2);
line
->
SetLineWidth
(10);
line
->
Draw
();
line
=
new
TLine
(15,0 + 0.5*
d
+ 0.2,15, 10);
line
->
SetLineWidth
(10);
line
->
Draw
();
pad ->
cd
();
TF2
*finter =
new
TF2
(
"interference"
,interference, 0.01, 14, -10, 10, 4);
finter->
SetParameters
(amp, lambda,
d
, 1);
finter->
SetNpx
(200);
finter->
SetNpy
(200);
finter->
SetContour
(colNum-2);
finter->
Draw
(
"samecol"
);
TArc
arc;
arc.
SetFillStyle
(0);
arc.
SetLineWidth
(2);
arc.
SetLineColor
(5);
Float_t
r
= 0.5 * lambda, dr = lambda;
for
(
Int_t
i = 0; i < 16; i++) {
arc.
DrawArc
(0, 0.5*
d
,
r
, 0., 360.,
"only"
);
arc.
DrawArc
(0, -0.5*
d
,
r
, 0., 360.,
"only"
);
r
+= dr;
}
pad ->
cd
();
TF2
*fresult =
new
TF2
(
"result"
,
result
, 14, 15, -10, 10, 4);
fresult->
SetParameters
(amp, lambda,
d
, 1);
fresult->
SetNpx
(300);
fresult->
SetNpy
(300);
fresult->
SetContour
(colNum-2);
fresult->
Draw
(
"samecol"
);
line
=
new
TLine
(13.8,-10, 14, 10);
line
->
SetLineWidth
(10);
line
->
SetLineColor
(0);
line
->
Draw
();
c1
->Modified(
kTRUE
);
c1
->Update();
c1
->SetEditable(
kTRUE
);
}
d
#define d(i)
Definition
RSha256.hxx:102
Int_t
int Int_t
Definition
RtypesCore.h:45
Float_t
float Float_t
Definition
RtypesCore.h:57
Double_t
double Double_t
Definition
RtypesCore.h:59
kTRUE
constexpr Bool_t kTRUE
Definition
RtypesCore.h:100
TArc.h
TCanvas.h
TColor.h
TF2.h
r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Definition
TGWin32VirtualXProxy.cxx:168
result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Definition
TGWin32VirtualXProxy.cxx:174
TGraph.h
TLatex.h
TLine.h
TMath.h
TROOT.h
TStyle.h
gStyle
R__EXTERN TStyle * gStyle
Definition
TStyle.h:414
TArc
Create an Arc.
Definition
TArc.h:26
TArc::DrawArc
virtual TArc * DrawArc(Double_t x1, Double_t y1, Double_t radius, Double_t phimin=0, Double_t phimax=360, Option_t *option="")
Draw this arc with new coordinates.
Definition
TArc.cxx:79
TAttFill::SetFillStyle
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition
TAttFill.h:39
TAttLine::SetLineWidth
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition
TAttLine.h:43
TAttLine::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition
TAttLine.h:40
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TColor::GetColor
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition
TColor.cxx:1823
TF1::SetNpx
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition
TF1.cxx:3431
TF1::SetParameters
virtual void SetParameters(const Double_t *params)
Definition
TF1.h:649
TF2
A 2-Dim function with parameters.
Definition
TF2.h:29
TF2::SetContour
virtual void SetContour(Int_t nlevels=20, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition
TF2.cxx:885
TF2::SetNpy
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition
TF2.cxx:920
TF2::Draw
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition
TF2.cxx:259
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition
TGraph.h:41
TLatex
To draw Mathematical Formula.
Definition
TLatex.h:18
TLatex::DrawLatex
TLatex * DrawLatex(Double_t x, Double_t y, const char *text)
Make a copy of this object with the new parameters And copy object attributes.
Definition
TLatex.cxx:1928
TLine
Use the TLine constructor to create a simple line.
Definition
TLine.h:22
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition
TObject.cxx:274
TPad
The most important graphics class in the ROOT system.
Definition
TPad.h:28
TPad::Range
void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Set world coordinate system for the pad.
Definition
TPad.cxx:5193
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition
TPad.cxx:597
TPad::Draw
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition
TPad.cxx:1268
TStyle::SetPalette
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition
TStyle.cxx:1781
line
TLine * line
Definition
entrylistblock_figure1.C:235
c1
return c1
Definition
legend1.C:41
x
Double_t x[n]
Definition
legend1.C:17
TMath::Power
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition
TMath.h:719
TMath::Pi
constexpr Double_t Pi()
Definition
TMath.h:37
graph
Definition
graph.py:1
Author
Otto Schaile
Definition in file
waves.C
.
tutorials
graphs
waves.C
ROOT v6-28 - Reference Guide Generated on Thu Oct 24 2024 01:50:18 (GVA Time) using Doxygen 1.9.8