diff --git a/SimG4CMS/Calo/src/CaloSD.cc b/SimG4CMS/Calo/src/CaloSD.cc index a7c8f12263dc5..9b0f172d4e102 100644 --- a/SimG4CMS/Calo/src/CaloSD.cc +++ b/SimG4CMS/Calo/src/CaloSD.cc @@ -321,8 +321,9 @@ bool CaloSD::checkHit() { found = true; } } else if (nCheckedHits > 0) { - size_t minhit = (theHC->entries() > nCheckedHits ? theHC->entries() - nCheckedHits : 0); - int maxhit = theHC->entries() - 1; + int nhits = theHC->entries(); + int minhit = std::max(nhits - nCheckedHits, 0); + int maxhit = - 1; for (int j = maxhit; j > minhit; --j) { if ((*theHC)[j]->getID() == currentID) {