Skip to content

Commit

Permalink
Merge branch 'main' into vertex-bitfield
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener authored Jul 8, 2024
2 parents 973faf4 + 116c832 commit 13b9411
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/downstream-build.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Do not edit this file, it will be overwritten!
# The template file can be found in
# https://github.com/key4hep/key4hep-actions/blob/main/workflows/downstream-build.yaml
name: downstream-build

on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
downstream-build:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/key4hep-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
schedule:
- cron: '16 5 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ k4edm4hep2lcioconv_set_compiler_flags()
find_package(LCIO 2.20.1 REQUIRED)
find_package(podio REQUIRED)
find_package(EDM4HEP 0.10.1 REQUIRED)
find_package(ROOT REQUIRED COMPONENTS MathCore)

add_subdirectory(k4EDM4hep2LcioConv)
add_subdirectory(standalone)
Expand Down
2 changes: 0 additions & 2 deletions k4EDM4hep2LcioConv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
find_package(ROOT REQUIRED COMPONENTS MathCore)

add_library(k4EDM4hep2LcioConv SHARED
src/k4EDM4hep2LcioConv.cpp
src/k4Lcio2EDM4hepConv.cpp
Expand Down
10 changes: 10 additions & 0 deletions k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ std::optional<int32_t> attachParticleIDMetaData(IMPL::LCEventImpl* lcEvent, cons
/**
* Convert EDM4hep Tracks to LCIO. Simultaneously populate the mapping from
* EDM4hep to LCIO objects for relation resolving in a second step.
*
* NOTE: Since the edm4hep::Track does not have a radiusOfInnermostHit field,
* this quantity is calculated on the fly from the attached TrackState using the
* getRadiusOfStateAtFirstHit function with the default 2D version.
*/
template <typename TrackMapT>
std::unique_ptr<lcio::LCCollectionVec> convertTracks(const edm4hep::TrackCollection* const edmCollection,
Expand Down Expand Up @@ -430,6 +434,12 @@ convEvent(const podio::Frame& edmEvent, const podio::Frame& metadata = podio::Fr
return convertEvent(edmEvent, metadata);
}

/**
* Get the radius of the TrackState at the first from the given track. This is
* used to set the radiusOfInnermostHit in the LCIO track during the conversion
*/
std::optional<double> getRadiusOfStateAtFirstHit(const edm4hep::Track& track, bool use3D = false);

} // namespace EDM4hep2LCIOConv

#include "k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "k4EDM4hep2LcioConv/MappingUtils.h"

#include <cassert>
#include <cmath>

#include "TMath.h"

Expand All @@ -25,7 +26,7 @@ std::unique_ptr<lcio::LCCollectionVec> convertTracks(const edm4hep::TrackCollect
lcio_tr->setNdf(edm_tr.getNdf());
lcio_tr->setdEdx(edm_tr.getDEdx());
lcio_tr->setdEdxError(edm_tr.getDEdxError());
lcio_tr->setRadiusOfInnermostHit(edm_tr.getRadiusOfInnermostHit());
lcio_tr->setRadiusOfInnermostHit(getRadiusOfStateAtFirstHit(edm_tr).value_or(-1.0));

// Loop over the hit Numbers in the track
lcio_tr->subdetectorHitNumbers().resize(edm_tr.subdetectorHitNumbers_size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ std::unique_ptr<edm4hep::TrackCollection> convertTracks(const std::string& name,
lval.setNdf(rval->getNdf());
lval.setDEdx(rval->getdEdx());
lval.setDEdxError(rval->getdEdxError());
lval.setRadiusOfInnermostHit(rval->getRadiusOfInnermostHit());

auto subdetectorHitNum = rval->getSubdetectorHitNumbers();
for (auto hitNum : subdetectorHitNum) {
Expand Down Expand Up @@ -866,11 +865,11 @@ createAssociations(const ObjectMappingT& typeMapping,
auto mc_a = createAssociationCollection<edm4hep::MCRecoTrackParticleAssociationCollection, true>(
relations, typeMapping.tracks, typeMapping.mcParticles);
assoCollVec.emplace_back(name, std::move(mc_a));
} else if (fromType == "TrackerHit" && toType == "SimTrackerHit") {
} else if ((fromType == "TrackerHit" || fromType == "TrackerHitPlane") && toType == "SimTrackerHit") {
auto mc_a = createAssociationCollection<edm4hep::MCRecoTrackerAssociationCollection, true>(
relations, typeMapping.trackerHits, typeMapping.simTrackerHits);
assoCollVec.emplace_back(name, std::move(mc_a));
} else if (fromType == "SimTrackerHit" && toType == "TrackerHit") {
} else if (fromType == "SimTrackerHit" && (toType == "TrackerHit" || fromType == "TrackerHitPlane")) {
auto mc_a = createAssociationCollection<edm4hep::MCRecoTrackerAssociationCollection, false>(
relations, typeMapping.simTrackerHits, typeMapping.trackerHits);
assoCollVec.emplace_back(name, std::move(mc_a));
Expand Down
10 changes: 10 additions & 0 deletions k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,14 @@ std::unique_ptr<lcio::LCEventImpl> convertEvent(const podio::Frame& edmEvent, co
return lcioEvent;
}

std::optional<double> getRadiusOfStateAtFirstHit(const edm4hep::Track& track, bool use3D) {
for (const auto& state : track.getTrackStates()) {
if (state.location == edm4hep::TrackState::AtFirstHit) {
const auto refP = state.referencePoint;
return std::sqrt(refP.x * refP.x + refP.y * refP.y + use3D * refP.z * refP.z);
}
}
return std::nullopt;
}

} // namespace EDM4hep2LCIOConv
15 changes: 14 additions & 1 deletion standalone/lcio2edm4hep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ int main(int argc, char* argv[]) {
}

const int nEvt = args.nEvents > 0 ? args.nEvents : lcreader->getNumberOfEvents();
bool haveSimCaloHits{false};
for (int i = 0; i < nEvt; ++i) {
int percEvt = i * 100 / (nEvt - 1);
if (percEvt % 10 == 0) {
Expand All @@ -218,7 +219,19 @@ int main(int argc, char* argv[]) {
if (patching == true) {
colPatcher.patchCollections(evt);
}
const auto edmEvent = LCIO2EDM4hepConv::convertEvent(evt, collsToConvert);
if (i == 0) {
for (const auto& name : *evt->getCollectionNames()) {
if (evt->getCollection(name)->getTypeName() == "SimCalorimeterHit") {
haveSimCaloHits = true;
break;
}
}
}

auto edmEvent = LCIO2EDM4hepConv::convertEvent(evt, collsToConvert);
if (haveSimCaloHits && edmEvent.get("AllCaloHitContributionsCombined") == nullptr) {
edmEvent.put(edm4hep::CaloHitContributionCollection(), "AllCaloHitContributionsCombined");
}

// For the first event we also convert some meta information for the
// ParticleID handling
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(edmCompare SHARED src/CompareEDM4hepLCIO.cc src/ObjectMapping.cc src/CompareEDM4hepEDM4hep.cc)
target_link_libraries(edmCompare PUBLIC EDM4HEP::edm4hep LCIO::lcio)
target_link_libraries(edmCompare PUBLIC EDM4HEP::edm4hep LCIO::lcio ROOT::MathCore)
target_include_directories(edmCompare
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/k4EDM4hep2LcioConv/include>
Expand All @@ -10,7 +10,7 @@ target_link_libraries(TestUtils PUBLIC EDM4HEP::edm4hep LCIO::lcio)
target_include_directories(TestUtils PUBLIC ${LCIO_INCLUDE_DIRS})

add_executable(compare-contents compare_contents.cpp)
target_link_libraries(compare-contents PRIVATE edmCompare podio::podioRootIO)
target_link_libraries(compare-contents PRIVATE edmCompare podio::podioRootIO k4EDM4hep2LcioConv)
target_include_directories(compare-contents PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>)

Expand Down
12 changes: 10 additions & 2 deletions tests/src/CompareEDM4hepLCIO.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "CompareEDM4hepLCIO.h"
#include "ComparisonUtils.h"
#include "k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h"

#include "IMPL/TrackerHitImpl.h"

#include <cmath>
#include <cstdint>

#include "TMath.h"
Expand Down Expand Up @@ -314,7 +316,13 @@ bool compare(const EVENT::Track* lcioElem, const edm4hep::Track& edm4hepElem, co
ASSERT_COMPARE_VALS(lcioElem->getdEdx(), dxQuantities[0].value, "dEdx in DxQuantities in Track");
ASSERT_COMPARE_VALS(lcioElem->getdEdxError(), dxQuantities[0].error, "dEdxError in DxQuantities in Track");

ASSERT_COMPARE(lcioElem, edm4hepElem, getRadiusOfInnermostHit, "radiusOfInnermostHit in Track");
double radius = EDM4hep2LCIOConv::getRadiusOfStateAtFirstHit(edm4hepElem).value_or(-1.0);
double radius3D = EDM4hep2LCIOConv::getRadiusOfStateAtFirstHit(edm4hepElem, true).value_or(-1.0);
const double radiusLCIO = lcioElem->getRadiusOfInnermostHit();
if (std::abs(radius - radiusLCIO) > radiusLCIO / 1e6 && std::abs(radius3D - radiusLCIO) > radiusLCIO / 1e6) {
std::cerr << "radiusOfInnermostHit in Track (LCIO: " << radiusLCIO << "), EDM4hep: 2d: " << radius
<< ", 3d: " << radius3D << ")" << std::endl;
}

ASSERT_COMPARE_RELATION(lcioElem, edm4hepElem, getTracks, objectMaps.tracks, "Tracks in Track");

Expand All @@ -323,7 +331,7 @@ bool compare(const EVENT::Track* lcioElem, const edm4hep::Track& edm4hepElem, co
ASSERT_COMPARE_VALS(lcioTrackStates.size(), edm4hepTrackStates.size(), "number of TrackStates in Track");
for (size_t i = 0; i < lcioTrackStates.size(); ++i) {
if (!compare(lcioTrackStates[i], edm4hepTrackStates[i])) {
std::cerr << " " << i << " in Track" << std::endl;
std::cerr << "TrackState " << i << " in Track" << std::endl;
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/src/EDM4hep2LCIOUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ edm4hep::TrackCollection createTracks(const int num_elements, const int subdetec
elem.setType(2); // TODO specific type
elem.setChi2(i * 10.f);
elem.setNdf(i * 12);
elem.setRadiusOfInnermostHit(i * 5.f);

elem.setDEdx(i);
elem.setDEdxError(i / std::sqrt(i + 1));
Expand Down

0 comments on commit 13b9411

Please sign in to comment.