Plotting points on the graph

hi :slight_smile: i intend to plot points in TGraph with some part of the code:

 TF1 *f1 = new TF1("f1","(((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)), 0.0025, 1.0);
 f1->SetParameter(0,1.0);
 f1->SetParameter(1,1.0);
 f1->SetParameter(2,1.0/137.0);
 f1->SetParameter(3,gRandom->Gaus(0.938272081,0.000000023));
 f1->SetParameter(4,10.0);
 f1->SetParameter(5,TMath::Pi());
 f1->SetParameter(7,2.793);
 f1->SetLineColor(kBlue);
 f1->SetLineWidth(2);

 //auto av3 = new TGraph(nop);
 TGraph *av3 = new TGraph();
 TGraph *av3 = new TGraph();
 Double_t xpt, ypt;

 av3->GetPoint(1, xpt, ypt);
 av3->SetPoint(1, 0.40, f1->Eval(0.40));

but i got an error…

In file included from input_line_12:1:
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:98:25: warning: missing terminating '"' character [-Winvalid-pp-token]
 TF1 *f1 = new TF1("f1","(((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*si...
                        ^
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:98:25: error: expected expression
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:113:2: error: use of undeclared identifier 'av3'
 av3->GetPoint(1, xpt, ypt);
 ^
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:114:2: error: use of undeclared identifier 'av3'
 av3->SetPoint(1, 0.40, f1->Eval(0.40));
 ^
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:151:11: error: use of undeclared identifier 'av3'
 mgp->Add(av3,"PL");

how will i make this work? please help :slight_smile:

regards,
jaybee

Start with fixing:

(…) missing terminating ‘"’ character (…)

BTW. Graph points are numbered from 0.

gracias :slight_smile:

with reference to a part of a code below:

 Int_t nop=100;
 Double_t xpt, ypt, del = 0.9975/nop;
 Int_t k;

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  //xpt = del*j;
  av1->SetPoint(j, xpt, 0.0);
 }

 for (Int_t i=0; i<nof; i++)
 {
  for (Int_t j=0; j < nop; j++)
  {
   av1->GetPoint(j, xpt, ypt);
   av1->SetPoint(j, xpt, ypt + fpf[i]->Eval(xpt)/(Double_t)nof);
  }
 }

for this, i just wanted to plot xpt=0.40, 0.50, 0.6, and 0.75
how is it done? please help :slight_smile:

regards.
jaybee

Make a graph with only these points.

gracias, okay will try it…

i don’t get it if i do this

 TGraph *av4 = new TGraph();

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  av4->SetPoint(j, xpt, 0.0);
 }

 for (Int_t i=0; i<nof; i++)
 {
   av4->GetPoint(k, xpt, ypt);
   av4->SetPoint(0, 0.40, ypt + ppf[i]->Eval(0.40)/(Double_t)nof);
   av4->SetPoint(1, 0.50, ypt + ppf[i]->Eval(0.50)/(Double_t)nof);
   av4->SetPoint(2, 0.60, ypt + ppf[i]->Eval(0.60)/(Double_t)nof);
   av4->SetPoint(3, 0.70, ypt + ppf[i]->Eval(0.70)/(Double_t)nof);
   av4->SetPoint(4, 0.80, ypt + ppf[i]->Eval(0.80)/(Double_t)nof);
   av4->SetPoint(5, 0.98, ypt + ppf[i]->Eval(0.98)/(Double_t)nof);
 }

You set the points in the same graph av4 … I suggested to take the points you need in av4 and put them in a new one av5

i see… i’ll take your suggestion… :slight_smile: but i have a problem with ppf[i] because “i” runs from 0 to nof-1.

I do not see why this is a problem …

because i do not know which “i”… can you suggest to me the code?

i did this

 TGraph *av4 = new TGraph();

 av4->GetPoint(k, xpt, ypt);
 av4->SetPoint(0, 0.40, ypt + ppf[nof]->Eval(0.40)/(Double_t)nof);
 av4->SetPoint(1, 0.50, ypt + ppf[nof]->Eval(0.50)/(Double_t)nof);
 av4->SetPoint(2, 0.60, ypt + ppf[nof]->Eval(0.60)/(Double_t)nof);
 av4->SetPoint(3, 0.70, ypt + ppf[nof]->Eval(0.70)/(Double_t)nof);
 av4->SetPoint(4, 0.80, ypt + ppf[nof]->Eval(0.80)/(Double_t)nof);
 av4->SetPoint(5, 0.98, ypt + ppf[nof]->Eval(0.98)/(Double_t)nof);

but it did not give the correct plot

Something like that …

TGraph *av5 = new TGraph();
int j = 0;
for (Int_t i=0; i<nof; i++)
 {
   av4->GetPoint(i, xpt, ypt);
   if (xpt ==  0.4 || xpt == 0.5 || xpt == 0.6 || apt = 0.75 ) { 
      av5->SetPoint(j, xpt, ypt + ppf[i]->Eval(xpt)/(Double_t)nof);
      j++;
   }
 }

But I am not complexity sure as you never sent a running example.

okay… gracias… i will do this later after dinner :slight_smile:

I could not see the specific points.
Anyway, here is the complete code:

