Search code examples
c++databasegraphroot-framework

CERN ROOT Extract Data from TNtuple


I am using CERN's ROOT framework (required), and I want to take data from a TNtuple and graph it. I can either graph the data when I create the TNtuple, or after I write it to a .root file. Some of the support documentation suggested that I create a TTree, but that seemed like it might be overkill/roundabout since I wouldn't be using it for anything else (and the TNtuple fulfills all of my other requirements). Does anyone have a better suggestion for how to extract data from the TNtuple and graph it?


Solution

  • As TNtuple inherits from TTree, you can use all the methods presented in the support documentation for TTrees directly on the TNtuple. This especially means that you can use TTree::Draw() which is typically more than sufficient for quickly graphing the data. This function is documented here.

    For more elaborate plots you will have to read the data from the TNtuple event by event and feed it to your favorite graphing tool in ROOT. This again follows the basic principles from a tree. The best example I could find on the ROOT homepage is in the user manual, section trees in the paragraph "Reading the Tree".