Message: Re: Storing Path Lengths Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: Storing Path Lengths 

Forum: Event and Track Management
Re: None Storing Path Lengths
Date: 25 Aug, 2009
From: Gumplinger Peter <Gumplinger Peter>

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.

 Add Message Add Message
to: "Re: Storing Path Lengths"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]