Skip to content

Commit

Permalink
Don't use radiusOfInnermostHit for EDM4hep tracks
Browse files Browse the repository at this point in the history
and compute it from hits when going from EDM4hep to LCIO. See
key4hep/EDM4hep#326
  • Loading branch information
jmcarcell committed Jun 20, 2024
1 parent 7ab25a5 commit edb9c9b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "k4EDM4hep2LcioConv/MappingUtils.h"

#include <cassert>
#include <cmath>
#include <limits>

namespace EDM4hep2LCIOConv {

Expand All @@ -23,7 +25,15 @@ 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());
double radius = std::numeric_limits<double>::max();
for (const auto& hit : edm_tr.getTrackerHits()) {
radius = std::min(radius, std::sqrt(hit.getPosition()[0] * hit.getPosition()[0] +
hit.getPosition()[1] * hit.getPosition()[1]));
}
if (radius == std::numeric_limits<double>::max()) {
radius = 0;
}
lcio_tr->setRadiusOfInnermostHit(radius);

// 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
13 changes: 12 additions & 1 deletion tests/src/CompareEDM4hepLCIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "IMPL/TrackerHitImpl.h"

#include <cmath>
#include <cstdint>

/**
Expand Down Expand Up @@ -312,7 +313,17 @@ 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 = std::numeric_limits<double>::max();
for (const auto& hit : edm4hepElem.getTrackerHits()) {
radius = std::min(
radius, std::sqrt(hit.getPosition()[0] * hit.getPosition()[0] + hit.getPosition()[1] * hit.getPosition()[1]));
}
if (radius == std::numeric_limits<double>::max()) {
radius = 0;
}
ASSERT_COMPARE_VALS_FLOAT(lcioElem->getRadiusOfInnermostHit(), radius, lcioElem->getRadiusOfInnermostHit() / 1e6,
"radiusOfInnermostHit in Track");
}

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

Expand Down
6 changes: 6 additions & 0 deletions tests/src/ComparisonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ bool compareValuesNanSafe(LCIO lcioV, EDM4hepT edm4hepV, const std::string& msg)
return false; \
}

#define ASSERT_COMPARE_VALS_FLOAT(lcioV, edm4hepV, tol, msg) \
if (std::abs(lcioV - edm4hepV) > tol) { \
std::cerr << msg << " (LCIO: " << (lcioV) << ", EDM4hep: " << (edm4hepV) << ")" << std::endl; \
return false; \
}

#define ASSERT_COMPARE(lcioE, edm4hepE, func, msg) \
{ \
const auto lcioV = lcioE->func(); \
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 edb9c9b

Please sign in to comment.