I have a TTree in a file which contains signals obtained from an oscilloscope.
I can draw traces with
for example, since the events have a unique index stored in the tree. The signals are stored as /F in the tree.
I would like to be able to draw what I mean when I try:
namely, draw the histogram of the average voltage per event. But I get an error:
Any ideas about how to use the very nice tree drawing function to do this (or other TMath functions that operate on arrays)?
Incidentally, why is there no TMath::Sum() function to return the sum of all values in an array? I’ll need to use TMath::Mean(1024,V4)*1024. Given the plethora of convenience functions in TMath, I expected a Sum().
You can use the TTreeFormula special functions. For example:
Thanks, that’s exactly what I was looking for. Is there a good reference page for examples of TTreeFormula usage? The page at http://root.cern.ch/root/html/TTreeFormula.html is not very pedagogical.
For the syntax of the string formula you can take a look at root.cern.ch/root/html/TTree.html#TTree:Draw%2 or at the User’s Guide chapter on TTree.
For the use of objects of type TTreeFormula, there is no specific documentation, looking at the implementation of root.cern.ch/root/html/TTreePlay … layer:Scan is usually a good start.
A more advanced usage question now. I might be pushing the limits of TTree->Draw()'s abilities.
I have a branch in a tree which is an array of integers, represending the wires hit by particle showers, with -1 being a default value meaning no wire hit. In particular, the numbers are a wire ID number, the array index itself would be the particle shower ID number.
I would like to draw a histogram of the number of hits on a particular wire number, event-by-event. E.g., for each entry in the tree, how many times does ‘15’ show up in the array.
I tried doing:
but I’m pretty sure that doesn’t do what I actually want, given that the x axis ends up going way past typical wire ID numbers. Any idea what it’s doing in this case? How is wire_hit == 15 not giving an error, what is it comparing exactly?
Then I tried:
as per the recommendation for implementing a ternary operator deep in the bowels of the TTree:Draw%2 page that you linked. It appears to do what I want, but I was hoping to have a second opinion, since this looks extremely easy to mess up, given the other example above.
intree->Draw("Sum$(wires_hit),"wires_hit == 15")This is equivalent to:
For each wires with wires_hist == 15:
plot the Sum of all wires_hit values
intree->Draw("Sum$(wires_hit==19)")plot the count/number of wires_hit which have the value 19.