Clean way to add many variables to NTuple?


ROOT Version: 6.08/06
Platform: CentOS Linux 7 (Core)


I’m following the beginner ROOT guide on storing arbitrary N-Tuples (7.2.3), and would like to know if there is a cleaner / easier way to branch many variables without having to explicitly write out each branch? See code below

double dsRatio, p1pps, m1pps, p1p0s, m1p0s, p1pms, m1pms,
    p1ppd, m1ppd, p1p0d, m1p0d, p1pmd, m1pmd, p1p, m1p;
double paramArray[] = {dsRatio, p1pps, m1pps, p1p0s, m1p0s, p1pms, m1pms,
    p1ppd, m1ppd, p1p0d, m1p0d, p1pmd, m1pmd, p1p, m1p;}

TTree *paramVals = new TTree("paramVals", "paramVals");
 paramVals->Branch("dsRatio", &dsRatio, "dsRatio/D");
 paramVals->Branch("p1pps", &p1pps, "p1pps/D");
// rest of variable branches here...

Is there a built in way of handling this? Doing variable name to string conversion seems generally frowned upon in my searches.

Hi @Kshire ,

sorry for the high latency, it looks like this post fell through the cracks!

In principle you can call paramVals->Branch in a for loop over the different arguments. You can also use RDataFrame which is a powerful interface to manipulate ROOT data which abstracts away many tedious TTree operations.

Cheers,
Enrico

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.