TTree::Draw and conditional loop over array elements

Hello,

I have a tree with a branch containing objects of this class:

class Event : public TObject
{
	...
	std::vector<double> TrkChi2Prob;
	...
}

An event can contain a number of tracks, the number is given by the size of the `TrkChi2Prob’ vector. The vector contains p-values of the chi^2 fits.

Now, for a given event selection, represented by a TCut cut, it is easy to plot the total number of tracks:

myTree->Draw("branch.@TrkChi2Prob.size()", cut);

Is it possible to modify the Draw command such as it plots only the number of tracks that fullfill a certain goodness-of-fit cut, i.e. TrkChi2Prob[i] > threshold?

Many thanks,

Kašpi.

Cheers,
Philippe.

Cool! Another question. Naturally, the Event class includes more information about the tracks. I’d like to make a scatter plot Y vs. X for all tracks that match a certain criterion. Is it possible to add this criterion to a command like this:

tree->Draw("branch.TrkY[] : branch.TrkX[]", cut);

Thanks,

Kašpi.

Yes, for example:tree->Draw("branch.TrkY[] : branch.TrkX[]", "branch.TrkX[] > 1.1");(You may want to re-read the reference’s guide entry on TTree::Draw :slight_smile: ).

Cheers,
Philippe.

[quote=“pcanal”]Yes, for example:tree->Draw("branch.TrkY[] : branch.TrkX[]", "branch.TrkX[] > 1.1");(You may want to re-read the reference’s guide entry on TTree::Draw :slight_smile: ).
[/quote]

Hmm… I’m not sure that this does what I want. You used “branch.TrkX[] > 1.1” as the event selection. But for the event selection, I need to use something else - a cut for a physics process. Then for the selected events, I want a scatter plot, but just for some tracks (good tracks from a part of the entire detector). Hence there are two selections, that are to be applied on two different levels. Does your suggested command do that?

As for my rereading the guide - this is what I’ve read:
root.cern.ch/root/html/TTree.html#TTree:Draw%1
but I’m not convinced that the answer is there. There is a section Drawing expressions using arrays and array elements' which describes what happens if array indeces are not specified in the drawing-expression. However, I haven't found anything similar for the selection-expression. I can only guess that it loops over all elements and puts a logical operator in between. Again I guess the operator isand’. But still this would be an event-selection. Not a selection of tracks within an event.

Thanks,

Kašpi.

Hi,

Did you try the (obvious to me :slight_smile:) combination:tree->Draw("branch.TrkY[] : branch.TrkX[]", "branch.TrkX[] > 1.1 && Sum$(TrkChi2Prob[i] > %f) > 10");where the cut is only representative of guessed/arbitrary crazy cuts based on the example you provided …

Cheers,
Philippe.

PS. Event vs tracks selection … internally it is has if you have 2 loops
for each event
for each track
select if EventBasedValue && TrackValue[i] is true

[quote=“pcanal”]PS. Event vs tracks selection … internally it is has if you have 2 loops
for each event
for each track
select if EventBasedValue && TrackValue[i] is true[/quote]

Great, this explains everything! IMHO, this logic should be properly explained in the documentation. (This might even avoid your need to reply to questions like mine :slight_smile:).

Thanks,

Kašpi.