From dccad222a30282714d93ee395eacf12ab4c7915d Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Tue, 31 Mar 2015 09:15:52 +0000 Subject: [PATCH] Geant4SDAction: Catch exception when calling cellID Create stringstream to avoid changing output format for cout --- DDG4/plugins/Geant4SDActions.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp index 00a0c5661..dcf8adf28 100644 --- a/DDG4/plugins/Geant4SDActions.cpp +++ b/DDG4/plugins/Geant4SDActions.cpp @@ -81,7 +81,26 @@ namespace DD4hep { StepHandler h(step); HitContribution contrib = Hit::extractContribution(step); HitCollection* coll = collection(m_collectionID); - long long int cell = cellID(step); + long long int cell; + try { + cell = cellID(step); + } catch(std::runtime_error &e) { + std::stringstream out; + out << std::setprecision(20) << std::scientific; + out << "ERROR: " << e.what() << std::endl; + out << "Position: " + << "Pre (" << std::setw(24) << step->GetPreStepPoint()->GetPosition() << ") " + << "Post (" << std::setw(24) << step->GetPostStepPoint()->GetPosition() << ") " + << std::endl; + out << "Momentum: " + << " Pre (" <<std::setw(24) << step->GetPreStepPoint() ->GetMomentum() << ") " + << " Post (" <<std::setw(24) << step->GetPostStepPoint()->GetMomentum() << ") " + << std::endl; + + std::cout << out; + + return true; + } Hit* hit = coll->find<Hit>(CellIDCompare<Hit>(cell)); if ( h.totalEnergy() < std::numeric_limits<double>::epsilon() ) { -- GitLab