| Message: Re: Storing Path Lengths | Not Logged In (login) |
|
If you want to know the track length of an optical photon (or the number of steps taken) when the photon hits your detector, or at any other time when your SteppingAction is called, all you need to do is:
theStep->GetTrack()->GetTrackLength(); or theStep->GetTrack()->GetCurrentStepNumber() The G4 track object adds up all of the step-segment lengths and keeps track for you how long the track is in total. There is no need for you to tally this again for yourself. If you want to count 'bounces' that's another matter. In this case, you need to code the following: In your SteppingAction.hh you define: // total number of bounces that a photon has been through G4int counterBounce and the inline methods:
void SteppingAction::ResetCounter() {counterBounce = 0;}
G4int SteppingAction::GetNumberOfBounces(){return counterBounce;}
in your SteppingAction.cc you code in the constructor:
ResetCounter(); and you call this method every time your optical photon is discarded. For example:
G4StepPoint* thePostPoint = theStep->GetPostStepPoint(); G4VPhysicalVolume* thePostPV = thePostPoint->GetPhysicalVolume();
// Record Photons that exit the world volume
if ( !thePostPV ) ResetCounters();
// Record Photons that were absorped
if (theTrack->GetTrackStatus() != fAlive) ResetCounter();
// Record Photons that hit the detector
G4String thePostPVname = " ";
if ( thePostPV ) {
thePostPVname = thePostPV->GetName();
if ( thePostPVname == "Detector" )
G4int bounces = GetNumberOfBounces();
.....
ResetCounters();
}
}
and in UserSteppingAction (this is somewhat involved):
// Retrieve the status of the photon G4OpBoundaryProcessStatus theStatus = Undefined;
G4ProcessManager* OpManager =
G4OpticalPhoton::OpticalPhoton()->GetProcessManager();
if (OpManager) {
G4int MAXofPostStepLoops =
OpManager->GetPostStepProcessVector()->entries();
G4ProcessVector* fPostStepDoItVector =
OpManager->GetPostStepProcessVector(typeDoIt);
for ( G4int i=0; i<MAXofPostStepLoops; i++) {
G4VProcess* fCurrentProcess = (*fPostStepDoItVector)[i];
opProcess = dynamic_cast<G4OpBoundaryProcess*>(fCurrentProcess);
if (opProcess) { theStatus = opProcess->GetStatus(); break;}
}
}
switch (theStatus) {
case TotalInternalReflection:
case FresnelReflection:
case LambertianReflection:
case LobeReflection:
case SpikeReflection:
counterBounce++;
}
I will soon add an extended optical example with this code implemented.
|
|
to: |