Segmentation fault from SetSensitiveDetector();

I have been following the Geant4 tutorials by Mustafa Schmidt but after implementing a sensitive detector (tutorial 7) I keep receiving the segmentation fault shown below:

Checking overlaps for volume physTarg:0 (G4Tubs) ... OK!
Checking overlaps for volume physScint:0 (G4Box) ... OK!
Checking overlaps for volume physDet:0 (G4Box) ... OK!
[1]    57973 segmentation fault  ./scat

I have managed to identify the source of this issue to be the line in construction.cc where I set the detector logical volume to a sensitive detector:

logicDet->SetSensitiveDetector(sensDet);

Im attaching the construction source and header files (as a new member I can only attach 2 links):
construction.cc (3.0 KB)
construction.hh (852 Bytes)

Any help or advice is greatly appreciated.

Is logicDet a data member of your DetectorConstruction class? If it is a data member, do you set it when you instantiate the volume in Construct()?

I believe so. I define the DetectorConstruction class in construction.hh as:

class DetectorConstruction : public G4VUserDetectorConstruction {
public:
  DetectorConstruction();
  ~DetectorConstruction();

  virtual G4VPhysicalVolume *Construct();

private:
  G4LogicalVolume *logicDet;

  virtual void ConstructSDandField();
};

Okay, so look at your Construct() function, and make sure that somewhere in there you have a line logicDet = new G4LogicalVolume(.....).

Also, in your .hh file, ConstructSDandField() should be public, not private – it is called from the RunManager in each worker thread, so it has to be available to them.

1 Like

I checked the Construct() function and the issue was caused by initialising the detector logical volume as:

G4LogicalVolume *logicDet = new G4LogicalVolume(solidDet, matWorld, "logicDet");

I corrected this to:

logicDet = new G4LogicalVolume(solidDet, worldMat, "logicDet");

Thank you.

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