Skip to content

Commit 6fb233d

Browse files
authored
Merge pull request #47738 from civanch/fixed_sens_det_initialisation
[SIM] Improved initialisation for calorimeters
2 parents 1a1787c + 1e04af4 commit 6fb233d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

SimG4CMS/Calo/src/CaloSD.cc

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,24 @@ void CaloSD::DrawAll() {}
432432

433433
void 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

442445
void 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) {
783789
void 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

10431053
void 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

Comments
 (0)