Y-axis visibility

I tried running the program below but I could not see the behavior of the graph. What could be the reason?

regards, jaybee

//=====
#include "TF1.h"
#include "Math/WrappedTF1.h"
#include "Math/GaussIntegrator.h"
#include <TGraph.h>
#include <TMultiGraph.h>

void StructurelessScatteringCrossSection()
{
 int    z1 = 2.0 / 3.0;                                         // charge of the target particle
 double z2 = 1.0;                                               // integral charge of the incident particle
 double al = 1.0 / 137.0;                                       // coupling of QED formula
 double eb = 6.0;                                               // energy of the electron beam

 double sc = 90.0;                                              // scattering angle in degrees
 double pi = TMath::Pi();                                       // value of pi
 double th = sc*pi/180.0;                                       // scattering angle in radians
 double st = sin(th/2.0);                                       // sine of scattering angle
 double ct = cos(th/2.0);                                       // cosine of scattering angle

 double mt = 0.336;                                             // mass of the target
 double qt = 1.140;                                             // momentum transfer

 double ko = (z1*z1*z2*z2*al*al) / (4.0*eb*eb*st*st*st*st);     // first coefficient
 double er = 1.0 / (1.0 + 2.0*eb*st*st/mt);                     // ratio of final and initial energy considering target recoiling

 TCanvas *c2 = new TCanvas("c2", "Electron Muon Scattering", 800, 800);
 c2->Divide(2,2);

 // ((z1*z1*z2*z2*al*al)*(1.0 - st*st - (qt*qt*st*st/(2.0*mt*mt)))) / ((4.0*eb*eb*st*st*st*st)*(1.0 + 2.0*eb*st*st/mt))
 // (([0]*[0]*[1]*[1]*[2]*[2])*(1.0 - [4]*[4] - ([6]*[6]*[4]*[4]/(2.0*[5]*[5])))) / ((4.0*[3]*[3]*[4]*[4]*[4]*[4])*(1.0 + 2.0*[3]*[4]*[4]/[5]))

 c2->cd(1);
 TF1 *f1 = new TF1("f1","([0]*[0]*[1]*[1]*[2]*[2])*(1.0 - [4]*[4] + x*x*[4]*[4]/(2.0*[5]*[5])) / ((4.0*[3]*[3]*[4]*[4]*[4]*[4])*(1.0 + 2.0*[3]*[4]*[4]/[5]))", 0.0, qt);
 f1->SetParameter(0,z1);
 f1->SetParameter(1,z2);
 f1->SetParameter(2,al);
 f1->SetParameter(3,eb);
 f1->SetParameter(4,st);
 f1->SetParameter(5,mt);
 //f1->SetParameter(6,qt);
 f1->SetLineColor(kBlue);
 f1->SetLineWidth(2);
 f1->SetTitle("Incident Beam Energy; Sine of Scattering Angle; Differential Cross Section");
 f1->Draw();
 // gPad->SetLogy(1);
 // gPad->SetLogx(1);

 c2->cd(2);
 TF1 *f2 = new TF1("f2","[0]*[1]*([2]*[2] - (x*x*[4]*[4])/(2.0*[3]*[3]))", 0.0, qt);
 f2->SetParameter(0,ko);
 f2->SetParameter(1,er);
 f2->SetParameter(2,ct);
 f2->SetParameter(3,mt);
 f2->SetParameter(4,st);
 f2->SetLineColor(kRed);
 f2->SetLineWidth(2);
 f2->SetTitle("Incident Beam Energy; Differential Cross Section");
 f2->Draw();
 // gPad->SetLogy(1);

 c2->cd(3);
 TF1 *f3 = new TF1("f3","[0]*[1]*([2]*[2] - (x*x*[4]*[4])/(2.0*[3]*[3]))", 0.0, qt);
 f3->SetParameter(0,ko);
 f3->SetParameter(1,er);
 f3->SetParameter(2,ct);
 f3->SetParameter(3,mt);
 f3->SetParameter(4,st);
 f3->SetLineColor(kBlack);
 f3->SetLineWidth(2);
 f3->SetTitle("Incident Beam Energy; Differential Cross Section");
 f3->Draw();
 // gPad->SetLogy(1);

 c2->cd(4);
 f3->Draw();
 f1->Draw("same");
 f2->Draw("same");
 // gPad->SetLogy(1);
}
//=====
double z1 = 2.0 / 3.0; // charge of the target particle

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

