From a61ade2e74c1f4d6d04f4f5d14f06edd0d656348 Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Wed, 16 Nov 2022 18:04:40 +0100 Subject: [PATCH] LCIOConversions: fix attaching SimCaloHit collections to event --- DDG4/lcio/LCIOConversions.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/DDG4/lcio/LCIOConversions.cpp b/DDG4/lcio/LCIOConversions.cpp index 00bc8a291..5bbbd7acc 100644 --- a/DDG4/lcio/LCIOConversions.cpp +++ b/DDG4/lcio/LCIOConversions.cpp @@ -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(); lcio::LCEventImpl* lc_evt = args.first->event().extension(); 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(lc_evt->getCollection(hc_nam)); + } catch (lcio::DataNotAvailableException &e) { + lc_coll = new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT); + isNewCollection = true; + } UTIL::CellIDEncoder decoder(dsc,lc_coll); int hit_creation_mode = sd->hitCreationMode(); @@ -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(); } @@ -225,6 +233,9 @@ namespace dd4hep { } } } + if(isNewCollection) { + lc_evt->addCollection(lc_coll, hc_nam); + } return lc_coll; }