Profile Plot Cutting out events in leaf arrays

Hey everyone,

I have a root tree with a fairly complicated structure. The root tree comprises of several branches that has multiple leafs that are usually arrays. So here is a an example in PyRoot:

taTree.GetEntry(1) 
taTree.stpln.ig
<cppyy.gbl.std.vector<int> object at 0x277476d8>
 print(taTree.stpln.ig)
[1,0,1,0,1,1,1,0,1,-2,-2,-2,-2,-2,1,0,1,0,0]

Now my problem is that I want to cut out events in profile plot that have too many “-2’s” in this array. I have created a function below that does just that:

Int_t event_saturation_cut(vector<int> tubeArray, Int_t saturation_limit)
{
  Double_t nentries = tubeArray.size();
  Double_t saturation_count = 0.0;
  for(Int_t i = 0;i < nentries;i++)
    {
      if (tubeArray[i] == -2)
	{
	  saturation_count += 1.0;
	}
    }
  Double_t saturation_percent = saturation_count / nentries;
  Double_t saturation_plimit  = saturation_limit / 100.;
  if (saturation_percent <= saturation_plimit)
    {
      return 1;
    }
  return 0;
}

It works outside the draw function just fine! But when I try to draw the profile with this cut I get an error:

taTree.Draw("(log((missing_E_corr(prfc->eng[6]))/mc04->energy)):log10(mc04-energy)","event_saturation_cut(stpln.ig,20) == 1","prof")
Error in <TTreeFormula::Compile>:  Bad numerical expression : "event_saturation_cut(stpln.ig,20)"
Info in <TSelectorDraw::AbortProcess>: Variable compilation failed: {(log((missing_E_corr(prfc-eng[6]))/mc04->energy)):log10(mc04->energy),event_saturation_cut(stpln.ig,20) == 1}

Any ideas on why this isn’t working? Also how exactly are the cuts applied? I couldn’t find out exactly how in the documentation of the draw function. Strangely enough this works:

taTree.Draw("(log((missing_E_corr(prfc->eng[6]))/mc04->energy)):log10(mc04->energy)","stpln.ig == 1 ","prof")

But I am unsure on how to interpret it since I don’t understand how root is implementing the cut.

Any help would be great!


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22.02
Platform: Ubuntu 18
Compiler: Not Provided


@moneta, @couet, any idea what could be the issue?

It looks like an issue with TFormula. @moneta will know better.

For the Bad numerical expression error, you can try:

taTree.Draw("(log((missing_E_corr(prfc->eng[6]))/mc04->energy)):log10(mc04-energy)",TString::Format("event_saturation_cut(stpln.ig,20) == 1"),"prof")

@dastudillo I tried this and got the same error. I don’t think the problem has to do with it not being interpreted as a string.

One of my colleges got back to me and emailed this link. Basically what I was doing isn’t possible.

The problem is in not in TFormula but TTreeFormula, and I think @pcanal explained it in the above linked post
Lorenzo

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