Getmaximum value of tree branch


I want to get the maximum value of tree branch.
Without any condition command is like this: tree->GetMaximum(“branch name”) - works fine.
But if I want maximum value of same branch after some condition then what will be the exact command?
tree->GetMaximum(“branch name”,“condition”) - doesn’t work.

Hi renu,
if you have access to ROOT v6-10, TDataFrame can help you:

#include "ROOT/TDataFrame.hxx"
using namespace ROOT::Experimental;

int main() {
  TDataFrame d("treename", "filename.root");
  auto max = d.Filter("condition").Max("branch");
  return 0;

where “condition” can be a string that must contain a valid c++ expression that returns a boolean, or you can pass a proper c++ function (or lambda, or functor class) like this:

d.Filter(functionFilter, {"branch1", "branch2"})
1 Like


Can we use same thing in ROOT 5 version?

I am afraid not, TDataFrame is a new interface introduced in v6.10. I suggest you upgrade if you can, ROOT 5 has not been updated in more than one year and has several known issues.

With that said, maybe @pcanal or @dpiparo know how to get the maximum of a filtered branch in ROOT 5.

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

You can do something like:

tree->Draw("branch name","condition");