Strange TClones Array Removal Problem

I have a method in my analysis code which was to remove untaggable jets. I was looking at the TClonesArray class which reports a RemoveAt(int) method which is what I thought that I should use for this. The problem is that I get a segfault when I try to dereference tmpjet after a RemovalAt(int) call. I thought that I might be something related to the end of the TClonesArray but it is not. I have included the method and the output of the code here. Thanks for any help.

void Analysis::stripUntaggabileJets() {
  for(int i = 0; i < jets_array->GetEntries(); i++) {
    cout << "There are " << jets_array->GetEntries() << " jets and trying to pull index " << i << endl;
    MyJet *tmpjet = (MyJet*) jets_array->At(i);

    if(!tmpjet->taggable) {
      jets_array->RemoveAt(i);
      i--;
      cout << "Removing a jet, the jet size is now: " << jets_array->GetEntries() << endl;
    }
  }
}

The version of root that I am using is

  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version  4.04/02b       3 June 2005   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************

Compiled on 16 March 2006 for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.15.169, Mar 14 2005
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.

Hi,

RemoveAt does not compact the TClonesArray. So you have the following:jets_array->RemoveAt(i); assert(jets_array->At(i) == 0);

You need to use GetEntriesFast instead of GetEntries in the for condition and you need to do decrease i [alternative but much slower you can call jets_array->Compress() after each RemoveAt]

Cheers,
Philippe