Problem 2373

Summary: the gdml file that's dumped by the G4GDMLParser is not a valid
Product: Geant4 Reporter: Hans Wenzel <wenzel>
Component: persistency/gdmlAssignee: Witold.Pokorski
Status: RESOLVED WONTFIX    
Severity: minor CC: daren.sawkey, Gabriele.Cosmo, resnegfk, wenzel, Witold.Pokorski
Priority: P4    
Version: 10.7   
Hardware: PC   
OS: All   
Attachments: gdml file produced by the parser: G4GDMLParser fParser; fParser.Write("junkie.gdml", expHall_phys);
working gdml file
working dump of NoviceExample

Description Hans Wenzel 2021-05-25 17:31:54 CEST
Created attachment 695 [details]
gdml file produced by the parser:     G4GDMLParser fParser;     fParser.Write("junkie.gdml", expHall_phys);

Hi 


it looks like the gdml file that's dumped by the G4GDMLParser  is not a valid gdml file since non existing physical volumes are referenced. To demonstrate the problem  for the Geometry I used the 
OpNoviceDetectorConstruction.cc example

just changing it to (to avoid bug reported in 2371) :
  // Water Tank
    //
    G4OpticalSurface* opWaterSurface = new G4OpticalSurface("WaterSurface");
    opWaterSurface->SetType(dielectric_dielectric);
    opWaterSurface->SetFinish(ground);
    opWaterSurface->SetModel(unified);
    // bug in gdml reader so fall back to dielectric_dielectric,ground,unified
    //opWaterSurface->SetType(dielectric_LUTDAVIS);
    //opWaterSurface->SetFinish(Rough_LUT);
    //opWaterSurface->SetModel(DAVIS);

and adding


    G4GDMLParser fParser;
    fParser.Write("junkie.gdml", expHall_phys);

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : ReadError
      issued by : G4GDMLReadStructure::GetPhysvol()
Referenced physvol 'World0x56181e363ba0' was not found!
*** Fatal Exception *** core dump ***
 **** Track information is not available at this moment
 **** Step information is not available at this moment

-------- EEEE -------- G4Exception-END --------- EEEE -------
Comment 1 Hans Wenzel 2021-05-25 21:59:54 CEST
Created attachment 696 [details]
working gdml  file

problem seems to be that one of the volumes brtween which the surface is declared is the top volume. The attached file adds abextra layer and now can be parsed.
Comment 2 Hans Wenzel 2021-05-26 17:08:16 CEST
Created attachment 697 [details]
working dump of NoviceExample

Hi 


I have attached a dump. I used the working gdml file in my previous attachment and then dumped it, checked that ithe dump is valid gdml and included it here just to be complete.
Comment 3 Gabriele Cosmo 2021-05-31 14:22:28 CEST
This is likely a problem of the OpNovice example itself, as adopting the surface of the world volume for optical settings is in principle NOT recommended.
The parser should eventually detect this and gracefully issue an error message...
Comment 4 Witold.Pokorski 2021-05-31 17:46:04 CEST
I have looked through G4GDMLWriteStructure::BorderSurfaceCache (the method writing out Border Surfaces) and everything seems correct there. 
It uses simply the G4LogicalBorderSurface::GetVolume1() and G4LogicalBorderSurface::GetVolume2() methods to get the pointers to the two volumes to which the surface is associated.

It seems that when one of the volumes is the world volume (which is not recommended, as Gabriele says), the pointer which is returned by GetVolume1/2 method does not correspond to the original 'world volume' object. 
I have no idea why. It seems as if Geant4 was creating another volume object just to avoid having the boarder surface to touch the world volume??

I think, we should modify the example OpNovice first (as this is a bad example), and then maybe put some protection in the GDML writer against such cases (I don't think, putting any work around to handle it would be the right think to do).
But I am certainly open to any suggestions.
Comment 5 Daren Sawkey 2021-05-31 20:16:25 CEST
Interesting. All four optical examples and the documentation do this. This particular example has had this feature since Geant4 version 7.1 (2004) when the examples were introduced! (according to lxr; the example was called N06 then).

If this is an issue with tracking (it doesn't seem to be, as tracking works) I'll fix the examples and documentation. Or is the problem limited to creating the GDML file? In which case, it's not clear anything needs to be modified.
Comment 6 Gabriele Cosmo 2021-06-01 08:01:09 CEST
Using the world volume as optical surface is wrong as it makes no sense, and should be corrected.
Comment 7 Daren Sawkey 2021-06-01 17:31:37 CEST
Maybe we're talking about different surfaces. In OpNovice, there is a daughter volume in the world. The surface of the daughter volume seems to make sense, doesn't it?
Comment 8 Gabriele Cosmo 2021-06-02 08:29:37 CEST
The problem in OpNovice is that the world volume is used for defining the logical-border surface (and optical surface). Such setup may not cause problems in the tracking itself but it is not recommended... The water tank should be placed in a container placed in the world.
Comment 9 Gabriele Cosmo 2021-08-19 09:49:52 CEST
OpNovice example has been corrected in the Master. Closing ticket.