In a TTree branch containing a vector, drawing the vector results in drawing all N elements for each event. Is there a way to select the best element per event given a criterion. I’m most interested in things like Min/Max element.

In the trunk you can use the TTreeFormula special function Min$,Max$,MinIf$,MaxIf$.

For older version you will to write some customized code and use either MakeSelector, MakeProxy or write a small TTree::Draw script (and use with tree->Draw(“myscript.C”); );

Error in TTreeFormula::Compile: Bad numerical expression : “Max$(RICH_Like[0],Max$(RICH_Like[1],Max$(RICH_Like[2],Max$(RICH_Like[3],Max$(RICH_Like[4],RICH_Like[5])))))”

Does this work in ROOT 6.08? I can not figure out how to use the Max$ and Min$ functionality for a TNtupleD although Draw is inherited from TTree. Here’s a working example of my problem:

TNtupleD* tup = new TNtupleD("tup","tup","x:y") tup->Fill(0.1,3) tup->Fill(0.2,2) tup->Fill(0.3,1) tup->Fill(0.4,0) int n = tup->Draw("x","y==Min$(y)","goff") double xAtMin = tup->GetV1()[0]

I expect xAtMin==0.4 corresponding to the minimum of y, but instead I find xAtMin==0.1. In fact, the number of entries drawn is the full n=4, so the Min$() does not seem to do anything in this case.

I apologize in advance if this is a silly mistake, but I’ve spent too much time looking for an existing answer.

These “$” functions work on the current entry.
So, you would need to have a leaf with an array “y[…]” and then “Min$(y)” would, for each entry separately, find its minimal value (for an ordinary scalar variable “y==Min$(y)==Max$(y)” for each entry, of course).