Message: How to change the particle momentum direction after leaving a certain volume Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question How to change the particle momentum direction after leaving a certain volume 

Forum: Event and Track Management
Date: 27 Jun, 2016
From: Soman <Soman>

Dear all,

I wrote a new Geant4 process to change the 20-keV photons direction after leaving certain volumes. As Peter helped me here, I see no errors but after putting a counter in my code and debugging, I noticed that my approach doesn't really work! This is the piece of my code which is written as a new process for geant4:

==========================================================================
G4VParticleChange*
  G4XDiff::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep)
{
   aParticleChange.Initialize(aTrack);
   G4StepPoint* pPreStepPoint = aStep.GetPreStepPoint();
   G4StepPoint* pPostStepPoint = aStep.GetPostStepPoint();  

   G4TouchableHandle touchpre = pPreStepPoint->GetTouchableHandle();
   G4VPhysicalVolume* volumepre = touchpre->GetVolume();
   G4String namepre = volumepre->GetName();

   G4TouchableHandle touchpost = pPostStepPoint->GetTouchableHandle();
   G4VPhysicalVolume* volumepost = touchpost->GetVolume();
   G4String namepost = volumepost->GetName();

   // Check if this point is in the slit volumes

   if ((namepre == "slit1_phys") || (namepre == "slit2_phys")) {

     // Check if this step is the last step in that
     // volume, if so, change the momentum direction, otherwise leave this
     // process

      if (pPostStepPoint->GetStepStatus() == fGeomBoundary) {

          num = num+1; // the counter
          cout << "NUM" << num;

          const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();

          G4double x_ang = aParticle->GetMomentumDirection().x();
          G4double y_ang = aParticle->GetMomentumDirection().y();

          G4double theta_ang = fAngleValue;
          G4double phi_ang = atan((y_ang)/(x_ang));

     // Change photon momentum direction vector according to the new random
     // polar angle and keep the azimuthal angle 
              G4double px = sin(theta_ang)*cos(phi_ang);
              G4double py = sin(theta_ang)*sin(phi_ang);
              G4double pz = cos(theta_ang);

              G4ThreeVector direction(px, py, pz); 
              aParticleChange.ProposeMomentumDirection(direction);
        }
    }

return pParticleChange; }

==============================================================================

There are two possible approaches for this process:

1- Check if the particle is in the certain volume, then check if the step is the last step in that volume and if so, change the momentum direction in the PostStepDoIt, as shown in above code.

2- Putting a control volume just after the certain volume and check if the step is the first step entering that control volume and if so, change the momentum direction in the PostStepDoIt.

However, none of above worked. I checked particles reaching and leaving the certain volumes. They are about 5000 particles undergo this process. But the code shows just around 35 particles hold in this condition (the first and then second "if"), which basically can't be true. Because essentially there should be a step which is the last step of a particle passing a volume!(if the photon is not still killed). These volumes are 0.005*90*0.100 mm Air boxes.

Does someone have any suggestion on this problem? Any comments would be highly appreciated.

Best Somayeh

 Add Message Add Message
to: "How to change the particle momentum direction after leaving a certain volume"

 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 ]