# Producing a Graph of Eta vs Polar Angle

Good morning everyone, I have just started using ROOT so am a complete newb with regards to ROOT and C/C++. As an initial exercise I am trying to produce a plot of eta versus polar angle. I have been reading through all the instruction manuals closely including the sections on polar graphs but am finding it all a bit difficult to understand as I am so new to this, I was wondering if someone could give me some pointers as to how I might go about writing some code to produce a plot of this kind, any guidance would be appreciated and apologies if this is an extremely basic question.

You can find an example showing how to use polygraph here:
https://root.cern.ch/doc/master/classTGraphPolar.html

Many thanks for your response. I am not sure if I am meant to be drawing a polar graph as I am trying to draw a graph of eta as it depends on polar angle as an exercise (ie. eta vs polar angle), apologies to ask a dumb question again but is eta a variable of some significance in particle physics?

You can use TGraph may be ? TGraph allows to draw one variable versus an other.
There is an example here:
https://root.cern/doc/master/classTGraph.html

Eta in particle physics represents pseudorapidity and in particle physics is used to describing the angle of a particle relative to the beam axis.
This variable is used instead of theta because in invariant for Lorentz boost along the beam line, this is valid only in the relativistic regime (which is usually the case in particle physics), otherwise you should use rapidity y.
https://en.wikipedia.org/wiki/Pseudorapidity
https://en.wikipedia.org/wiki/Rapidity

2 Likes
``````{
// https://en.wikipedia.org/wiki/Pseudorapidity

double t[] =
{0.1, 0.5, 1., 2., 5., 10., 20., 30., 45., 60., 80., 90.,
100., 120., 135., 150., 160., 170., 175., 178., 179., 179.5, 179.9};
double e[] =
{7.04, 5.43, 4.74, 4.05, 3.13, 2.44, 1.74, 1.32, 0.88, 0.55, 0.157, 0.,
-0.175, -0.55, -0.88, -1.32, -1.74, -2.44, -3.13, -4.05, -4.74, -5.43, -7.04};
if (sizeof(t) != sizeof(e)) return; // just a precaution
TGraph *g = new TGraph((sizeof(t) / sizeof(double)), t, e);
g->SetTitle("A plot of polar angle vs. pseudorapidity.;#theta [deg];#eta");
g->GetXaxis()->SetLimits(0., 180.);
g->GetXaxis()->CenterTitle(kTRUE);
g->GetYaxis()->CenterTitle(kTRUE);
g->SetLineColor(kRed);
g->SetLineWidth(2);

TF1 *eta = new TF1("eta",
"- TMath::Log(TMath::Tan(x / 2. * TMath::DegToRad()))",
0.01, 179.99); // x = "theta [deg]", returns "eta"
eta->SetNpx(1000);
eta->SetLineColor(kRed);
eta->SetLineWidth(2);

std::cout << "eta(10. [deg]) = " << eta->Eval(10.) << std::endl;

TF1 *theta = new TF1("theta",
"2. * TMath::ATan(TMath::Exp(- x)) * TMath::RadToDeg()",
-10., 10.); // x = "eta", returns "theta [deg]"
theta->SetNpx(1000);
theta->SetLineColor(kRed);
theta->SetLineWidth(2);

std::cout << "theta(1.) = " << theta->Eval(1.) << " [deg]" << std::endl;

TCanvas *c = new TCanvas("c", "c", 500, 750);
c->Divide(1, 3);
c->cd(1);
g->Draw("AL"); // ("AL") or ("AC")
c->cd(2);
eta->Draw("L"); // ("L") or ("C")