Problem with TH2F::Add()


I’m trying to do the following:

  • retreave several TH2F objects from the same TTree but with different selection cuts, and add them to a TList:
    TList* list;
    tree->Draw(“variable(binning)”, cut1);
    TH2F* histo1 = (TH2F*) tree->GetHistogram();
    tree->Draw(“variable(binning)”, cut2);
    TH2F* histo2 = (TH2F*) tree->GetHistogram();
    etc …

  • to merge them into a final TTree:
    TH2F* finalhisto = (TH2F*) histo1->Clone(“finalhisto”);

I have the following message:
Error in TH2F::Add: Attempt to add object of class: TObject to a TH2F

but I define the TH2F* histogrammes I merge properly …

Thank you very much for your help.

Best regards, Selim

Are you sure all the histogram in your list are TH2 objects ? Maybe you have some histograms which are one dimensional. I woult try to print the list elements, by doing


Thank you for the prompt reply, the display of the list content lead me to the error: there were a few histograms with identical name in the argument of their declaration …

Regards, Selim