Can't call TGraph function

Hello,

I’m writing a code to specify an optical system.

I’m stuck with this in calling TGraph, and I really don’t understand, since I already done this in other codes.

The error I get is this:

Error: Can’t call TGraph::TGraph(n_points_GSD,GSD,Optical_Diameter_1) in current scope Optical_System_2.C:95:
Possible candidates are…
(in TGraph)
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(void);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Int_t* x,const Int_t* y);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Float_t* x,const Float_t* y);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Double_t* x,const Double_t* y);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TGraph& gr);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TVectorF& vx,const TVectorF& vy);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TVectorD& vx,const TVectorD& vy);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TH1* h);
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TF1* f,Option_t* option="");
/usr/lib/x86_64-linux-gnu/root5.34/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const char* filename,const char* format="%lg %lg",Option_t* option="");
Error: Illegal Assignment to an undeclared symbol Gra1 Optical_System_2.C:95:
*** Interpreter error recovered ***

And my code is:

void Optical_System_2(){

// Earth Radius, Mass and Graviational Constant
double Rt,Mt,Gt;
Rt = 6.371e6; // m
Mt = 5.972e24; // kg
Gt = 6.67384e-11; // m3.kg-1.s-2

// Planck Constant & Light Speed
double h,c;
h = 6.6262e-34; // J.s
c = 3.0e8; // m.s-1

// Integration Time Constant
double K_int = 0.5;

// Input Parameters
double Electronic_Noise = 80.;
double Quantum_Eff = 0.5;

double Radiance1,Radiance2;
Radiance1 = 1.4; // W.m-2.sr-1.um-1
Radiance2 = 36.; // W.m-2.sr-1.um-1

// Altitude, Optical Transmittance
double GSD,H,L_km,T_opt,lambda,BW,Visibility;
//GSD = 10.; // m
H = 600.e3; // m
L_km = 4.; // km
T_opt = 0.7;

// Central Wavelength, Bandwidth & Visibility
lambda = 0.59; BW = 0.15; // um
Visibility = 15; // km

// Signal To Noise Ratio -> INPUT VALUES
const int SNR1 = 40; // dB
const int SNR2 = 100; // dB
const int n_points_SNR = SNR2-SNR1+1;
double SNR[n_points_SNR];

// Ground Sample Distance -> INPUT VALUES
int GSD1 = 5; // m
int GSD2 = 20; // m
const int n_points_GSD = GSD2-GSD1+1;
double GSD[n_points_GSD];

// Atmospheric Transmittance
double T_atm = exp(-2.77L_km/(Visibilitypow(lambda,0.7)));

// Vectors Definition
double Omega[n_points_GSD][n_points_SNR];
double T_int[n_points_GSD][n_points_SNR];

double Alpha[n_points_GSD][n_points_SNR];
double Beta[n_points_GSD][n_points_SNR];
double Optical_Diameter[n_points_GSD][n_points_SNR];

double Optical_Diameter_1[n_points_GSD];
double Optical_Diameter_2[n_points_GSD];
double Optical_Diameter_3[n_points_GSD];

for(int i=0;i<n_points_GSD;i++){
for(int j=0;j<n_points_SNR;j++){

  GSD[i] = i+GSD1;
  SNR[j] = j+SNR1;

  Omega[i][j] = pow((GSD[i])/H,2);
  T_int[i][j] = K_int*(GSD[i])/sqrt((Gt*Mt)/(H+Rt));
  
  Alpha[i][j] = 4*h*c*Electronic_Noise*pow(10,(SNR[j])/20);
  Beta[i][j] = Quantum_Eff*Radiance2*T_atm*Omega[i][j]*BW*T_opt*T_int[i][j]*lambda*TMath::Pi();
  
  Optical_Diameter[i][j] = 1e5*sqrt(Alpha[i][j]/Beta[i][j]);
                    
}
cout<<"GSD = "<<GSD[i]<<endl;

}

for(int k=0;k<n_points_GSD;k++)
{
Optical_Diameter_1[k] = Optical_Diameter[k][10];
Optical_Diameter_2[k] = Optical_Diameter[k][20];
Optical_Diameter_3[k] = Optical_Diameter[k][30];

cout<<"Optical_Diameter_1 = "<<Optical_Diameter_1[k]<<endl;   

}
//cout<<" = "<<GSD[5]<<endl;

cout<<"n_points_GSD = "<<n_points_GSD<<endl;
cout<<"n_points_SNR = "<<n_points_SNR<<endl;

// Plotting Section :: Creating Canvas
TCanvas *c1 = new TCanvas(“c1”);
c1->SetFillColor(10);
c1->SetGrid();

Gra1 = new TGraph(n_points_GSD,GSD,Optical_Diameter_1);
Gra1->SetLineColor(4);
Gra1->SetLineWidth(4);
Gra1->SetTitle(“Optical System Specification”);
Gra1->GetXaxis()->SetTitle(“GSD [m]”);
Gra1->GetYaxis()->SetTitle(“Optics Diameter [cm]”);
Gra1->DrawClone();
}

A I see in the error message, TGraph accepts as input (int, double, double), which is what I’m doing.

Thank you for the help.

Best Regards.

Always try to precompile your macro using ACLiC, in order to find source code problems, e.g. try something like:
root [0] .L Optical_System_2.cxx++

#include “TCanvas.h”
#include “TGraph.h”
#include “TAxis.h”
#include “TMath.h”
#include
// …
double GSD0,H,L_km,T_opt,lambda,BW,Visibility;
//GSD0 = 10.; // m
// …
TGraph *Gra1 = new TGraph(n_points_GSD,GSD,Optical_Diameter_1);
// …

Hello,

Thank you for your help!!

With the pre-compilation I found the problem, which was that I had already declared the variable GSD as another kind before:

/home/lghizoni/Documents/EQSA/WFI/Optics System Specification/./Optical_System_2.cpp:52:26: error: conflicting declaration ‘double GSD [(long int)n_points_GSD]’
double GSD[n_points_GSD];

Thanks a lot. Now I’ll always precompile before :smiley:

Best Regards.
Leonardo.