Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from Associations to Links #128

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions converter/include/k4SimDelphes/DelphesEDM4HepConverter.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef DELPHESEDM4HEP_DELPHESEDM4HEP_CONVERTER_H__
#define DELPHESEDM4HEP_DELPHESEDM4HEP_CONVERTER_H__

// podio
#include "podio/CollectionBase.h"

// edm4hep
#include "edm4hep/MCParticle.h"
#include "edm4hep/MCRecoParticleAssociationCollection.h"
#include "edm4hep/MutableReconstructedParticle.h"
#include "edm4hep/RecoMCParticleLinkCollection.h"

// podio
#include "podio/CollectionBase.h"

// ROOT
#include "TClonesArray.h"
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace k4SimDelphes {
std::string className;
};

std::vector<BranchSettings> getBranchSettings(ExRootConfParam /*const&*/ treeConf) {
inline std::vector<BranchSettings> getBranchSettings(ExRootConfParam /*const&*/ treeConf) {
std::vector<k4SimDelphes::BranchSettings> branches;
for (int b = 0; b < treeConf.GetSize(); b += 3) {
k4SimDelphes::BranchSettings branch{treeConf[b].GetString(), treeConf[b + 1].GetString(),
Expand Down Expand Up @@ -102,7 +102,7 @@ namespace k4SimDelphes {
*/
CollectionMapT getCollections() { return std::move(m_collections); }

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

private:
Expand Down Expand Up @@ -159,7 +159,7 @@ namespace k4SimDelphes {

std::string m_recoCollName;
std::string m_particleIDName;
std::string m_mcRecoAssocCollName;
std::string m_recoMCLinkCollName;

// map from UniqueIDs (delphes generated particles) to MCParticles
std::unordered_map<UInt_t, edm4hep::MCParticle> m_genParticleIds;
Expand Down
21 changes: 15 additions & 6 deletions converter/include/k4SimDelphes/DelphesEDM4HepOutputConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ExRootAnalysis/ExRootConfReader.h"

#include <iomanip>
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -77,10 +78,10 @@ namespace k4SimDelphes {
std::string RecoParticleCollectionName{"ReconstructedParticles"};

/**
* Name of the MCRecoParticleAssociationCollection holding the associations of
* Name of the RecoMCParticleLinkCollection holding the links of
* generated to reconstructed particles.
*/
std::string MCRecoAssociationCollectionName{"MCRecoAssociations"};
std::string RecoMCParticleLinkCollectionName{"MCRecoAssociations"};

/**
* Name of the ParticleIDCollection holding the ctags / isolation variables.
Expand Down Expand Up @@ -112,7 +113,7 @@ namespace k4SimDelphes {
os << std::setw(40) << " MissingETCollections: " << settings.MissingETCollections << "\n";
os << std::setw(40) << " ScalarHTCollections: " << settings.ScalarHTCollections << "\n";
os << std::setw(40) << " RecoParticleCollectionName: " << settings.RecoParticleCollectionName << "\n";
os << std::setw(40) << " MCRecoAssociationCollectionName: " << settings.MCRecoAssociationCollectionName << "\n";
os << std::setw(40) << " RecoMCParticleLinkCollectionName: " << settings.RecoMCParticleLinkCollectionName << "\n";
os << "------------------------------------------------------------\n";

return os;
Expand Down Expand Up @@ -155,13 +156,21 @@ namespace k4SimDelphes {
settings.RecoParticleCollectionName =
confReader->GetString("EDM4HepOutput::RecoParticleCollectionName", "ReconstructedParticles");

settings.MCRecoAssociationCollectionName =
confReader->GetString("EDM4HepOutput::MCRecoAssociationCollectionName", "MCRecoAssociations");
const auto assocName = confReader->GetString("EDM4HepOutput::MCRecoAssociationCollectionName", "not-available");
if (assocName != std::string("not-available")) {
std::cerr << "WARNING: k4SimDelphes::getEDM4hepOutputSettings | MCRecoAssociationCollectionName is deprecated, "
"use RecoMCParticleLinkCollection instead"
<< std::endl;
settings.RecoMCParticleLinkCollectionName = assocName;
}

settings.RecoMCParticleLinkCollectionName =
confReader->GetString("EDM4HepOutput::RecoMCParticleLinkCollectionName", "MCRecoAssociations");

return settings;
}

OutputSettings getEDM4hepOutputSettings(const char* confFile) {
inline OutputSettings getEDM4hepOutputSettings(const char* confFile) {
ExRootConfReader confReader{};
confReader.ReadFile(confFile);
return getEDM4hepOutputSettings(&confReader);
Expand Down
28 changes: 14 additions & 14 deletions converter/src/DelphesEDM4HepConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "edm4hep/ClusterCollection.h"
#include "edm4hep/EventHeaderCollection.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/MCRecoParticleAssociationCollection.h"
#include "edm4hep/ParticleIDCollection.h"
#include "edm4hep/RecDqdxCollection.h"
#include "edm4hep/RecoMCParticleLinkCollection.h"
#include "edm4hep/ReconstructedParticleCollection.h"
#include "edm4hep/TrackCollection.h"
#if __has_include("edm4hep/TrackerHit3DCollection.h")
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace k4SimDelphes {
: m_magneticFieldBz(magFieldBz),
m_recoCollName(outputSettings.RecoParticleCollectionName),
m_particleIDName(outputSettings.ParticleIDCollectionName),
m_mcRecoAssocCollName(outputSettings.MCRecoAssociationCollectionName) {
m_recoMCLinkCollName(outputSettings.RecoMCParticleLinkCollectionName) {
for (const auto& branch : branches) {
if (contains(PROCESSING_ORDER, branch.className)) {
m_branches.push_back(branch);
Expand Down Expand Up @@ -224,7 +224,7 @@ namespace k4SimDelphes {
auto* magFieldCollection = createCollection<podio::UserDataCollection<float>>("magFieldBz");
magFieldCollection->push_back(m_magneticFieldBz);

auto* mcRecoRelations = getCollection<edm4hep::MCRecoParticleAssociationCollection>(m_mcRecoAssocCollName);
auto* mcRecoRelations = getCollection<edm4hep::RecoMCParticleLinkCollection>(m_recoMCLinkCollName);
auto* idCollection = getCollection<edm4hep::ParticleIDCollection>(m_particleIDName);
auto* trackerHitColl = getCollection<edm4hep::TrackerHit3DCollection>(TRACKERHIT_OUTPUT_NAME);

Expand Down Expand Up @@ -279,8 +279,8 @@ namespace k4SimDelphes {
UInt_t genId = delphesCand->Particle.GetUniqueID();
if (const auto genIt = m_genParticleIds.find(genId); genIt != m_genParticleIds.end()) {
auto relation = mcRecoRelations->create();
relation.setSim(genIt->second);
relation.setRec(cand);
relation.setTo(genIt->second);
relation.setFrom(cand);
}

m_recoParticleGenIds.emplace(genId, cand);
Expand All @@ -291,7 +291,7 @@ namespace k4SimDelphes {
void DelphesEDM4HepConverter::processClusters(const TClonesArray* delphesCollection, std::string const& branch) {
auto* particleCollection = getCollection<edm4hep::ReconstructedParticleCollection>(m_recoCollName);
auto* clusterCollection = createCollection<edm4hep::ClusterCollection>(branch);
auto* mcRecoRelations = getCollection<edm4hep::MCRecoParticleAssociationCollection>(m_mcRecoAssocCollName);
auto* mcRecoRelations = getCollection<edm4hep::RecoMCParticleLinkCollection>(m_recoMCLinkCollName);
auto* calorimeterHitColl = getCollection<edm4hep::CalorimeterHitCollection>(CALORIMETERHIT_OUTPUT_NAME);

for (auto iCand = 0; iCand < delphesCollection->GetEntries(); ++iCand) {
Expand Down Expand Up @@ -335,8 +335,8 @@ namespace k4SimDelphes {
for (const auto genId : getAllParticleIDs(delphesCand)) {
if (const auto genIt = m_genParticleIds.find(genId); genIt != m_genParticleIds.end()) {
auto relation = mcRecoRelations->create();
relation.setSim(genIt->second);
relation.setRec(cand);
relation.setTo(genIt->second);
relation.setFrom(cand);
}

m_recoParticleGenIds.emplace(genId, cand);
Expand Down Expand Up @@ -489,15 +489,15 @@ namespace k4SimDelphes {
return {};
}

edm4hep::MCRecoParticleAssociationCollection* DelphesEDM4HepConverter::createExternalRecoAssociations(
edm4hep::RecoMCParticleLinkCollection* DelphesEDM4HepConverter::createExternalRecoMCLinks(
const std::unordered_map<UInt_t, edm4hep::MCParticle>& mc_map) {
auto mcRecoRelations = new edm4hep::MCRecoParticleAssociationCollection();
auto mcRecoRelations = new edm4hep::RecoMCParticleLinkCollection();
for (const auto& particleID : mc_map) {
const auto [recoBegin, recoEnd] = m_recoParticleGenIds.equal_range(particleID.first);
for (auto it = recoBegin; it != recoEnd; ++it) {
auto relation = mcRecoRelations->create();
relation.setSim(particleID.second);
relation.setRec(it->second);
relation.setTo(particleID.second);
relation.setFrom(it->second);
}
}
return mcRecoRelations;
Expand All @@ -508,8 +508,8 @@ namespace k4SimDelphes {
if (m_collections.find(m_recoCollName) == m_collections.end()) {
createCollection<edm4hep::ReconstructedParticleCollection>(m_recoCollName);
}
if (m_collections.find(m_mcRecoAssocCollName) == m_collections.end()) {
createCollection<edm4hep::MCRecoParticleAssociationCollection>(m_mcRecoAssocCollName);
if (m_collections.find(m_recoMCLinkCollName) == m_collections.end()) {
createCollection<edm4hep::RecoMCParticleLinkCollection>(m_recoMCLinkCollName);
}
if (m_collections.find(m_particleIDName) == m_collections.end()) {
createCollection<edm4hep::ParticleIDCollection>(m_particleIDName);
Expand Down
30 changes: 15 additions & 15 deletions doc/output_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ The filled collection contains only one element per event.


The parameters **`RecoParticleCollectionName`** and
**`MCRecoAssociationCollectionName`** control the names of the [global
**`RecoMCParticleLinkCollectionName`** control the names of the [global
reconstructed particle collection](#reconstructedparticlecollections) and the
collection with the `MCRecoParticleAssociation`s that can be used to find the
collection with the `RecoMCParticleLink`s that can be used to find the
`MCParticle`s associated to `ReconstructedParticle`s (and vice versa).

## Class conversions
Expand All @@ -99,19 +99,19 @@ The following table lists which Delphes classes correspond to which `edm4hep`
classes. For the conversion the Delphes classes are taken from the `TreeWriter`
(the `BranchClass` for each `Branch` defined in there)

| Delphes | `edm4hep` |
|---------------|---------------------------------------------------|
| `GenParticle` | `MCParticle` |
| `Track` | `ReconstructedParticle` with associated `Track` |
| `Tower` | `ReconstructedParticle` with associated `Cluster` |
| `Jet` | `ReconstructedParticle` |
| `Muon` | `ReconstructedParticle` (subset collection) |
| `Electron` | `ReconstructedParticle` (subset collection) |
| `Photon` | `ReconstructedParticle` (subset collection) |
| `MissingET` | `ReconstructedParticle` |
| `ScalarHT` | `ParticleID` |
| `ParticleFlowCandidate` | `ReconstructedParticle` |
| n/a | `MCRecoParticleAssociation` |
| Delphes | `edm4hep` |
|-------------------------|---------------------------------------------------|
| `GenParticle` | `MCParticle` |
| `Track` | `ReconstructedParticle` with associated `Track` |
| `Tower` | `ReconstructedParticle` with associated `Cluster` |
| `Jet` | `ReconstructedParticle` |
| `Muon` | `ReconstructedParticle` (subset collection) |
| `Electron` | `ReconstructedParticle` (subset collection) |
| `Photon` | `ReconstructedParticle` (subset collection) |
| `MissingET` | `ReconstructedParticle` |
| `ScalarHT` | `ParticleID` |
| `ParticleFlowCandidate` | `ReconstructedParticle` |
| n/a | `RecoMCParticleLink` |

All Delphes classes that are not listed here are currently not converted.

Expand Down
35 changes: 0 additions & 35 deletions examples/AssociationHelper.h

This file was deleted.

2 changes: 1 addition & 1 deletion examples/edm4hep_output_config.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ module EDM4HepOutput EDM4HepOutput {
add MissingETCollections MissingET
add ScalarHTCollections ScalarHT
set RecoParticleCollectionName ReconstructedParticles
set MCRecoAssociationCollectionName MCRecoAssociations
set RecoMCParticleLinkCollectionName MCRecoAssociations
}
118 changes: 0 additions & 118 deletions examples/higgs_recoil_plots.C

This file was deleted.

Loading
Loading