i missed it… sorry but thanks :slight_smile:

why is it that only one plot is shown in the down-right corner, where I was supposed to draw three plots?

#include "TF1.h"
#include "Math/WrappedTF1.h"
#include "Math/GaussIntegrator.h"
#include <TGraph.h>
#include <TMultiGraph.h>

void StructurelessScatteringCrossSection()
{
 double z1 = 2.0 / 3.0;                                         // charge of the target particle
 double z2 = 1.0;                                               // integral charge of the incident particle
 double al = 1.0 / 137.0;                                       // coupling of QED formula
 double eb = 6.5;                                               // energy of the electron beam

 double sc = 5.0;                                               // scattering angle in degrees
 double pi = TMath::Pi();                                       // value of pi
 double th = sc*pi/180.0;                                       // scattering angle in radians
 double st = sin(th/2.0);                                       // sine of scattering angle
 double ct = cos(th/2.0);                                       // cosine of scattering angle

 double mt = 0.336;                                             // mass of the target
 double qt = 1.140;                                             // momentum transfer

 double ko = (z1*z1*z2*z2*al*al) / (4.0*eb*eb*st*st*st*st);     // first coefficient
 double er = 1.0 / (1.0 + 2.0*eb*st*st/mt);                     // ratio of final and initial energy considering target recoiling

 TCanvas *c2 = new TCanvas("c2", "Electron Muon Scattering", 800, 800);
 c2->Divide(2,2);

 // ((z1*z1*z2*z2*al*al)*(1.0 - st*st - (qt*qt*st*st/(2.0*mt*mt)))) / ((4.0*eb*eb*st*st*st*st)*(1.0 + 2.0*eb*st*st/mt))
 // (([0]*[0]*[1]*[1]*[2]*[2])*(1.0 - [4]*[4] - ([6]*[6]*[4]*[4]/(2.0*[5]*[5])))) / ((4.0*[3]*[3]*[4]*[4]*[4]*[4])*(1.0 + 2.0*[3]*[4]*[4]/[5]))

 c2->cd(1);
 TF1 *f1 = new TF1("f1","([0]*[0]*[1]*[1]*[2]*[2])*(1.0 - [4]*[4] - x*x*[4]*[4]/(2.0*[5]*[5])) / ((4.0*[3]*[3]*[4]*[4]*[4]*[4])*(1.0 + 2.0*[3]*[4]*[4]/[5]))", 0.0, 1.140);
 f1->SetParameter(0,z1);
 f1->SetParameter(1,z2);
 f1->SetParameter(2,al);
 f1->SetParameter(3,2.280);     // electron beam energy
 f1->SetParameter(4,st);
 f1->SetParameter(5,mt);
 //f1->SetParameter(6,qt);
 f1->SetLineColor(kBlue);
 f1->SetLineWidth(2);
 f1->SetTitle("Electron Up-Quark Scattering; Tranfer Momentum; Differential Cross Section");
 f1->Draw();
 // gPad->SetLogy(1);
 // gPad->SetLogx(1);

 c2->cd(3);
 TF1 *f3 = new TF1("f3","([0]*[0]*[1]*[1]*[2]*[2])*(1.0 - [4]*[4] - x*x*[4]*[4]/(2.0*[5]*[5])) / ((4.0*[3]*[3]*[4]*[4]*[4]*[4])*(1.0 + 2.0*[3]*[4]*[4]/[5]))", 0.0, 2.449);
 f3->SetParameter(0,z1);
 f3->SetParameter(1,z2);
 f3->SetParameter(2,al);
 f3->SetParameter(3,4.898);     // electron beam energy
 f3->SetParameter(4,st);
 f3->SetParameter(5,mt);
 //f3->SetParameter(6,qt);
 f3->SetLineColor(kBlack);
 f3->SetLineWidth(2);
 f3->SetTitle("Electron Up-Quark Scattering; Tranfer Momentum; Differential Cross Section");
 f3->Draw();
 // gPad->SetLogy(1);

 c2->cd(4);
 f3->Draw();
 f2->Draw("same");
 f1->Draw("same");
 //gPad->SetLogy(1);
}

