Cannot determine the type contained in the collection of branch

Hello,

I am trying to read values from a Branch containing collection of sub-branches. However, I get the following error:

[size=85]Error in <GetBranchContentDataType()>: The branch edep was created using a leaf list and cannot be represented as a C++ type. Please access one of its siblings using a TTreeReaderValueArray:
Error in <GetBranchContentDataType()>: edep.edep1
Error in <GetBranchContentDataType()>: edep.edep2
Error in <GetBranchContentDataType()>: edep.edep3
Error in <GetBranchContentDataType()>: edep.edep4
Error in <GetBranchContentDataType()>: edep.edep5
Error in <GetBranchContentDataType()>: edep.edep6
Error in <GetBranchContentDataType()>: edep.edep7
Error in <GetBranchContentDataType()>: edep.edep8
Error in <CreateContentProxy()>: Cannot determine the type contained in the collection of branch edep. That’s weird - please report![/size]

  1. I created the TTree in the following way:

fTTree->Branch("edep",fEdep,"edep1/D:edep2/D:edep3/D:edep4/D:edep5/D:edep6/D:edep7/D:edep8/D");

  1. I am using the following to read values from the Branch:

TTreeReader diodeReader("diode",rootFile); TTreeReaderArray<double> energyDep(diodeReader, "edep"); TH1F *dE = new TH1F("dE","dE",100,0.0,1000.0); while(diodeReader.Next()) { for (int diode_i = 0, nDiodes = energyDep.GetSize(); diode_i < nDiodes; ++diode_i) { dE->Fill(energyDep[diode_i]); } }

How can I rectify the program to read values stored in the branch?

Thank you.

You can read the values using TTreeReaderArray<> if you have stored then as an array (vector) using for example

std::vector<double> fEdep(8);
tree = new TTree("diode", "diode");
tree->Branch("edep",&fEdep);

or alternatively

double fEdep[8];
tree = new TTree("diode", "diode");
tree->Branch("edep",fEdep,"edep[8]/D");

If you have stored as independent leaf as you have done, then you need to create an array or vector of TTreeReaderValue.

Yes, I ended up storing my data in an array instead of leaves (as you also recommend here) and I am able to read the values by simply going through them entry by entry.

I had created independent leaves (by fTTree->Branch(“edep”,fEdep,“edep1/D:edep2/D:edep3/D:edep4/D:edep5/D:edep6/D:edep7/D:edep8/D”)) as then I could see in the TBrowser the list of leaves for each Branch and of course the data stored in them via TBrowser created histograms. Which is nice as you can directly see if what you’re doing makes sense.

Anyway, due to the simplicity of accessing the data and not waste time to find methods to access data from leaves, I chose to go with the arrays at the end.

I appreciate your response, thanks a bunch!

Hello,
I am running into the same problem, or at least the same error message. Problems with the solution is that I already have the TTree, and I would have to ask someone else to recreate it using the vector description above, and that each branch contains multiple data types (e.g. float, double, bool) so I would then have to recast them–not pretty but possible. Is there any way to access a branch as a struct?

Thanks,

Paul

Try running

tree->MakeSelector("sel.h");

and either look in sel.h for inspiration or use it directly (see documentation of TTree::MakeSelector and TTree::Process).

Cheers,
Philippe.