diff --git a/SimG4CMS/Calo/src/CaloSD.cc b/SimG4CMS/Calo/src/CaloSD.cc index da109078f9ef9..eedb48d30ad4f 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) { - int 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 = nhits - 1; for (int j = maxhit; j > minhit; --j) { if ((*theHC)[j]->getID() == currentID) { @@ -503,8 +504,8 @@ void CaloSD::update(const ::EndOfEvent*) { double zloc(0.0); double zglob(0.0); double ee(0.0); - - for (int i = 0; i < theHC->entries(); ++i) { + int hc_entries = theHC->entries(); + for (int i = 0; i < hc_entries; ++i) { if (!saveHit((*theHC)[i])) { ++wrong; } diff --git a/SimG4CMS/Calo/src/HcalTestAnalysis.cc b/SimG4CMS/Calo/src/HcalTestAnalysis.cc index e37ed31c7e0e0..d46278523ff28 100644 --- a/SimG4CMS/Calo/src/HcalTestAnalysis.cc +++ b/SimG4CMS/Calo/src/HcalTestAnalysis.cc @@ -325,8 +325,9 @@ void HcalTestAnalysis::fill(const EndOfEvent* evt) { CaloG4HitCollection* theHCHC = (CaloG4HitCollection*)allHC->GetHC(HCHCid); edm::LogVerbatim("HcalSim") << "HcalTestAnalysis :: Hit Collection for " << names_[0] << " of ID " << HCHCid << " is obtained at " << theHCHC; + int hchc_entries = theHCHC->entries(); if (HCHCid >= 0 && theHCHC != nullptr) { - for (j = 0; j < theHCHC->entries(); j++) { + for (j = 0; j < hchc_entries; j++) { CaloG4Hit* aHit = (*theHCHC)[j]; double e = aHit->getEnergyDeposit() / GeV; @@ -371,8 +372,9 @@ void HcalTestAnalysis::fill(const EndOfEvent* evt) { CaloG4HitCollection* theEBHC = (CaloG4HitCollection*)allHC->GetHC(EBHCid); edm::LogVerbatim("HcalSim") << "HcalTestAnalysis :: Hit Collection for " << names_[1] << " of ID " << EBHCid << " is obtained at " << theEBHC; + int ebhc_entries = theEBHC->entries(); if (EBHCid >= 0 && theEBHC != nullptr) { - for (j = 0; j < theEBHC->entries(); j++) { + for (j = 0; j < ebhc_entries; j++) { CaloG4Hit* aHit = (*theEBHC)[j]; double e = aHit->getEnergyDeposit() / GeV; @@ -407,8 +409,9 @@ void HcalTestAnalysis::fill(const EndOfEvent* evt) { CaloG4HitCollection* theEEHC = (CaloG4HitCollection*)allHC->GetHC(EEHCid); edm::LogVerbatim("HcalSim") << "HcalTestAnalysis :: Hit Collection for " << names_[2] << " of ID " << EEHCid << " is obtained at " << theEEHC; + int eehc_entries = theEEHC->entries(); if (EEHCid >= 0 && theEEHC != nullptr) { - for (j = 0; j < theEEHC->entries(); j++) { + for (j = 0; j < eehc_entries; j++) { CaloG4Hit* aHit = (*theEEHC)[j]; double e = aHit->getEnergyDeposit() / GeV; diff --git a/SimG4CMS/FP420/plugins/FP420SD.cc b/SimG4CMS/FP420/plugins/FP420SD.cc index 705cd4564aadc..6b97d731ed5aa 100644 --- a/SimG4CMS/FP420/plugins/FP420SD.cc +++ b/SimG4CMS/FP420/plugins/FP420SD.cc @@ -195,8 +195,8 @@ G4bool FP420SD::HitExists() { G4bool found = false; // LogDebug("FP420Sim") << "FP420SD: HCollection= " << theHC->entries() <entries() && !found; j++) { + int nhits = theHC->entries(); + for (int j = 0; j < nhits && !found; j++) { FP420G4Hit* aPreviousHit = (*theHC)[j]; if (aPreviousHit->getTrackID() == primaryID && aPreviousHit->getTimeSliceID() == tSliceID && aPreviousHit->getUnitID() == unitID) { @@ -333,7 +333,8 @@ void FP420SD::EndOfEvent(G4HCofThisEvent*) { // for (int j=0; jentries() && j<100; j++) { int nhitsHPS240 = 0; int nhitsFP420 = 0; - for (int j = 0; j < theHC->entries(); j++) { + int nhits = theHC->entries(); + for (int j = 0; j < nhits; j++) { FP420G4Hit* aHit = (*theHC)[j]; if ((fabs(aHit->getTof()) > 780. && fabs(aHit->getTof()) < 840.)) ++nhitsHPS240; diff --git a/SimG4CMS/FP420/plugins/FP420Test.cc b/SimG4CMS/FP420/plugins/FP420Test.cc index 3c4379dfad5ba..95ddeb1e68959 100644 --- a/SimG4CMS/FP420/plugins/FP420Test.cc +++ b/SimG4CMS/FP420/plugins/FP420Test.cc @@ -953,8 +953,8 @@ void FP420Test::update(const EndOfEvent* evt) { //UserNtuples->fillg67(theCAFI->entries(),1.); varia = 2; } // no MI end: - - for (int j = 0; j < theCAFI->entries(); j++) { + int nhits = theCAFI->entries(); + for (int j = 0; j < nhits; j++) { FP420G4Hit* aHit = (*theCAFI)[j]; G4ThreeVector hitPoint = aHit->getEntry(); double zz = hitPoint.z(); @@ -973,7 +973,7 @@ void FP420Test::update(const EndOfEvent* evt) { // ............. int nhit11 = 0, nhit12 = 0, nhit13 = 0; double totallosenergy = 0.; - for (int j = 0; j < theCAFI->entries(); j++) { + for (int j = 0; j < nhits; j++) { FP420G4Hit* aHit = (*theCAFI)[j]; G4ThreeVector hitEntryLocalPoint = aHit->getEntryLocalP(); @@ -1297,7 +1297,7 @@ void FP420Test::update(const EndOfEvent* evt) { //======================================================================================================CHECK if (totallosenergy == 0.0) { std::cout << "FP420Test: number of hits = " << theCAFI->entries() << std::endl; - for (int j = 0; j < theCAFI->entries(); j++) { + for (int j = 0; j < nhits; j++) { FP420G4Hit* aHit = (*theCAFI)[j]; double losenergy = aHit->getEnergyLoss(); std::cout << " j hits = " << j << "losenergy = " << losenergy << std::endl; diff --git a/SimG4CMS/Forward/src/BscTest.cc b/SimG4CMS/Forward/src/BscTest.cc index 1d3221dda4cab..da48a297073f4 100644 --- a/SimG4CMS/Forward/src/BscTest.cc +++ b/SimG4CMS/Forward/src/BscTest.cc @@ -627,7 +627,8 @@ void BscTest::update(const EndOfEvent* evt) { } else { varia = 2; } // no MI end: - for (int j = 0; j < theCAFI->entries(); j++) { + int nhits = theCAFI->entries(); + for (int j = 0; j < nhits; j++) { BscG4Hit* aHit = (*theCAFI)[j]; const CLHEP::Hep3Vector& hitPoint = aHit->getEntry(); double zz = hitPoint.z(); @@ -639,7 +640,7 @@ void BscTest::update(const EndOfEvent* evt) { if (varia == 2) { int nhit11 = 0, nhit12 = 0, nhit13 = 0; double totallosenergy = 0.; - for (int j = 0; j < theCAFI->entries(); j++) { + for (int j = 0; j < nhits; j++) { BscG4Hit* aHit = (*theCAFI)[j]; const CLHEP::Hep3Vector& hitEntryLocalPoint = aHit->getEntryLocalP(); @@ -782,7 +783,7 @@ void BscTest::update(const EndOfEvent* evt) { } // MIonly or noMIonly ENDED if (totallosenergy == 0.0) { std::cout << "BscTest: number of hits = " << theCAFI->entries() << std::endl; - for (int j = 0; j < theCAFI->entries(); j++) { + for (int j = 0; j < nhits; j++) { BscG4Hit* aHit = (*theCAFI)[j]; double losenergy = aHit->getEnergyLoss(); std::cout << " j hits = " << j << "losenergy = " << losenergy << std::endl; diff --git a/SimG4CMS/Forward/src/TimingSD.cc b/SimG4CMS/Forward/src/TimingSD.cc index 540102b77490e..620f8228c3d93 100644 --- a/SimG4CMS/Forward/src/TimingSD.cc +++ b/SimG4CMS/Forward/src/TimingSD.cc @@ -201,7 +201,8 @@ bool TimingSD::hitExists(const G4Step* aStep) { //tSliceID already exists: bool found = false; - for (int j = 0; j < theHC->entries(); ++j) { + int thehc_entries = theHC->entries(); + for (int j = 0; j < thehc_entries; ++j) { BscG4Hit* aHit = (*theHC)[j]; if (aHit->getTimeSliceID() == tSliceID && aHit->getUnitID() == unitID) { if (checkHit(aStep, aHit)) { diff --git a/SimG4CMS/Forward/src/TotemSD.cc b/SimG4CMS/Forward/src/TotemSD.cc index 4ec17a85a6851..e5d473c917610 100644 --- a/SimG4CMS/Forward/src/TotemSD.cc +++ b/SimG4CMS/Forward/src/TotemSD.cc @@ -117,7 +117,8 @@ void TotemSD::Initialize(G4HCofThisEvent* HCE) { void TotemSD::EndOfEvent(G4HCofThisEvent*) { // here we loop over transient hits and make them persistent - for (int j = 0; j < theHC->entries() && j < 15000; j++) { + int thehc_entries = theHC->entries(); + for (int j = 0; j < thehc_entries && j < 15000; j++) { TotemG4Hit* aHit = (*theHC)[j]; #ifdef ddebug LogDebug("ForwardSim") << "HIT NUMERO " << j << "unit ID = " << aHit->getUnitID() << "\n" @@ -223,8 +224,8 @@ bool TotemSD::hitExists() { //tSliceID already exists: bool found = false; - - for (int j = 0; j < theHC->entries() && !found; j++) { + int thehc_entries = theHC->entries(); + for (int j = 0; j < thehc_entries && !found; j++) { TotemG4Hit* aPreviousHit = (*theHC)[j]; if (aPreviousHit->getTrackID() == primaryID && aPreviousHit->getTimeSliceID() == tSliceID && aPreviousHit->getUnitID() == unitID) { diff --git a/SimG4CMS/HcalTestBeam/plugins/HcalTB04Analysis.cc b/SimG4CMS/HcalTestBeam/plugins/HcalTB04Analysis.cc index 55a33282527b7..b9d5c22f20d90 100644 --- a/SimG4CMS/HcalTestBeam/plugins/HcalTB04Analysis.cc +++ b/SimG4CMS/HcalTestBeam/plugins/HcalTB04Analysis.cc @@ -471,11 +471,11 @@ void HcalTB04Analysis::fillBuffer(const EndOfEvent* evt) { theHC = (CaloG4HitCollection*)allHC->GetHC(idHC); LogDebug("HcalTBSim") << "HcalTB04Analysis:: Hit Collection for " << sdName << " of ID " << idHC << " is obtained at " << theHC; - + int thehc_entries = theHC->entries(); if (idHC >= 0 && theHC != nullptr) { hhits.reserve(theHC->entries()); hhitl.reserve(theHC->entries()); - for (j = 0; j < theHC->entries(); j++) { + for (j = 0; j < thehc_entries; j++) { CaloG4Hit* aHit = (*theHC)[j]; double e = aHit->getEnergyDeposit() / GeV; double time = aHit->getTimeSlice(); @@ -589,7 +589,7 @@ void HcalTB04Analysis::fillBuffer(const EndOfEvent* evt) { << theHC; if (idHC >= 0 && theHC != nullptr) { ehits.reserve(theHC->entries()); - for (j = 0; j < theHC->entries(); j++) { + for (j = 0; j < thehc_entries; j++) { CaloG4Hit* aHit = (*theHC)[j]; double e = aHit->getEnergyDeposit() / GeV; double time = aHit->getTimeSlice(); diff --git a/SimG4CMS/PPS/src/PPSPixelSD.cc b/SimG4CMS/PPS/src/PPSPixelSD.cc index 954b476cebb4d..70d800fcb0ba4 100644 --- a/SimG4CMS/PPS/src/PPSPixelSD.cc +++ b/SimG4CMS/PPS/src/PPSPixelSD.cc @@ -227,8 +227,8 @@ bool PPSPixelSD::hitExists() { //look in the HitContainer whether a hit with the same primID_, unitID_, //tSliceID_ already exists: bool found = false; - - for (int j = 0; j < theHC_->entries() && !found; j++) { + int nhits = theHC_->entries(); + for (int j = 0; j < nhits && !found; j++) { PPSPixelG4Hit* aPreviousHit = (*theHC_)[j]; if (aPreviousHit->trackID() == primaryID_ && aPreviousHit->timeSliceID() == tSliceID_ && aPreviousHit->unitID() == unitID_) { diff --git a/SimG4CMS/ShowerLibraryProducer/src/CastorShowerLibraryMaker.cc b/SimG4CMS/ShowerLibraryProducer/src/CastorShowerLibraryMaker.cc index b3c36740e25cb..3c5229d594ab6 100644 --- a/SimG4CMS/ShowerLibraryProducer/src/CastorShowerLibraryMaker.cc +++ b/SimG4CMS/ShowerLibraryProducer/src/CastorShowerLibraryMaker.cc @@ -310,6 +310,7 @@ void CastorShowerLibraryMaker::update(const BeginOfEvent* evt) { void CastorShowerLibraryMaker::update(const G4Step* aStep) { static thread_local int CurrentPrimary = 0; G4Track* trk = aStep->GetTrack(); + int pvec_size; if (trk->GetCurrentStepNumber() == 1) { if (trk->GetParentID() == 0) { CurrentPrimary = (int)trk->GetDynamicParticle()->GetPDGcode(); @@ -320,7 +321,8 @@ void CastorShowerLibraryMaker::update(const G4Step* aStep) { if (DeActivatePhysicsProcess) { G4ProcessManager* p_mgr = trk->GetDefinition()->GetProcessManager(); G4ProcessVector* pvec = p_mgr->GetProcessList(); - for (int i = 0; i < pvec->size(); i++) { + pvec_size = pvec->size(); + for (int i = 0; i < pvec_size; i++) { G4VProcess* proc = (*pvec)(i); if (proc->GetProcessName() != "Transportation" && proc->GetProcessName() != "Decay") { std::cout << "DeActivating process: " << proc->GetProcessName() << std::endl; @@ -358,7 +360,8 @@ void CastorShowerLibraryMaker::update(const G4Step* aStep) { if (trk->GetParentID() == 0 && DeActivatePhysicsProcess) { G4ProcessManager* p_mgr = trk->GetDefinition()->GetProcessManager(); G4ProcessVector* pvec = p_mgr->GetProcessList(); - for (int i = 0; i < pvec->size(); i++) { + pvec_size = pvec->size(); + for (int i = 0; i < pvec_size; i++) { G4VProcess* proc = (*pvec)(i); if (proc->GetProcessName() != "Transportation" && proc->GetProcessName() != "Decay") { std::cout << " Activating process: " << proc->GetProcessName() << std::endl; @@ -524,8 +527,8 @@ void CastorShowerLibraryMaker::update(const EndOfEvent* evt) { } } // Check for unassociated energy - - if (NEvtAccepted == int(thePrims.size()) && theCAFI->entries() != NHitInEvent) { + int thecafi_entries = theCAFI->entries(); + if (NEvtAccepted == int(thePrims.size()) && thecafi_entries != NHitInEvent) { std::cout << "WARNING: Inconsistent Number of Hits -> Hits in collection: " << theCAFI->entries() << " Hits in the showers: " << NHitInEvent << std::endl; double miss_energy = 0; @@ -1025,7 +1028,8 @@ void CastorShowerLibraryMaker::GetMissingEnergy(CaloG4HitCollection* theCAFI, do // Get the total deposited energy and the one from hit not associated to a primary miss_energy = 0; tot_energy = 0; - for (int ihit = 0; ihit < theCAFI->entries(); ihit++) { + int nhits = theCAFI->entries(); + for (int ihit = 0; ihit < nhits; ihit++) { int id = (*theCAFI)[ihit]->getTrackID(); tot_energy += (*theCAFI)[ihit]->getEnergyDeposit(); int hit_prim = 0; diff --git a/SimG4CMS/ShowerLibraryProducer/src/HcalForwardAnalysis.cc b/SimG4CMS/ShowerLibraryProducer/src/HcalForwardAnalysis.cc index 29d36fc59ff90..6a4eecc142442 100644 --- a/SimG4CMS/ShowerLibraryProducer/src/HcalForwardAnalysis.cc +++ b/SimG4CMS/ShowerLibraryProducer/src/HcalForwardAnalysis.cc @@ -129,9 +129,10 @@ void HcalForwardAnalysis::setPhotons(const EndOfEvent* evt) { std::vector LongFiberPhotons; LongFiberPhotons.clear(); ShortFiberPhotons.clear(); + int thehc_entries = theHC->entries(); if (idHC >= 0 && theHC != nullptr) { - std::cout << "FiberhitSize " << theHC->entries() << std::endl; - for (j = 0; j < theHC->entries(); j++) { + std::cout << "FiberhitSize " << thehc_entries << std::endl; + for (j = 0; j < thehc_entries; j++) { FiberG4Hit* aHit = (*theHC)[j]; std::vector thePhotonsFromHit = aHit->photon(); std::cout << "Fiberhit " << j << " has " << thePhotonsFromHit.size() << " photons." << std::endl; @@ -172,7 +173,8 @@ void HcalForwardAnalysis::setPhotons(const EndOfEvent* evt) { // multiple hits. We want to take last one which is close the HF absorber if (idHC >= 0 && theChamberHC != nullptr) { LogDebug("HcalForwardLib") << "HcalForwardAnalysis::setPhotons() Chamber Hits size: " << theChamberHC->entries(); - for (j = 0; j < theChamberHC->entries(); ++j) { + int thec_hc_entries = theChamberHC->entries(); + for (j = 0; j < thec_hc_entries; ++j) { HFShowerG4Hit* aHit = (*theChamberHC)[j]; LogDebug("HcalForwardLib") << "HcalForwardAnalysis::setPhotons() Chamber Hit id " << aHit->hitId() << " track id " << aHit->trackId() << " prim. pos. " << aHit->globalPosition() << " prom mom. dir. " diff --git a/SimG4Core/GFlash/src/GflashHadronWrapperProcess.cc b/SimG4Core/GFlash/src/GflashHadronWrapperProcess.cc index 495cb6fccffaa..aa2f9d51b307f 100644 --- a/SimG4Core/GFlash/src/GflashHadronWrapperProcess.cc +++ b/SimG4Core/GFlash/src/GflashHadronWrapperProcess.cc @@ -96,8 +96,8 @@ G4VParticleChange *GflashHadronWrapperProcess::PostStepDoIt(const G4Track &track const G4TrackStatus keepStatus = track.GetTrackStatus(); (const_cast(&track))->SetTrackStatus(fPostponeToNextEvent); - - for (G4int ipm = 0; ipm < fProcessVector->entries(); ipm++) { + int fpv_entries = fProcessVector->entries(); + for (G4int ipm = 0; ipm < fpv_entries; ipm++) { fProcess = (*fProcessVector)(ipm); if (fProcess->GetProcessType() == fParameterisation) { diff --git a/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc b/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc index b2b5b5decf29b..23290aa8c2059 100644 --- a/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc +++ b/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc @@ -173,7 +173,8 @@ void PrintGeomInfoAction::dumpG4LVLeaf(G4LogicalVolume *lv, //--- If a volume is placed n types as daughter of this LV, it should only be counted once std::map lvCount; std::map::const_iterator cite; - for (int ii = 0; ii < lv->GetNoDaughters(); ii++) { + int siz = lv->GetNoDaughters(); + for (int ii = 0; ii < siz; ii++) { cite = lvCount.find(lv->GetDaughter(ii)->GetLogicalVolume()); if (cite != lvCount.end()) lvCount[cite->first] = (cite->second) + 1; diff --git a/Validation/EcalHits/src/EcalSimHitsValidProducer.cc b/Validation/EcalHits/src/EcalSimHitsValidProducer.cc index 8ad22f8dc28ab..2490e2fe3c6ac 100644 --- a/Validation/EcalHits/src/EcalSimHitsValidProducer.cc +++ b/Validation/EcalHits/src/EcalSimHitsValidProducer.cc @@ -283,7 +283,8 @@ void EcalSimHitsValidProducer::update(const EndOfEvent *evt) { // EB Hit collection start MapType ebmap; - for (int j = 0; j < theEBHC->entries(); j++) { + int theebhc_entries = theEBHC->entries(); + for (int j = 0; j < theebhc_entries; j++) { CaloG4Hit *aHit = (*theEBHC)[j]; totalEInEB += aHit->getEnergyDeposit(); float he = aHit->getEnergyDeposit(); @@ -306,8 +307,8 @@ void EcalSimHitsValidProducer::update(const EndOfEvent *evt) { // EE Hit collection start MapType eemap, eezpmap, eezmmap; - - for (int j = 0; j < theEEHC->entries(); j++) { + int theeehc_entries = theEEHC->entries(); + for (int j = 0; j < theeehc_entries; j++) { CaloG4Hit *aHit = (*theEEHC)[j]; totalEInEE += aHit->getEnergyDeposit(); float he = aHit->getEnergyDeposit(); @@ -342,7 +343,8 @@ void EcalSimHitsValidProducer::update(const EndOfEvent *evt) { nCrystalInEEzp = eezpmap.size(); // Hits from ES - for (int j = 0; j < theSEHC->entries(); j++) { + int thesehc_entries = theSEHC->entries(); + for (int j = 0; j < thesehc_entries; j++) { CaloG4Hit *aHit = (*theSEHC)[j]; totalEInES += aHit->getEnergyDeposit(); ESDetId esid = ESDetId(aHit->getUnitID()); diff --git a/Validation/HcalHits/src/SimG4HcalValidation.cc b/Validation/HcalHits/src/SimG4HcalValidation.cc index dc8d7a421ae21..e366a07ae9b07 100644 --- a/Validation/HcalHits/src/SimG4HcalValidation.cc +++ b/Validation/HcalHits/src/SimG4HcalValidation.cc @@ -276,7 +276,8 @@ void SimG4HcalValidation::fill(const EndOfEvent *evt) { LogDebug("ValidHcal") << "SimG4HcalValidation :: Hit Collection for " << names[0] << " of ID " << HCHCid << " is obtained at " << theHCHC; if (HCHCid >= 0 && theHCHC != nullptr) { - for (j = 0; j < theHCHC->entries(); j++) { + int nhits = theHCHC->entries(); + for (j = 0; j < nhits; j++) { CaloG4Hit *aHit = (*theHCHC)[j]; double e = aHit->getEnergyDeposit() / GeV; @@ -353,8 +354,9 @@ void SimG4HcalValidation::fill(const EndOfEvent *evt) { CaloG4HitCollection *theECHC = (CaloG4HitCollection *)allHC->GetHC(ECHCid); LogDebug("ValidHcal") << "SimG4HcalValidation:: Hit Collection for " << names[idty] << " of ID " << ECHCid << " is obtained at " << theECHC; + int theechc_entries = theECHC->entries(); if (ECHCid >= 0 && theECHC != nullptr) { - for (j = 0; j < theECHC->entries(); j++) { + for (j = 0; j < theechc_entries; j++) { CaloG4Hit *aHit = (*theECHC)[j]; double e = aHit->getEnergyDeposit() / GeV;