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 Aug 4, 2023
2 parents 55e7ab1 + d4eb7f8 commit 780f7fa
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 54 deletions.
230 changes: 210 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
### C++ ###
# Prerequisites
spack*
*.swp
build*
*.d
install
*.root
*.png
*.pdf
*.log
*.dat
spack*

# podio generated code files
edm4hep/edm4hep
edm4hep/src

# CI subfolders
podio/
tricktrack/

# Compiled Object files
*.slo
Expand Down Expand Up @@ -49,6 +32,213 @@ tricktrack/
*.out
*.app

# Tooling
.clangd
### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

### CMake Patch ###
# External projects
*-prefix/

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# Editors
.vscode
*~
\#*\#
.projectile

# Key4hep
spack-*
install/
## podio
podio_generated_files.cmake
/include/podio/podioVersion.h
/python/podio/__init__.py
## EDM4hep
/python/edm4hep/__version__.py
edm4hep/edm4hep/
edm4hep/src/
## k4MarlinWrapper
test/inputFiles/*.slcio
test/gaudi_opts/testConverterConstants.py

8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ option(USE_EXTERNAL_CATCH2 "If off, build the catch2 unittest framework locally"

#--- Declare project version --------------------------------------------------
SET( ${PROJECT_NAME}_VERSION_MAJOR 0 )
SET( ${PROJECT_NAME}_VERSION_MINOR 4 )
SET( ${PROJECT_NAME}_VERSION_MINOR 5 )
SET( ${PROJECT_NAME}_VERSION_PATCH 0 )

SET( ${PROJECT_NAME}_VERSION
Expand Down Expand Up @@ -47,9 +47,9 @@ if (NOT CMAKE_CONFIGURATION_TYPES)
endif()

#--- add version files ---------------------------------------------------------
configure_file(${CMAKE_SOURCE_DIR}/k4SimDelphesVersion.h
${CMAKE_BINARY_DIR}/k4SimDelphesVersion.h )
install(FILES ${CMAKE_BINARY_DIR}/k4SimDelphesVersion.h
configure_file(${PROJECT_SOURCE_DIR}/k4SimDelphesVersion.h
${PROJECT_BINARY_DIR}/k4SimDelphesVersion.h )
install(FILES ${PROJECT_BINARY_DIR}/k4SimDelphesVersion.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/k4SimDelphes )


Expand Down
6 changes: 3 additions & 3 deletions cmake/k4SimDelphesCPack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "[email protected]")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PACKAGE_HOMEPAGE_URL})
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "delphes, edm4hep")

set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")

#--- source package settings ---------------------------------------------------
set(CPACK_SOURCE_IGNORE_FILES
Expand Down
6 changes: 3 additions & 3 deletions cmake/k4SimDelphesUninstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
if (NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/k4SimDelphes_uninstall.cmake.in"
"${CMAKE_BINARY_DIR}/k4SimDelphes_uninstall.cmake"
"${PROJECT_BINARY_DIR}/k4SimDelphes_uninstall.cmake"
IMMEDIATE
@ONLY
)

add_custom_target(uninstall
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/k4SimDelphes_uninstall.cmake"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/k4SimDelphes_uninstall.cmake"
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
)
endif()

6 changes: 3 additions & 3 deletions cmake/k4SimDelphes_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
if(NOT EXISTS "@PROJECT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @PROJECT_BINARY_DIR@/install_manifest.txt")
endif()

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
file(READ "@PROJECT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
Expand Down
8 changes: 7 additions & 1 deletion converter/include/k4SimDelphes/DelphesEDM4HepConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ namespace k4SimDelphes {
*/
constexpr std::array<std::string_view, 1> RECO_CLUSTER_OUTPUT = {"Tower"};

/**
* Classes that will be stored as particle flow candidates
*/
constexpr std::array<std::string_view, 1> RECO_CANDIDATES_OUTPUT = {"ParticleFlowCandidate"};

