From 5f136a33d757d486b08d98941776125d76bd6cc1 Mon Sep 17 00:00:00 2001 From: bistapf <79460851+bistapf@users.noreply.github.com> Date: Wed, 19 Apr 2023 13:08:33 +0200 Subject: [PATCH] Add event header to conversion (#106) --- .../k4SimDelphes/DelphesEDM4HepConverter.h | 8 +++++++ converter/src/DelphesEDM4HepConverter.cc | 21 +++++++++++++++++-- standalone/src/DelphesPythia8Common.h | 2 +- standalone/src/DelphesPythia8Reader.h | 2 ++ tests/CMakeLists.txt | 1 - 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/converter/include/k4SimDelphes/DelphesEDM4HepConverter.h b/converter/include/k4SimDelphes/DelphesEDM4HepConverter.h index 878b10a..0358090 100644 --- a/converter/include/k4SimDelphes/DelphesEDM4HepConverter.h +++ b/converter/include/k4SimDelphes/DelphesEDM4HepConverter.h @@ -14,6 +14,7 @@ #include "TTree.h" //Delphes +#include "classes/DelphesClasses.h" #include "modules/Delphes.h" #include @@ -51,6 +52,11 @@ namespace k4SimDelphes { */ constexpr auto CALORIMETERHIT_OUTPUT_NAME = "CalorimeterHits"; + /** + * * Eventheader class will be stored only + */ + constexpr auto EVENTHEADER_NAME = "EventHeader"; + struct BranchSettings { std::string input; std::string name; @@ -95,6 +101,8 @@ namespace k4SimDelphes { const std::unordered_map& mc_map); private: + void createEventHeader(const HepMCEvent* delphesEvent); + void processParticles(const TClonesArray* delphesCollection, std::string const& branch); void processTracks(const TClonesArray* delphesCollection, std::string const& branch); void processClusters(const TClonesArray* delphesCollection, std::string const& branch); diff --git a/converter/src/DelphesEDM4HepConverter.cc b/converter/src/DelphesEDM4HepConverter.cc index 7a518fb..280840f 100644 --- a/converter/src/DelphesEDM4HepConverter.cc +++ b/converter/src/DelphesEDM4HepConverter.cc @@ -5,6 +5,7 @@ #include "edm4hep/CalorimeterHitCollection.h" #include "edm4hep/ClusterCollection.h" +#include "edm4hep/EventHeaderCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/MCRecoParticleAssociationCollection.h" #include "edm4hep/ParticleIDCollection.h" @@ -15,8 +16,6 @@ #include "podio/UserDataCollection.h" -#include "classes/DelphesClasses.h" - #include #include @@ -130,6 +129,15 @@ namespace k4SimDelphes { // Make sure the shared collections are present registerGlobalCollections(); + //filling the event header + auto* eventBranch = delphesTree->GetBranch("Event"); + + if (eventBranch) { + auto* delphesEvents = *(TClonesArray**)eventBranch->GetAddress(); + auto* delphesEvent = static_cast(delphesEvents->At(0)); + createEventHeader(delphesEvent); + } + for (const auto& branch : m_branches) { // at this point it is not guaranteed that all entries in branch (which follow // the input from the delphes card) are also present in the processing @@ -153,6 +161,15 @@ namespace k4SimDelphes { m_recoParticleIds.clear(); } + //convert the eventHeader with metaData + void DelphesEDM4HepConverter::createEventHeader(const HepMCEvent* delphesEvent) { + auto* collection = createCollection(EVENTHEADER_NAME); + auto cand = collection->create(); + + cand.setWeight(delphesEvent->Weight); + cand.setEventNumber(delphesEvent->Number); + } + void DelphesEDM4HepConverter::processParticles(const TClonesArray* delphesCollection, std::string const& branch) { auto* collection = createCollection(branch); diff --git a/standalone/src/DelphesPythia8Common.h b/standalone/src/DelphesPythia8Common.h index bf64111..8b03b55 100644 --- a/standalone/src/DelphesPythia8Common.h +++ b/standalone/src/DelphesPythia8Common.h @@ -41,7 +41,7 @@ void ConvertInput(Long64_t eventCounter, Pythia8::Pythia* pythia, ExRootTreeBran Double_t x, y, z, t; // event information - element = new HepMCEvent(); //(branch->NewEntry()); + element = static_cast(branch->NewEntry()); element->Number = eventCounter; diff --git a/standalone/src/DelphesPythia8Reader.h b/standalone/src/DelphesPythia8Reader.h index 9522542..a0d4151 100644 --- a/standalone/src/DelphesPythia8Reader.h +++ b/standalone/src/DelphesPythia8Reader.h @@ -51,6 +51,8 @@ class DelphesPythia8Reader : public DelphesInputReader { m_treeWriter->SetTree(m_converterTree.get()); modularDelphes->SetTreeWriter(m_treeWriter); + m_branchEvent = std::unique_ptr(m_treeWriter->NewBranch("Event", HepMCEvent::Class())); + // Initialize Pythia m_pythia = std::make_unique(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b86f4c2..f22fda8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,4 +56,3 @@ if(DELPHES_CARD) else() message(WARNING "Cannot find IDEA delphes card from the delphes installation. Cannot use it for testing") endif() -