Skip to content

Commit

Permalink
Write contributions only if we convert sim calo hits
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jul 2, 2024
1 parent f9a5b78 commit 838d74f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion standalone/lcio2edm4hep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ int main(int argc, char* argv[]) {
UTIL::CheckCollections colPatcher{};
std::vector<NamesType> namesTypes{};
const bool patching = !args.patchFile.empty();
// Keep track of whether we have any SimCalorimeterHits
if (patching) {
namesTypes = getNamesAndTypes(args.patchFile);
if (namesTypes.empty()) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
}

Expand Down

0 comments on commit 838d74f

Please sign in to comment.