gma
July 13, 2009, 2:01am
1
Hi,
I got the following error message by running a very simple macro
Error: Can’t call TGraph::TGraph(nentry,timeidx,x) in current scope Plotx.cxx:22:
Possible candidates are…
(in TGraph)
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(void);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Int_t* x,const Int_t* y);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Float_t* x,const Float_t* y);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(Int_t n,const Double_t* x,const Double_t* y);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TGraph& gr);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TVectorF& vx,const TVectorF& vy);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TVectorD& vx,const TVectorD& vy);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TH1* h);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const TF1* f,Option_t* option=“”);
/usr/local/root/lib/libHist.so -1:-1 0 public: TGraph TGraph::TGraph(const char* filename,const char* format=“%lg %lg”,Option_t* option=“”);
*** Interpreter error recovered ***
void Plotx()
{
TFile *f = new TFile("$HOME/Desktop/test.root");
TTree * T = (TTree*) f->Get("T");
Double_t Close;
T->SetBranchAddress("Close",&Close);
Int_t* timeidx;
Double_t* x;
Int_t nentry = (Int_t)T->GetEntries();
timeidx = new Int_t[nentry];
x = new Double_t[nentry];
for (Int_t i=0; i<nentry;i++)
{
T->GetEntry(i);
x[i]=Close;
timeidx[i]= i;
}
TGraph * gr = new TGraph(nentry,timeidx,x);
gr->Draw("test");
delete f;
}
I know TGraph’s signature is const Double_t, but it should work for this case. And my example is no different from the examples in the manual. Thank for your helps.
regards,
gma
brun
July 13, 2009, 5:06am
2
C++ cannot promote a Int_t* to a Double_t*. Change the type of timeidx from Int_t to Double_t
Rene
gma
July 13, 2009, 12:10pm
3
Many thanks, Brun. I was focused on the first argument.
regards,
Gang Ma
gma
July 14, 2009, 2:07am
4
Hi, Brun
My code generates a blank graph and I don’t know why this is the case. Attached please find my root file. (I checked it to and looks good to me).
void Plotx()
{
TFile *f = new TFile("$HOME/Desktop/test.root");
TTree * T = (TTree*) f->Get("T");
Double_t Close;
T->SetBranchAddress("Close",&Close);
Double_t* timeidx;
Double_t* x;
Int_t nentry = (Int_t)T->GetEntries();
timeidx = new Int_t[nentry];
x = new Double_t[nentry];
for (Int_t i=0; i<nentry;i++)
{
T->GetEntry(i);
//cout<<Close<<endl;
x[i]=Close;
//cout<<"x_i is "<<x[i]<<endl;
timeidx[i]= (Double_t)i;
}
//cout << x[10]<<endl;
//cout << timeidx[10]<<endl;
TGraph * gr = new TGraph(nentry,timeidx,x);
//TCanvas *c1 = new TCanvas("c1","Graph options",200,10,600,400);
gr->Draw("test");
delete f;
// delete [] timeidx;
// delete [] x;
// timeidx =0;
// x = 0;
}
Many thanks.
regards,
gma
test.root (351 KB)
brun
July 14, 2009, 5:04am
5
Replace the statement
gr->Draw("test");
by
gr->Draw("al");
Please read the doc TGraph::Draw
Rene
Hi,
And if you declare a pointer on an array of Double_t:
You must create your array like this (with Double_t instead of Int_t):
Cheers,
Bertrand.
gma
July 14, 2009, 11:39am
7
many thanks for your helps. Still got a blank figure. I just read the user manual. Will take a look at the reference.
regards,
gma