Message: Re: particles exiting volume Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: particles exiting volume 

Forum: Event and Track Management
Re: Question particles exiting volume (A. Hod)
Date: 09 Feb, 2017
From: Marc Verderi <Marc Verderi>

Hello,

If your sample code is actually the one you have you should do:

      if ( ( 
(aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()=="Phy_volume1")
          || (aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()== 
"Phy_Sphere3") ) ...

ie : note the extra "(" ")" around the conditions with the "||".

What logically happens with your code is:

(aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()=="Phy_volume1")

     "or"

     [ (aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()== 
"Phy_Sphere3") "AND" 
(aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName()== " 
Phy_volume2") "AND" (aStep->GetPostStepPoint()->GetStepStatus() == 
fGeomBoundary) ]

Cheers,

Marc

PS :

     - for performances reasons, you should better store and compare 
with the pointers of the volumes, instead of comparing with string names.

     - same for the particle : compare the (...)->GetDefinition() with 
G4Electron::GetDefinition()

     - for your code, the comparison with fGeomBoundary should be 
redundant (as the pre step and post step are in different volumes) but 
you may make a first improvement by doing:

     if (
             (aStep->GetPostStepPoint()->GetStepStatus() == 
fGeomBoundary) &&   <-- C++ will check this condition first, if false, 
it does not go further, because of the "&&"
             (
                 (
(aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()== "Phy_volume1")
                  || 
(aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()== "Phy_Sphere3")
                 )
                 && 
(aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName()== " Phy_volume2")
             )
         )
     {
...
     }



On 09/02/2017 16:25, A. Hod wrote:
> *** Discussion title: Event and Track Management
>
> Dear geant4 users,
>
> I have a volume1 containing liquid and three carbon spheres (see
> attached fig.). The volume1 is irradiated with a planar electron beam.
>
> I would like to calculate the positions (x, y and z), energy and the
> direction of electrons exiting volume1 and entering volume2.
>
> Volume1 dimension: 800 nm x 800 nm x 500 nm
> Volume1 dimension: 800 nm x 800 nm x 30  nm
>
> Shperes: 20 nm diamter
>
> I did it in the SteppinAction in the following way:
>
> if (aStep->GetTrack()->GetTrackID()>=1 && (aStep->GetTrack()->GetDynamicParticle()->GetDefinition()->GetParticleName() == "e-") )
>   {
>       if ( (aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()=="Phy_volume1")
> || (aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()== "Phy_Sphere3")
> && (aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName()== " Phy_volume2")
> && (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary)) // to the particle particles left volume1 and eneter volume2.
>
> {
>
>      G4StepPoint* postPoint = aStep->GetPostStepPoint();
>      G4double x1=postPoint->GetPosition().x();
>      G4double y1=postPoint->GetPosition().y();
>      G4double z1=postPoint->GetPosition().z();
>
>      G4ThreeVector direction = track->GetMomentumDirection();
>      G4double ux1=direction.x();
>      G4double uy1=direction.y();
>      G4double uz1=direction.z();
>
>     G4double Energy1 = aStep->GetPostStepPoint()->GetKineticEnergy();
> ....
> ....
> ....
>
> These output data are used to plot an image and visualize the spheres.
>
> } But the results I obtained are sometimes strange ( I can only see the
> image of the sphere in the center of volume 1, shpere2) and dramatically
> affected by the StepMax value. Without SpepMax it works and with StepMax
> the results are entirely different. Is the above code correct? Thanks
> for your helps..
>
> Best regards
>
> A.H.
>
>     Attachment:
>        http://hypernews.slac.stanford.edu/HyperNews/geant4/get/AUX/2017/02/09/07.21-88482-figue01.png
>
> -------------------------------------------------------------
> Visit this GEANT4 at hypernews.slac.stanford.edu message (to reply or unsubscribe) at:
> http://hypernews.slac.stanford.edu/HyperNews/geant4/get/eventtrackmanage/1339.html

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: particles exiting volume   (A. Hod - 09 Feb, 2017)
(_ None: Re: particles exiting volume   (michel maire - 10 Feb, 2017)
 Add Message Add Message
to: "Re: particles exiting 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 ]