Skip to content

Commit

Permalink
Make necessary changes for mutable classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jan 26, 2022
1 parent 8884902 commit 9c6b75c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions converter/include/k4SimDelphes/DelphesEDM4HepConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "podio/CollectionBase.h"

// edm4hep
#include "edm4hep/MCParticleConst.h"
#include "edm4hep/ReconstructedParticle.h"
#include "edm4hep/MCParticle.h"
#include "edm4hep/MutableReconstructedParticle.h"
#include "edm4hep/MCRecoParticleAssociationCollection.h"

// ROOT
Expand Down Expand Up @@ -92,7 +92,7 @@ class DelphesEDM4HepConverter {
fillReferenceCollection<Electron>(delphesCollection, branch, "electron");
}

edm4hep::MCRecoParticleAssociationCollection* createExternalRecoAssociations(const std::unordered_map<UInt_t, edm4hep::ConstMCParticle>& mc_map);
edm4hep::MCRecoParticleAssociationCollection* createExternalRecoAssociations(const std::unordered_map<UInt_t, edm4hep::MCParticle>& mc_map);

private:

Expand All @@ -108,7 +108,7 @@ edm4hep::MCRecoParticleAssociationCollection* createExternalRecoAssociations(con
// cannot mark DelphesT as const, because for Candidate* the GetCandidates()
// method is not marked as const.
template<typename DelphesT>
std::optional<edm4hep::ReconstructedParticle> getMatchingReco(/*const*/ DelphesT* delphesCand) const;
std::optional<edm4hep::MutableReconstructedParticle> getMatchingReco(/*const*/ DelphesT* delphesCand) const;

using ProcessFunction = void (DelphesEDM4HepConverter::*)(const TClonesArray*, std::string_view const);

Expand All @@ -123,10 +123,10 @@ edm4hep::MCRecoParticleAssociationCollection* createExternalRecoAssociations(con
std::string m_mcRecoAssocCollName;

// map from UniqueIDs (delphes generated particles) to MCParticles
std::unordered_map<UInt_t, edm4hep::ConstMCParticle> m_genParticleIds;
std::unordered_map<UInt_t, edm4hep::MCParticle> m_genParticleIds;
// map from UniqueIDs (delphes generated particles) to (possibly multiple)
// ReconstructedParticles
std::unordered_multimap<UInt_t, edm4hep::ReconstructedParticle> m_recoParticleGenIds;
std::unordered_multimap<UInt_t, edm4hep::MutableReconstructedParticle> m_recoParticleGenIds;
};

template<typename CollectionT>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class k4GenParticlesDelphesConverter {
//
}

std::unordered_map<UInt_t, edm4hep::ConstMCParticle> getGenParticleIdMap() { return m_genParticleIds;}
std::unordered_map<UInt_t, edm4hep::MCParticle> getGenParticleIdMap() { return m_genParticleIds;}

private:

std::unordered_map<UInt_t, edm4hep::ConstMCParticle> m_genParticleIds;
std::unordered_map<UInt_t, edm4hep::MCParticle> m_genParticleIds;

};

Expand Down
14 changes: 7 additions & 7 deletions converter/src/DelphesEDM4HepConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ template<size_t N>
void sortBranchesProcessingOrder(std::vector<BranchSettings>& branches,
std::array<std::string_view, N> const& processingOrder);

edm4hep::Track convertTrack(Track const* cand, const double magFieldBz);
edm4hep::MutableTrack convertTrack(Track const* cand, const double magFieldBz);

void setMotherDaughterRelations(GenParticle const* delphesCand,
edm4hep::MCParticle particle,
edm4hep::MutableMCParticle particle,
edm4hep::MCParticleCollection& mcParticles);

/**
Expand Down Expand Up @@ -376,7 +376,7 @@ void DelphesEDM4HepConverter::processScalarHT(const TClonesArray* delphesCollect


template<typename DelphesT>
std::optional<edm4hep::ReconstructedParticle> DelphesEDM4HepConverter::getMatchingReco(DelphesT* delphesCand) const
std::optional<edm4hep::MutableReconstructedParticle> DelphesEDM4HepConverter::getMatchingReco(DelphesT* delphesCand) const
{
// Here we have to do some work to actually match the Delphes candidate to
// the correct edm4hep::ReconstructedParticle because the possibility exists
Expand Down Expand Up @@ -416,7 +416,7 @@ std::optional<edm4hep::ReconstructedParticle> DelphesEDM4HepConverter::getMatchi
return {};
}

edm4hep::MCRecoParticleAssociationCollection* DelphesEDM4HepConverter::createExternalRecoAssociations(const std::unordered_map<UInt_t, edm4hep::ConstMCParticle>& mc_map) {
edm4hep::MCRecoParticleAssociationCollection* DelphesEDM4HepConverter::createExternalRecoAssociations(const std::unordered_map<UInt_t, edm4hep::MCParticle>& mc_map) {

auto mcRecoRelations = new edm4hep::MCRecoParticleAssociationCollection();
for (const auto& particleID: mc_map) {
Expand Down Expand Up @@ -469,9 +469,9 @@ void sortBranchesProcessingOrder(std::vector<BranchSettings>& branches,
}


edm4hep::Track convertTrack(Track const* cand, const double magFieldBz)
edm4hep::MutableTrack convertTrack(Track const* cand, const double magFieldBz)
{
edm4hep::Track track;
edm4hep::MutableTrack track;
// Delphes does not really provide any information that would go into the
// track itself. But some information can be used to at least partially
// populate a TrackState
Expand Down Expand Up @@ -535,7 +535,7 @@ edm4hep::Track convertTrack(Track const* cand, const double magFieldBz)
}

void setMotherDaughterRelations(GenParticle const* delphesCand,
edm4hep::MCParticle particle,
edm4hep::MutableMCParticle particle,
edm4hep::MCParticleCollection& mcParticles)
{
// NOTE: it is in general probably not possible to handle all the different
Expand Down
8 changes: 4 additions & 4 deletions tests/src/compare_delphes_converter_outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ void assertSameKinematics(const DelphesT* delphesCand, const EDM4HepT& edm4hepCa
* Get all MCParticles related to a given ReconstructedParticle
*
*/
std::vector<edm4hep::ConstMCParticle>
getAssociatedMCParticles(edm4hep::ConstReconstructedParticle reco,
std::vector<edm4hep::MCParticle>
getAssociatedMCParticles(edm4hep::ReconstructedParticle reco,
const edm4hep::MCRecoParticleAssociationCollection& associations) {
std::vector<edm4hep::ConstMCParticle> sims;
std::vector<edm4hep::MCParticle> sims;
// NOTE: looping over the whole collection of associations here is super
// inefficient, but as long as there is no utility for this, implementing the
// necessary caching is just too much work for this test case here
Expand Down Expand Up @@ -102,7 +102,7 @@ std::vector<GenParticle*> getAssociatedMCParticles(const DelphesT* delphesCand)
*/
template<typename DelphesT>
bool compareMCRelations(const DelphesT* delphesCand,
edm4hep::ConstReconstructedParticle edm4hepCand,
edm4hep::ReconstructedParticle edm4hepCand,
const edm4hep::MCRecoParticleAssociationCollection& associations) {

const auto delphesGenParticles = getAssociatedMCParticles(delphesCand);
Expand Down

0 comments on commit 9c6b75c

Please sign in to comment.