Hello!
I am trying to create a TGraph2D array and fill the individual elements in a loop. Then I want to plot them. Here is my code:
[code]void databaseerzeugung()
{
Int_t m = 100;
Int_t l = 1;
char histname[m];
char filename[m];
char canvasname[m];
char graphname[m];
int n=0;
double p;
double mean, meana;
TGraph2D** graph =new TGraph2D* [10];
TCanvas** canvas = new TCanvas* [10];
int x, y;
int j;
int i=0;
int o;
int earray[4]={5, 55, 105, 155};
FILE* database;
database = fopen(“database.txt”, “a+”);
for (o=0;o<4;o++)
{
int energy = earray[o];
graph[o] = new TGraph2D();
for (x=-200; x<200; x=x+10)
{
for (y=-200; y<200;y=y+10)
{
TH1F *hist_Deg = new TH1F("h1", "title", 250, -0.5, 249.5);
for (j=5000; j<5010; j++)
{
sprintf(filename,"electronsrough/%d.000000MeV/x%d/y%d/process%d.txt", energy,x,y,j);
cout<<filename<<endl;
FILE* pfile =fopen(filename,"r");
while(!feof(pfile))
{
fscanf(pfile, "%lf /n", &p);
hist_Deg->Fill(p);
}
fclose(pfile);
}
meana = hist_Deg->GetMean();
graph[o]->SetPoint(i, x, y, meana);
i=i+1;
fprintf(database, "%d %d %d %f\n", energy, x, y, meana);
printf("%f\n", meana);
fflush(database);
delete hist_Deg;
}
}
sprintf(canvasname,"%d", energy);
canvas[o] = new TCanvas(canvasname);
sprintf(graphname,"%d", energy);
graph[o]->SetTitle(graphname);
graph[o]->GetXaxis()->SetLimits(-200,200);
graph[o]->GetYaxis()->SetRange(0,200);
graph[o]->GetXaxis()->SetTitle(“X”);
graph[o]->GetYaxis()->SetTitle(“Y”);
graph[o]->GetZaxis()->SetTitle(“Z”);
gStyle->SetPalette(1);
graph[o]->Draw(“surf1”);
}
}[/code]
But only the first TGraph2D in the o-loop is properly drawn. For the others I just get a canvas with axis.
Do you have any ideas?
Cheers and thanks to all!!!