diff --git a/src/musrSteppingAction.cc b/src/musrSteppingAction.cc index 6f804ca..175b2c8 100644 --- a/src/musrSteppingAction.cc +++ b/src/musrSteppingAction.cc @@ -119,6 +119,20 @@ void musrSteppingAction::UserSteppingAction(const G4Step* aStep) { myRootOutput->htest3->Fill(E); aTrack->SetTrackStatus(fStopAndKill); } + + // put energy to 0 if muon+ energy is too low in the moderator wires (hack for Geant4 11.1, not sure before it seemed to work without. GJ) + if(aTrack->GetDynamicParticle()->GetDefinition()->GetParticleName() == "mu+" && aTrack->GetVolume()->GetLogicalVolume()->GetName().find("Wire") != std::string::npos){ + + if(preStepPoint->GetKineticEnergy() < 0.001*CLHEP::electronvolt){ + + postStepPoint->SetMomentumDirection(G4ThreeVector(0,0,0)); + postStepPoint->SetKineticEnergy(0.001*CLHEP::electronvolt); //0 doesn't work. This is the minimum. + //aTrack->SetTrackStatus(fStopAndKill); //not optimal, no decay here + musrErrorMessage::GetInstance()->musrError(WARNING, + "musrSteppingAction: Mu+ has hit Wires in Moderator and wont stop 'wiggling'. Got stopped manually.",true); + } + } + // abort the event if it takes too long to finish (e.g. more than 60 seconds) if ((time(0) - realTimeWhenThisEventStarted)>musrParameters::maximumTimePerEvent) {