Question about Files in TChain

Hello. I have a question about the files in TChain. I have a large number of root files which I chain together. For my analysis, I want only the first 25% of entries in each individual root file of the chain. My idea was to create a variable eventFrac = (ientry/events_total). As my code runs, ientry resets for each individual file in the chain. The problem is that events_total is calculated for the chain and not the individual files. I have tried two method to calculate events_total:
2) Long64_t nentries = fChain->GetEntiresFast();
double events_total = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++)
//load the event number jentry
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
//Count the number of events
events_total += 1.;

Both methods calculate the entries in the chain. I know there is a method fChain->GetCurrentFile(). Is there anyway to get the number of entries in the current file, and then reset for each file? I know that I could run the analysis with 1 file per job to fix this, but I was wondering if there was a better way. Thanks.


Modify your “event loop”: // ... if (ientry < 0) break; if (ientry >= (fChain->GetTree()->GetEntries() / 4)) continue; // at most 25% of entries // ...