Message: Segmentation fault after material re-use Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Segmentation fault after material re-use 

Forum: Geometry
Date: 18 Oct, 2013
From: Marek Szuba <Marek Szuba>

Hello,

I have built very simple Geant4 geometry consisting of an aluminium box with mylar windows in two walls and filled, for the time being, the same material as the world volume. In the code it looks roughly like this:

G4NistManager* nist = G4NistManager::Instance();

/* World volume */
G4Material* air = nist->FindOrBuildMaterial("G4_AIR");
G4VSolid* worldSolid = new G4Box("World", 6*m, 2*m, 20*m);
G4LogicalVolume* logicalWorld = new G4LogicalVolume(worldSolid, air, "World");
new PVPlacement(NULL, G4ThreeVector(), logicalWorld, "World", NULL, false, 0, true);

/* Box part 1 - solid aluminium */
G4Material* boxWalls = nist->FindOrBuildMaterial("G4_Al");
G4VSolid* boxSolid = new G4Box("Box", 270*cm, 49*cm, 180*cm);
G4LogicalVolume* boxLV = new G4LogicalVolume(boxSolid, boxWalls, "Box");
new PVPlacement(NULL, G4ThreeVector(0., 0., 300*cm), boxLV, "Box", logicalWorld, false, 0, true);

/* Box part 2 - gaps in walls, same material as surroundings */
G4VSolid* windowGapSolid = new G4Box("Box window gap", 270*cm - 1*cm, 49*cm - 1*cm, 1*mm);
G4LogicalVolume* windowGapLV = new G4LogicalVolume(windowGapSolid, logicalWorld->GetMaterial(), "Box window gap");
new PVPlacement(NULL, G4ThreeVector(0., 0., -(180*cm - 1*mm)), windowGapLV, "Box window gap upstream", boxLV, false, 0, true);
new PVPlacement(NULL, G4ThreeVector(0., 0., +(180*cm - 1*mm)), windowGapLV, "Box window gap downstream", boxLV, false, 1, true);

/* Box part 3 - gas inside it. At the moment the box is leaky i.e. is filled with same material as surroundings. */
G4Material* gasInBox = logicalWorld->GetMaterial();
G4VSolid* boxGasSolid = new G4Box("Box gas", 270*cm - 2*mm, 49*cm - 2*mm, 180*cm - 2*mm);
G4LogicalVolume* boxGasLV = new G4LogicalVolume(boxGasSolid, gasInBox, "Box gas");
new PVPlacement(NULL, G4ThreeVector(), boxGasLV, "Box gas", boxLV, false, 0, true);

/* Box part 4 - mylar foil in windows */
G4Material* mylar = nist->FindOrBuildMaterial("G4_MYLAR");
G4VSolid* windowFoilSolid = new G4Box("Box window foil", 270*cm - 2*mm, 49*cm - 2*mm, 0.05*mm);
G4LogicalVolume* windowFoilLV = new G4LogicalVolume(windowFoilSolid, mylar, "Box window foil");
new PVPlacement(NULL, G4ThreeVector(0., 0., -(180*cm - 2*mm - 0.05*mm)), windowFoilLV, "Box window foil upstream", boxGasLV, false, 0, true);
new PVPlacement(NULL, G4ThreeVector(0., 0., +(180*cm - 2*mm - 0.05*mm)), windowFoilLV, "Box window foil downstream", boxGasLV, false, 1, true);

Now, if I stop detector construction after part 2 everything works fine even though I do re-use world material for window gaps. If however I include part 3 in the process, initialisation of Geant aborts with a segmentation fault and the following stack trace:

[...snipped irrelevant bit...]
#5  
#6  AddMaterial (aMaterial=0x7f5d00000005, this=0x25cc890) at /path/to/geant4.9.6.p02/source/geometry/management/src/G4Region.cc:422
#7  G4Region::ScanVolumeTree (this=this
entry=0x25cc890, lv=0x3f88500, region=region
entry=true) at /path/to/geant.9.6.p02/source/geometry/management/src/G4Region.cc:129
#8  0x00007f5dee979c01 in G4Region::ScanVolumeTree (this=this
entry=0x25cc890, lv=0x2e29000, region=region
entry=true) at /path/to/geant4.9.6.p02/source/geometry/management/src/G4Region.cc:215
#9  0x00007f5dee97b4fe in G4Region::AddRootLogicalVolume (this=0x25cc890, lv=lv
entry=0x2e29000) at /path/to/geant4.9.6.p02/source/geometry/management/src/G4Region.cc:243
#10 0x00007f5df14bab3a in G4RunManagerKernel::DefineWorldVolume (this=0x253c8e0, worldVol=, topologyIsChanged=topologyIsChanged
entry=false) at /path/to/geant4.9.6.p02/source/run/src/G4RunManagerKernel.cc:220
#11 0x00007f5df14b41b6 in G4RunManager::InitializeGeometry (this=0x253d000) at /path/to/geant4.9.6.p02/source/run/src/G4RunManager.cc:388
#12 0x00007f5df14b3ed1 in G4RunManager::Initialize (this=0x253d000) at /path/to/geant4.9.6.p02/source/run/src/G4RunManager.cc:373
[...snipped irrelevant bit...]

The error also happens if I stop construction after creating boxGasLV - i.e. not only is there no foil in windows but even the gas volume itself doesn't get placed inside the box. To make things even more interesting, if instead of setting gasInBox to logicalWorld->GetMaterial() I invoke nist->FindOrBuildMaterial("G4_AIR") again, the error vanishes - only to appear again as a result of creation of windowFoilLV.

Having spent the larger part of today going over my code both visually and with gdb, I had to eventually admit defeat and ask my question here. Thank you in advance for any hints which will help me fix this issue! If you need any more information, just let me know.

All the best,
--
MS

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

1 None: Re: Segmentation fault after material re-use   (Marc Verderi - 18 Oct, 2013)
1 None: Re: Segmentation fault after material re-use   (Marek Szuba - 05 Nov, 2013)
2 None: Re: Segmentation fault after material re-use   (Marek Szuba - 21 Oct, 2013)
 Add Message Add Message
to: "Segmentation fault after material re-use"

 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 ]