Subtract elements of same branch with different selections

Hi, I have a question regarding TTree.Draw().

I have one branch “phi” and another branch “station”. I want to draw the difference of phi’s for certain stations, so something along the lines of:

Tree.Draw(“phi in St. 1 - phi in St.2”)

As I understand a selection would go in the second argument ie Tree.Draw(“var1-var2”, “selections”), although I don’t see how to apply that for my case. Any help is appreciated!

-Matthew

Seems that you are asking an ambiguous question, or you are not providing enough information in your question. How do you determine the pairs to use for each difference? consider, for instance, what if entry one is “station 1” and then entries 2,3,4 are “station 2”?

By default answer would be tree->Draw("phi:station") to get you a 2D plot. Shall we go from there - what is it that you need on top of this?

Hello, thank you for the responses.

Sorry if I am not clear enough with my question, I am not trying to make a 2D plot. Let’s say I want a 1D histogram of the differences in phi between stations. One branch holds the phi values and a second branch holds the station numbers. So if I want a 1D histogram that draws “phi in station 1 - phi in station 2”, does Tree.Draw() support this or is the answer more complicated?

@ dastudillo, I suppose in this case I would want to draw all three combinations. Although for now we should keep it simple and assume there is only one hit per station in the branch.

So you have say 6 stations and you want to plot all… 15 respective differences? And how do you fill the TTree, do you have

TTree entry station phi
0 0 2.3
1 1 2.4
2 5 0.7
3 3 1.1
4 1 2.2
5 0 1.0

How do you plan to calculate differences here? (As you see I’m still lost about what you try to achieve, and without understanding that I cannot suggest what to do.)

@Axel, Say in your example I specifically want to plot the difference in phi between the station 3 and st. 5 hit. Assume you don’t have repeated stations hits just to keep this simple. Does Tree.Draw have a way to pick out these two hits and draw the difference?

Maybe it is more clear if I show what I want to do using an event loop:

 for iEvt in range(evt_tree.GetEntries()):  
    evt_tree.GetEntry(iEvt)
    
    for i in range(len(evt_tree.hit_station)):
       if evt_tree.hit_station[i] == 1: var1 = evt_tree.hit_phi[i]
       if evt_tree.hit_station[i] == 2: var2 = evt_tree.hit_phi[i]
 
    h_dPhi.Fill(var1-var2)

(Of course you must have both station hits available in the event, but hopefully the idea is clear).
I am trying to avoid using an event loop because it takes too long to fill histograms for millions of events. Instead I want to do this with Tree.Draw because that is much faster. Is this more clear what I am trying to do, or still not clear enough?

Maybe:

evt_tree.Draw("Sum$(hit_phi * (hit_station==1)):Sum$(hit_phi * (hit_station==2))"),"Sum$(hit_station==1)>0 && Sum$(hit_station==2)) >0");

But this is still not well defined. Say:

TTree entry station phi
0 5 2.3
1 3 2.4
2 5 0.7
2 5 1.7
2 3 0.9

Which entries (delta) do you expect to have in your histogram: -0.1 (or 0.1?), 1.7, … and then?

I’m not stubborn :wink: - this is about you explaining exactly what you want to get, which again is required for us to be able to help. It might be worthwhile to share a bit of the physics / experimental background of what you try to do; I suspect that the tree / branch layout doesn’t correspond to what you need, but right now all I can do is poke around and ask questions that force you to explain exactly what you’re after…

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