Home | News | Documentation | Download

TTree::GetEntryWithIndex - error due to cast long -> Int_t

tree

#1

ROOT Version 6.11/01
gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

Hi,

I’m working on a machine learning project. I want to store the output of a classifier in a TTree, along with the corresponding eventNumber and runNumber for each given event. I also want to apply a cut based on some other criteria (number of b-jets for example) so I do not have to run the classifier over ALL the events.

In order to retrieve this information during the actual analysis, I load this “classifier tree” cls_tree and build the index:

cls_tree->BuildIndex( "runNumber", "eventNumber" )

During the event loop, I do:

for ientry in range(n_entries):
    nominal_tree->GetEntry( ientry )
    eventNumber = nominal_tree. eventNumber
    runNumber     = nominal_tree. runNumber
    cls_tree.GetEntryWithIndex( runNumber, eventNumber )

This works fine with some events, but for some others fails. I tracked it down to the following issue: the eventNumber is stored in the nominal tree as a long int, while the GetEntryWithIndex() function accepts both parameters as Int_t . See for example:

root [0] TFile * f = TFile::Open( "derived_trees/classifier.dataAll.2b_incl.root")
(TFile *) 0x113f5720
root [1] TTree * t = (TTree*)f->Get("nominal")
(TTree *) 0x11311e80
root [2] t->BuildIndex( "runNumber", "eventNumber" )
(int) 37542
root [3] t->GetEntryWithIndex( 303638, 4972725192 )
ROOT_prompt_3:1:31: warning: implicit conversion from 'long' to 'Int_t' (aka 'int') changes value from 4972725192 to 677757896 [-Wconstant-conversion]
t->GetEntryWithIndex( 303638, 4972725192 )
   ~~~~~~~~~~~~~~~~~          ^~~~~~~~~~
(int) -1

I can’t change the definition of long int’s in the nominal tree, which is centrally produced. Is there a way to fix this problem in pyroot?

Cheers,
Riccardo


#2

Hi Riccardo,

Could you use TTree::GetEntryNumberWithIndex(), which accepts long ints as parameters, on cls_tree to get the entry number from the index, and then do a regular TTree::GetEntry() on the same tree with that entry number?

Cheers,
Enric


#3

Hi,

the trick you proposed seemed to have worked fine. Thanks! However, I believe I uncovered an inconsistency between the two functions, which are supposed to behave in a similar manner. IMO this situation should be fixed in subsequent releases of ROOT.

Cheers,
Riccardo


#4

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