TClonesArray with TH1F: help needed

I’m stuck and I need some help. I’m trying to write to a file a TClonesArray with an array of float as object but because TArrayF are not TObjects I use TH1F… so my problem is correctly write (and then read back) a TClonesArray of TH1F. I wrote 2 simple macro which illustrate my problem: what I’m not able to do is to reset the TH1F… it looks like each time I instantiate the TH1F, the histogram is not reset and all the bins keep the previous value adding the new TH1F to the old one…

      tmpHisto = (TH1F*)muoHits->ConstructedAt(n);

I tried different solutions but I was not able to find the correct way to implement what I’d like to do. So if you run first the macro testTClonesArraty.cpp, you write to disk the file out.root with the TClonesArray and then readTClonesArraty.cpp read it back… but what I get is not what I intended to write… What am I doing wrong?

Thanks for helping…


testTClonesArraty.cpp (1.1 KB)
readTClonesArraty.cpp (974 Bytes)

Try adding:



Hi Philippe,
I tried to reset the histogram but I was not able to solve the problem (the read function still returned value different from what I was suppose to write). Actually I switched to the other suggested way to fill the TClonesArray:

      new((*muoHits)[n]) TH1F( *tmpHisto );

and this approach gave me the expected behavior…


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