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 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?
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());
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 …
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?