Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCIOConversions: fix attaching SimCaloHit collections to event #1019

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions DDG4/lcio/LCIOConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,21 @@ namespace dd4hep {
Geant4Calorimeter::Hit>::operator()(const arg_t& args) const {
typedef Geant4HitData::Contributions Contributions;
Geant4HitCollection* coll = args.second;
string hc_nam = coll->GetName();
Geant4Sensitive* sd = coll->sensitive();
size_t nhits = coll->GetSize();
string dsc = encoding(sd->sensitiveDetector());
Geant4ParticleMap* pm = args.first->event().extension<Geant4ParticleMap>();
lcio::LCEventImpl* lc_evt = args.first->event().extension<lcio::LCEventImpl>();
EVENT::LCCollection* lc_parts = lc_evt->getCollection(lcio::LCIO::MCPARTICLE);
lcio::LCCollectionVec* lc_coll = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT);
lcio::LCCollectionVec* lc_coll = nullptr;
bool isNewCollection = false;
try {
lc_coll = static_cast<lcio::LCCollectionVec*>(lc_evt->getCollection(hc_nam));
} catch (lcio::DataNotAvailableException &e) {
lc_coll = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT);
isNewCollection = true;
}
UTIL::CellIDEncoder<SimCalorimeterHit> decoder(dsc,lc_coll);
int hit_creation_mode = sd->hitCreationMode();

Expand All @@ -194,7 +202,7 @@ namespace dd4hep {
else
lc_coll->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_ID1));

lc_coll->reserve(nhits);
lc_coll->reserve(nhits + lc_coll->getNumberOfElements());
if ( sd->hasProperty("HitCreationMode") ) {
hit_creation_mode = sd->property("HitCreationMode").value<int>();
}
Expand Down Expand Up @@ -225,6 +233,9 @@ namespace dd4hep {
}
}
}
if(isNewCollection) {
lc_evt->addCollection(lc_coll, hc_nam);
}
return lc_coll;
}

Expand Down