I have a simulation made from 80 distinct volumes all of which I want to make “sensitive”. To facilitate this I have a text file which contains all the information I need to make the required materials and volumes and I store the pointers to all of my volumes in arrays. I similarly create 80 distinct instances of my sensitive detector class and assign each of them to my volumes.
My code compiles without objection but I get a set fault at runtime:
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f962d4d6457 in __GI___waitpid (pid=6056, stat_loc=stat_loc
entry=0x7ffc513c92e8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1 0x00007f962d441177 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2 0x00007f963089ade3 in TUnixSystem::StackTrace() () from /opt/root/root-6.22.02-build/lib/libCore.so
#3 0x00007f963089d8d5 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/root-6.22.02-build/lib/libCore.so
#4 <signal handler called>
#5 0x00007f962eb22560 in G4LogicalVolume::GetSensitiveDetector() const () from /home/students/GEANT4/g4install/lib/libG4geometry.so
#6 0x00007f962fb6b402 in G4VUserDetectorConstruction::SetSensitiveDetector(G4LogicalVolume*, G4VSensitiveDetector*) () from /home/students/GEANT4/g4install/lib/libG4run.so
#7 0x000055af270e037b in ConstructJupiter::ConstructSDandField() ()
#8 0x00007f962fb3ccff in G4RunManager::InitializeGeometry() () from /home/students/GEANT4/g4install/lib/libG4run.so
#9 0x00007f962fb3cb71 in G4RunManager::Initialize() () from /home/students/GEANT4/g4install/lib/libG4run.so
#10 0x000055af270de22c in main ()
===========================================================
This error does not persist when I comment out the code which assigns the sensitive detectors to my logical volumes.
I create the arrays in my header file
G4SDManager* DetectorManager;
G4VSensitiveDetector *SDetectors[num_layers];
And the actual detectors + assignment in my source file
void ConstructJupiter::ConstructSDandField()
{
DetectorManager = G4SDManager::GetSDMpointer();
for(int i = 0; i < num_layers; i++)
{
SDetectors[i] = new JupiterSD("SensitiveAtmo");
DetectorManager -> AddNewDetector(SDetectors[i]);
layers_logical[i] -> SetSensitiveDetector(SDetectors[i]);
}
}
(I have tried doing the assignment with the SetSensitiveDetector() method to no avail)
I have tried to create an individual instance of a sensitive detector and assign it to a single volume but without success which leads me to suspect that the problem lies in the logical volumes (though they seem to become physical volumes without complaint).
The code I use to create the volumes is here:
ifstream geometry_file;
geometry_file.open("Layers.txt");
int i = -1;
Rin = 0*km;
while (getline(geometry_file, line))
{
i += 1;
layers_solid[i] = new G4Sphere("Atmoshpere_Solid", Rin, Rin + stod(line)*km, 0*degree, 306*degree, 0*degree, 180*degree);
layers_logical[i] = new G4LogicalVolume(layers_solid[i], materials[i], "Atmoshpere_Logical");
layers_physical[i] = new G4PVPlacement(0, G4ThreeVector(0, 0, 0), layers_logical[i], "Atmoshpere_Physical", WorldLogical, false, CopyAtmo);
Rin += stod(line)*km;
}
geometry_file.close();
If anything obvious in these code snippets stands out please let me know (I suspect that it has something to do with pointers/values but, I admit, I am not quite as proficient in C++ as I’d like to be). If nothing stands out I have also attached the source and header files for the relevant pieces.
ConstructJupiter.cc (6.3 KB) JupiterSD.cc (2.2 KB) Layers.txt (261 Bytes) ConstructJupiter.hh (2.8 KB) JupiterSD.hh (543 Bytes)