Hi all.
This is regarding RDataFrame. However, if another way like TTreeReader is a way to solve, I will appreciate it.
I have following structure in my ROOT file.
I wanted to draw the ‘energy_’ histogram just simply by double click using mouse. However, I ended up knowing that root throws a following error:
Warning in <TTreeFormula::DefinedVariable>: TTreeFormula support only 2 level of variables size collections. Assuming '@' notation for the collection singles_.
So, now I want to print (and eventually fill a histogram) the values stored inside ‘energy_’.
I have seen the following topics, but haven’t actually got anything to work for me.
year2012 year2020
I tried to write the following script using RDataFrame (which is not correct).
What are the modifications that are needed?
void beta_rdataframe(){
auto fileName = "beta_3120.root";
auto treeName = "OutputTree";
ROOT::RDataFrame d(treeName, fileName, {"output_vec_"});
auto columnNames = d.GetColumnNames();
std::cout << "Column Names are: " << std::endl;
for (const auto &col : columnNames){
std::cout << col << std::endl;
}
//FOLLOWING LINES OF CODE DOESN'T WORK
TH1F henergy("energy","energy",3000,0,3000);
const auto fillenergy = [&henergy](auto output_vec_)
{
for (const auto &imp : output_vec_)
{
const auto &gam_vec = imp.input_.output_vec_;
for (const auto &gam : gam_vec)
{
for (const auto &single : gam.singles_)
{
std::cout << "Energies are: " << std::endl;
std::cout << single.energy_ << std::endl;
henergy.Fill(single.energy_);
}
}
}
};
d.Foreach(fillenergy, {"output_vec_"});
auto c1 = new TCanvas();
henergy.DrawClone();
}
The ‘partial’ output for the command ‘GetColumnNames’ is the following:
root -l beta_rdataframe.C
Processing beta_rdataframe.C...
Column Names are:
Beta
Beta.input_
Beta.output_vec_
Beta.output_vec_.input_.output_vec_
input_
output_vec_
output_vec_.input_.output_vec_
... (many more)
The root file is large (in tens of GB), so I cannot attach. Sorry for that.
Any help will be appreciated.
ROOT Version: 6.26/08
Platform: Ubuntu 22.04.2 LTS
Thanks.