Try with:

 c2->cd(4);
 gPad->DrawFrame(0., 0.05, 2.45, 0.35, "Electron Up-Quark Scattering;Tranfer Momentum;Differential Cross Section");
 f3->Draw("same");
 // f2->Draw("same");
 f1->Draw("same");

muchas gracias :slight_smile:

 c2->cd(4);
 gPad->DrawFrame(0.0, 0.05, 2.50, 0.35, "Electron Up-Quark Scattering;Transfer Momentum;Differential Cross Section");
 f3->Draw("same");
 f2->Draw("same");
 f1->Draw("same");
 gPad->SetLogy(1);

but what does the first 4 arguments in the DrawFrame function mean?

regards, jaybee

Those are the limits of the x- and y-axis.
You can find further informatin here:
https://root.cern.ch/doc/master/classTPad.html#a3285f3e515108d8a41016c3359689195

For information like this I alsways suggest to look to the Class Reference guide of root, cause the documentation of root is in most cases very good.

1 Like

okay thanks for that :slight_smile:

No problem, I’m always happy to help.

I don’t get what is wrong here. Needing your help again. :slight_smile:

regards, jaybee

#include "TF1.h"
#include "Math/WrappedTF1.h"
#include "Math/GaussIntegrator.h"
#include <TGraph.h>
#include <TMultiGraph.h>

void MottScatteringCrossSection()
{
 int    csp = 1.0;                                              // charge of the scattering particle
 int    ctp = 1.0;                                              // charge of the target particle
 double alp = 1.0 / 137.0;                                      // coupling of QED formula

 double sca = 10.0;                                             // scattering angle in degrees
 double piv = TMath::Pi();                                      // value of pi
 double the = sca*piv/180.0;                                    // scattering angle in radians
 double sth = sin(the/2.0);                                     // sine of scattering angle
 double mat = 1.0;                                              // mass of target particle
 double qtm = 1.0;                                              // photonic transfer momentum

 TCanvas *c4 = new TCanvas("c4", "Mott Scattering Cross Section", 800, 800);
 c4->Divide(2,2);

 // (2.0*mat*mat*csp*csp*ctp*ctp*alp*alp)*(1.0-sth*sth) / (qtm*qtm*qtm*qtm*sth*sth*sth*sth-2.0*mat*mat*qtm*qtm*sth*sth-qtm*qtm*qtm*sth*sth*sth*sqrt(qtm*qtm*sth*sth-4.0*mat*mat))
 // (2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])*(1.0-[4]*[4]) / ([5]*[5]*[5]*[5]*[4]*[4]*[4]*[4]-2.0*[0]*[0]*[5]*[5]*[4]*[4]-[5]*[5]*[5]*[4]*[4]*[4]*sqrt([5]*[5]*[4]*[4]-4.0*[0]*[0]))

 c4->cd(1);
 TF1 *f1 = new TF1("f1","(2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])*(1.0-[4]*[4]) / (x*x*x*x*[4]*[4]*[4]*[4]-2.0*[0]*[0]*x*x*[4]*[4]-x*x*x*[4]*[4]*[4]*sqrt(x*x*[4]*[4]-4.0*[0]*[0]))", 0.0, 10.0);
 f1->SetParameter(0,mat);
 f1->SetParameter(1,csp);
 f1->SetParameter(2,ctp);
 f1->SetParameter(3,alp);
 f1->SetParameter(4,sth);
 //f1->SetParameter(5,qtm)
 f1->SetLineColor(kBlue);
 f1->SetLineWidth(2);
 f1->SetTitle("Incident Beam Energy; Differential Cross Section");
 f1->Draw();
 gPad->SetLogy(1);
 //gPad->SetLogx(1);

 c4->cd(2);
 TF1 *f2 = new TF1("f2","(2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])*(1.0-[4]*[4]) / (x*x*x*x*[4]*[4]*[4]*[4]-2.0*[0]*[0]*x*x*[4]*[4]+x*x*x*[4]*[4]*[4]*sqrt(x*x*[4]*[4]-4.0*[0]*[0]))", 0.0, 10.0);
 f2->SetParameter(0,mat);
 f2->SetParameter(1,csp);
 f2->SetParameter(2,ctp);
 f2->SetParameter(3,alp);
 f2->SetParameter(4,sth);
 //f2->SetParameter(5,qtm)
 f2->SetLineColor(kRed);
 f2->SetLineWidth(2);
 f2->SetTitle("Incident Beam Energy; Differential Cross Section");
 f2->Draw();
 gPad->SetLogy(1);
 //gPad->SetLogx(1);
c4->cd(3);
 TF1 *f3 = new TF1("f3","[0]*[1]*([2]*[2] - (x*x*[4]*[4])/(2.0*[3]*[3]))", 0.0, 10.0);
 f3->SetParameter(0,mat);
 f3->SetParameter(1,csp);
 f3->SetParameter(2,ctp);
 f3->SetParameter(3,alp);
 f3->SetParameter(4,sth);
 //f3->SetParameter(5,qtm)
 f3->SetLineColor(kBlack);
 f3->SetLineWidth(2);
 f3->SetTitle("Incident Beam Energy; Differential Cross Section");
 f3->Draw();
 //gPad->SetLogy(1);
 //gPad->SetLogx(1);

 c4->cd(4);
 f1->Draw();
 f2->Draw("same");
 f3->Draw("same");
 // gPad->SetLogy(1);
}

