If I add two histograms to the same place in a TObjArray do they get merged?

Hello, I have 12 categories of events depending on their multiplicity, and for each event I care about 3 quantities, that makes 36 histograms in total.

I created a collection:

  TObjArray *all_histos    = new TobjArray(12);

and in each “drawer” I included another collection like so:

  TObjArray *mult1_histos  = new TobjArray(3);
  TObjArray *mult2_histos  = new TobjArray(3);
...
  TObjArray *mult12_histos  = new TobjArray(3);

  all_histos->Add(mult1_histos);
  all_histos->Add(mult2_histos);
...
  all_histos->Add(mult12_histos);

so I have 12 “drawers” each with 3 divisions to order all my histograms.

Then I calculate the multiplicity, and put everything in place:

    for (int n = 0; i < 12; ++n)
    {
     if ( mult >= mult_range[n] )
     {
      all_histos->At(n)->AddAt(hist_pTdelta_AjInc,0);
      all_histos->At(n)->AddAt(hist_pTdelta_AjA,1);
      all_histos->At(n)->AddAt(hist_pTdelta_AjB,2);
      break; //otherwise it would put this data in the drawers for events with lower multiplicity as well
     } 
    }

But then I wasn’t so sure of my reasoning, mi idea was, that if two events fall in the same multiplicity range, when I try to store the histograms, they will merge, adding the data of the two events, similar to how you can Fill() a histogram with more data without the previous data being deleted, but now I’m not so sure.

If this is mentioned in the documentation, I haven’t been able to find it or I didn’t understand it.

Thanks

Edit:

I came up with this alternative in case the histograms get replaced and not added, I just need to know which one to use now.

Also is a little confusing that for TCollections Add() includes new objects into the collection but for Histograms it adds the contents of the histograms.

    for (int n = 0; i < 12; ++n)
    {
     if (mult>=mult_range[n])
     {
      hist_pTdelta_AjInc->Add( (TH2D*) all_histos->At(n)->At(0), 1 );
      hist_pTdelta_AjInc->Add( (TH2D*) all_histos->At(n)->At(1), 1 );
      hist_pTdelta_AjInc->Add( (TH2D*) all_histos->At(n)->At(2), 1 );

      all_histos->At(n)->Clear();

      all_histos->At(n)->AddAt(hist_pTdelta_AjInc,0);
      all_histos->At(n)->AddAt(hist_pTdelta_AjA,1);
      all_histos->At(n)->AddAt(hist_pTdelta_AjB,2);
      break; //otherwise it would put every event in all the events with lower multiplicity
     } 
    }

Hi,

I might be wrong, but I think the object is replaced (you can just try…)

Cheers, Bertrand.

1 Like

It is replaced, thanks

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