# Accessing the data in ntuples

**URL:** <https://root-forum.cern.ch/t/accessing-the-data-in-ntuples/47026>\
**Category:** Newbie\
**Created:** [September 28, 2021, 12:05am UTC](https://root-forum.cern.ch/t/accessing-the-data-in-ntuples/47026 "2021-09-28T00:05:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abunka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@abunka](https://root-forum.cern.ch/u/abunka)\
**Post date:** [September 28, 2021, 12:05am UTC](https://root-forum.cern.ch/t/accessing-the-data-in-ntuples/47026/1 "2021-09-28T00:05:33Z")

</div>

Hello,  
I have seen some similar topics here but cannot find quite what I’m looking for.  
I used EventLoop to create ntuples, following the tutorial for ATLAS at:  
[[ATLAS Analysis Software Tutorial | Creating and Filling Trees/NTuples](https://atlassoftwaredocs.web.cern.ch/ABtutorial/basic_trees/)]  
Each variable is filled into a vector of floats which is then filled into the tree.  
I want to work with the resulting ntuple, going through each variable and calculating simple things like mean and covariance.  
The problem is that I cannot seem to extract the data from the ntuple. Here is what my Tree looks like:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/5/f/5f4654dffc538ed112d336c1cafaaa65d76745a9.png)  
I have tried following instructions that involve

```auto
TFile *mainInput = new TFile("path/to/file", "READ");
	TTree* mainTree = (TTree*)mainInput->Get("VarNTuple");
	
	std::vector<float>* WidthHigh;

	mainTree->SetBranchAddress("WidthHigh", &WidthHigh);

```

But any attempts to Draw or scan or show after this are failing.  
What do I need to do to access data from a Tree of vectors like this?  
Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 28, 2021, 7:43am UTC](https://root-forum.cern.ch/t/accessing-the-data-in-ntuples/47026/2 "2021-09-28T07:43:49Z")

</div>

At least: `std::vector<float> *WidthHigh = 0;`

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [October 4, 2021, 8:17am UTC](https://root-forum.cern.ch/t/accessing-the-data-in-ntuples/47026/3 "2021-10-04T08:17:23Z")

</div>

Here’s what you _should_ do:

```auto
ROOT::EnableImplicitMT(); // use all cores
ROOT::RDataFrame rdf("VarNTuple", "path/to/file");
auto hist = rdf.Histo1D("EMB1FracHigh");
auto meanTrackPt500 = rdf.Mean("AvgTrackPt500FracHigh");
std::cout << "meanTrackPt500 = " << *meanTrackPt500 << '\n';
hist->Draw();

```

This is an example showing a histogram and an average; you can do way more, see [the documentation](https://root.cern/doc/master/classROOT_1_1RDataFrame.html). This is _way_ faster, and it’s _way_ easier for you to evolve this into a full-blown analysis.
