@@ -103,7 +103,7 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
103103 const G4StepPoint* postStep = aStep->GetPostStepPoint ();
104104
105105 // NaN energy deposit
106- if (sAlive == tstat && edm::isNotFinite (aStep->GetTotalEnergyDeposit ())) {
106+ if (edm::isNotFinite (aStep->GetTotalEnergyDeposit ())) {
107107 tstat = sEnergyDepNaN ;
108108 if (nWarnings < 5 ) {
109109 ++nWarnings;
@@ -115,48 +115,60 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
115115 }
116116 }
117117
118+ // the track is killed by the process
119+ if (tstat == sKilledByProcess ) {
120+ if (nullptr != steppingVerbose) {
121+ steppingVerbose->NextStep (aStep, fpSteppingManager, false );
122+ }
123+ return ;
124+ }
125+
118126 if (sAlive == tstat && theTrack->GetCurrentStepNumber () > maxNumberOfSteps) {
119127 tstat = sNumberOfSteps ;
120128 if (nWarnings < 5 ) {
121129 ++nWarnings;
122130 edm::LogWarning (" SimG4CoreApplication" )
123131 << " Track #" << theTrack->GetTrackID () << " " << theTrack->GetDefinition ()->GetParticleName ()
124132 << " E(MeV)= " << preStep->GetKineticEnergy () / MeV << " Nstep= " << theTrack->GetCurrentStepNumber ()
125- << " is killed due to limit on number of steps;PV: " << preStep->GetPhysicalVolume ()->GetName () << " at "
133+ << " is killed due to limit on number of steps;/n PV: " << preStep->GetPhysicalVolume ()->GetName () << " at "
126134 << theTrack->GetPosition () << " StepLen(mm)= " << aStep->GetStepLength ();
127135 }
128136 }
137+ const double time = theTrack->GetGlobalTime ();
129138
130139 // check Z-coordinate
131140 if (sAlive == tstat && std::abs (theTrack->GetPosition ().z ()) >= maxZCentralCMS) {
132- tstat = (theTrack-> GetGlobalTime () > maxTrackTimeForward) ? sOutOfTime : sVeryForward ;
141+ tstat = (time > maxTrackTimeForward) ? sOutOfTime : sVeryForward ;
133142 }
134143
135144 // check G4Region
136- if (sAlive == tstat && postStep->GetPhysicalVolume () != nullptr ) {
137- const G4Region* theRegion = preStep->GetPhysicalVolume ()->GetLogicalVolume ()->GetRegion ();
145+ if (sAlive == tstat) {
146+ // next logical volume and next region
147+ const G4LogicalVolume* lv = postStep->GetPhysicalVolume ()->GetLogicalVolume ();
148+ const G4Region* theRegion = lv->GetRegion ();
138149
139150 // kill in dead regions
140- if (isInsideDeadRegion (theRegion)) {
151+ if (isInsideDeadRegion (theRegion))
141152 tstat = sDeadRegion ;
142- }
143153
144154 // kill out of time
145- if (sAlive == tstat && isOutOfTimeWindow (theTrack, theRegion)) {
146- tstat = sOutOfTime ;
155+ if (sAlive == tstat) {
156+ if (isOutOfTimeWindow (theRegion, time))
157+ tstat = sOutOfTime ;
147158 }
148159
149160 // kill low-energy in volumes on demand
150- if (sAlive == tstat && numberEkins > 0 && isLowEnergy (aStep)) {
151- tstat = sLowEnergy ;
161+ if (sAlive == tstat && numberEkins > 0 ) {
162+ if (isLowEnergy (lv, theTrack))
163+ tstat = sLowEnergy ;
152164 }
153165
154166 // kill low-energy in vacuum
155- const G4double kinEnergy = theTrack-> GetKineticEnergy ();
156- if ( sAlive == tstat && killBeamPipe && kinEnergy < theCriticalEnergyForVacuum &&
157- theTrack->GetDefinition ()->GetPDGCharge () != 0.0 && kinEnergy > 0.0 &&
158- theTrack-> GetNextVolume ()-> GetLogicalVolume ()-> GetMaterial ()-> GetDensity () <= theCriticalDensity) {
159- tstat = sLowEnergyInVacuum ;
167+ if ( sAlive == tstat && killBeamPipe) {
168+ if (theTrack-> GetKineticEnergy () < theCriticalEnergyForVacuum &&
169+ theTrack->GetDefinition ()->GetPDGCharge () != 0.0 && lv-> GetMaterial ()-> GetDensity () <= theCriticalDensity) {
170+ tstat = sLowEnergyInVacuum ;
171+ }
160172 }
161173 }
162174 // check transition tracker/calo
@@ -185,11 +197,9 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
185197 }
186198}
187199
188- bool SteppingAction::isLowEnergy (const G4Step* aStep) const {
189- const G4StepPoint* sp = aStep->GetPostStepPoint ();
190- const G4LogicalVolume* lv = sp->GetPhysicalVolume ()->GetLogicalVolume ();
191- const double ekin = sp->GetKineticEnergy ();
192- int pCode = aStep->GetTrack ()->GetDefinition ()->GetPDGEncoding ();
200+ bool SteppingAction::isLowEnergy (const G4LogicalVolume* lv, const G4Track* theTrack) const {
201+ const double ekin = theTrack->GetKineticEnergy ();
202+ int pCode = theTrack->GetDefinition ()->GetPDGEncoding ();
193203
194204 for (auto & vol : ekinVolumes) {
195205 if (lv == vol) {
@@ -281,9 +291,6 @@ void SteppingAction::PrintKilledTrack(const G4Track* aTrack, const TrackStatus&
281291 std::string rname = " " ;
282292 std::string typ = " " ;
283293 switch (tst) {
284- case sKilledByProcess :
285- typ = " G4Process " ;
286- break ;
287294 case sDeadRegion :
288295 typ = " in dead region " ;
289296 break ;
@@ -309,14 +316,16 @@ void SteppingAction::PrintKilledTrack(const G4Track* aTrack, const TrackStatus&
309316 break ;
310317 }
311318 G4VPhysicalVolume* pv = aTrack->GetNextVolume ();
312- if (pv) {
313- vname = pv->GetLogicalVolume ()->GetName ();
314- rname = pv->GetLogicalVolume ()->GetRegion ()->GetName ();
315- }
319+ vname = pv->GetLogicalVolume ()->GetName ();
320+ rname = pv->GetLogicalVolume ()->GetRegion ()->GetName ();
316321
317- edm::LogVerbatim (" SimG4CoreApplication" )
322+ const double ekin = aTrack->GetKineticEnergy ();
323+ if (ekin < 2 * CLHEP::MeV) {
324+ return ;
325+ }
326+ edm::LogWarning (" SimG4CoreApplication" )
318327 << " Track #" << aTrack->GetTrackID () << " StepN= " << aTrack->GetCurrentStepNumber () << " "
319- << aTrack->GetDefinition ()->GetParticleName () << " E(MeV)= " << aTrack-> GetKineticEnergy () / MeV
320- << " T(ns)= " << aTrack->GetGlobalTime () / ns << " is killed due to " << typ << " inside LV: " << vname << " ("
321- << rname << " ) at " << aTrack->GetPosition ();
328+ << aTrack->GetDefinition ()->GetParticleName () << " E(MeV)=" << ekin / CLHEP:: MeV
329+ << " T(ns)=" << aTrack->GetGlobalTime () / CLHEP:: ns << " is killed due to " << typ << " \n LV: " << vname << " ("
330+ << rname << " ) at " << aTrack->GetPosition () << " step(cm)= " << aTrack-> GetStep ()-> GetStepLength () / CLHEP::cm ;
322331}
0 commit comments