Skip to content

Commit

Permalink
Merge branch 'key4hep:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bistapf authored Apr 19, 2023
2 parents 7a8bcc5 + 5f136a3 commit 55e7ab1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
8 changes: 8 additions & 0 deletions converter/include/k4SimDelphes/DelphesEDM4HepConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "TTree.h"

//Delphes
#include "classes/DelphesClasses.h"
#include "modules/Delphes.h"

#include <array>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -95,6 +101,8 @@ namespace k4SimDelphes {
const std::unordered_map<UInt_t, edm4hep::MCParticle>& 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);
Expand Down
21 changes: 19 additions & 2 deletions converter/src/DelphesEDM4HepConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -15,8 +16,6 @@

#include "podio/UserDataCollection.h"

#include "classes/DelphesClasses.h"

#include <TMatrixDSym.h>

#include <iostream>
Expand Down Expand Up @@ -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<HepMCEvent*>(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
Expand All @@ -153,6 +161,15 @@ namespace k4SimDelphes {
m_recoParticleIds.clear();
}

//convert the eventHeader with metaData
void DelphesEDM4HepConverter::createEventHeader(const HepMCEvent* delphesEvent) {
auto* collection = createCollection<edm4hep::EventHeaderCollection>(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<edm4hep::MCParticleCollection>(branch);

Expand Down
2 changes: 1 addition & 1 deletion standalone/src/DelphesPythia8Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<HepMCEvent*>(branch->NewEntry());

element->Number = eventCounter;

Expand Down
2 changes: 2 additions & 0 deletions standalone/src/DelphesPythia8Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class DelphesPythia8Reader : public DelphesInputReader {
m_treeWriter->SetTree(m_converterTree.get());
modularDelphes->SetTreeWriter(m_treeWriter);

m_branchEvent = std::unique_ptr<ExRootTreeBranch>(m_treeWriter->NewBranch("Event", HepMCEvent::Class()));

// Initialize Pythia
m_pythia = std::make_unique<Pythia8::Pythia>();

Expand Down

0 comments on commit 55e7ab1

Please sign in to comment.