@@ -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,62 @@ 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+
147+ // next logical volume and next region
148+ const G4LogicalVolume* lv = postStep->GetPhysicalVolume ()->GetLogicalVolume ();
149+ const G4Region* theRegion = lv->GetRegion ();
138150
139151 // kill in dead regions
140- if (isInsideDeadRegion (theRegion)) {
152+ if (isInsideDeadRegion (theRegion))
141153 tstat = sDeadRegion ;
142- }
143154
144155 // kill out of time
145- if (sAlive == tstat && isOutOfTimeWindow (theTrack, theRegion)) {
146- tstat = sOutOfTime ;
156+ if (sAlive == tstat) {
157+ if (isOutOfTimeWindow (theRegion, time))
158+ tstat = sOutOfTime ;
147159 }
148160
149161 // kill low-energy in volumes on demand
150- if (sAlive == tstat && numberEkins > 0 && isLowEnergy (aStep)) {
151- tstat = sLowEnergy ;
162+ if (sAlive == tstat && numberEkins > 0 ) {
163+ if (isLowEnergy (lv, theTrack))
164+ tstat = sLowEnergy ;
152165 }
153166
154167 // 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 ;
168+ if (sAlive == tstat && killBeamPipe) {
169+ if (theTrack->GetKineticEnergy () < theCriticalEnergyForVacuum &&
170+ theTrack->GetDefinition ()->GetPDGCharge () != 0.0 &&
171+ lv->GetMaterial ()->GetDensity () <= theCriticalDensity) {
172+ tstat = sLowEnergyInVacuum ;
173+ }
160174 }
161175 }
162176 // check transition tracker/calo
@@ -185,11 +199,9 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
185199 }
186200}
187201
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 ();
202+ bool SteppingAction::isLowEnergy (const G4LogicalVolume* lv, const G4Track* theTrack) const {
203+ const double ekin = theTrack->GetKineticEnergy ();
204+ int pCode = theTrack->GetDefinition ()->GetPDGEncoding ();
193205
194206 for (auto & vol : ekinVolumes) {
195207 if (lv == vol) {
@@ -281,9 +293,6 @@ void SteppingAction::PrintKilledTrack(const G4Track* aTrack, const TrackStatus&
281293 std::string rname = " " ;
282294 std::string typ = " " ;
283295 switch (tst) {
284- case sKilledByProcess :
285- typ = " G4Process " ;
286- break ;
287296 case sDeadRegion :
288297 typ = " in dead region " ;
289298 break ;
@@ -309,14 +318,18 @@ void SteppingAction::PrintKilledTrack(const G4Track* aTrack, const TrackStatus&
309318 break ;
310319 }
311320 G4VPhysicalVolume* pv = aTrack->GetNextVolume ();
312- if (pv) {
313- vname = pv->GetLogicalVolume ()->GetName ();
314- rname = pv->GetLogicalVolume ()->GetRegion ()->GetName ();
315- }
316-
317- edm::LogVerbatim (" SimG4CoreApplication" )
318- << " 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 ();
321+ vname = pv->GetLogicalVolume ()->GetName ();
322+ rname = pv->GetLogicalVolume ()->GetRegion ()->GetName ();
323+
324+ const double ekin = aTrack->GetKineticEnergy ();
325+ if (ekin < 2 *CLHEP::MeV) { return ; }
326+ edm::LogWarning (" SimG4CoreApplication" )
327+ << " Track #" << aTrack->GetTrackID () << " StepN= "
328+ << aTrack->GetCurrentStepNumber () << " "
329+ << aTrack->GetDefinition ()->GetParticleName ()
330+ << " E(MeV)=" << ekin / CLHEP::MeV
331+ << " T(ns)=" << aTrack->GetGlobalTime () / CLHEP::ns
332+ << " is killed due to " << typ << " \n LV: " << vname << " ("
333+ << rname << " ) at " << aTrack->GetPosition ()
334+ << " step(cm)=" << aTrack->GetStep ()->GetStepLength ()/CLHEP::cm;
322335}
0 commit comments