Issue with TTree::Draw and Conditional Branch Selection

Hey guys… :wave:

I am currently working on analyzing a ROOT file containing a large TTree with multiple branches, and I am running into some trouble when using the TTree::Draw method with conditional branch selection.

Specifically, I need to apply a condition to select events where one branch (let’s call it BranchA) satisfies a specific range, and then plot the corresponding values of another branch (BranchB). Here’s a simplified version of the code I’m using:

TFile* file = TFile::Open("data.root");  
TTree* tree = (TTree*)file->Get("myTree");  
tree->Draw("BranchB", "BranchA > 10 && BranchA < 50");  

While this works for some of my datasets, I occasionally encounter unexpected results—plots that appear empty even though I know the condition is satisfied for several entries. I’ve double-checked the branch names and values in the TTree Viewer, and everything seems fine.

I have not found any solution. Has anyone else experienced similar issues? Could it be related to the way the branches are stored or some internal optimization in TTree::Draw? Any advice on debugging this further or alternative approaches would be greatly appreciated.

Thanks in advance!

How exactly do you know? For example, does

tree->Scan("BranchB", "BranchA > 10 && BranchA < 50"); 

give you entries while

tree->Draw("BranchB", "BranchA > 10 && BranchA < 50"); 

doesn’t? If this is the case, check in detail the events that Scan shows but Draw doesn’t, maybe there’s some issue with the tree.

Another idea is to look at the result of:

tree->Scan(tBranchB:BranchA:BranchA>10:BranchA<50:BranchA > 10 && BranchA < 50");

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