Skip to content

Commit

Permalink
Merge pull request #2 from MuonColliderSoft/mc-lbl
Browse files Browse the repository at this point in the history
Fix Overlay when not preserving truth particles
  • Loading branch information
gianelle committed Sep 13, 2021
2 parents 0278600 + c551936 commit 750dafd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -21,7 +21,7 @@ SET( ${PROJECT_NAME}_VERSION_PATCH 0 )
FIND_PACKAGE( ILCUTIL REQUIRED COMPONENTS ILCSOFT_CMAKE_MODULES )

# load default settings from ILCSOFT_CMAKE_MODULES
INCLUDE( ilcsoft_default_settings )
#INCLUDE( ilcsoft_default_settings )


FIND_PACKAGE( Marlin 1.0 REQUIRED ) # minimum required Marlin version
Expand Down
24 changes: 22 additions & 2 deletions src/OverlayTiming.cc
Expand Up @@ -712,11 +712,30 @@ namespace overlay {
source_collection->removeElementAt(i);
}
}
else if ((source_collection->getTypeName() == LCIO::SIMTRACKERHIT) && ((std::fabs(time_offset) < std::numeric_limits<float>::epsilon()) || !TPC_hits))
else if (source_collection->getTypeName() == LCIO::SIMTRACKERHIT) {
//If truth is removed in the overlay, we need to remove the pointer since it will become invalid
if (not _mergeMCParticles) {
for (int k = 0; k < number_of_elements; ++k)
{
SimTrackerHitImpl *TrackerHit = static_cast<SimTrackerHitImpl*>(source_collection->getElementAt(k));
EVENT::MCParticle *mcParticle = TrackerHit->getMCParticle();
//if a valida pointer exists, keep momentum information
if (mcParticle) {
const double *preserveMomentum = mcParticle->getMomentum();
TrackerHit->setMomentum(preserveMomentum[0], preserveMomentum[1], preserveMomentum[2]);
}
TrackerHit->setMCParticle(nullptr);
}
}
//Adjust timing information on hits depending on BX and set overlay flag
if ((std::fabs(time_offset) < std::numeric_limits<float>::epsilon()) || !TPC_hits)
{
for (int k = number_of_elements - 1; k >= 0; --k)
{
SimTrackerHitImpl *TrackerHit = static_cast<SimTrackerHitImpl*>(source_collection->getElementAt(k));

TrackerHit->setOverlay(true);

const float _time_of_flight = time_of_flight(TrackerHit->getPosition()[0], TrackerHit->getPosition()[1], TrackerHit->getPosition()[2]);

if (((TrackerHit->getTime() + time_offset) > (this_start + _time_of_flight)) && ((TrackerHit->getTime() + time_offset) < (this_stop + _time_of_flight)))
Expand All @@ -727,7 +746,7 @@ namespace overlay {
}
}
}
else if ((source_collection->getTypeName() == LCIO::SIMTRACKERHIT) && TPC_hits)
else if (TPC_hits)
{
for (int k = number_of_elements - 1; k >= 0; --k)
{
Expand All @@ -752,6 +771,7 @@ namespace overlay {
}
}
}
}
else if (source_collection->getTypeName() == LCIO::SIMCALORIMETERHIT)
{
// create a map of dest Collection
Expand Down

0 comments on commit 750dafd

Please sign in to comment.