Message: Problems in accessing materials and volumes in SteppingAction Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Problems in accessing materials and volumes in SteppingAction 

Forum: Event and Track Management
Date: 06 Jun, 2011
From: Daniel Matthiń <Daniel Matthiń>

Dear GEANT4 community,
I have a problem concerning the access of volumes and materials in my geometry. If I use the following code in my SteppingAction:

  const G4Material *material = step->GetTrack()->GetMaterial();
  G4StepPoint* postStep = step->GetPostStepPoint();
  const G4ThreeVector postStepV = postStep->GetPosition();
  G4StepPoint* preStep = step->GetPreStepPoint();
  const G4ThreeVector preStepV = preStep->GetPosition();
  G4String preName = preStep->GetTouchable()->GetVolume()->GetName();
  G4ThreeVector preTrans = preStep->GetTouchable()->GetTranslation();
  G4String postName = postStep->GetTouchable()->GetVolume()->GetName();
  G4ThreeVector postTrans = postStep->GetTouchable()->GetTranslation();
  if(preStep->GetTouchable() && postStep->GetTouchable()){
    G4cout << "Step: "
   << "Edep [MeV] = " << step->GetTotalEnergyDeposit()/MeV << ", "
   << preName << " (" << preStepV[0] << ", " << preStepV[1] << ", " << preStepV[2] << ")"
         << " to "
   << postName << " (" << postStepV[0] << ", " << postStepV[1] << ", " << postStepV[2] << ")"
         << "\t"
         << "material = " << material -> GetName() //<< "->" << aTrack->GetNextMaterial()->GetName()
   << "(" << preStep->GetTouchable()->GetVolume()->GetLogicalVolume()->GetMaterial()->GetName()
   << "/" << postStep->GetTouchable()->GetVolume()->GetLogicalVolume()->GetMaterial()->GetName() << ")"
   << "(" << preStep->GetMaterial()->GetName()
   << "/" << postStep->GetMaterial()->GetName() << ")"
   << ", density [g/cm^3] = " << material->GetDensity()/(g/cm3) << G4endl;
  }

the output contains:

Step: Edep [MeV] = 7.24828e-22, ICRPPhantom_phys (0, -63.6995, 0) to ICRPPhantom_phys (0, -63.0415, 0) material = Vacuum(Vacuum/Vacuum)(Vacuum/Skin), density [g/cm^3] = 1e-21
Step: Edep [MeV] = 0.774251, ICRPPhantom_phys (0, -63.0415, 0) to ICRPPhantom_phys (0, -62.0415, 0) material = Skin(Skin/Skin)(Skin/Vacuum), density [g/cm^3] = 1.09
Step: Edep [MeV] = 1.10836e-21, ICRPPhantom_phys (0, -62.0415, 0) to ICRPPhantom_phys (-0.000771055, -61.0415, 0.0052615) material = Vacuum(Skin/Skin)(Vacuum/Skin), density [g/cm^3] = 1e-21

As you can see in the last two lines there are differences between the methods
preStep->GetTouchable()->GetVolume()->GetLogicalVolume()->GetMaterial()
and
preStep->GetMaterial()
What is the output of the two methods and why is it different?

Additionally, in the second and third step the material should be skin rather than vacuum. I tried to investigate that using the G4Navigator class and added the following lines to the SteppingAction:

    G4Navigator* theNavigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
    G4VPhysicalVolume* myVolume = theNavigator->LocateGlobalPointAndSetup(preStepV);
    G4LogicalVolume* myLogVolume = myVolume->GetLogicalVolume();
    G4Material* myMaterial = myLogVolume->GetMaterial();
    G4double dd = myMaterial->GetDensity()/(g/cm3);
    G4cout << "pre: "<< myMaterial->GetName() << ": density [g/cm^3] = " << dd << G4endl;
    myVolume = theNavigator->LocateGlobalPointAndSetup(postStepV);
    myLogVolume = myVolume->GetLogicalVolume();
    myMaterial = myLogVolume->GetMaterial();
    dd = myMaterial->GetDensity()/(g/cm3);
    G4cout << "post: " << myMaterial->GetName() << ": density [g/cm^3] = " << dd << G4endl;

which resulted in the output:

Step: Edep [MeV] = 7.24828e-22, ICRPPhantom_phys (0, -63.6995, 0) to ICRPPhantom_phys (0, -63.0415, 0) material = Vacuum(Vacuum/Vacuum)(Vacuum/Skin), density [g/cm^3] = 1e-21
pre: Vacuum: density [g/cm^3] = 1e-21
post: Skin: density [g/cm^3] = 1.09
Step: Edep [MeV] = 0.706161, ICRPPhantom_phys (0, -63.0415, 0) to ICRPPhantom_phys (0, -62.0415, 0) material = Skin(Skin/Skin)(Skin/Skin), density [g/cm^3] = 1.09
pre: Skin: density [g/cm^3] = 1.09
post: Skin: density [g/cm^3] = 1.09
Step: Edep [MeV] = 0.701355, ICRPPhantom_phys (0, -62.0415, 0) to ICRPPhantom_phys (-6.24129e-05, -61.0415, 0.000529958) material = Skin(Skin/Skin)(Skin/Skin), density [g/cm^3] = 1.09
pre: Skin: density [g/cm^3] = 1.09
post: Skin: density [g/cm^3] = 1.09

Only by using the G4Navigator the discrepancies have vanished and the material is skin as it is supposed to be. As I did not change anything in the geometry I can not explain these differences.
Any help is appreciated.
Best regards,
Daniel

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

1 Disagree: Re: Problems in accessing materials and volumes in SteppingAction   (Gumplinger Peter - 13 Jun, 2011)
(_ More: Re: Problems in accessing materials and volumes in SteppingAction   (Daniel Matthiń - 15 Jun, 2011)
 Add Message Add Message
to: "Problems in accessing materials and volumes in SteppingAction"

 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 ]