Hello all, I want to plot 9 graphs using TMultiGraph class on one canvas-as single plot, but I would like to make code so that every graph is filled with data from files automaticly and not by me. Here is what I tried but was getting errors.
(And this same code but for histograms is working perfectly by using the TH1F class for creating histograms and THStack for drawing them all on a single plot ).
I’m new to root and apologize in advance for any major mistakes, thank you for your time.
TCanvas *c1 = new TCanvas();
int graph_ang_counts_all() {
ifstream ang_file[9];
ang_file[0].open("theta-fe54-e335.asc");
ang_file[1].open("theta-fe54-e340.asc");
ang_file[2].open("theta-fe54-e346.asc");
ang_file[3].open("theta-fe54-e351.asc");
ang_file[4].open("theta-fe54-e354.asc");
ang_file[5].open("theta-fe54-e358.asc");
ang_file[6].open("theta-fe54-e362.asc");
ang_file[7].open("theta-fe54-e365.asc");
ang_file[8].open("theta-fe54-e370.asc");
double ang, counts;
TMultiGraph *mgr = new TMultiGraph();
TGraph *gr[9];
for(int i=0; i<9; i++){
gr[i] = new TGraph(i, ang, counts);
gr[i]->SetMarkerStyle(20);
gr[i]->SetMarkerColor(i+2);
while (ang_file[i] >> ang >> counts )
{
gr[i]->SetPoint(i, ang, counts);
mgr->Add(gr[i]);
}
}
mgr->Draw("ALP");
return 0;
}
error: no matching constructor for initialization of ‘TGraph’
gr[i] = new TGraph(i, ang, counts);
^ ~~~~~~~~~~~~~~
/snap/root-framework/753/usr/local/include/TGraph.h:82:4: note: candidate constructor not viable: no known conversion from ‘double’ to ‘const Double_t *’ (aka ‘const double *’) for 2nd argument; take the address of the argument with &
TGraph(Int_t n, const Double_t *x, const Double_t *y);
^
/snap/root-framework/753/usr/local/include/TGraph.h:80:4: note: candidate constructor not viable: no known conversion from ‘double’ to ‘const Int_t *’ (aka ‘const int *’) for 2nd argument
TGraph(Int_t n, const Int_t *x, const Int_t *y);
^
/snap/root-framework/753/usr/local/include/TGraph.h:81:4: note: candidate constructor not viable: no known conversion from ‘double’ to ‘const Float_t *’ (aka ‘const float *’) for 2nd argument
TGraph(Int_t n, const Float_t *x, const Float_t *y);
^
/snap/root-framework/753/usr/local/include/TGraph.h:89:4: note: candidate constructor not viable: no known conversion from ‘int’ to ‘const char *’ for 1st argument
TGraph(const char *filename, const char *format=“%lg %lg”, Option_t *option=“”);
^
/snap/root-framework/753/usr/local/include/TGraph.h:85:4: note: candidate constructor not viable: requires 2 arguments, but 3 were provided
TGraph(const TVectorF &vx, const TVectorF &vy);
^
/snap/root-framework/753/usr/local/include/TGraph.h:86:4: note: candidate constructor not viable: requires 2 arguments, but 3 were provided
TGraph(const TVectorD &vx, const TVectorD &vy);
^
/snap/root-framework/753/usr/local/include/TGraph.h:88:4: note: candidate constructor not viable: requires at most 2 arguments, but 3 were provided
TGraph(const TF1 *f, Option_t *option=“”);
^
/snap/root-framework/753/usr/local/include/TGraph.h:79:4: note: candidate constructor not viable: requires single argument ‘n’, but 3 arguments were provided
TGraph(Int_t n);
^
/snap/root-framework/753/usr/local/include/TGraph.h:83:4: note: candidate constructor not viable: requires single argument ‘gr’, but 3 arguments were provided
TGraph(const TGraph &gr);
^
/snap/root-framework/753/usr/local/include/TGraph.h:87:4: note: candidate constructor not viable: requires single argument ‘h’, but 3 arguments were provided
TGraph(const TH1 *h);
^
/snap/root-framework/753/usr/local/include/TGraph.h:78:4: note: candidate constructor not viable: requires 0 arguments, but 3 were provided
TGraph();
^