I am using a TTree with a custom made Event class which has a list of tracks (TClonesArray) as data member. The latter owns a TRefArray, pointing to the hits on track which are filled among other hits in another data member of the event class (TClonesArray as well). I now would like to know how I can use the TTree::Scan method for printing out information of the hits on track referenced by the TRefArray like:
My attempts to access the hits (and typecasting appropriately) failed…
Which version of ROOT are you using?
When you wrote the ROOT file, did you enable the autoloading feature of the TRef and TRefArray by calling mytree->BranchRef(); ?
thanks for your answer! I am using ROOT 5.18. I tried to write the tree with BranchRef() and without and can’t spot any difference, however if I understand correctly BranchRef() is necessary. Possibly it is just the syntax I am using.
fHits is a TRefArray but points references to TObjects. To access the properties of the hits I need to cast to the hit class inheriting from TObject which I tried by
This doesn’t work…it isn’t quite clear to me how I have to do that.
[quote]To access the properties of the hits I need to cast to the hit class inheriting from TObject which I tried by[/quote]With BranchRef on, you should not need to specify the type (as long as the TRefArray always points to the same type of objects and has some elements in the first entry).
Error in <TTreeFormula::DefinedVariable>: fStraw is not a datamember of TRefArray
Error in <TTreeFormula::Compile>: Bad numerical expression : "fIDTracks.fTRTHits.fStraw"
The variable fStraw is of type Int_t and belongs to a class inheriting from TObject. fTRTHits is a TRefArray providing the 1:n relationship between a track and its respective hits.
The tree was created with BranchRef() called. The ref table is exisiting in the tree. TTree::Print() gives:
...
*............................................................................*
*Br 92 :fTRTHits.fStraw : fStraw[fTRTHits_] *
*Entries : 10 : Total Size= 8830 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 93 :TRefTable : List of branch numbers with referenced objects *
*Entries : 10 : Total Size= 8774 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
Do we have to do something special when reading the tree? Or is the order of the branches important (ie call t->BranchRef() first and then create the other branches)?
I also tried without esetting the object count in every event which we use for saving disk space. It didn’t help either.
I believe I have the same problem, or at least one that is closely related. It is related to having a TRef(Array) inside a TClonesArray and the relevant code within TTreeFormula never gets called to properly call TRefProxy (which dereferences the TRef object).
A fuller description and a test case has been posted on the bug report: