Skip to content

Commit

Permalink
Add an option to copy CellID metadata when overlaying
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Oct 17, 2024
1 parent f93b00e commit 6b4e0ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions k4Reco/Overlay/components/OverlayTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

#include "podio/Frame.h"

#include "edm4hep/Constants.h"
#include "edm4hep/MutableCaloHitContribution.h"

#include "k4FWCore/MetadataUtils.h"

#include <TMath.h>

#include <limits>
Expand Down Expand Up @@ -378,4 +381,24 @@ retType OverlayTiming::operator()(const edm4hep::EventHeaderCollection&
std::move(ocaloHitContribs));
}

StatusCode OverlayTiming::finalize() {
if (m_copyCellIDMetadata) {
for (auto& [input, output] :
{std::make_pair(inputLocations(SIMTRACKERHIT_INDEX_POSITION), outputLocations("OutputSimTrackerHits")),
std::make_pair(inputLocations(SIMCALOHIT_INDEX_POSITION), outputLocations("OutputSimCalorimeterHits"))}) {
for (size_t i = 0; i < input.size(); ++i) {
auto name = input[i];
auto value = k4FWCore::getParameter<std::string>(name + "__" + edm4hep::labels::CellIDEncoding, this);
if (value.has_value()) {
k4FWCore::putParameter(output[i] + "__" + edm4hep::labels::CellIDEncoding, value.value(), this);
} else {
warning() << "No metadata found for " << name << endmsg;
}
}
}
}

return Gaudi::Algorithm::finalize();
}

DECLARE_COMPONENT(OverlayTiming)
4 changes: 4 additions & 0 deletions k4Reco/Overlay/components/OverlayTiming.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct OverlayTiming : public k4FWCore::MultiTransformer<retType(
template <typename T> void overlayCollection(std::string collName, const podio::CollectionBase& inColl);

virtual StatusCode initialize() final;
virtual StatusCode finalize() final;

retType virtual operator()(
const edm4hep::EventHeaderCollection& headers, const edm4hep::MCParticleCollection& mcParticles,
Expand Down Expand Up @@ -140,6 +141,9 @@ struct OverlayTiming : public k4FWCore::MultiTransformer<retType(
this, "TimeWindows", std::map<std::string, std::vector<float>>(), "Time windows for the different collections"};
Gaudi::Property<bool> m_allowReusingBackgroundFiles{
this, "AllowReusingBackgroundFiles", false, "If true the same background file can be used for the same event"};
Gaudi::Property<bool> m_copyCellIDMetadata{this, "CopyCellIDMetadata", false,
"If metadata is found in the signal file, copy it to the output file, "
"replacing the old names with the new names"};

// Gaudi::Property<int> m_maxCachedFrames{
// this, "MaxCachedFrames", 0, "Maximum number of frames cached from background files"};
Expand Down
1 change: 1 addition & 0 deletions k4Reco/Overlay/options/runOverlayTiming.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
["background_group2_1.root"],
]
overlay.TimeWindows = {"MCParticle": [0, 23.5], "VertexBarrelCollection": [0, 23.5], "VertexEndcapCollection": [0, 23.5], "HCalRingCollection": [0, 23.5]}
overlay.CopyCellIDMetadata = True

ApplicationMgr(TopAlg=[overlay],
EvtSel="NONE",
Expand Down

0 comments on commit 6b4e0ae

Please sign in to comment.