Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12_4] Protection for negative kinetic energy in Geant4 tracking #40128

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion SimG4Core/Application/src/ExceptionHandler.cc
Expand Up @@ -33,7 +33,7 @@ bool ExceptionHandler::Notify(const char* exceptionOrigin,
// part of exception happens outside tracking loop
if (nullptr != track) {
ekin = track->GetKineticEnergy();
message << "\n"
message << "\n CMS info: "
<< "TrackID=" << track->GetTrackID() << " ParentID=" << track->GetParentID() << " "
<< track->GetParticleDefinition()->GetParticleName() << "; Ekin(MeV)=" << ekin / CLHEP::MeV
<< "; time(ns)=" << track->GetGlobalTime() / CLHEP::ns << "; status=" << track->GetTrackStatus()
Expand Down
10 changes: 10 additions & 0 deletions SimG4Core/Application/src/SteppingAction.cc
Expand Up @@ -98,6 +98,16 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
G4Track* theTrack = aStep->GetTrack();
TrackStatus tstat = (theTrack->GetTrackStatus() == fAlive) ? sAlive : sKilledByProcess;

if (theTrack->GetKineticEnergy() < 0.0) {
if (nWarnings < 5) {
++nWarnings;
edm::LogWarning("SimG4CoreApplication")
<< "Track #" << theTrack->GetTrackID() << " " << theTrack->GetDefinition()->GetParticleName()
<< " Ekin(MeV)= " << theTrack->GetKineticEnergy() / MeV;
}
theTrack->SetKineticEnergy(0.0);
}

const G4StepPoint* preStep = aStep->GetPreStepPoint();
const G4StepPoint* postStep = aStep->GetPostStepPoint();

Expand Down
11 changes: 10 additions & 1 deletion SimG4Core/SensitiveDetector/src/SensitiveDetector.cc
Expand Up @@ -105,7 +105,16 @@ void SensitiveDetector::setNames(const std::vector<std::string>& hnames) {
}

void SensitiveDetector::NaNTrap(const G4Step* aStep) const {
const G4Track* currentTrk = aStep->GetTrack();
G4Track* currentTrk = aStep->GetTrack();
double ekin = currentTrk->GetKineticEnergy();
if (ekin < 0.0) {
const G4VPhysicalVolume* pCurrentVol = aStep->GetPreStepPoint()->GetPhysicalVolume();
edm::LogWarning("SensitiveDetector")
<< "Negative kinetic energy Ekin(MeV)=" << ekin / CLHEP::MeV << " of "
<< currentTrk->GetDefinition()->GetParticleName() << " trackID= " << currentTrk->GetTrackID() << " inside "
<< pCurrentVol->GetName();
currentTrk->SetKineticEnergy(0.0);
}
const G4ThreeVector& currentPos = currentTrk->GetPosition();
double xyz = currentPos.x() + currentPos.y() + currentPos.z();
const G4ThreeVector& currentMom = currentTrk->GetMomentum();
Expand Down