#include "TFile.h" #include "TMultiGraph.h" #include "TGraph.h" #include "TObject.h" #include "TRandom.h" #include #include using namespace std; TGraph* generate_graph() { double rnd, x, y, z; double e = 0.3; int nd = 500; TRandom r; TF1 *f1 = new TF1("f2","1000*(sin(x)/x)+200",-6,6); TGraph *dte = new TGraph(nd); // Fill the 2D graph double zmax = 0; for (int i=0; iGetRandom(); rnd = r.Uniform(-e,e); // Generate a random number in [-e,e] z = f1->Eval(x)*(1+rnd); if (z>zmax) zmax = z; dte->SetPoint(i,x,z); } return dte; } void add_multi_graph(int i){ TFile file("graphs.root","UPDATE"); TMultiGraph *multi_gr; if(i != 0) multi_gr = (TMultiGraph*)(file.Get("graphs")); multi_gr->Add((TGraph*)(generate_graph())); multi_gr->Write("graphs", TObject::kOverwrite); file.Close(); } int main(){ int n = 3; TFile file("graphs.root","UPDATE"); TMultiGraph *multi_gr[n]; for(int i =0; i