TFile* file = new TFile("myFile.root", "RECREATE");
TFile* file = new TFile("myFile.root", "READ"); if (!file->IsOpen()) { cout << "Error opening file!" << endl; }
TH1F* hist = new TH1F("hist", "Histogram", 100, 0, 1); hist->FillRandom("gaus", 10000); file->WriteObject(hist, "myHist");
TH1F* hist = (TH1F*)file->GetObject("myHist"); hist->Draw();This will read the previously written histogram named "myHist" from the ROOT file and draw it on a canvas using ROOT's graphics library. In summary, TFile is a class provided by the ROOT package library that allows C++ programs to create, open, read and write ROOT files for data analysis purposes.