Problem with doing GetEntry() twice in the code

Hello,

I am reading a root tree. I want to do

only when a criteria is satisfied (in my case if 2 electrons are found)
To check if doing GetEntry twice doesn’t create any problem, I do the following
in the code:

Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; cout<<"==============NEW============="<<endl; cout<<"jentry "<<jentry<<endl; b_patelesize->GetEntry(jentry); cout<<"patelesize "<<patelesize<<endl; nb = fChain->GetEntry(jentry); nbytes += nb; cout<<"after second round patelesize "<<patelesize<<endl;

For some events I do not find any problem. But for the events listed below I find this problem:

==============NEW============= jentry 39380 patelesize 0 after second round patelesize 1 ==============NEW============= jentry 39381 patelesize 1 after second round patelesize 0 ==============NEW============= jentry 39382 patelesize 0 after second round patelesize 1 ==============NEW============= jentry 39383 patelesize 1 after second round patelesize 0 ==============NEW============= jentry 39384 patelesize 0 after second round patelesize 0 ==============NEW============= jentry 39385 patelesize 0 after second round patelesize 1 ==============NEW=============

So number of electrons before fChain->GetEntry() and number of electrons
after doing if are different.
Is doing this way in the code not advisable?
If not then is there any other way of achieving the same?

Thanks & Regards,
Shilpi

Hi,

The value to be passed to TChain::GetEntry and to TBranch::GetEntry is different. For TChain::GetEntry you must pass the entry index in the TChain while for TBranch::GetEntry you must enter the entry index within the current underlying TTree (i.e. the value returned by LoadTree). So your code should look like:Long64_t for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t local_entry = LoadTree(jentry); .... b_patelesize->GetEntry(local_entry); .... nb = fChain->GetEntry(jentry); ....

Cheers,
Philippe.

Hello Philippe,

Thanks for your reply. I did this and its working.

Best Regards,
Shilpi