00001
00002
00003
00004 #include "TROOT.h"
00005 #include "TCanvas.h"
00006 #include "TColor.h"
00007 #include "TArc.h"
00008 #include "TGraph.h"
00009 #include "TF2.h"
00010 #include "TLine.h"
00011 #include "TLatex.h"
00012 #include "TMath.h"
00013 #include "TStyle.h"
00014 #include "Riostream.h"
00015
00016 TF2 * finter;
00017
00018
00019
00020 Double_t interference( Double_t *x, Double_t *par)
00021 {
00022 Double_t x_p2 = x[0] * x[0];
00023 Double_t d_2 = 0.5 * par[2];
00024 Double_t ym_p2 = (x[1] - d_2) * (x[1] - d_2);
00025 Double_t yp_p2 = (x[1] + d_2) * (x[1] + d_2);
00026 Double_t tpi_l = TMath::Pi() / par[1];
00027 Double_t amplitude = par[0] * (cos(tpi_l * sqrt(x_p2 + ym_p2))
00028 + par[3] * cos(tpi_l * sqrt(x_p2 + yp_p2)));
00029 return amplitude * amplitude;
00030 }
00031
00032
00033
00034 Double_t result( Double_t *x, Double_t *par)
00035 {
00036 Double_t xint[2];
00037 Double_t maxintens = 0, xcur = 14;
00038 Double_t dlambda = 0.1 * par[1];
00039 for(Int_t i=0; i<10; i++){
00040 xint[0] = xcur;
00041 xint[1] = x[1];
00042 Double_t intens = interference(xint, par);
00043 if(intens > maxintens) maxintens = intens;
00044 xcur -= dlambda;
00045 }
00046 return maxintens;
00047 }
00048
00049
00050
00051 void waves( Double_t d = 3, Double_t lambda = 1, Double_t amp = 10)
00052 {
00053 TCanvas *c1 = new TCanvas("waves", "A double slit experiment",
00054 300,40, 1004, 759);
00055 c1->Range(0, -10, 30, 10);
00056 c1->SetFillColor(0);
00057 TPad *pad = new TPad("pr","pr", 0.5, 0 , 1., 1);
00058 pad->Range(0, -10, 15, 10);
00059 pad->Draw();
00060
00061 const Int_t colNum = 30;
00062 Int_t palette[colNum];
00063 for (Int_t i=0;i<colNum;i++) {
00064 TColor *color = new TColor(1001+i
00065 , pow(i/((colNum)*1.0),0.3)
00066 , pow(i/((colNum)*1.0),0.3)
00067 ,0.5*(i/((colNum)*1.0)),"");
00068 palette[i] = 1001+i;
00069 if(color);
00070 }
00071 gStyle->SetPalette(colNum,palette);
00072 c1->cd();
00073 TF2 * f0 = new TF2("ray_source",interference, 0.02, 15, -8, 8, 4);
00074
00075 f0->SetParameters(amp, lambda, 0, 0);
00076 f0->SetNpx(200);
00077 f0->SetNpy(200);
00078 f0->SetContour(colNum-2);
00079 f0->Draw("samecolz");
00080
00081 TLatex title;
00082 title.DrawLatex(1.6, 8.5, "A double slit experiment");
00083
00084 TGraph *graph = new TGraph(4);
00085 graph->SetFillColor(0);
00086 graph->SetFillStyle(1001);
00087 graph->SetLineWidth(0);
00088 graph->SetPoint(0, 0., 0.1);
00089 graph->SetPoint(1, 14.8, 8);
00090 graph->SetPoint(2, 0, 8);
00091 graph->SetPoint(3, 0, 0.1);
00092 graph->Draw("F");
00093
00094 graph = new TGraph(4);
00095 graph->SetFillColor(0);
00096 graph->SetFillStyle(1001);
00097 graph->SetLineWidth(0);
00098 graph->SetPoint(0, 0, -0.1);
00099 graph->SetPoint(1, 14.8, -8);
00100 graph->SetPoint(2, 0, -8);
00101 graph->SetPoint(3, 0, -0.1);
00102 graph->Draw("F");
00103
00104 TLine * line;
00105 line = new TLine(15,-10, 15, 0 - 0.5*d -0.2);
00106 line->SetLineWidth(10); line->Draw();
00107 line = new TLine(15, 0 - 0.5*d +0.2 ,15, 0 + 0.5*d -0.2);
00108 line->SetLineWidth(10); line->Draw();
00109
00110 line = new TLine(15,0 + 0.5*d + 0.2,15, 10);
00111 line->SetLineWidth(10); line->Draw();
00112
00113 pad ->cd();
00114 finter = new TF2("interference",interference, 0.01, 14, -10, 10, 4);
00115
00116 finter->SetParameters(amp, lambda, d, 1);
00117 finter->SetNpx(200);
00118 finter->SetNpy(200);
00119 finter->SetContour(colNum-2);
00120 finter->Draw("samecolorz");
00121
00122 TArc *arc = new TArc();;
00123 arc->SetFillStyle(0);
00124 arc->SetLineWidth(2);
00125 arc->SetLineColor(5);
00126 Float_t r = 0.5 * lambda, dr = lambda;
00127 for (Int_t i = 0; i < 16; i++) {
00128 arc->DrawArc(0, 0.5*d, r, 0., 360., "only");
00129 arc->DrawArc(0, -0.5*d, r, 0., 360., "only");
00130 r += dr;
00131 }
00132
00133 pad ->cd();
00134 TF2 * fresult = new TF2("result",result, 14, 15, -10, 10, 4);
00135
00136 fresult->SetParameters(amp, lambda, d, 1);
00137 fresult->SetNpx(300);
00138 fresult->SetNpy(300);
00139 fresult->SetContour(colNum-2);
00140 fresult->Draw("samecolor");
00141 line = new TLine(13.8,-10, 14, 10);
00142 line->SetLineWidth(10); line->SetLineColor(0); line->Draw();
00143 c1->Modified(kTRUE);
00144 c1->Update();
00145 c1->SetEditable(kTRUE);
00146 }