Method volume and Get Copy Number problem

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version: 4 10 7
Operating System: mint
Compiler/Version: gcc version 7.5.0
CMake Version: cmake version 3.10.2


Hello, dear all! Help me, please!

In my detector geometry, I put one volume inside another volume and make 10 such elements in a loop, thus obtaining many objects with the same name. further, using the method:

G4int No = step->GetPreStepPoint()->GetTouchableHandle()->Get Volume(1)->GetCopyNo();

or

G4int No = step->GetPreStepPoint()->GetTouchableHandle()->Get Copy Number(0)+ step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(1)+ step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(2);

when I run the detector, I always get this error, even though the program compiles without errors. What is the problem?

my error:

CoulombScat: for pi-, integral:1 SubType=1 BuildTable=1 Used Lambda table of pi+ ThetaMin(p) < Theta(degree) < 180; p Limit(Get^1)= 0.139531 ===== ===== EM models for the G4Region Default Regions For The World ====== eCoulombScattering : Emin= 0 eV Emax= 100 TeV ./gc.sh: line 4: 11533 Segmentation fault (memory stack dumped to disk) ./detector

Hello,

a total shot in the dark here but it looks like maybe the volumes you think you are handling are not the ones you think they are.
Because it is a segfault. I imagine that there is no “depth” 2 or 1.
Feel free to adapt this and debug your code.

G4VPhysicalVolume* detector_phys = touchable->GetVolume();    
G4ExceptionDescription msg;
G4String               detector_name = detector_phys->GetName();
msg << detector_name << " :" << G4endl;
for (G4int depth = touchable->GetHistoryDepth(); depth >= 0; depth--)
  {
     msg << depth << " -> " << touchable->GetReplicaNumber(depth);
  }
G4Exception(__PRETTY_FUNCTION__, "=(", FatalException, msg);

Cheers,

/Pico

thank you very much for your attention and answer!

thank you!

This method is true:

G4int No = step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(0)+ step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(1)+ step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(2);

but next method do not work:

G4int No = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume(1)->GetCopyNo();

Why don’t you split your calculation into separate pieces, and apply a properly null-pointer check before each piece in the summ?