Geant4 error with making Calorimeter construction cell for CMS

ROOT Version: ROOT 6.14/06
_Geant4
Geant4 version Name: geant4-10-05 (7-December-2018)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/
Platform: linuxx8664gcc
Compiler: cmake version 3.8.2


I want to make calorimeter cell construction with geant4 and simulate particle event. But, I got error with “violation segmentation”. It didn’t push any errors when I make some little cells like 9x9 size.

  • cell construction ( 9x9 )
// DetectorConstruction.cc
...
G4VPhysicalVolume* DetectorConstruction::DefineVolumes() {
  // Geometry parameters
  // World
  const G4double kWorldXSide = 1000.0 * cm;
  const G4double kWorldYSide = 1000.0 * cm;
  const G4double kWorldZSide = 1000.0 * cm;

  // Calorimeter
  // PbWO4 crystal calorimeter
  const G4int kNumOfCrystalsPerRow = 9;
  const G4int kNumOfCrystalsPerColumn = 9;

  const G4double kCrystalWidth = 2.2*cm;
  const G4double kCrystalLength = 23.0*cm;

  const G4double kCaloXSide = (kCrystalWidth * kNumOfCrystalsPerRow) + 1*cm;
  const G4double kCaloYSide = (kCrystalWidth * kNumOfCrystalsPerColumn) + 1*cm;
  const G4double kCaloZSide = kCrystalLength;

...
  • output
    None error

But, I got violation segmentation errors when I make many cells like 13x13 size, 15x15 size, 30x30 size … (all same condition).

  • cell construction ( 9x9 )
// DetectorConstruction.cc
...
G4VPhysicalVolume* DetectorConstruction::DefineVolumes() {
  // Geometry parameters
  // World
  const G4double kWorldXSide = 1000.0 * cm;
  const G4double kWorldYSide = 1000.0 * cm;
  const G4double kWorldZSide = 1000.0 * cm;

  // Calorimeter
  // PbWO4 crystal calorimeter
  const G4int kNumOfCrystalsPerRow = 13;
  const G4int kNumOfCrystalsPerColumn = 13;

  const G4double kCrystalWidth = 2.2*cm;
  const G4double kCrystalLength = 23.0*cm;

  const G4double kCaloXSide = (kCrystalWidth * kNumOfCrystalsPerRow) + 1*cm;
  const G4double kCaloYSide = (kCrystalWidth * kNumOfCrystalsPerColumn) + 1*cm;
  const G4double kCaloZSide = kCrystalLength;

...

And, It didn’t push these errors when I make cells less than 9x9 size, like 4x4.

Plz help me

Hi.

segmentation violation errors often occur if you exceed array size somewhere.
The error not in those declarations of numbers, but probably somewhere else in the code where you use them to loop through cells. Like:

double cells_energies[9]

for (int i; i<kNumOfCrystalsPerRow; i++){
   //push energy into cell
   cells_energies[i] = energy;
   }

This will work with 9x9, 4x4, but will crash with 13 if you don’t change array size to 13.

How I debug these errors:
Put cout<<"WTFFFFFFFF1/2/3/4"<<endl; everywhere in the code.

And see at which cout it stops printing it and throws segmentation violation. Then you will have a clue which parts of codes it passes through and which not.

best regards,
fox

1 Like

Thank you FoxWise,

I found my mistake thanks to you, I set wrong energy cells number. I changed the number in header file.

// AnalysisHelper.hh
...
// const static G4int kNumCrystals = 81;
const static G4int kNumCrystals = 13*13;
...

But, I’d still got same errors. I’d checked how many crystal cells and energy cells with G4cout.

Finally I figure out another problem. It have wrong list size of some variable using make G4PVPlacement, too.

// DetectorConstruction.cc
...
// G4VPhysicalVolume* crystal_phys_[81];
// crystal_phys_[idx] = new G4PVPlacement(...
...
G4VPhysicalVolume* crystal_phys_[13*13];
crystal_phys_[idx] = new G4PVPlacement(...

All functions successfully work thanks to you.

thank you,

Hello,

there cannot be anything magic: use valgrind which will tell you what is wrong in your application. The crash happens during instantiation of physics processes, which has nothing to do with cell geometry. It is the case for valgrind analysis of your application.

VI