TFile* inputFile = TFile::Open("input.root"); // opening a ROOT file TH1F* hist = nullptr; // declaring a null pointer to TH1F object inputFile->GetObject("histogramName", hist); // retrieving the histogram object by its name hist->Draw(); // plotting the histogram
TFile* inputFile = TFile::Open("input.root"); // opening a ROOT file TTree* tree = nullptr; // declaring a null pointer to TTree object inputFile->GetObject("treeName", tree); // retrieving the TTree object by its name tree->Scan(); // printing the contents of the treeIn this example, we are opening a ROOT file named "input.root" and then retrieving a TTree named "treeName" from the file using GetObject method. The TTree object is stored in a pointer variable named "tree". Finally, we are printing the contents of the tree using the Scan() method. Both examples use the ROOT package library, a scientific software framework for data analysis and visualization.