I think I am beginning to understand what is happening! Though I definitely need help from GAMOS or GEANT folks. Not sure where the problem lies. Here is a not so short (tried to be brief summary)
- If I use new version of G4OpRayleigh, I get segmentation fault
- If I use older version of G4OpRayleigh, I am not getting segmentation fault
- I inserted some G4Cout statements as suggested by dsawkey and recompiled the code
New Version of G4OpRayleigh (10.6)
GAMOS input file has a generator useraction. I think it runs the first initialize() that is needed.
It then builds the physics table from G4OpRayleigh method and outputs material property statements that I had inserted in and everything looks good as my geom file indicates for Energy and Rayleigh attenuation lengths
1.18e-6 100
2.18e-6 101
3.18e-6 102
However, the generate Useraction issues again a second build_table command (or maybe that is how GEANT works?) i.e., after processing one event it rebuilds the physicstable? This is where the problem appears
This second time, it does not put out properly the material property
22e-324 1.4e-322
2.18e-6 101
-1.9e-340 16e-322
And it is this that results in segmentation fault
Older Version of G4OpRayleigh(10.2)
GAMOS input file has a generator useraction. This runs the first initialize() that is needed.
It builds the physics table from G4OpRayleigh method and outputs material property statements that I had inserted in and everything looks good as my geom file indicates for Energy and Rayleigh attenuation lengths
1.18e-6 100
2.18e-6 101
3.18e-6 102
Then the generate Useraction issues again a second build_table command after the first event (my reading so far)
This second time, it does not do anything because the table is already built
And everything runs fine to the end
I think in new G4OpRayleigh.cc, when a buildtable command is issued, it destroys the old table and a new table is built based on particle definition using void G4OpRayleigh::BuildPhysicsTable(const G4ParticleDefinition&). So here immediately this method checks if physics table exists. If it does, then it destroys it. And in the next step it rebuilds it again from the particle definition.
But when it accesses the material property table it does not appear to do its job well for example a snippet from new G4OpRayleigh.cc in BuildPhysicsTable(&particledefinition) method
const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
const G4int numOfMaterials = G4Material::GetNumberOfMaterials();
thePhysicsTable = new G4PhysicsTable( numOfMaterials );
for( G4int iMaterial = 0; iMaterial < numOfMaterials; iMaterial++ )
{
G4Material* material = (theMaterialTable)[iMaterial];
G4MaterialPropertiesTable materialProperties =
material->GetMaterialPropertiesTable();
G4cout << " Materialproperty: for numofMaterials " << numOfMaterials << G4endl;// by me
materialProperties->DumpTable();// by me
The output from the last G4cout is this:
Materialproperty: for numofMaterials 1
11: RAYLEIGH
1.3052e-316 9.72299e-317
2e-06 1050
1.10671e-321 9.48606e-322
14: ABSLENGTH
1e-06 1010
2e-06 1020
3e-06 1030
23: ENERGIES
1e-06 1e-06
2e-06 2e-06
3e-06 3e-06
rayleigh Materialproperty: 0x12c4890
1.3052e-316 9.72299e-317
2e-06 1050
1.10671e-321 9.48606e-322
So first column is energy and second is attenuation length. For some reason only Rayleigh has been affected. Also energy values have been stripped of their decimals. I have absolutely no idea what happened to the original table? Maybe during the first event the photon got absorbed? But first event was only for the first energy…It should have jumped to the next energy isn’t it? That does not appear to have been corrupted. And the third energy is also weird.
In the older version, it uses void G4OpRayleigh::BuildthePhysicsTable()
In that, the very first step is to check if there exists a table. If there is one then it just ‘returns’ but does not destroy anything or rebuild. Which is why it works!? For example the above G4cout statements are printed out only once and not twice. So it appears that it prints out the physicstable after one event, then it is supposed to change physicstable if things change as in cut values are adjusted though what are those cut values for optical photon (I am not familiar with the Geant logic here, really need help. Tried looking at examples but its not clear there too)? But the older version does not do this. It just returns with the table intact
However, notice this carefully. The two methods have a different name, one is BuildPhysicsTable and the older one is BuildthePhysicsTable. However, the latter does originate from the former so not an issue here.