New defined column in RDataframe return nan value

So there are two things going on:

  1. TTree::Draw converts nans to zeros on the fly, RDataFrame does not – one one hand TTree::Draw’s behavior is nicer, on the other it might silently hide issues in your calculations
  2. ROOT histograms that have been filled with nans cannot be drawn, as you experienced

I guess Electron_dxy is an array of values, so what we are returning is an array of true/false values.
In that case, you can use RVec’s masking feature instead to discard the non-positive elements before taking the logarithm:

auto zMean = d.Define("logd" , "log(Electron_dxy[Electron_dxy > 0])").Mean("logd"); 

Cheers,
Enrico

1 Like