Function should give G4VPhysicalVolume*, gives NULL pointer instead

Hi everyone,

I’m new to Geant4, so I apologize if the question is naive (or if it’s in the wrong category).

In my DetectorConstruction class I have defined some functions such as

const G4VPhysicalVolume* GetAbsorber() {return fPhysiAbsorber;};
const G4VPhysicalVolume* GetICS() {return ICS_phy;};

(I need those functions to study the particle flux from or in some regions of my detector)

I’m having some problem with the ICS function; after some tests I found out that GetICS() returns the NULL pointer instead of ICS_phy, even if ICS_phy (which is a private variable in the DetectorConstruction class) is initialized and not zero; in particular, to check if there were some problem, I added the following code after the initialization of ICS_phy and fPhysAbsorber

fPhysiAbsorber = new G4PVPlacement(0, //no rotation
G4ThreeVector(0.,0.,0.), //its position
fLogicAbsorber, //its logical volume
“Absorber”, //its name
logicWorld, //its mother
false, //no boulean operat
0); //copy number
// […]
G4VPhysicalVolume* ICS_phy = new G4PVPlacement(0,
G4ThreeVector(), // at (0,0,0)
ICS_log, // its logical volume
“ICS”, // its name
logicWorld, // its mother volume
false, // no boolean operations
0); // copy number

G4cout<<"ICS pointer (variable): "<<ICS_phy<<G4endl;
G4cout<<"Absorber pointer (variable): "<<fPhysiAbsorber<<G4endl;
G4cout<<"ICS pointer (using the function): "<GetICS()<<G4endl;
G4cout<<"Absorber pointer (using the function): "<GetAbsorber()<<G4endl;

The output is

ICS pointer (variable): 0x560ea2b264e0
Absorber pointer (variable): 0x560ea2b254e0
ICS pointer (using the function): 0
Absorber pointer (using the function): 0x560ea2b254e0

Any idea why this is happening? Suggestions?

My. suspicion is
G4VPhysicalVolume* ICS_phy = new G4PVPlacement(0,
shadows the class data member ICS_phy. Was there a warning? Change to
ICS_phy = new G4PVPlacement(0,

Yep, that was the problem, thank you very much for your help!