Skip to content

fix incorrect usage of TClonesArray::GetEntries() instead of ::GetEntriesFast()

Sergey Gorbunov requested to merge se.gorbunov/cbmroot:GetEntriesFast into master

Bildschirmfoto_2021-03-29_um_11.45.08 The name of the TClonesArray::GetEntries() method is very confusing.

It does not return the array size, as one would expect. Instead, it returns the number of non-zero entries in the array.

To get the array size one should use TClonesArray::GetEntriesFast().

A bad thing about GetEntries() is that it takes O(N) operations since at each call it rolls over the entire array.

For example, a typical code:

for( int i=0; i < fMCTracks->GetEntries(); i++){

...

}

takes O(N^2) operations, because at each step GetEntries() performs an additional loop over the array.

I fixed all the places in CbmRoot where I think GetEntriesFast() must be used.

Edited by Sergey Gorbunov

Merge request reports