Skip to content

Commit bd51470

Browse files
authored
Make conversion accept MCParticles with helicity (#120)
* Make conversion accept MCParticles with helicity Transparent for now * Switch to pre-processor constant for compatility checks * Do not include version header as it's not necessary * Fix warning for narrowing conversion
1 parent cfce02d commit bd51470

5 files changed

Lines changed: 22 additions & 1 deletion

File tree

k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ std::unique_ptr<lcio::LCCollectionVec> convertMCParticles(const edm4hep::MCParti
489489
lcio_mcp->setMomentumAtEndpoint(momentumEndpoint);
490490
lcio_mcp->setMass(edm_mcp.getMass());
491491
lcio_mcp->setCharge(edm_mcp.getCharge());
492+
#ifdef EDM4HEP_MCPARTICLE_HAS_HELICITY
493+
float spin[3] = {0, 0, static_cast<float>(edm_mcp.getHelicity())};
494+
#else
492495
float spin[3] = {edm_mcp.getSpin()[0], edm_mcp.getSpin()[1], edm_mcp.getSpin()[2]};
496+
#endif
493497
lcio_mcp->setSpin(spin);
494498
int colorflow[2] = {0, 0};
495499
lcio_mcp->setColorFlow(colorflow);

k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ convertMCParticles(const std::string& name, EVENT::LCCollection* LCCollection, M
108108
lval.setCharge(rval->getCharge());
109109
lval.setTime(rval->getTime());
110110
lval.setMass(rval->getMass());
111+
#ifdef EDM4HEP_MCPARTICLE_HAS_HELICITY
112+
lval.setHelicity(rval->getSpin()[2]);
113+
#else
111114
lval.setSpin(edm4hep::Vector3f(rval->getSpin()));
115+
#endif
112116
lval.setVertex(edm4hep::Vector3d(rval->getVertex()));
113117
lval.setEndpoint(edm4hep::Vector3d(rval->getEndpoint()));
114118
lval.setMomentum(rval->getMomentum());

tests/src/CompareEDM4hepEDM4hep.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ bool compare(const edm4hep::MCParticleCollection& origColl, const edm4hep::MCPar
5858
"momentumAtEndpoint in particle " << i);
5959
REQUIRE_SAME(origPart.getMass(), part.getMass(), "mass in particle " << i);
6060
REQUIRE_SAME(origPart.getCharge(), part.getCharge(), "charge in particle " << i);
61+
#ifdef EDM4HEP_MCPARTICLE_HAS_HELICITY
62+
REQUIRE_SAME(origPart.getHelicity(), part.getHelicity(), "helicity in particle " << i);
63+
#else
6164
REQUIRE_SAME(origPart.getSpin(), part.getSpin(), "spin in particle " << i);
65+
#endif
6266

6367
REQUIRE_SAME(origPart.isCreatedInSimulation(), part.isCreatedInSimulation(), " in particle " << i);
6468
REQUIRE_SAME(origPart.isBackscatter(), part.isBackscatter(), " in particle " << i);

tests/src/CompareEDM4hepLCIO.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
#include "IMPL/TrackerHitImpl.h"
66

7+
#include <edm4hep/VertexRecoParticleLinkCollection.h>
8+
79
#include <cmath>
810
#include <cstdint>
9-
#include <edm4hep/VertexRecoParticleLinkCollection.h>
1011

1112
#include "TMath.h"
1213

@@ -110,7 +111,11 @@ bool compare(const EVENT::MCParticle* lcioElem, const edm4hep::MCParticle& edm4h
110111
ASSERT_COMPARE(lcioElem, edm4hepElem, getEndpoint, "endpoint in MCParticle");
111112
ASSERT_COMPARE(lcioElem, edm4hepElem, getMomentum, "momentum in MCParticle");
112113
ASSERT_COMPARE(lcioElem, edm4hepElem, getMomentumAtEndpoint, "momentumAtEndpoint in MCParticle");
114+
#ifdef EDM4HEP_MCPARTICLE_HAS_HELICITY
115+
ASSERT_COMPARE_VALS(lcioElem->getSpin()[2], edm4hepElem.getHelicity(), "spin.z / helicity in MCParticle");
116+
#else
113117
ASSERT_COMPARE(lcioElem, edm4hepElem, getSpin, "spin in MCParticle");
118+
#endif
114119

115120
ASSERT_COMPARE_RELATION(lcioElem, edm4hepElem, getDaughters, objectMaps.mcParticles, "daughters in MCParticle");
116121
ASSERT_COMPARE_RELATION(lcioElem, edm4hepElem, getParents, objectMaps.mcParticles, "parents in MCParticle");

tests/src/EDM4hep2LCIOUtilities.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ edm4hep::MCParticleCollection createMCParticles(const int num_elements,
5252
elem.setMomentum({i * 1.f, i * 2.f, i * 3.f});
5353
elem.setMomentumAtEndpoint({i * 3.f, i * 2.f, i * 1.f});
5454
elem.setMass(125. * i);
55+
#ifdef EDM4HEP_MCPARTICLE_HAS_HELICITY
56+
elem.setHelicity(i * 42); // avoid ever hitting the magic value of 9
57+
#else
5558
elem.setSpin({i * 0.5f, i * 0.25f, i * 0.25f});
59+
#endif
5660
elem.setCreatedInSimulation(1);
5761
elem.setBackscatter(0);
5862
elem.setVertexIsNotEndpointOfParent(1);

0 commit comments

Comments
 (0)