From 838d74f49136c0dd03b1c915a6ae549de8aeecff Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 2 Jul 2024 10:02:03 +0200 Subject: [PATCH] Write contributions only if we convert sim calo hits --- standalone/lcio2edm4hep.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/standalone/lcio2edm4hep.cpp b/standalone/lcio2edm4hep.cpp index 4ffdb8b..a0135b2 100644 --- a/standalone/lcio2edm4hep.cpp +++ b/standalone/lcio2edm4hep.cpp @@ -161,6 +161,7 @@ int main(int argc, char* argv[]) { UTIL::CheckCollections colPatcher{}; std::vector namesTypes{}; const bool patching = !args.patchFile.empty(); + // Keep track of whether we have any SimCalorimeterHits if (patching) { namesTypes = getNamesAndTypes(args.patchFile); if (namesTypes.empty()) { @@ -208,6 +209,7 @@ int main(int argc, char* argv[]) { } const int nEvt = args.nEvents > 0 ? args.nEvents : lcreader->getNumberOfEvents(); + bool haveSimCaloHits{false}; for (int i = 0; i < nEvt; ++i) { int percEvt = i * 100 / (nEvt - 1); if (percEvt % 10 == 0) { @@ -218,8 +220,17 @@ int main(int argc, char* argv[]) { if (patching == true) { colPatcher.patchCollections(evt); } + if (i == 0) { + for (const auto& name : *evt->getCollectionNames()) { + if (evt->getCollection(name)->getTypeName() == "SimCalorimeterHit") { + haveSimCaloHits = true; + break; + } + } + } + auto edmEvent = LCIO2EDM4hepConv::convertEvent(evt, collsToConvert); - if (edmEvent.get("AllCaloHitContributionsCombined") == nullptr) { + if (haveSimCaloHits && edmEvent.get("AllCaloHitContributionsCombined") == nullptr) { edmEvent.put(edm4hep::CaloHitContributionCollection(), "AllCaloHitContributionsCombined"); }