How to access a variable of a static method from a non-static method of the same class (PhysicsList)

Hello, I have a problem to access a variable of a static method from an other method which is non static. I needed to get the material of each step from the SteppingAction.cc, so i made a static method called GetNameMat(G4String) that get the step’s name material in this source file.

SteppingAction.cc:

class PhysicsList;

SteppingAction::SteppingAction(DetectorConstruction* det, G4Event* aEvent, EventAction* EA)

: event(aEvent),Detector(det),anEventAction(EA),fScoringVolume(0)

{}

SteppingAction::~SteppingAction()

{}

void SteppingAction::UserSteppingAction(const G4Step* step)

{
matname=step->GetPreStepPoint()->GetMaterial()->GetName();

PhysicsList::GetNameMat(matname);

}

SteppingAction.hh:

#include “PhysicsList.hh”

class PhysicsList;

class SteppingAction : public G4UserSteppingAction

{

public:

SteppingAction(DetectorConstruction*,G4Event*,EventAction*);

virtual ~SteppingAction();

PhysicsList* GetNameMat(G4String*);

private:

};

Then I describe this method in PhysicsList.cc where I need it for an other method (non-static) ConstructEM() which needs the material name.

PhysicsList.cc:

PhysicsList::PhysicsList()
: G4VModularPhysicsList()
{
SetDefaultCutValue(0.1*nm);
SetVerboseLevel(1);

}

PhysicsList::~PhysicsList()
{}

void PhysicsList::GetNameMat(const G4String& matname)
{

G4String npname=matname;
G4cout <<" MatName1: " <<npname<<G4endl;
}

void PhysicsList::ConstructEM()
{
G4String matname;
GetNameMat(matname);
G4String npname=matname;
G4cout <<" MatName2: " <<npname<<G4endl;
G4bool isGNP=false;
fphysname=“DNA”;

if(npname==“G4_Au”) isGNP=true;

}

PhysicsList.hh:

class SteppingAction;

class PhysicsList: public G4VModularPhysicsList
{
public:
PhysicsList();
virtual ~PhysicsList();

...
void ConstructEM();
static void GetNameMat(const G4String&);

private:

const G4Step* step;
G4VPhysicsConstructor*        fEmPhysicsList;
G4String fphysname;
G4LogicalVolume* logicWater;
G4LogicalVolume* logicTarget;

};

I can get the material name with the static method GetNameMat(const G4String& matname) in PhysicsList.cc where the G4cout displays the material of each step (G4cout <<" MatName1: " <<npname<<G4endl) but I need it in the method ConstructEM() which does not display the material (G4cout <<" MatName2: " <<npname<<G4endl does not work).

So I wanted to know how to access this G4String matname in the ConstructEM() method. I hope that someone could help me. Thanks you

Hi, there is something I do not undertand. You should be able to access to the volume material of the preStepPoint as follows: preStepPoint ->GetTouchableHandle()->GetVolume()->GetLogicalVolume()->GetMaterial(). Is this not working?

Cheers
Susanna

Hi Susanna,

I need to get this material name in the method ConstructEM in the PhysicsList class. First I tried to get it by your way directly into the ConstructEM method but it didn’t work. I know now that my method isn’t correct.
In fact, I try to implement the AuNP example’s physicslist to my example (based on the microyz example) and I am searching how.
However, thank you for your answer. Have a nice day.

Hi, do you know that we have a new extended example called AuNP that shows how to use Geant4-DNA physics models when modelling gold nanoparticles?

Cheers
Susanna

From what I can see here, you have declared two different GetNameMat functions.
1.) First function: belongs to your SteppingAction and returns a PhysicsList* pointer.

PhysicsList* SteppingAction::GetNameMat(G4String*);

2.) Second function: Is static and belongs to your PhysicsList. It returns a void type:

static void PhysicsList::GetNameMat(const G4String& matname)

Keep in mind that these are two entirely different functions. When you call GetNameMat from your PhysicsList you are calling the static function you have defined. When you call GetNameMat from your SteppingAction, you are calling a non-static function, belonging to SteppingAction. The non-static function belonging to SteppingAction is declared in the header, but has no definition anywhere else. I’m surprised the compiler allowed this to compile!

I hope this helps explain the behavior,

Joseph