ROOT Version: 6.26.04
Platform: Ubuntu 20.04
Compiler: g++ 9.4.0
Hello, I wonder how to skip some entries that do not meet criteria when using TSelector?
Below is an example when using traditional event loop:
TFile* file = new TFile("test.root","read");
TTree* tree = (TTree*)file->Get("TestTree");
Int_t x;
tree->SetBranchAddress("x",&x);
Int_t nEntries = tree->GetEntries();
for (int entry = 0; entry < nEntries; entry++)
{
tree->GetEntry(entry);
if(x>=10) continue; // skip events that x>=10;
printf("x=%d\n",x);
}
When using TSelector, I do not have control of the event loop. I tried to do something in the Bool_t Selector::Process(Long64_t entry)
like this:
Bool_t Selector::Process(Long64_t entry)
{
// The Process() function is called for each entry in the tree (or possibly
// keyed object in the case of PROOF) to be processed. The entry argument
// specifies which entry in the currently loaded tree is to be processed.
// It can be passed to either Selector::GetEntry() or TBranch::GetEntry()
// to read either all or the required parts of the data. When processing
// keyed objects with PROOF, the object is already loaded and is available
// via the fObject pointer.
//
// This function should contain the "body" of the analysis. It can contain
// simple or elaborate selection criteria, run algorithms on the data
// of the event and typically fill histograms.
//
// The processing can be stopped by calling Abort().
//
// Use fStatus to set the return value of TTree::Process().
//
// The return value is currently not used.
if (x >= 10)
{
return kFALSE;
}
printf("x=%d\n", x);
return kTRUE;
}
Is this the proper way to skip some entries, or do the “preselection”?
Thanks!