I have the following problem: I have an array of TH1D objects and I want to use the same style TH1D to initialize them all. If I do this initialization explicitly by specifying the index of each object in the array than everything is perfectly fine (see attached macro withoutLoop.C), but if I use the loop, than the code crashes (see attached macro withLoop.C).
Can anybody suggest what I am missing here?
I am using ROOT 5.24/00 (tags/v5-24-00@29258, Jul 01 2009, 12:22:53 on linuxx8664gcc)
You can insert directly your histograms inside the list as shown below. You can add a Tlist to a TList, but not insert the objects of a list into another list.
I know that I can add histograms directly to TList in the way you have outlined or that I can have nested TLists, but my question was going in a slightly different direction.
Namely, if I have an array of histograms and a list
TH1D *histArray[n];
TList *list;
than I thought (naively) that perhaps it is possible to call method Add() of TList in the following way (or something similar)
list->Add([] histArray);
and than the list ‘would know’ that I want to store all entries of histArray, without a need to loop over all entries of histArray in my code. This would become very handy for multi-dimensional arrays.
In principle the analogous syntax could work if I want to access entries of histArray from the list, but I do not claim that I really understand all possible issues and sideeffects here
So I will stick to what is available now in Root and organize my histograms in the nested lists, instead of arrays.