27#include <G4AffineTransform.hh>
28#include <G4Navigator.hh>
29#include <G4OpticalPhoton.hh>
30#include <G4ProcessManager.hh>
31#include <G4ProcessVector.hh>
32#include <G4SteppingManager.hh>
33#include <G4TransportationManager.hh>
34#include <G4TransportationProcessType.hh>
35#include <G4UImanager.hh>
36#include <G4UserLimits.hh>
37#include <G4VProcess.hh>
38#include <G4VTouchable.hh>
40#include <TLorentzVector.h>
42#include <TMCParticleStatus.h>
69 "Cannot create two instances of singleton.");
81 if (userGeometry ==
"RootToGeant4" || userGeometry ==
"Geant4")
104 "TG4StepManager",
"CheckTrack",
"Track is not defined.");
124 "TG4StepManager", method,
"Gflash spot is not defined.");
135 "Stepping manager is not defined.");
140 G4ThreeVector xyz, G4double t, TLorentzVector& lv)
const
160 G4ReferenceCountedHandle<G4VTouchable> touchableHandle =
162 return touchableHandle();
165 return fTrack->GetTouchable();
167 return fTrack->GetNextTouchable();
172 G4int off, G4int& component)
const
180 G4int remaining = off;
181 G4bool crossedAssembly =
false;
183 for (G4int level = 0; level <= touchable->GetHistoryDepth(); ++level) {
184 G4VPhysicalVolume* pv = touchable->GetVolume(level);
189 const G4int nofLevels =
190 levels.
fNames.empty() ? 1 : G4int(levels.
fNames.size());
192 if (remaining < nofLevels) {
193 if (nofLevels == 1 && !crossedAssembly)
return 0;
194 component = levels.
fNames.empty() ? -1 : nofLevels - 1 - remaining;
197 crossedAssembly = crossedAssembly || nofLevels > 1;
198 remaining -= nofLevels;
205 G4int off, G4bool warn)
const
216 if (touchable->GetHistoryDepth() < off) {
218 TString text =
"level=";
221 "Volume " + TString(touchable->GetVolume()->GetName()) +
222 " has not defined mother in " + text +
".");
227 return touchable->GetVolume(off);
252 fTrack->SetTrackStatus(fStopAndKill);
258 "There is no current track to be stopped.");
268 fTrack->SetTrackStatus(fStopAndKill);
273 "There is no current track to be interrupted.");
283 fTrack->SetTrackStatus(fKillTrackAndSecondaries);
287 G4UImanager::GetUIpointer()->ApplyCommand(
"/event/abort");
298 G4UImanager::GetUIpointer()->ApplyCommand(
"/run/abort");
310 if (!userLimits)
return;
329 "TG4StepManager",
"SetMaxStepBack",
"No limits modified on fly found.");
364 fTrack->GetDynamicParticle()->GetDefinition();
405 return fGflashSpot->GetTouchableHandle()->GetVolume();
407 return fTrack->GetVolume();
409 return fTrack->GetNextVolume();
427 "TG4StepManager",
"Get current limits",
"User limits not defined.");
443 "TG4StepManager",
"CurrentVolID",
"No current physical volume found");
448 if (physVolume->IsParameterised() || physVolume->IsReplicated())
463 G4int component = -1;
464 if (G4VPhysicalVolume* pv =
GetOffLevel(off, component)) {
467 const G4int encoded =
468 (component >= 0 && component < G4int(levels.
fCopyNos.size()))
471 copyNo = (encoded >= 0 ? encoded : pv->GetCopyNo()) +
fCopyNoOffset;
486 if (mother->IsParameterised() || mother->IsReplicated())
516 G4int component = -1;
517 if (G4VPhysicalVolume* pv =
GetOffLevel(off, component)) {
520 const G4String& name =
521 (component >= 0 && component < G4int(levels.
fNames.size()))
522 ? levels.
fNames[component]
523 : pv->GetLogicalVolume()->GetName();
532 mother->GetLogicalVolume()->GetName());
552 G4int depth = touchable->GetHistoryDepth();
557 for (G4int i = 0; i < depth; i++) {
558 G4VPhysicalVolume* physVolume = touchable->GetHistory()->GetVolume(i);
577 Double_t& x, Double_t& y, Double_t& z)
const
581 G4Navigator* theNavigator =
582 G4TransportationManager::GetTransportationManager()
583 ->GetNavigatorForTracking();
586 G4ThreeVector theLocalNormal = theNavigator->GetLocalExitNormal(&valid);
587 if (!valid)
return false;
589 G4ThreeVector theGlobalNormal =
590 theNavigator->GetLocalToGlobalTransform().TransformAxis(theLocalNormal);
592 x = theGlobalNormal.x();
593 y = theGlobalNormal.y();
594 z = theGlobalNormal.z();
601 Float_t& a, Float_t& z, Float_t& dens, Float_t& radl, Float_t& absl)
const
613 G4Material* material = physVolume->GetLogicalVolume()->GetMaterial();
615 G4int nofElements = material->GetNumberOfElements();
617 a = geometryServices->
GetEffA(material);
618 z = geometryServices->
GetEffZ(material);
621 dens = material->GetDensity();
625 radl = material->GetRadlen();
656 Gmtod(dxm, dxd, iflag);
659 for (G4int i = 0; i < 3; i++) {
680 if (iflag != 1 && iflag != 2) {
681 TString text =
"iflag=";
684 "TG4StepManager",
"Gmtod", text +
" is different from 1..2.");
689 const G4AffineTransform& affineTransform =
694 G4ThreeVector theLocalPoint;
696 theLocalPoint = affineTransform.TransformPoint(theGlobalPoint);
699 theLocalPoint = affineTransform.TransformAxis(theGlobalPoint);
721 Gdtom(dxd, dxm, iflag);
724 for (G4int i = 0; i < 3; i++) {
744 if (iflag != 1 && iflag != 2) {
745 TString text =
"iflag=";
748 "TG4StepManager",
"Gmtod", text +
" is different from 1..2.");
753 const G4AffineTransform& affineTransform =
758 G4ThreeVector theGlobalPoint;
760 theGlobalPoint = affineTransform.TransformPoint(theLocalPoint);
763 theGlobalPoint = affineTransform.TransformAxis(theLocalPoint);
777 G4LogicalVolume* curLogVolume =
781 G4UserLimits* userLimits = curLogVolume->GetUserLimits();
784 if (userLimits == 0) {
786 "User Limits are not defined for the current logical volume " +
787 TString(curLogVolume->GetName()) +
".");
791 const G4Track& trackRef = *(
fTrack);
792 maxStep = userLimits->GetMaxAllowedStep(trackRef);
817 G4ThreeVector positionVector;
819 positionVector =
fGflashSpot->GetEnergySpot()->GetPosition();
824 positionVector =
fTrack->GetPosition();
829 G4double time =
fTrack->GetGlobalTime();
845 G4ThreeVector positionVector;
847 positionVector =
fGflashSpot->GetEnergySpot()->GetPosition();
852 positionVector =
fTrack->GetPosition();
856 x = positionVector.x();
857 y = positionVector.y();
858 z = positionVector.z();
870 x =
static_cast<float>(dx);
871 y =
static_cast<float>(dy);
872 z =
static_cast<float>(dz);
885 G4ThreeVector momentumVector =
fTrack->GetMomentum();
888 G4double energy =
fTrack->GetDynamicParticle()->GetTotalEnergy();
896 Double_t& px, Double_t& py, Double_t& pz, Double_t& etot)
const
905 G4ThreeVector momentumVector =
fTrack->GetMomentum();
908 px = momentumVector.x();
909 py = momentumVector.y();
910 pz = momentumVector.z();
912 etot =
fTrack->GetDynamicParticle()->GetTotalEnergy();
918 Float_t& px, Float_t& py, Float_t& pz, Float_t& etot)
const
923 Double_t dpx, dpy, dpz, detot;
926 px =
static_cast<float>(dpx);
927 py =
static_cast<float>(dpy);
928 pz =
static_cast<float>(dpz);
929 etot =
static_cast<float>(detot);
997 if (proc && physicsManager->
GetMCProcess(proc) == kPLightScattering &&
1039 return fTrack->GetCurrentStepNumber();
1049 return fTrack->GetWeight();
1054 Double_t& polX, Double_t& polY, Double_t& polZ)
const
1058 const G4ThreeVector& pol =
fTrack->GetPolarization();
1069 const G4ThreeVector& polG4 =
fTrack->GetPolarization();
1085 fTrack->GetDynamicParticle()->GetDefinition();
1094 if (pdgEncoding == 50000050) {
1113 return fTrack->GetDynamicParticle()->GetDefinition()->GetPDGCharge() /
1126 return fTrack->GetDynamicParticle()->GetDefinition()->GetPDGMass() /
1183 if (
fStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary)
1202 if (
fStep->GetPostStepPoint()->GetStepStatus() == fWorldBoundary)
1231 G4TrackStatus status =
fTrack->GetTrackStatus();
1232 if ((status == fStopAndKill) || (status == fKillTrackAndSecondaries) ||
1233 (status == fSuspend) || (status == fPostponeToNextEvent)) {
1252 G4TrackStatus status =
fTrack->GetTrackStatus();
1253 if ((status == fStopAndKill) || (status == fKillTrackAndSecondaries) ||
1254 (status == fPostponeToNextEvent)) {
1270 G4TrackStatus status =
fTrack->GetTrackStatus();
1271 if ((status == fAlive) || (status == fStopButAlive))
1300 G4int nofSecondaries = 0;
1305 return nofSecondaries;
1310 TLorentzVector& position, TLorentzVector& momentum)
1324 if (!nofSecondaries)
return;
1328 if (!secondaryTracks) {
1330 "TG4StepManager",
"GetSecondary",
"Secondary tracks vector is empty");
1333 if (index >= nofSecondaries) {
1335 "TG4StepManager",
"GetSecondary",
"Wrong secondary track index.");
1340 G4int startIndex = secondaryTracks->size() - nofSecondaries;
1343 G4Track* track = (*secondaryTracks)[startIndex + index];
1346 particleId = track->GetDynamicParticle()->GetDefinition()->GetPDGEncoding();
1349 G4ThreeVector positionVector = track->GetPosition();
1351 G4double time = track->GetGlobalTime();
1356 G4ThreeVector momentumVector = track->GetMomentum();
1358 G4double energy = track->GetDynamicParticle()->GetTotalEnergy();
1384 if (!secondaryTracks) {
1386 "TG4StepManager",
"ProdProcess",
"Secondary tracks vector is empty.");
1391 if (isec >= nofSecondaries) {
1393 "TG4StepManager",
"ProdProcess",
"Wrong secondary track index.");
1400 G4int startIndex = secondaryTracks->size() - nofSecondaries;
1405 G4Track* track = (*secondaryTracks)[startIndex + isec];
1407 const G4VProcess* kpProcess = track->GetCreatorProcess();
1412 if (mcProcess == kPEnergyLoss) mcProcess = kPDeltaRay;
1427 G4int nofProcesses = 1;
1428 processes.Set(nofProcesses);
1429 processes[0] = kPNull;
1430 return nofProcesses;
1443 G4ProcessVector* processVector =
fStep->GetTrack()
1445 ->GetProcessManager()
1446 ->GetAlongStepProcessVector();
1447 G4int nofAlongStep = processVector->entries();
1451 fStep->GetPostStepPoint()->GetProcessDefinedStep();
1454 processes.Set(nofAlongStep + 2);
1463 for (G4int i = 0; i < nofAlongStep; i++) {
1466 if (g4Process && g4Process->GetProcessSubType() != TRANSPORTATION)
1467 processes[counter++] = physicsManager->
GetMCProcess(g4Process);
1471 if (
fStep->GetTrack()->GetDefinition() == G4OpticalPhoton::Definition() &&
1472 kpLastProcess->GetProcessSubType() == TRANSPORTATION &&
1476 processes[counter++] = kPLightScattering;
1481 processes[counter++] = physicsManager->
GetMCProcess(kpLastProcess);
Definition of the TG4G3Units class.
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4Limits class.
Definition of the TG4ParticlesManager class.
Definition of the TG4PhysicsManager class.
Definition of the TG4SDServices class.
Definition of the TG4StepManager class.
@ kGflashSpot
in post step point with Gflash
@ kBoundary
when crossing geometrical boundary
@ kNormalStep
in post step point
Definition of the TG4SteppingAction class.
Definition of the TG4TrackManager class.
static G4double InverseLength()
static G4double InverseTime()
static G4double InverseEnergy()
static G4double MassDensity()
Services for accessing to Geant4 geometry.
G4double * CreateG4doubleArray(Float_t *array, G4int size, G4bool copyValues=true) const
const G4String & UserVolumeName(const G4String &name) const
static TG4GeometryServices * Instance()
TG4Limits * GetLimits(G4UserLimits *limits) const
G4double GetEffA(G4Material *material) const
const TG4AssemblyLevels & GetAssemblyLevels(const G4VPhysicalVolume *pv) const
G4double GetEffZ(G4Material *material) const
static void AppendNumberToString(G4String &string, G4int number)
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
Extended G4UserLimits class.
void SetCurrentMaxAllowedStep(G4double step)
G4int GetPDGEncoding(G4ParticleDefinition *particle)
static TG4ParticlesManager * Instance()
Geant4 implementation of the TVirtualMC interface methods for building Geant4 physics and access to i...
static TG4PhysicsManager * Instance()
G4bool IsOpBoundaryProcess() const
TMCProcess GetMCProcess(const G4VProcess *process)
TMCProcess GetOpBoundaryStatus()
G4int GetMediumID(G4LogicalVolume *volume) const
void SetIsStopRun(G4bool stopRun)
G4int GetVolumeID(const G4String &volumeName) const
static TG4SDServices * Instance()
Geant4 implementation of the TVirtualMC interface methods for access to Geant4 at step level.
const char * CurrentVolPath()
G4Track * fTrack
current track
Int_t CurrentMaterial(Float_t &a, Float_t &z, Float_t &dens, Float_t &radl, Float_t &absl) const
Int_t StepProcesses(TArrayI &proc) const
TMCProcess ProdProcess(Int_t isec) const
G4int fDivisionCopyNoOffset
division copy number offset
Int_t CurrentVolOffID(Int_t off, Int_t ©No) const
void TrackMomentum(TLorentzVector &momentum) const
const char * CurrentVolOffName(Int_t off) const
Bool_t IsTrackStop() const
Bool_t IsTrackDisappeared() const
Bool_t IsTrackEntering() const
Double_t TrackStep() const
TG4StepManager(const TString &userGeometry)
Double_t TrackTime() const
void SetMaxNStep(Int_t maxNofSteps)
const char * CurrentVolName() const
G4String fNameBuffer
buffer for current volume name or path
void GetSecondary(Int_t index, Int_t &particleId, TLorentzVector &position, TLorentzVector &momentum)
G4SteppingManager * fSteppingManager
G4SteppingManager.
TG4Limits * GetCurrentLimits() const
G4VPhysicalVolume * GetOffLevel(G4int off, G4int &component) const
Double_t TrackMass() const
Int_t NSecondaries() const
Double_t NIELEdep() const
void CheckGflashSpot(const G4String &method) const
Bool_t CurrentBoundaryNormal(Double_t &x, Double_t &y, Double_t &z) const
Double_t TrackWeight() const
G4GFlashSpot * fGflashSpot
current Gflash spot
TG4TrackManager * fTrackManager
Cached pointer to thread-local track manager.
TG4StepStatus fStepStatus
step status
const G4VTouchable * GetCurrentTouchable() const
Int_t CurrentVolID(Int_t ©No) const
Bool_t IsTrackAlive() const
void CheckSteppingManager() const
Double_t TrackCharge() const
Int_t CurrentMedium() const
Double_t TrackLength() const
Bool_t IsTrackInside() const
static G4ThreadLocal TG4StepManager * fgInstance
this instance
Bool_t IsCollectTracks() const
void Gdtom(Double_t *xd, Double_t *xm, Int_t iflag)
G4int fCopyNoOffset
volume copy number offset
Bool_t IsNewTrack() const
Bool_t IsTrackOut() const
void CheckStep(const G4String &method) const
G4VPhysicalVolume * GetCurrentPhysicalVolume() const
TG4Limits * fLimitsModifiedOnFly
limits which step limit was modified during tracking
void SetTLorentzVector(G4ThreeVector xyz, G4double t, TLorentzVector &lv) const
Bool_t IsTrackExiting() const
void Gmtod(Double_t *xm, Double_t *xd, Int_t iflag)
TMCParticleStatus * fInitialVMCTrackStatus
The initial status of a VMC track when it was popped from the VMC stack.
void SetCollectTracks(Bool_t collectTracks)
void ForceDecayTime(Float_t pdg)
G4Step * fStep
current step
void TrackPolarization(Double_t &polX, Double_t &polY, Double_t &polZ) const
Int_t GetMaxNStep() const
G4VPhysicalVolume * GetCurrentOffPhysicalVolume(G4int off, G4bool warn=false) const
void TrackPosition(TLorentzVector &position) const
void SetInitialVMCTrackStatus(TMCParticleStatus *status)
void SetMaxStep(Double_t step)
void SetMaxNofSteps(G4int number)
void SetCollectTracks(G4bool collectTracks)
void ProcessTrackIfGeneralProcess(const G4Step *step)
G4bool GetCollectTracks() const
static TG4SteppingAction * Instance()
G4int GetMaxNofSteps() const
static TG4TrackManager * Instance()
std::vector< G4int > fCopyNos
-1 where the Geant4 copy number applies
std::vector< G4String > fNames
outermost first; last is the placed volume