/**
* Classes that will be stored as TrackerHits
*/
Expand All @@ -53,7 +58,7 @@ namespace k4SimDelphes {
constexpr auto CALORIMETERHIT_OUTPUT_NAME = "CalorimeterHits";

/**
* * Eventheader class will be stored only
* * Eventheader class will be stored only once
*/
constexpr auto EVENTHEADER_NAME = "EventHeader";

Expand Down Expand Up @@ -105,6 +110,7 @@ namespace k4SimDelphes {

void processParticles(const TClonesArray* delphesCollection, std::string const& branch);
void processTracks(const TClonesArray* delphesCollection, std::string const& branch);
void processPFlowCandidates(const TClonesArray* delphesCollection, std::string const& branch);
void processClusters(const TClonesArray* delphesCollection, std::string const& branch);
void processJets(const TClonesArray* delphesCollection, std::string const& branch);
void processPhotons(const TClonesArray* delphesCollection, std::string const& branch) {
Expand Down
32 changes: 30 additions & 2 deletions converter/src/DelphesEDM4HepConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ namespace k4SimDelphes {
* NOTE: not a configuration parameter. this has to be done in this order to
* ensure that products required by later stages are producd early enough
*/
constexpr std::array<std::string_view, 9> PROCESSING_ORDER = {
"GenParticle", "Track", "Tower", "Muon", "Electron", "Photon", "Jet", "MissingET", "SclalarHT"};
constexpr std::array<std::string_view, 10> PROCESSING_ORDER = {
"GenParticle", "Track", "Tower", "ParticleFlowCandidate", "Muon", "Electron", "Photon",
"Jet", "MissingET", "SclalarHT"};

template <size_t N>
void sortBranchesProcessingOrder(std::vector<BranchSettings>& branches,
Expand Down Expand Up @@ -97,6 +98,11 @@ namespace k4SimDelphes {
m_processFunctions.emplace(branch.name, &DelphesEDM4HepConverter::processTracks);
}

if (contains(outputSettings.ReconstructedParticleCollections, branch.name.c_str()) &&
contains(RECO_CANDIDATES_OUTPUT, branch.className.c_str())) {
m_processFunctions.emplace(branch.name, &DelphesEDM4HepConverter::processPFlowCandidates);
}

if (contains(outputSettings.ReconstructedParticleCollections, branch.name.c_str()) &&
contains(RECO_CLUSTER_OUTPUT, branch.className.c_str())) {
m_processFunctions.emplace(branch.name, &DelphesEDM4HepConverter::processClusters);
Expand Down Expand Up @@ -371,11 +377,30 @@ namespace k4SimDelphes {
}
}

void DelphesEDM4HepConverter::processPFlowCandidates(const TClonesArray* delphesCollection,
std::string const& branch) {
auto* candidateCollection = createCollection<edm4hep::ReconstructedParticleCollection>(branch);

for (auto iCand = 0; iCand < delphesCollection->GetEntries(); ++iCand) {
auto* delphesCand = static_cast<ParticleFlowCandidate*>(delphesCollection->At(iCand));
auto candidate = candidateCollection->create();

candidate.setCharge(delphesCand->Charge);
candidate.setMass(delphesCand->Mass);
const auto momentum = delphesCand->P4();
candidate.setEnergy(momentum.E());
candidate.setMomentum({(float)momentum.Px(), (float)momentum.Py(), (float)momentum.Pz()});
}
}

template <typename DelphesT>
void DelphesEDM4HepConverter::fillReferenceCollection(const TClonesArray* delphesCollection,
std::string const& branch, std::string_view const type) {
auto* collection = createCollection<edm4hep::ReconstructedParticleCollection>(branch, true);

//add collection for the isolation variable calculated by delphes:
auto* isoIDColl = createCollection<podio::UserDataCollection<float>>(std::string(branch) + "_IsolationVar");

for (auto iCand = 0; iCand < delphesCollection->GetEntries(); ++iCand) {
auto* delphesCand = static_cast<DelphesT*>(delphesCollection->At(iCand));

Expand All @@ -393,6 +418,9 @@ namespace k4SimDelphes {
matchedReco->setCharge(delphesCand->Charge);
}

//fill the isolation var
isoIDColl->push_back(delphesCand->IsolationVar);

} else {
std::cerr << "**** WARNING: No matching ReconstructedParticle was found for a Delphes " << type << std::endl;
}
Expand Down
Loading

0 comments on commit 780f7fa

Please sign in to comment.