Bad use of TObjArray

Hi all,
hi wrote a program, that mimincs a more complex one,
that create an array of TH2D histos, but could be of any other type, that are filled with data.

The behaviour of the code is simple: I fill an histo of some data, when some conditions are satisfied, the actual one is added to the array with the command Add() or AddLast(), after it’s content is reset, and starts again the process of filling.
(this is done since in the real case i don’t know how many histograms I need, it depends on data …)

When I try to read the histo in the array, these are all equal!! Why ???
All the histo has to be different, in my example I use a gRandom call, but they appear not to be.
Any solution? Where I do wrong ?

Thanks a lot !
Example1.C (1.96 KB)

Well! they must look the same. You should add a copy (Clone) of the histogram and anot a reference to the histogram.
Instead of
array_z_x2y2->AddLast( h_z_x2y2 );
array_z_x2y2->AddLast( h_z_x2y2->Clone() );


Hi Rene,
everthing now works fine!

Thanks a lot!