Hi Stefano,
your concern ist correct. The removal process will be bugged. Let me point you to a forum message I wrote some time ago exactly concerning that topic
https://forum.gsi.de/index.php?t=tree&th=3737
To do it correctly you can either store the length of the list beforehand like
Int_t n=l.GetLength();
for (l=0; l<n; ++l)
{
i = l-n_removed;
if( ... Some criterion ...)
{
list.Remove( list[i] );
n_removed++;
}
}
or (suggested by Radek) loop reversely through the list with
for (ii=l.GetLength()-1 ; ii>=0; --ii)
Or, as you mention, fill a new empty list with the non-removed candidates.
Best,
Klaus