Hi Topher, You might want to look at the TEventList class. This class contains a list of events (indices, really) from a TTree that satisfy a cut condition. To use it, you could do (assuming TTree *T and TCut cuts): T->Draw(">>elist",cuts); TEventList *elist = (TEventList*)gDirectory->Get("elist"); Int_t npassed = elist->GetN(); // number of events to pass cuts The advantage is that if you then wanted to look at only those events that passed the cuts, that list exists and T->SetEventList(elist); will have future Draw's and Projects use only those events. This can lead to significant time saving. Also, no need for a 'dummy' variable. After you are finished with that list, the TTree can be reset with: T->SetEventList(0); Good luck, Rob On Wed, 24 Sep 2003, Topher Cawlfield wrote: > Date: Wed, 24 Sep 2003 16:44:27 -0400 > From: Topher Cawlfield <cawlfiel@uiuc.edu> > To: roottalk@pcroot.cern.ch > Subject: [ROOT] Making cut scans from a TTree -- counting events > > Hi, > > Does anyone know how I can (quickly and easily) get a count of events in > a TTree that pass a certain cut? One method is to make a histogram, use > TTree::Project to fill it, and then get the total bin contents from > TH1::GetStats. But this seems unnecessarily tedious and time-consuming, > creating (and later destroying) a histogram, and requires knowing of a > dummy variable to bin in. > > The reason for this is that I want to make a simple, general-purpose > utility for creating plots of quantities like yield and S/N for a > variety of cuts. One common way to assess yield and background is to > perform a fit. Simpler still, one could perform background subtraction > (such as sideband, wrong-sign, Monte Carlo, etc.). > > So, I thought I'd make a function that takes a baseline cut, an array of > experimental cuts, and an instance of a subclass of "Evaluator", and > makes a plot (one point per cut). Evaluator would be an abstract class > that defines a "getXY" virtual function that takes a cut and returns an > x, dx, y, and dy. X and Y would be, for example, S/N and yield. Then > I'd make a derived class, say "EvalSubtract", that you can hand a TTree, > signal cut, and background cut. The evaluation of signal (or > background) would simply be a count of events passing both the analysis > cuts and the signal (or background) cuts. Well, it sounded trivial to > me, until I ended up searching through the root docs for a TTree member > function that performed the count. No luck! > > I suppose one solution could be to write a counting TSelector and using > TTree::Process. But I don't know how to write the ProcessCut function > to evaluate a TCut, or whether or not this is the best way. > > Any ideas? > > Topher Cawlfield > > -- /*************************************************** * Robert Feuerbach feuerbac@jlab.org * * Jefferson Lab CEBAF Center A120 * * 12000 Jefferson Avenue Office: (757) 269-7254 * * Mail Stop 12H Page: 584-7254 * * Newport News, VA 23606 Fax: (757) 269-5703 * ***************************************************/
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET