Message: Re: Geometry segmentation fault core dump Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: Geometry segmentation fault core dump  

Forum: Geometry
Re: Question Geometry segmentation fault core dump
Date: 10 Aug, 2012
From: Michael H. Kelsey <Michael H. Kelsey>

On Thu, 09 Aug 2012 20:39:52 GMT, matthieu wrote:
> Hi!
> I am trying to upgrade geant4 from 4.8.2 to 4.9.5. Got rid of many bugs,
> had to modify plenty of lines and files. Took me a good week to get
> everything up to date...
> Now I think the upgrade is almost done, cause the compilation works, at
> least. But when I execute the code, I get a seg fault, because of the
> following line of code (which was working just fine in version 4.8.2):
> TPCSphys = new
> G4PVPlacement(0,G4ThreeVector(trackerPosX,trackerPosY,trackerPosZ),TPCSlog1,tName2,airCubeInsideWaterShieldingLog,false,TPCScopyNo++,true);
> The previous line is embedded in a FOR loop. (Because of this line, I
> get: Segmentation fault, Core dump, Cannot access memory at address
> 0x7fff6d266db0. Even though I tried to use gdb, it is not usefull here
> cause geant4 was not compiled with the required flags to work along with
> gdb... I need to ask my computer tech at the university to reinstall and
> recompile geant4 accordingly.)
> The entire usefull bloc of code is the following. I am trying to create
> 8 copies of the same box, with a FOR loop, looping on each box. So, I am
> thinking that the changes from 4.8.2 to 4.9.5 prevents the use of the
> command G4PVPlacement to create more than one instance of one object. Is
> that my problem, or did I miss something more trivial?
>  G4Box* TPCSbox = new  G4Box("TPCSbox",halfDimensionTPCS*cm,halfDimensionTPCS*cm,halfDimensionTPCS*cm);
>  G4LogicalVolume* TPCSlog1 = new G4LogicalVolume(TPCSbox,TPCSboxMat,"TPCSlog1");
>  G4String tName2("TPCSphys");   // Allow all target physicals to share
>  G4PVPlacement* TPCSphys;
>  G4int TPCScopyNo=0;
>  G4double TPCSDistanceToFloor = -51.0+floorThickness;
> for (G4int i=0;i<2;i++)
>         {
>         for(G4int j=0;j<2;j++)
>                 {
>                 for (G4int k=0;k<2;k++)
>                         {
>                         TPCSphys = new G4PVPlacement(0,G4ThreeVector(trackerPosX,trackerPosY,trackerPosZ),TPCSlog1,tName2,airCubeInsideWaterShieldingLog,false,TPCScopyNo++,true);
>                         }
>                 }
>          }

The general case you've shown should work fine (I have lots of placements within loops in my own application). There is nothing in the creation of volumes which should cause a segfault, _unless_ you try to use the TPCSphys pointer elsewhere in your code (having overwritten it inside the loop).

However, in the code above, you are placing all of the volumes at exactly the same location! That is quite likely to make the tracking code very confused. Whether it segfaults or does something else unpleasant probably depends on the details of the event.

Somewhere inside your loop, you should be computing trackerPosX,Y,Z as a function of the loop indices. You could declare a G4ThreeVector outside the loop and simply set those components within the loop (to avoid creating and deleting all those temporaries).

There are some minor issues with the code you've quoted. None of these would cause segfaults, but they might be causing your geometry to be different than you think it is. You should consider moving the "*cm" dimensions into the code where "halfDimensionTPCS" is actually set. In general, the unit multipliers should be applied to numerical constants, not already assigned variables (as it is, you run the risk of accidentially assigning units more than once). Similarly, the "-51.0" should have a length-units multiplier applied to it (is it -51.0 cm, or -51.0 mm, or -51.0 km?).

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

1 None: Re: Geometry segmentation fault core dump   (matthieu - 12 Sep, 2012)
 Add Message Add Message
to: "Re: Geometry segmentation fault core dump "

 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 ]