TCut objects as arguments


I have made a routine according to the MakeClass example. I read a Tree and then use the Loop() function to Fill a histogram of the selected TBranch. What I would like to do is to set a TCut when I Fill. I can of course do the TTree::Draw(…,TCut arguments, …), but for obvious reasons I dont want to use this routine. I couldn’t find any other function than the TTree::Draw function that accepts TCut objects as arguments. I couldnt put any TCut object into the Draw function for the TH1F.

Where do I set my TCut objects in this case?

Andreas Ekstrom

the only way I can think of is a bit of a workaround. To test whether TTree* tree passes the TCut cut for entry number iEntry (so you can fill the histogram hist), run if (tree->Draw("arbitrary tree var", cut, "goff", 1, iEntry)) myHist->Fill(...); As TTree::Draw returns the number of selected entries you can use it to test whether the current event passed your cuts.

For “simple” functions you can run tree->Draw(“arbitrary tree var>>myHist”, cut) outside the loop (i.e. on the whole tree). This will draw the “arbitrary tree var” into the histogram called myHist, using the TCut cut. See for doc on how to specify the histogram which TTree::Draw should fill.
Cheers, Axel.

1 Like