*** Break *** segmentation violation while using geometry package


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.26
Platform: Ubuntu 22.04.1
Compiler: Cling
Hello everyone,
I am trying of design an array of 20 silicon pixeled detectors and I am getting this crash:

root [0] 
Processing active_target_geometry_pixeled.C...
Info in <TGeoManager::TGeoManager>: Geometry manager, Active Target Geometry created
Info in <TGeoManager::SetTopVolume>: Top volume is Top. Master volume is Top
Info in <TGeoNavigator::BuildCache>: --- Maximum geometry depth set to 100
Info in <TGeoManager::CheckGeometry>: Fixing runtime shapes...
Info in <TGeoManager::CheckGeometry>: ...Nothing to fix
Info in <TGeoManager::CloseGeometry>: Counting nodes...
Info in <TGeoManager::Voxelize>: Voxelizing...

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f6b93bd745a in __GI___wait4 (pid=276781, stat_loc=stat_loc
entry=0x7ffe34cd9618, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1  0x00007f6b93bd741b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffe34cd9618, options=options
entry=0) at ./posix/waitpid.c:38
#2  0x00007f6b93b3dbcb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3  0x00007f6b9428b8a4 in TUnixSystem::StackTrace() () from /home/solne/root/lib/libCore.so.6.26
#4  0x00007f6b94288bb5 in TUnixSystem::DispatchSignals(ESignals) () from /home/solne/root/lib/libCore.so.6.26
#5  <signal handler called>
#6  0x00007f6b79579aaa in TGeoVoxelFinder::SortAll(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#7  0x00007f6b7957af6e in TGeoVoxelFinder::Voxelize(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#8  0x00007f6b795724cf in TGeoVolume::Voxelize(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#9  0x00007f6b794ea0e8 in TGeoManager::Voxelize(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#10 0x00007f6b794f39cf in TGeoManager::CloseGeometry(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#11 0x00007f6b93f65617 in ?? ()
#12 0x000003ff00000000 in ?? ()
#13 0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f6b79579aaa in TGeoVoxelFinder::SortAll(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#7  0x00007f6b7957af6e in TGeoVoxelFinder::Voxelize(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#8  0x00007f6b795724cf in TGeoVolume::Voxelize(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#9  0x00007f6b794ea0e8 in TGeoManager::Voxelize(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#10 0x00007f6b794f39cf in TGeoManager::CloseGeometry(char const*) () from /home/solne/root/lib/libGeom.so.6.26.10
#11 0x00007f6b93f65617 in ?? ()
#12 0x000003ff00000000 in ?? ()
#13 0x0000000000000000 in ?? ()
===========================================================

This is the sample code where the pixel volume is defined, and then placed with the help of three for loops:

 TGeoVolume *top = manager->MakeBox("Top", Air, 100, 100, 200); //units in mm
	manager->SetTopVolume(top);
	
	//MAPSpixel
	Double_t xPixel = 0.02924, yPixel = 0.02688, zPixel = 0.1;
	TGeoVolume *volumePixel = manager->MakeBox("volumePixel", MAPSmedium, xPixel/2., yPixel/2., zPixel/2.);

	Int_t numberPlanes = 20;
	Double_t distBetweenPlanes = 8.;
	Int_t numPixels = 1024;
	for(int k = 0; k < numberPlanes; k++){
		for (int i = 0; i < numPixels; i++){
			for (int j = 0; j < numPixels; j++){
				top->AddNode(volumePixel, i*10000+j, new TGeoTranslation(xPixel*(0.5-512+j), yPixel*(512-0.5-i), k*distBetweenPlanes));
			}
		}
	}
	
	manager->CloseGeometry();
	
	top->Draw("ogl");

I think it could be related with memory allocation corruption, but I am not sure. What should I do to solve this predicament?
Thank you in advance.

Please provide a macro we can run

active_target_geometry_pixeled.C (1.2 KB)

Right, I think 20971520 (20 * 1024 * 1024) nodes is probably too much…

It is indeed, but those are the technical requirements for the experiment I need to simulate. What do you recommend me to do? How correct is, from a simulating point of view, to only use a solid silicon plane? Regards.

Maybe @agheata can help with that

For me, it crashed at 16GB RAM memory usage, whereas I have 32GB computer memory.

Where it crashes is here:

So it seems there is some issue with the code in this class, or some overflow in the data type.

EDIT: after fixing the overflow bug in the code, it is indeed related to too much memory consumption.

Thanks @ferhue ! So maybe @agheata will be interested!

The overflow gets solved with the highlighted changes:

and the program ‘cleanly’ crashes on 1691 with a more senseful error message:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Hi,
Sure, getting a “clean” crash is important, and I’ll adapt the code. The real issue here is how to avoid needing that much memory though. In the real geometry pixels are attached to sensors, sensors to some chips and the chips to some modules. Therefore you need to add at least some of these hierarchical levels in your geometry description, which will reduce the memory required which grows like the squared number of objects per level.
Cheers, Andrei

1 Like

Thank you very much for your help and suggestions. Perhaps I was too ambitious trying to generate every pixel, it seems I will need to simplify the detector design or run it in a stronger computer. Regards.