TH1D->GetMean()

Hi guys,
I have a naive question.
I try to get the mean value of a TH1D through TH1D->GetMean().
But I found the Mean: nan, std dev: nan in the statistic box.
I didn’t find the inner reason.

How have you created your histogram?
Can it be that some of its bins are “nan”?

Thanks,
the main process I created the histogram is below:

TH1D* hist_Q4Q4_TrkmTrkp_Re_centbin[N_CENTBIN];
TH1D* hist_Q4Q4_TrkmTrkp_Im_centbin[N_CENTBIN];
TH1D* aux_hist_Q4Q4_TrkmTrkp = new TH1D(“aux_hist_Q4Q4_TrkmTrkp”,"",2000,-0.02,0.02);

for(Int_t i=0; i<N_CENTBIN; i++){
hist_Q4Q4_TrkmTrkp_Re_centbin[i] = (TH1D*)aux_hist_Q4Q4_TrkmTrkp->Clone(“Q4Q4_TrkmTrkp_Re_”+label_centbin[i]);
hist_Q4Q4_TrkmTrkp_Im_centbin[i] = (TH1D*)aux_hist_Q4Q4_TrkmTrkp->Clone(“Q4Q4_TrkmTrkp_Im_”+label_centbin[i]);
}

hist_Q4Q4_TrkmTrkp_Re_centbin[i]->Fill(aux_Q4Q4_TrkmTrkp_Re * 1./wi, wi);

The strange place is there is no “nan” bug just a small sample. When I filled large dataset, the nan bug will appear.
In addition, how can i check whether some of it bins are “nan”?

What is label_centbin[i] (a std::string or a TString?)?

Try something like this:
if ((!TMath::IsNaN(aux_Q4Q4_TrkmTrkp_Re)) && (aux_Q4Q4_TrkmTrkp_Re != TMath::Infinity()) && (!TMath::IsNaN(wi)) && (wi != TMath::Infinity()) && (wi != 0)) hist_Q4Q4_TrkmTrkp_Re_centbin[i]->Fill(aux_Q4Q4_TrkmTrkp_Re / wi, wi);

Thanks a lot, label_centbin[i] is a TString to create different centrality.
I check that and found there is the condition that wi=0, I think that is the true reason.

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