I need to copy a histogram in an another histogram for that I was doing like this:
hist[var1+19] = hist[var1]->Clone();
where hist is an array of histogram.
but then I am getting error stating:
Error: Incorrect assignment to hist[var1+19], wrong type ‘TObject*’ Data_MC_Comparision_v0.C:264:
*** Interpreter error recovered ***
(const class TObject*)0x29b2b010
Please suggest what may be the error.
Thanks & regards,
this is a C++ issue. You need to cast the result of the clone method to the right type, i.e. the type of pointer stored in your array (it is not possible to deduce which kind of histogram it is from your message - TH1F,TH1D, …)
I defined histogram like
TH1F * hist[20*nbranch];
where nbranch=4 of type int.
Then I defined hist[var1] (reading this from tree) like
hist[var1]= new TH1F(TString(“H_Data_”)+TString(Str),TString(bnames[i]),100,range[r],range[r+1]);
till this point my code is working fine and histogram is correct.
But when I tried to make clone of it, I got error.
Just cast the pointer correctly, for example:
hist[var1+19] = static_cast<TH1F*>(hist[var1]->Clone());