Conversion from MeV to GeV with TDataFrame

I am not sure how to convert select certain brances within a TTree from MeV to GeV. I have the branch names saved to a python dictionary as the keys. So I have something like this:

for key, values in var_dict.items():
	if ('pt' or 'pT' or 'mB') in key:
		hist[key] = df[f].Histo1D(("hist_name",  "hist_name", 40, 0.0, values[-1]/1000), key)

I’ve tried numerous things such as trying to redefine a column using ‘Redefine’ and using ‘Foreach’ to divide each event by 1000 but it complains because I am trying to pass the key as a python string to these functions.

Maybe you can try passing ROOT.std.string(key) to Histo1D, instead of key. This may or may not be the problem, but I don’t use pyroot, so I don’t know whether key should work, but it’s probably worth trying.

So I tried the following:

if ('pt' or 'pT' or 'mB') in key:
		string_key = ROOT.std.string(key)
		hist[key] = df[f].Foreach("string_key /1000").Histo1D((hist_name,  hist_name, 40, 0.0, values[-1]/1000), key)

Now I can pass in ‘key’ as the variable fine and it will create the histogram, but I cannot seem to do anything with it that requires a c++ string.

And it says:

TypeError: Template method resolution failed:
Failed to instantiate "Foreach(std::string)"

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