Storing a histogram array in a TTree


ROOT Version: 6.26/02
Platform: Ubuntu
Compiler: Not Provided


I needed some help to build a tree so that I could store subsets of a multidimensional array of histograms in different branches, i.e: An array in each branch. I can’t really provide much code as an example because I don’t really know how to do it: I’ve got a dynamically allocated 2d array that I want to split in columns and add to a named branch that indicates where the data came from. Here’s what I’ve got so far (It ends up on a segmentation violation ):


TH1 ***vetor_histos=(TH1 ***)malloc(sizeof(TH1 **)*num_chips);
extract_from_tree(sequoia, foldername, vetor_histos);/*The array itself is populated by this function*/
TTree *araucaria=new TTree(titulo_tree,titulo_tree);
char standard[6]="ASIC:";
for (int chip=0;chip<num_chips;chip++){
    char temporario[200];
    char temporario_2[200];
    strcpy(temporario,standard);
    char buffering[5];
    sprintf(buffering,"%d",chip);
    strcat(temporario,buffering);
    strcpy(temporario_2,temporario);
    strcat(temporario_2,"/I");
    TH1 **temporario_3;
    araucaria->Branch(temporario,temporario_3,temporario_2);
    for (int ch=0;ch<(canais);ch++){
      temporario_3=&vetor_histos[chip][ch];
      araucaria->Fill();
    }
  }
  araucaria->Write();

Welcome to the ROOT forum.

I think @pcanal can help you.

Can you clarify why you need this particular setup? What benefit to you hope to get? (i.e. the setup seems unusual and/or I misunderstood what you are trying to achieve).

Sorry for the delayed response! I want the output data to be as organized as possible. For each run, I have got to generate more than a thousand histograms at once (one for each of the multiple channels in multiple ASICs), so just storing them directly in a root file makes for a really messy and hard to navigate output. I want to store the results for each ASIC in different branches, so that it will be easier to access the resulting data from each one of them

What kind of ‘run’ are you meaning here? Is this each execution of the process or do you mean ‘run’ in the LHC Run (subdivised in luminosity block and events)? Asked a different way, how many ‘TTree’ entries do you envision?

more than a thousand histograms at once … for each ASIC in different branches,

Does that mean a thousand branches? How many histogram does each entry of each branch contains? (1 or more than one).

How do you plan to navigate/view the histograms? (Gui, complex C++ code, simple macro, etc.?)

From your code, it seems that the branches are “ASIC:something” (something=chip), and in each of these branches you want one array (of histos) that contains all channels (one histo per channel) in that chip. And these branches are filled once for each event (each run, not shown in the code you shared).
Maybe temporario_3 should be an array of size canais, and then you should assign to it vetor_hitos[chip][0] (only one time for each iteration of chip, i.e. without the loop over canais), so that all the histos in chip are passed and filled into the tree. I don’t know if this would work (probably there’s a better way), butI’d try it; and I’m not sure whether Fill will ignore all the ‘extra’ array elements from vetor_hitos and only take canais elements each time (I suppose it should, since temporario_3 will have that size?).

What kind of ‘run’ are you meaning here?

I mean a run as in one iteration of an experiment, with one TTree for each iteration.

Does that mean a thousand branches? How many histogram does each entry of each branch contains? (1 or more than one).

No. My objective was to divide these histograms among 20 different branches (one branch for each ASIC), to a total of 72 histograms for each branch. My initial plan was to have the histograms as entries of the branches.

How do you plan to navigate/view the histograms? (Gui, complex C++ code, simple macro, etc.?)

I’m still using the root browser for navigating the histograms (this is still the very beginning of the analysis), but they will be further analyzed by more complex C code in the future

Exactly!

I Don’t actually know if I’ve done it right. This code has been written based off some examples I found on the web but I haven’t found any sufficiently clear (at least to me) explanations on how these methods are implemented. I had tried to fill them for each event but I don’t know if it is the best way to do it.

I don’t know if I really understand what you mean. Basically, I should assign a subset of vetor_histos to temporario_3 and pass its adress to the new branch for each iteration?

I don’t think having thousands of histograms is a good idea; how much time will it take to just look at all of them? let alone try to remember enough to make meaningful analysis or comparisons; plus, once the data is in histograms you lose access to the raw data, so they won’t be so useful after that and you’ll need to go back to the original tree anyway.
Since all histos probably have the same structure maybe it’s better to simply make a generic macro to plot any of those histograms on demand, once you know what you want, but maybe that’s still not the best option, before that you should try to better understand what you want, how to look at the data and a good, practical way get what you want from it.

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