Inf/NaN propagated to the pad

Hello experts,

I am trying to draw a histogram, but I got a empty plot because of the following warning.

(TFile *) 0x1f93330

root [1] h_pion_invariant_mass_Stat_Syst->Draw("wo_Inf_NaN")

Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1

Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.

Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

root [2] Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.

Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.

Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

I tried the way that h_pion_invariant_mass_Stat_Syst->Draw("wo_Inf_NaN")option but still got the empty plot.
Is there a way to get rid of “Inf/nan” values and draw the plot?

Thank You

Did you try to search on the forum? Search results for 'Inf/NaN propagated to the pad' - ROOT Forum
If you did and didn’t find a solution, I think @couet can help

what is h_pion_invariant_mass_Stat_Syst ? an TTree ?
If yes it looks like your variable wo_Inf_NaN is corrupted with Inf and/or Nan and it cannot be drawn.

Even if I used it as follows, I got Inf or nan values.Why is that?

TH1D* h_pion_invariant_mass_weight=new TH1D("h_pion_invariant_mass_weight", "pion invariant mass weight by efficiency",200,0.0,2.5);

if ((!TMath::Finite(weight_total)) || (weight_total < 0.0) ) {
    std::cout  << " weight total  = " << weight_total  << std::endl;
   } else {

I found this from Inf/NaN propagated to the pad. Check drawn objects - #7 by Soumyadip


You do not protect weight_total against being a NaN.

Wouldn’t Finite(weight_total) also catch a NaN? but I don’t know whether the mask in Finite behaves like isfinite, according to the docs.
@Dil: Have you checked pion_invariant.M() too?
By the way, h_pion_invariant_mass_weight>Fill... is missing a “-” but I suppose it’s just here, not in the actual code.

I do not think so. You should use also IsNaN.

1 Like

@couet How to skip nan numbers in txt file - #7 by Wile_E_Coyote

@dastudillo Checking “pion_invariant.M()” is not necessary (only the “weight_total” matters).

@Dil Histograms have no "wo_Inf_NaN" drawing option. Can it be that you “scale” the histogram (before drawing)? If yes, it could be that the “scaling factor” is invalid.

1 Like

In the first post it was not clear if h_pion_invariant_mass_Stat_Syst was a tree or an histogram. wo_Inf_NaN may have been a tree variable.

@dastudillo I checked pion_invariant.M().That didn’t work.

Wile_E_Coyote I haven’t scaled the histogram.

h_pion_invariant_mass_Stat_Syst is follows.May be h_pion_invariant_mass_Stat_Syst is having problem because I cloned it to the h_pion_invariant_mass_weight histogram. h_pion_invariant_mass_weight crashes because of Inf/Nan values.

TH1F * h_pion_invariant_mass_Stat_Syst= (TH1F*)h_pion_invariant_mass_weight->Clone("h_pion_invariant_mass_Stat_Syst");
    for(int j=1;j<=200;j++){
        error_weight = h_pion_invariant_mass_weight->GetBinError(j);
      error_systamatic= h_pion_invariant_mass_weight_systamatic->GetBinError(j);
       if(h_pion_invariant_mass_weight->GetBinLowEdge(j)<2.*Mpi) {
           Sys_error = 0.0;
       } else{
           Sys_error= sqrt(error_weight * error_weight  + error_systamatic* error_systamatic);

So try with:
h_pion_invariant_mass_Stat_Syst->SetBinError(j, (TMath::Finite(Sys_error) ? Sys_error : 0.));

BTW. In one of your previous posts, you have “TH1D* h_pion_invariant_mass_weight” but in the last post, you have “(TH1F*)h_pion_invariant_mass_weight”. This is not allowed. You need to make sure that all involved histograms are of the same class.

Thank you Wile_E_Coyote,
I will try this.

Meanwhile I am trying TMath::IsNaN() and txt file How to skip nan numbers in txt file - #7 by Wile_E_Coyote


Not sure I understand your new edit?

Uncle Google → C++ ternary operator

Got it. Will try this.Thank You

Hello all,

My weight histogram still has the same Inf/Nan issue even if I used following. I used How to skip nan numbers in txt file - #7 by Wile_E_Coyote too

This happens when I running more data. For few data files, this works.

if(weight_total > 0.0){
       if(TMath::Finite(weight_total) && !TMath::IsNaN(weight_total)){ h_pion_invariant_mass_weight->Fill(pion_invariant.M(),weight_total);

I can post a .txt file with values. It contains e^-315 etc… values.(this is not all data I have)
weight_total.txt (12.5 KB)

Those values haven’t skipped from TMath::Finite(weight_total).
Any ideas would be great.

On 64-bit linux I have:

root [0] cout << std::numeric_limits<float>::min_exponent << endl;
root [1] cout << std::numeric_limits<double>::min_exponent << endl;

It seems that you are using TH1F

TH1F * h_pion_invariant_mass_Stat_Syst= (TH1F*)h_pion_invariant_mass_weight->Clone("h_pion_invariant_mass_Stat_Syst");

Can you try with doubles instead of floats?

Try (for a TH1F which uses “float”):
h_pion_invariant_mass_weight->Fill(pion_invariant.M(), ((weight_total > std::numeric_limits<float>::min()) ? weight_total : 0.));

I tried both methods.

dastudillo TH1D–No didn’t work.Still e^-315 is there

Wile_E_Coyote. h_pion_invariant_mass_weight->Fill(pion_invariant.M(), ((weight_total > std::numeric_limits::min()) ? weight_total : 0.));
–This also has e^-315.

Not sure what is it.