i have transferred the bin values of histograms into graphes , now i’m trying to merge those graphes.
Is it possible to add graphes to a multigraph from different root files?
for example: i have 3 root files like output_bla_1.root … output_bla_3.root . in every of these root files is a graph i’d like to add to my multigraph.
now lets say i have like 1000 files in one directory with names i cannot use for a loop. Is it possible to extract the graph of all files inside a directory?
You define “fname” and “gname” twice. Once as a “char fname[6];” / “char gname[6];” and then as a “TFile *fname” / “TGraph *gname” (and there are no such drawing options like “graph”, so you cannot use them in the “mg->Add(…);” call).
Try to replace the lines: TFile*fname = new TFile(output);
TGraph *gname = (TGraph*)fname->Get("gr");
mg->Add(gname,"graph"); with: TFile *f = new TFile(output);
TGraph *g; f->GetObject("gr", g);
if (g) {
g->SetName(gname);
mg->Add(g);
} else printf("Warning: graph %d not found.", i);
delete f;
In general, always try to pre-compile your macros with ACLiC, so that the c++ compiler checks your source code.