@@ -432,18 +432,24 @@ void CaloSD::DrawAll() {}
432432
433433void CaloSD::PrintAll () {
434434 for (int k = 0 ; k < nHC_; ++k) {
435+ if (nullptr == theHC[k]) {
436+ continue ;
437+ }
435438#ifdef EDM_ML_DEBUG
436- edm::LogVerbatim (" CaloSim" ) << " CaloSD: Collection " << theHC[k]->GetName ();
439+ edm::LogVerbatim (" CaloSim" ) << " CaloSD: Collection " << k << " " << theHC[k]->GetName ();
437440#endif
438441 theHC[k]->PrintAllHits ();
439442 }
440443}
441444
442445void CaloSD::fillHits (edm::PCaloHitContainer& cc, const std::string& hname) {
443446 for (int k = 0 ; k < nHC_; ++k) {
447+ if (nullptr == slave[k].get ()) {
448+ continue ;
449+ }
444450#ifdef EDM_ML_DEBUG
445- edm::LogVerbatim (" CaloSim" ) << " CaloSD: Tries to transfer " << slave[k].get ()->hits ().size () << " hits for "
446- << slave[k].get ()->name () << " " << hname;
451+ edm::LogVerbatim (" CaloSim" ) << " CaloSD: " << k << " . Tries to transfer " << slave[k].get ()->hits ().size ()
452+ << " hits for " << slave[k].get ()->name () << " " << hname;
447453#endif
448454 if (slave[k].get ()->name () == hname) {
449455 cc = slave[k].get ()->hits ();
@@ -783,6 +789,9 @@ void CaloSD::update(const EndOfTrack* trk) {
783789void CaloSD::update (const ::EndOfEvent*) {
784790 endEvent ();
785791 for (int k = 0 ; k < nHC_; ++k) {
792+ if (nullptr == slave[k].get ()) {
793+ continue ;
794+ }
786795 slave[k].get ()->ReserveMemory (theHC[k]->entries ());
787796
788797 int count (0 );
@@ -857,7 +866,8 @@ void CaloSD::clearHits() {
857866 edm::LogVerbatim (" CaloSim" ) << " CaloSD: Clears hit vector for " << GetName ()
858867 << " and initialise slave: " << slave[k].get ()->name ();
859868#endif
860- slave[k].get ()->Initialize ();
869+ if (nullptr != slave[k].get ())
870+ slave[k].get ()->Initialize ();
861871 }
862872}
863873
@@ -1042,10 +1052,13 @@ void CaloSD::update(const BeginOfTrack* trk) {
10421052
10431053void CaloSD::cleanHitCollection () {
10441054 for (int k = 0 ; k < nHC_; ++k) {
1055+ if (nullptr == theHC[k]) {
1056+ continue ;
1057+ }
10451058 std::vector<CaloG4Hit*>* theCollection = theHC[k]->GetVector ();
10461059
10471060#ifdef EDM_ML_DEBUG
1048- edm::LogVerbatim (" CaloSim" ) << " CaloSD: collection before merging, size = " << theHC[k]->entries ();
1061+ edm::LogVerbatim (" CaloSim" ) << " CaloSD: collection " << k << " before merging, size = " << theHC[k]->entries ();
10491062#endif
10501063 if (reusehit[k].empty ())
10511064 reusehit[k].reserve (theHC[k]->entries () - cleanIndex[k]);
@@ -1112,7 +1125,6 @@ void CaloSD::cleanHitCollection() {
11121125 CaloG4Hit* aHit ((*theCollection)[i]);
11131126
11141127 // selection
1115-
11161128 double time = aHit->getTimeSlice ();
11171129 if (corrTOFBeam)
11181130 time += correctT;
@@ -1121,9 +1133,7 @@ void CaloSD::cleanHitCollection() {
11211133 edm::LogVerbatim (" CaloSim" ) << " CaloSD: dropped CaloG4Hit "
11221134 << " " << *aHit;
11231135#endif
1124-
11251136 // create the list of hits to be reused
1126-
11271137 reusehit[k].emplace_back ((*theCollection)[i]);
11281138 (*theCollection)[i] = nullptr ;
11291139 ++addhit;
0 commit comments