Applying TCuts

Hi all,

I would like to apply a TCut object “for myself” instead of using TTree::Draw. Looking into the source code of TTreePlayer::DrawSelect leads me to the TSelector class. Nevertheless I was not able to find the point where root determines from the TCut-string if an event is drawn or not. How can I loop over my events and determine “by hand” if an event should be drawn in respect to a given TCut?

Thanks in advance,

Mathias

1 Like

For the TTree::Draw implementation you need to look the TSelectorDraw class. The evaluation of the TCut themselves is done via the TTreeFormula class.

Philippe

1 Like

Hi Philippe,

Thanks for your reply. I had a look at the classes you told me and also at the TTreePlayer::Scan method. But it seems to be very difficult to find the clue of the selection mechanism. Nevertheless I think that the EvalInstance()-method is a good point to start from, isn’t it? What does the Int_t parameter mean that can be specified there? Is it the entry-number? If not, where can I specify the entry which should be tested against the TCut?

So I tried to write a test-script to find out how all this works and encountered some other errors. When executing the script with:

.x test.c

cint tells me:

Error: Can't call TTreeFormula::TTreeFormula("select","Nflg==0",tree) in current scope /home/mathias/ana/root/macros/test.c:5:
Possible candidates are...
filename       line:size busy function type and name  (in TTreeFormula)
*** Interpreter error recovered ***

When compiling a test program the error message looks like:

apps/proc_sel8.dir/procsel8.o(.text+0x3da): In function `kg::ProcSel8::run()':
: undefined reference to `TTreeFormula::TTreeFormula[in-charge](char const*, char const*, TTree*)'

In both cases the error seems to be in the line:

TTreeFormula *select = new TTreeFormula("select", "Nflg==0", data);

I’m using version 5.08/00 of root and according to the manual the specified constructor should be there and should also be public. Any hints on that?

Thanks, Mathias

Humm … the plugin manager should have properly loaded libTreePlayer in the first case (did run gmake map (or gmake install).
In the second case you need to link against libTreePlayer

To set the entry number do:

mytree->LoadTree(myentrynumber); myformula->EvalInstance(array_index);where array_index is the a value between 0 and the maximum number of array element in the expression for this event (this value is return by myformula->GetNdata());

Cheers,
Philippe.

1 Like

Hi Philippe,

Ok, now I got it, thanks again. Though the app is working when linking against libTreePlayer the macros still isn’t. Not a problem for me since I use this in a compiled app … but strange enough …

Cheers, Mathias

For the macro you can load the library explicitly:

gSystem->Load("libTreePlayer);Cheers,
Philippe

Sorry for bothering you again but I was a bit too enthusiastic when telling you that everything is working now. In fact it is working for trees but not for chains. To give you a minimal example:

TFile *f = new TFile("/data/sel8_v10/SEL8.04691f44-04703f04.root"); TTree *tree = (TTree*)f->Get("h3"); TTreeFormula *select = new TTreeFormula("select", "Nflg<0", tree); for (Int_t entry = 0 ; entry < tree->GetEntries() ; entry++) { tree->LoadTree(entry); if (select->EvalInstance()) cout << entry << endl; }
works perfectly but

TChain *chain = new TChain("h3"); chain->AddFile("/data/sel8_v10/SEL8.04691f44-04703f04.root"); chain->AddFile("/data/sel8_v10/SEL8.04685f01-04691f43.root"); TTreeFormula *select = new TTreeFormula("select", "Nflg<0", chain); for (Int_t entry = 0 ; entry < chain->GetEntries() ; entry++) { chain->LoadTree(entry); if (select->EvalInstance()) cout << entry << endl; }
gives me the following error:

*** Break *** segmentation violation Generating stack trace... 0x08050478 in kg::ProcSel8::run() + 0x1bc from apps/proc_sel8 0x08051c6d in kg::App::exec() + 0x35 from apps/proc_sel8 0x08050208 in main + 0x6c from apps/proc_sel8 0x41b5c500 in __libc_start_main + 0xe0 from /lib/tls/libc.so.6 0x08050101 in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x59 from apps/proc_sel8 Is there a difference between Trees and Chains I did not take into account?

Thanks, Mathias

The TTreeFormula object has to be informed each time the chain moves to a new TTree:

TChain *chain = new TChain("h3"); chain->AddFile("/data/sel8_v10/SEL8.04691f44-04703f04.root"); chain->AddFile("/data/sel8_v10/SEL8.04685f01-04691f43.root"); TTreeFormula *select = new TTreeFormula("select", "Nflg<0", chain); Int_t treenumber = 0; for (Int_t entry = 0 ; entry < chain->GetEntries() ; entry++) { chain->LoadTree(entry); if (treenumber!=chain->GetTreeNumber()) { treenumber = chain->GetTreeNumber(); select->Notify(); // or UpdateFormulaLeaves() } if (select->EvalInstance()) cout << entry << endl; }

Cheers,
Philippe

Hi Philippe,

I had to change

to

to get this working. But now I’m happy :slight_smile:

Thanks a lot,

Mathias