Why detectorconstruction class pointer can not access its solution?

Here is the key code:

the hint output from session is:

by the way, in other my projections, it works well.
_Geant4 Version:_Geant4 11.1.1
_Operating System:_Ubuntu 20.04
_Compiler/Version:_GCC 9.4.0
_CMake Version:_3.16.3


Hi,

The example B4b shows how to initialize the SteppingAction from a pointer to a DetectorConstruction object, so it can be accessed during the UserSteppingAction. I think it is similar to the piece of code that you showed.

Does the ActionInitialization class definition looks like this? (from B4b example)

ActionInitialization::ActionInitialization(DetectorConstruction* detConstruction)
 : fDetConstruction(detConstruction)
{}

void ActionInitialization::BuildForMaster() const
{
  SetUserAction(new RunAction);
}

void ActionInitialization::Build() const
{
  SetUserAction(new PrimaryGeneratorAction);
  SetUserAction(new RunAction);
  SetUserAction(new EventAction);
  SetUserAction(new SteppingAction(fDetConstruction));
}

As a side note, maybe the line fTargetVolume = fDetector->GetTargetVolume(); can be moved to the fpSteppingAction constructor, so it does not have to be called at every step. Please see slide 6 for further information about the SteppingAction.

I hope this helps.

Best,
Alvaro

@atolosad , thanks for replying, here is the codes from ActionInitialization class:

The codes are similar with them from example B4b.

The key code is the GetTargetVolume member function of the fpDetectorConstruction class. It’s obviously returning nullptr so that’s the thing to investigate. Please also review How to post code snippets as screenshots aren’t so good for discussing problems like this.

yes, you are right,
the fDetector is not a nullptr, but fDetector->GetTargetVolume() is.
why?

You’d need to review the content of GetTargetVolume to determine why the returned pointer is null. Feel free to post that method/class here as a snippet or reduced example.

‘’’
class fpDetectorConstruction : public G4VUserDetectorConstruction
{
public:
fpDetectorConstruction();
virtual ~fpDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
G4VPhysicalVolume* GetTargetVolume() const { return fTargetVolume; };

protected:
G4VPhysicalVolume* fTargetVolume;
}

G4VPhysicalVolume* fpDetectorConstruction::Construct()
{
//
G4Tubs* solid_Ge=new G4Tubs(“Ge”,0mm,28.4mm,28.985mm,0,360deg);
G4LogicalVolume* logic_Ge=new G4LogicalVolume(solid_Ge,mGe,“Ge”);
G4VPhysicalVolume* physic_Ge=new G4PVPlacement(
0,
G4ThreeVector(0,0,33.915*mm),
logic_Ge,
“Ge”,
logicWorld,
false,
0,
true
);
fTargetVolume = physic_Ge;
}
‘’’

Thanks! That all looks fine, so all I can think of is that fTargetVolume in fpDetectorConstruction is being overwritten somewhere else in the Construct or other member functions of that class. Construct should have been called by the time UserSteppingAction is called, so there should be a valid object at that point.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.