TTreeReaderArray: erase an element

Hi,

I’m looking at the TTreeReader tutorial at https://root.cern.ch/7-using-ttreereader, specifically at this excerpt:

TTreeReader reader("MyTree", file);
TTreeReaderArray<float> raMuonPt(reader, "muons.fPt");
while (reader.Next()) {
    for (int iMuon = 0, nMuons =  raMuonPt.GetSize(); iMuon < nMuons; ++iMuon)
        hist->Fill(raMuonPt[iMuon]);
}

My question is: is there a way to delete some raMuonPt element, similarly to what std::vector::erase would do? What I’d like to do is to introduce another loop over muon pTs before the current one, check e.g. if muon pT > 1 MeV, and if not, to just get rid of this value altogether. Note I don’t want to do it via a continue statement - I want to have raMuonPt.GetSize() decreased, too. Is it possible?

Thanks!


ROOT Version: 6.14/04


The TTreeReaderArray interface does not (want to) know what kind of collection in underneath and thus it is likely challenging to modify it. Depending what you need to do in the end, you might either need to cache the value that pass the criteria in a new container or maybe just simply keep a count of the value that pass the criteria.

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