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;
}
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));
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?
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.