TTree::Draw of TRef


I looked inside a lot of topics, but I didn’t find any answer to my problem. The more similar is Problem using TTree::Draw command with data in TRefArray but is not exactly the same problem and, anyhow, nobody replied to the guy…

I have a class, DecodeDataAMSL0 acting as “factory” (i.e. filling another event class to be stored inside a TTree. This class has:

class DecodeDataAMSL0 : public DecodeData {
  using EventAMSL0 = GenericEvent<2, 9, 64, 8, 16, 0>;
  using calibelemAMSL0 = calibelem<1024>;

  EventAMSL0 *ev;
  static calibelemAMSL0 calped[2][9];


template <size_t NCh> class calibelem : public TObject {
  float value[NCh];

  ClassDef(calibelem, 2)

and GenericEvent is a template class that is holding my “event”, that is the only TBranch of a TTree. This GenericEvent class has

  TRef refCalPed[2][9];

with the idea to have, on event-by-event basis, the calibration that is a thing that would be the same for all the events (i.e. writing directly calibelem as data member would, and I check is actually doing, waste a lot of disk space even with a quite high compression, both at file level that at branch level).

When filling the first event into the tree, these calibelem’s (2 * 9 elements) are created/populated, written into the TTree::GetUserInfo() and “assigned” to the 2 * 9 TRef’s.

If I try to Draw the resulting TTree what happens is:

  • the TRef is working: without any action it “appears” as a real leaf of the tree and can be draw
  • the plotted values are correct


  • to print 1024 values (first event, notice the “1” passed as last argument) I have to do t4->Draw("refCalPed[0][0][0].value[0]", "", "", 1). Essentially I have to use four indices, while only two were expected:
root [8] t4->Draw("refCalPed[0][0][0].value[0]", "", "", 1)
(long long) 1024

If I do:

root [9] t4->Draw("refCalPed[0][0][0].value", "", "", 1)
(long long) 9216

I end up drawing 9 * 1024. If I do

root [10] t4->Draw("refCalPed[0][0].value", "", "", 1)
(long long) 18432

2 * 9 * 1024 values are drawn, even if I specified refCalPed[0][0]…
With less indices it still works and the result is even more strange:

root [11] t4->Draw("refCalPed[0].value", "", "", 1)
(long long) 165888
root [12] t4->Draw("refCalPed.value", "", "", 1)
(long long) 331776

Another strange point is that:

root [13] t4->Draw("refCalPed[0][0][0][0].value", "", "", 1)
(long long) 1024
root [14] t4->Draw("refCalPed[0][0].value[0][0]", "", "", 1)
(long long) 1024
root [15] t4->Draw("refCalPed.value[0][0][0][0]", "", "", 1)
(long long) 1024

all give the very same result…

Where I’m wrong?


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.26/06
Platform: M1Pro / MacOs Monterey 12.6.8
Compiler: Apple clang version 14.0.0 (clang-1400.0.29.202)

Hi @bozzochet,

thank you for your question. Maybe @pcanal could help here?


Any ideas?

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

This is expected. Due to a quirk of the TTree::Draw parsing (and the fact that it knows what is an array and what is not), the position of the bracket is ‘flexible’ ; note [0][][][0] is also a possible value if you want to iterate over the inner dimensions)

This is also expected. You always need to specify all the dimensions that you want to fix. Any dimensions not specified with be implicitly added as a [].

So if you request the plotting of a 4 dimensional entity (compounding all the dimensions all the way) and only specify 2 (i.e. [0][0]) it will be implicitly completed with [] requesting the iteration through all the elements of those dimensions (i.e. [0][0][][])

If you want get a specific elements elements of the inner dimensions for all instances of the other dimensions, you need something like: [][][0][0] which will plot calped[0][0] for all the elements of refCalPed.