Could you describe the problem? What did you expect? What did the code do instead? Is there any error message?

I think the problem can be reduced to a simple question … how much is sqrt(-4.0)?

here, I did not see the first 2 plots :slight_smile:

this is the error

Warning in <TPad::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TPad::ResizePad>: c4_1 height changed from 0 to 10


 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007fe25130d07a in __GI___waitpid (pid=27282, stat_loc=stat_loc
entry=0x7ffe1a7c6040, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007fe251285fbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007fe25228c3f4 in TUnixSystem::StackTrace() () from /home/jaybee/ROOT/root-6.08.06/lib/libCore.so
#3  0x00007fe25228ea5c in TUnixSystem::DispatchSignals(ESignals) () from /home/jaybee/ROOT/root-6.08.06/lib/libCore.so
#4  <signal handler called>
#5  0x00007fe23b8a2d51 in FT_Done_Glyph () from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#6  0x00007fe23bc013d8 in TTF::LayoutGlyphs() () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#7  0x00007fe239e52f41 in TGX11TTF::DrawText(int, int, float, float, char const*, TVirtualX::ETextMode) () from /home/jaybee/ROOT/root-6.08.06/lib/libGX11TTF.so
#8  0x00007fe23befe4b0 in TPad::PaintText(double, double, char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#9  0x00007fe23bc1dcc0 in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#10 0x00007fe23bc1860f in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#11 0x00007fe23bc204dc in TLatex::PaintLatex1(double, double, double, double, char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#12 0x00007fe23bc2120f in TLatex::PaintLatex(double, double, double, double, char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#13 0x00007fe23bbef258 in TGaxis::PaintAxis(double, double, double, double, double&, double&, int&, char const*, double, bool) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#14 0x00007fe238c00057 in THistPainter::PaintAxis(bool) () from /home/jaybee/ROOT/root-6.08.06/lib/libHistPainter.so
#15 0x00007fe238bf736d in THistPainter::Paint(char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libHistPainter.so
#16 0x00007fe23c60296f in TF1::Paint(char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libHist.so
#17 0x00007fe23bf1a4fb in TPad::PaintModified() () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#18 0x00007fe23bf1a434 in TPad::PaintModified() () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#19 0x00007fe23bf3d79d in TCanvas::Update() () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#20 0x00007fe24d9d9219 in TCling::UpdateAllCanvases() () from /home/jaybee/ROOT/root-6.08.06/lib/libCling.so
#21 0x00007fe24d9df3a4 in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/jaybee/ROOT/root-6.08.06/lib/libCling.so
#22 0x00007fe24d9d1e07 in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/jaybee/ROOT/root-6.08.06/lib/libCling.so
#23 0x00007fe251ddd19b in TRint::HandleTermInput() () from /home/jaybee/ROOT/root-6.08.06/lib/libRint.so
#24 0x00007fe25228df4c in TUnixSystem::CheckDescriptors() () from /home/jaybee/ROOT/root-6.08.06/lib/libCore.so
#25 0x00007fe25228f38a in TUnixSystem::DispatchOneEvent(bool) () from /home/jaybee/ROOT/root-6.08.06/lib/libCore.so
#26 0x00007fe252214a64 in TSystem::InnerLoop() () from /home/jaybee/ROOT/root-6.08.06/lib/libCore.so
#27 0x00007fe25221359f in TSystem::Run() () from /home/jaybee/ROOT/root-6.08.06/lib/libCore.so
#28 0x00007fe2522232df in TApplication::Run(bool) () from /home/jaybee/ROOT/root-6.08.06/lib/libCore.so
#29 0x00007fe251dde807 in TRint::Run(bool) () from /home/jaybee/ROOT/root-6.08.06/lib/libRint.so
#30 0x000000000040106c in main ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007fe23b8a2d51 in FT_Done_Glyph () from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#6  0x00007fe23bc013d8 in TTF::LayoutGlyphs() () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#7  0x00007fe239e52f41 in TGX11TTF::DrawText(int, int, float, float, char const*, TVirtualX::ETextMode) () from /home/jaybee/ROOT/root-6.08.06/lib/libGX11TTF.so
#8  0x00007fe23befe4b0 in TPad::PaintText(double, double, char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#9  0x00007fe23bc1dcc0 in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#10 0x00007fe23bc1860f in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#11 0x00007fe23bc204dc in TLatex::PaintLatex1(double, double, double, double, char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#12 0x00007fe23bc2120f in TLatex::PaintLatex(double, double, double, double, char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#13 0x00007fe23bbef258 in TGaxis::PaintAxis(double, double, double, double, double&, double&, int&, char const*, double, bool) () from /home/jaybee/ROOT/root-6.08.06/lib/libGraf.so
#14 0x00007fe238c00057 in THistPainter::PaintAxis(bool) () from /home/jaybee/ROOT/root-6.08.06/lib/libHistPainter.so
#15 0x00007fe238bf736d in THistPainter::Paint(char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libHistPainter.so
#16 0x00007fe23c60296f in TF1::Paint(char const*) () from /home/jaybee/ROOT/root-6.08.06/lib/libHist.so
#17 0x00007fe23bf1a4fb in TPad::PaintModified() () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#18 0x00007fe23bf1a434 in TPad::PaintModified() () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#19 0x00007fe23bf3d79d in TCanvas::Update() () from /home/jaybee/ROOT/root-6.08.06/lib/libGpad.so
#20 0x00007fe24d9d9219 in TCling::UpdateAllCanvases() () from /home/jaybee/ROOT/root-6.08.06/lib/libCling.so
===========================================================


Root > Warning in <TPad::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TPad::ResizePad>: c4_1 height changed from 0 to 10

Warning in <TPad::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TPad::ResizePad>: c4_1 height changed from 0 to 10

What is the source of that Wile? It is not that clear to me :slight_smile:

Comment out all: gPad->SetLogy(1);

okay, i will do it and i’ll see…

I could see no plots either…

Use proper domains for your functions, e.g. instead of “0.0, 10.0.” try “23.0, 100.0”.

i tried 0.0, 100.0 until 1000000000.0 but no plot is seen still… :slight_smile: