Problem 1884 - G4LogicalVolume::GetMaterial() crashes for mixtures
Summary: G4LogicalVolume::GetMaterial() crashes for mixtures
Status: RESOLVED INVALID
Alias: None
Product: Geant4
Classification: Unclassified
Component: materials (show other problems)
Version: 10.2
Hardware: All All
: P4 normal
Assignee: Marc.Verderi
URL:
Depends on:
Blocks:
 
Reported: 2016-09-01 12:10 CEST by Paola
Modified: 2016-09-13 11:46 CEST (History)
0 users

See Also:


Attachments
Description of the error (618 bytes, text/plain)
2016-09-01 12:10 CEST, Paola
Details
Relevant classes of the code related with the issue (24.59 KB, application/zip)
2016-09-12 23:33 CEST, Paola
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Paola 2016-09-01 12:10:02 CEST
Created attachment 410 [details]
Description of the error

Hi! I found the following error when I use the GetMaterial() method of the G4LogicalVolume class, in the case my material is a mixture of different element (thus, there's no one Z defined):

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : mat036
     issued by : G4Material::GetZ()
the Atomic number is not well defined.
*** Fatal Exception *** core dump ***
-------- EEEE -------- G4Exception-END --------- EEEE -------

Is it a bug? Why is this method trying to retrieve Z, if materials are allowed to be mixtures of more than one element?

I'm using geant4.10.02.p01.

Thanks

Paola
Comment 1 Marc.Verderi 2016-09-12 16:24:53 CEST
The G4Exception when calling GetZ() on a mixture material is a normal behavior. But it is surprising that this call is triggered by GetMaterial() method of the G4LogicalVolume class, as this method just returns the material pointer.

Before calling GetZ() on a material, you should verify it is not a mixture, for example checking if GetNumberOfElements() of the material is 1.

Could you check if your code is calling GetZ() by itself, and provide feed-back on the GetNumberOfElements() usage ?

Marc
Comment 2 Paola 2016-09-12 16:47:04 CEST
Hi! My code is not calling GetZ() explicitly, it's just calling G4LogicalVolume::GetMaterial(). I've checked GetNumberOfElements() in the code which defines the material for the first volume used, and the result is 2, as expected (I'm using a mixture of two elements).

Paola
Comment 3 Marc.Verderi 2016-09-12 17:27:16 CEST
I am confused, I don't see how GetZ() could be called by G4LogicalVolume::GetMaterial(). I would suspect the call to GetZ() happens elsewhere, on the material returned by G4LogicalVolume::GetMaterial().

Could you attach your code ?

Marc
Comment 4 Paola 2016-09-12 23:33:30 CEST
Created attachment 413 [details]
Relevant classes of the code related with the issue
Comment 5 Paola 2016-09-12 23:34:00 CEST
Comment on attachment 413 [details]
Relevant classes of the code related with the issue

Hi! The code is a bit complicated, I'm attaching the relevant classes, let me know if you need anything else.
In MaterialsList.cc the material is defined, with name "GXeAr" at line 140.
In NextNewVessel.cc, the material is called for the first time at line 373.
In NextNewFieldCage.cc, the material is retrieved at line 238.
The main geometry class from which the different parts of the detector are built is NextNew.cc. In particular, NextNewFieldCage is instantiated in NextNewInnerElements.
Comment 6 Marc.Verderi 2016-09-13 10:08:08 CEST
Thank you for the code.

In the MaterialsList class, in method CopyMaterial(...), you have calls to the GetZ() of materials. This call looks to be made for newly created materials, and is not protected. CopyMaterial(...) is called by FakeDielectric(...), itself called by NextNewFieldCage.cc.
Is the crash happening in CopyMaterial(...) ?
Comment 7 Paola 2016-09-13 10:48:43 CEST
You're right, it's in the CopyMaterial() method that the method GetZ() is called and causes the crash, I hadn't realized that. I will have to generalize the copy for a mixture.
Sorry to bother you with this, and thank for the help!
Comment 8 Marc.Verderi 2016-09-13 11:44:56 CEST
You're welcome ;) 

Marc