Hi, I have this problem, I’m trying to program the Klein-Nishina formula and to compare different energies in the same Canvas, how you know it is a Polar plot, but when I change the parameter of a draw the others drawings change. I don’t find the mistake.
Thanks.
#include <vector>
#include <string>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <TMath.h>
#include <TGraphPolar.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TLegend.h>
#include <TAxis.h>
#include <TLatex.h>
int main(){
double min=0;
double max=2*TMath::Pi();
int nsteps =1000 ;
double x,ep,S,P;
double r[nsteps], phi[nsteps];;
TCanvas *CPol= new TCanvas("CPol","TGraphPolar",600,600);
CPol->cd();
ep=1000./511.; //If I change this for example to 2/511 the others drawings change. why?
for (int i = 0; i < nsteps; i++){
x= min+i*(max-min)/nsteps;
phi[i]=x;
S= 1-cos(x);
P=1/(1+ep*S);
r[i] = (0.0397)*(pow(P,2))*(-pow(TMath::Sin(x),2)+P +(1/P)) ;
}
TGraphPolar grP(nsteps,phi,r);
grP.SetMarkerStyle(10);
grP.SetMarkerSize(0.3);
grP.SetMarkerColor(2);
grP.SetTitle("");
grP.Draw("cp");
ep=511/511.;
for (int i = 0; i < nsteps; i++){
x= min+i*(max-min)/nsteps;
phi[i]=x;
S= 1-TMath::Cos(x);
P=1/(1+ep*S);
r[i] = (0.0794/2.)*(pow(P,2))*(-pow(TMath::Sin(x),2) +P +(1/P)) ;
}
TGraphPolar grP1(nsteps,phi,r);
grP1.SetMarkerStyle(10);
grP1.SetMarkerSize(0.3);
grP1.SetMarkerColor(3);
grP1.SetTitle("");
grP1.Draw("cp");
ep=170/511.;
for (int i = 0; i < nsteps; i++){
x= min+i*(max-min)/nsteps;
phi[i]=x;
S= 1-TMath::Cos(x);
P=1/(1+ep*S);
r[i] = (0.0794/2.)*(pow(P,2))*(-pow(TMath::Sin(x),2) +P +(1/P)) ;
}
TGraphPolar grP2(nsteps,phi,r);
grP2.SetMarkerStyle(10);
grP2.SetMarkerSize(0.3);
grP2.SetMarkerColor(4);
grP2.SetTitle("");
grP2.Draw("cp");
ep=10/511.;
for (int i = 0; i < nsteps; i++){
x= min+i*(max-min)/nsteps;
phi[i]=x;
S= 1-TMath::Cos(x);
P=1/(1+ep*S);
r[i] = (0.0794/2.)*(pow(P,2))*(-pow(TMath::Sin(x),2) +P +(1/P)) ;
}
TGraphPolar grP3(nsteps,phi,r);
grP3.SetMarkerStyle(10);
grP3.SetMarkerSize(0.3);
grP3.SetTitle("");
grP3.Draw("cp");
ep=10000/511.;
for (int i = 0; i < nsteps; i++){
x= min+i*(max-min)/nsteps;
phi[i]=x;
S= 1-TMath::Cos(x);
P=1/(1+ep*S);
r[i] = (0.0794/2.)*(pow(P,2.))*(-pow(TMath::Sin(x),2) +P +(1/P)) ;
}
TGraphPolar grP4(nsteps,phi,r);
grP4.SetMarkerStyle(10);
grP4.SetMarkerSize(0.3);
grP4.SetMarkerColor(6);
grP4.SetTitle("");
grP4.Draw("cp");
CPol->Update();
grP4.GetPolargram()->SetTextColor(8);
grP4.GetPolargram()->SetNdivPolar(112);
grP4.GetPolargram()->SetNdivRadial(606);
grP4.GetPolargram()->SetToRadian();
TLegend leg( 0.8,0.8,0.99,0.99,"");
leg.AddEntry((TObject*)0, "", "");
leg.AddEntry((TObject*)0, "#frac{d#sigma}{d#Omega}(#theta) [barn]", "");
leg.AddEntry((TObject*)0, "", "");
leg.AddEntry( &grP4, "10000 keV", "p");
leg.AddEntry( &grP, "1000 keV", "p");
leg.AddEntry( &grP1, "511 keV" , "p");
leg.AddEntry( &grP2, "170 keV" , "p");
leg.AddEntry( &grP3, "10 keV" , "p");
leg.Draw("SAME");
CPol->Print( "Klein6.pdf" );
return 0;
}