How to use TEventList correctly

Dear,

I have been trying to use TEventList to select events from a Tree, but I am getting the full collection of data. For instance, I am getting the total number of entries, instead of the desired selection. Could you please indicate me what I am doing wrong in this piece of code:
TTree OptData = (TTree)gDirectory->Get(“Hits”);
OptData->SetBranchAddress(“edep”,&edep);
OptData->SetBranchAddress(“time”,&time);
OptData->SetBranchAddress(“posX”,&posX);
OptData->SetBranchAddress(“posY”,&posY);
OptData->SetBranchAddress(“pixelID”,&pixelID);
OptData->SetBranchAddress(“eventID”,&eventID);
OptData->SetBranchAddress(“PDGEncoding”,&PDGEncoding);

OptData->Draw(">>elist",“PDGEncoding==-22 && pixelID == 0 && eventID==0”);
TEventList* tel = (TEventList*)gDirectory->Get(“elist”);
OptData->SetEventList(tel);
nEntries = OptData->GetEntries();
cout<<" nEntries= “<< nEntries << endl;
if (nEntries>0)
{
tMinimum = OptData->GetMinimum(“time”);
cout<<” Arrival time of the first fóton = “<< tMinimum << endl;
for(int n=0;n<nEntries;n++)
{
OptData->GetEntry(n);
// Do something
nHits++;
}
cout<<” nHits= "<< nHits << endl;
nHits = 0;
}

regards,
Daniel


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24.06
Platform: Linux
Compiler: g++


Hi,
the Draw return the number of entries in the selection like said here

So if you change the line below
OptData->Draw(">>elist",“PDGEncoding==-22 && pixelID == 0 && eventID==0”);
with
Double_t entries_cut=OptData->Draw(">>elist",“PDGEncoding==-22 && pixelID == 0 && eventID==0”);

you will have the correct entries number.

Anyway to get the correct instance from the TTree you have to change
OptData->GetEntry(n);
with
OptData->GetEntry(tel->GetEntry(n));

Stefano

Dear Stefano,

Thank you for your reply. Now it seems to work fine, but I notice my code run very slow when I use thousands of eventID. Is there a way to make the computation more time efficient?

Regards,
Daniel

You can use the SetBranchStatus,
first you disable all the Branches with
OptData->SetBranchStatus("*",0);
then you enable only the branches you need like
OptData->SetBranchStatus("edep",1);

This should help.
If it is not enough you have to use RDataFrame which is designed for the multithread approach.

Stefano

Thanks, Stefano! I will try it.
Could you recommend an example using RDataFrame that suits my needs?

Daniel

Unfortunately apart from the example on the documentation page, I do not know any

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.