void StatNewEPScatteringSample01()
{
 static Int_t nof = 500;                        // number of functions to be generated
 auto can = new TCanvas("c1", "c1", 800,800);   // setting the canvas
 //gStyle->SetOptStat("nerf");
 //gStyle->SetOptStat();
 gStyle->SetOptStat(0);
 can->Draw();

 auto avf = new TH1F("avf", "Average of Functions", 100, 0.0025, 1.0);
 avf->Draw();

//=== generating the functions ===//

 TF1 *fpf[nof], *ppf[nof];
 TString fna;

 for (Int_t i=0; i<nof; i++)
 {
  fna = "f"; fna += i;
  fpf[i] = new TF1("fna","(((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+2.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+(x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)))))*((2.0*[3]*[3])/(2.0*[3]*[3]+x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))))*((4.0*[3]*[3])/(4.0*[3]*[3]+x))*((0.71)/(0.71+x))*((0.71)/(0.71+x))*((0.71)/(0.71+x))*((0.71)/(0.71+x))*((8.0*[3]*[3]*[3]*[3]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+2.0*[3]*[3]*x*[6]*[6]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+4.0*[3]*[3]*x*[6]*[6]*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+x*x*[6]*[6]*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))/(8.0*[3]*[3]*[3]*[3])))", 0.0025, 1.0);
  fpf[i]->SetParameter(0,1.0);
  fpf[i]->SetParameter(1,1.0);
  fpf[i]->SetParameter(2,1.0/137.0);
  fpf[i]->SetParameter(3,gRandom->Gaus(0.938272081,0.000000023));
  fpf[i]->SetParameter(4,10.0);
  fpf[i]->SetParameter(5,TMath::Pi());
  fpf[i]->SetParameter(6,2.793);
 }

 for (Int_t i=0; i<nof; i++)
 {
  fna = "f"; fna += i;
  ppf[i] = new TF1("fna","((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+2.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+(x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)))))*((2.0*[3]*[3])/(2.0*[3]*[3]+x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))))*((2.0*[3]*[3]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))/(2.0*[3]*[3]))", 0.0025, 1.0);
  ppf[i]->SetParameter(0,1.0);
  ppf[i]->SetParameter(1,1.0);
  ppf[i]->SetParameter(2,1.0/137.0);
  ppf[i]->SetParameter(3,gRandom->Gaus(0.938272081,0.000000023));
  ppf[i]->SetParameter(4,10.0);
  ppf[i]->SetParameter(5,TMath::Pi());
  ppf[i]->SetParameter(6,2.793);
 }

//=== getting the average ===//

 Int_t nop=100;
 Double_t xpt, ypt, del = 0.9975/nop;

 TGraph *av1 = new TGraph();

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  av1->SetPoint(j, xpt, 0.0);
 }
 for (Int_t i=0; i<nof; i++)
 {
  for (Int_t j=0; j < nop; j++)
  {
   av1->GetPoint(j, xpt, ypt);
   av1->SetPoint(j, xpt, ypt + fpf[i]->Eval(xpt)/(Double_t)nof);
  }
 }

 TGraph *av2 = new TGraph();

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  av2->SetPoint(j, xpt, 0.0);
 }

 for (Int_t i=0; i<nof; i++)
 {
  for (Int_t j=0; j < nop; j++)
  {
   av2->GetPoint(j, xpt, ypt);
   av2->SetPoint(j, xpt, ypt + ppf[i]->Eval(xpt)/(Double_t)nof);
  }
 }

 TGraph *av4 = new TGraph();
 int j = 0;

 for (Int_t i=0; i<nof; i++)
 {
   av2->GetPoint(i, xpt, ypt);
   if (xpt == 0.4 || xpt == 0.5 || xpt == 0.6 || xpt == 0.75 ) {
                                                                av4->GetPoint(i, xpt, ypt);
                                                                av4->SetPoint(j, xpt, ypt + ppf[i]->Eval(xpt)/(Double_t)nof);
                                                                j++;
                                                               }
 }

//=== pLotting the average on canvas ===//

 gPad->SetLogy(1);

 av1->SetMarkerStyle(7);
 av1->SetMarkerColor(kBlue);
 av1->SetMarkerSize(1);

 av2->SetMarkerStyle(6);
 av2->SetMarkerColor(kRed);
 av2->SetMarkerSize(1);

 av4->SetMarkerStyle(3);
 av4->SetMarkerColor(kMagenta);
 av4->SetMarkerSize(1);

 TMultiGraph *mgp = new TMultiGraph();
 mgp->SetMinimum(1.e-4);
 mgp->SetMaximum(1.e0);
 mgp->Add(av1,"PL");
 mgp->Add(av2,"PL");
 mgp->Add(av4,"PL");
 mgp->Draw("a");

 avf->SetMaximum(1.e0);
 can->Modified();
 can->Update();
}

please help me about this.

your code gives me:

root [0] 
Processing StatNewEPScatteringSample01.C...
Error in <TGraphPainter::PaintGraph>: illegal number of points (0)

what does it mean? :frowning:

It means that one of your graph has 0 points

that would be av4… but i do not know the reason why?

because the test:

if (xpt == 0.4 || xpt == 0.5 || xpt == 0.6 || xpt == 0.75 ) 

is never true