// Create TChain object and add files to it TChain chain("myTree"); chain.Add("file1.root"); chain.Add("file2.root"); // Create variable to store data from branch double myVariable; // Set branch address in TChain to given variable chain.SetBranchAddress("myBranch", &myVariable);
// Create TChain object and add single file to it TChain chain("myTree"); chain.Add("file1.root"); // Create variable to store data from branch float myVariable; // Set branch address in TChain to given variable chain.SetBranchAddress("myBranch", &myVariable); // Loop over entries in TChain and print out value of variable for each entry for (int i = 0; i < chain.GetEntries(); ++i) { chain.GetEntry(i); std::cout << "Value of myVariable: " << myVariable << std::endl; }In this example, we create a `TChain` object and add a single ROOT file `file1.root` to it. We then create a variable `myVariable` of type float to store data from the branch `myBranch`. Finally, we use `SetBranchAddress` function to set the address of `myBranch` in `TChain` to the address of `myVariable`. We loop over all entries in `TChain` and use `GetEntry` function to read the data into our variable and then print it out to the console. Package library: ROOT C++ package library.