Inf/NaN propagated to the pad

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);
h_pion_invariant_mass_weight->Sumw2();




if ((!TMath::Finite(weight_total)) || (weight_total < 0.0) ) {
    std::cout  << " weight total  = " << weight_total  << std::endl;
         continue;
   } else {
     h_pion_invariant_mass_weight>Fill(pion_invariant.M(),weight_total);
     }
                                            

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

Thanks
Dil

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);
       }
        //h_pion_invariant_mass_Stat_Syst->SetBinContent(j,h_pion_invariant_mass_weight->GetBinContent(j));
       h_pion_invariant_mass_Stat_Syst->SetBinError(j,Sys_error);
    }

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
too.

Thanks
Dil

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;
-125
root [1] cout << std::numeric_limits<double>::min_exponent << endl;
-1021

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.

Thanks
Dil

Using TH1D is not to remove the e-315, but to avoid the “Inf/NaN propagated to the pad” issue when you plot the histogram. Did it still happen with TH1D? If so, can you post a complete macro (using for example the small data file you posted, weight_total.txt) that you use that leads to this problem?

dastudilloYes I should’ve mentioned it I had Inf/Nan problem even after TH1D.(sorry for the wrong reply)

Finally I was able to get rid of Inf/nan pad using following.

if(weight_total < std::numeric_limits<float>::min() || weight_total > std::numeric_limits<float>::max()) continue;