Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geant4Converter bug in dd4hep::Polyhedra #578

Closed
ianna opened this issue Oct 14, 2019 · 18 comments
Closed

Geant4Converter bug in dd4hep::Polyhedra #578

ianna opened this issue Oct 14, 2019 · 18 comments

Comments

@ianna
Copy link
Contributor

ianna commented Oct 14, 2019

Having Geant4Converter successfully converted geometry to Geant4:

Geant4Converter  INFO  +++  Successfully converted geometry to Geant4.

a run-time error is reported by G4:

**************************************************** 
*  A runtime error has occured :                     
*    
-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : GeomMgt0002
      issued by : G4SmartVoxelHeader::BuildNodes()
PANIC! - Overlapping daughter with mother volume.
         Daughter physical volume hcalbarrelalgo:HBLayer0In1_3001
         is entirely outside mother logical volume hcalbarrelalgo:HBLayer0InSide !!
-------- EEEE -------- G4Exception-END --------- EEEE -------

*  the program will have to be terminated - sorry.   
**************************************************** 

Looking at Root geometry, the shape in question (in green) is not outside of its mother (in blue):
Screen Shot 2019-10-14 at 15 16 58

*** Shape hcalbarrelalgo:HBLayer0InSide_shape_0x7faac6540780: TGeoPgon ***
    Nedges = 1
*** Shape hcalbarrelalgo:HBLayer0InSide_shape_0x7faac6540780: TGeoPcon ***
    Nz    = 3
    phi1  =   -10.00000
    dphi  =    20.00000
     plane 0: z=    0.00000 Rmin=  177.50000 Rmax=  178.70000
     plane 1: z=  308.23896 Rmin=  177.50000 Rmax=  178.70000
     plane 2: z=  310.32582 Rmin=  178.70000 Rmax=  178.70000
 Bounding box:
*** Shape hcalbarrelalgo:HBLayer0InSide_shape_0x7faac6540780: TGeoBBox ***
    dX =     3.32668
    dY =    31.50963
    dZ =   155.16291
    origin: x=  178.13006 y=    0.00000 z=  155.16291
*** Shape hcalbarrelalgo:HBLayer0In1_shape_0x7faacf055600: TGeoBBox ***
    dX =     0.60000
    dY =     7.88440
    dZ =   154.11948
    origin: x=    0.00000 y=    0.00000 z=    0.00000
@ianna
Copy link
Contributor Author

ianna commented Oct 14, 2019

@cvuosalo and @bsunanda - FYI

@ianna
Copy link
Contributor Author

ianna commented Oct 14, 2019

Another message that looks like from G4:

**************************************************** 
*  A runtime error has occured :                     
*    Failed to handle unknown solid shape:pixfwdInnerDiskZminus:PixelForwardInnerDiskInnerRing_uni2_left of type TGeoCtub
*  the program will have to be terminated - sorry.   
**************************************************** 

@MarkusFrankATcernch
Copy link
Contributor

MarkusFrankATcernch commented Oct 14, 2019

This printout here:

*** Shape hcalbarrelalgo:HBLayer0InSide_shape_0x7faac6540780: TGeoPgon ***
    Nedges = 1

looks very strange. 1 edge should be impossible. There should be 3 or more to span a plane - no?

@ianna
Copy link
Contributor Author

ianna commented Oct 14, 2019

well, I'm not inventing it :-)

@ianna
Copy link
Contributor Author

ianna commented Oct 14, 2019

they look quite reasonable:
Screen Shot 2019-10-14 at 16 47 09
Screen Shot 2019-10-14 at 16 49 41

@MarkusFrankATcernch
Copy link
Contributor

Bad argument: The problem must be more subtle.
Polygons are used in every cylindrical calorimeter - but only in your case a problem arises.

@ianna
Copy link
Contributor Author

ianna commented Oct 14, 2019

Ideally the blue shapes should be hidden by the red ones. I guess, it's a precision problem - the inner faces are almost identical. See the swap in red when a cursor is over the shape in the second snapshot:
Screen Shot 2019-10-14 at 16 53 29
Screen Shot 2019-10-14 at 16 54 37

@MarkusFrankATcernch
Copy link
Contributor

This is a good candidate for the problem. I agree.

@ianna
Copy link
Contributor Author

ianna commented Oct 29, 2019

Here is produced GDML:

    <polyhedra aunit="deg" deltaphi="10" lunit="mm" name="hcalbarrelalgo_HBLayer0InSide_shape_0x7f5e06777d800x7f5e01857400" numsides="1" startphi="350">
      <zplane rmax="1787" rmin="1775" z="0"/>
      <zplane rmax="1787" rmin="1775" z="3082.38960788158"/>
      <zplane rmax="1787" rmin="1787" z="3103.25824748416"/>
    </polyhedra>

    <box lunit="mm" name="hcalbarrelalgo_HBLayer0In1_shape_0x7f5e01df3e800x7f5e01807680" x="12" y="157.68801299901" z="3082.38960788158"/>

    <volume name="hcalbarrelalgo_HBLayer0In10x7f5e01506480">
      <materialref ref="materials_Air0x7f5e0a642100"/>
      <solidref ref="hcalbarrelalgo_HBLayer0In1_shape_0x7f5e01df3e800x7f5e01807680"/>
      <physvol copynumber="1" name="hcalbarrelalgo_HBLayer0In1Plastic_1_10x7f5e00fb89c0">
        <volumeref ref="hcalbarrelalgo_HBLayer0In1Plastic_10x7f5e014ea2a0"/>
        <position name="hcalbarrelalgo_HBLayer0In1Plastic_1_10x7f5e00fb89c0_pos" unit="mm" x="-5" y="0" z="0"/>
      </physvol>
      <physvol name="hcalbarrelalgo_HBScintillatorLayer0In1_00x7f5e00fb8a10">
        <volumeref ref="hcalbarrelalgo_HBScintillatorLayer0In10x7f5e014ea340"/>
        <position name="hcalbarrelalgo_HBScintillatorLayer0In1_00x7f5e00fb8a10_pos" unit="mm" x="0.499999999999999" y="0" z="0"/>
      </physvol>
      <physvol copynumber="1" name="hcalbarrelalgo_HBLayer0In1Plastic_2_10x7f5e00fb8a60">
        <volumeref ref="hcalbarrelalgo_HBLayer0In1Plastic_20x7f5e014ea3e0"/>
        <position name="hcalbarrelalgo_HBLayer0In1Plastic_2_10x7f5e00fb8a60_pos" unit="mm" x="5.5" y="0" z="0"/>
      </physvol>
    </volume>
    
    <volume name="hcalbarrelalgo_HBLayer0InSide0x7f5e01559b80">
      <materialref ref="materials_Air0x7f5e0a642100"/>
      <solidref ref="hcalbarrelalgo_HBLayer0InSide_shape_0x7f5e06777d800x7f5e01857400"/>
      <physvol copynumber="1" name="hcalbarrelalgo_HBLayer0InSideSpacer_10x7f5e01007260">
        <volumeref ref="hcalbarrelalgo_HBLayer0InSideSpacer0x7f5e015063e0"/>
      </physvol>
      <physvol copynumber="3001" name="hcalbarrelalgo_HBLayer0In1_30010x7f5e010072b0">
        <volumeref ref="hcalbarrelalgo_HBLayer0In10x7f5e01506480"/>
        <position name="hcalbarrelalgo_HBLayer0In1_30010x7f5e010072b0_pos" unit="mm" x="1781" y="234.13638425802" z="1541.19480394079"/>
      </physvol>
      <physvol copynumber="3002" name="hcalbarrelalgo_HBLayer0In1_30020x7f5e01007300">
        <volumeref ref="hcalbarrelalgo_HBLayer0In10x7f5e01506480"/>
        <position name="hcalbarrelalgo_HBLayer0In1_30020x7f5e01007300_pos" unit="mm" x="1781" y="-234.13638425802" z="1541.19480394079"/>
        <rotation name="hcalbarrelalgo_HBLayer0In1_30020x7f5e01007300_rot" unit="deg" x="-180" y="0" z="0"/>
      </physvol>
    </volume>

@ianna
Copy link
Contributor Author

ianna commented Oct 30, 2019

OK, here is what ROOT to G4 converter should produce as a G4 geometry. The HBLayer0In1_3002 rotation should be different: note the sign of x="180"

    <volume name="HBLayer0InSide0x7f732daaf1a0">
      <materialref ref="Air0x7f733243d3c0"/>
      <solidref ref="HBLayer0InSide0x7f732dbfed00"/>
      <physvol copynumber="1" name="HBLayer0InSideSpacer0x7f732dbf4b20">
        <volumeref ref="HBLayer0InSideSpacer0x7f732dab7780"/>
      </physvol>
      <physvol copynumber="3001" name="HBLayer0In10x7f732dbf4bc0">
        <volumeref ref="HBLayer0In10x7f732dab7820"/>
        <position name="HBLayer0In10x7f732dbf4bc0_pos" unit="mm" x="1781" y="234.13638425802" z="1541.19480394079"/>
      </physvol>
      <physvol copynumber="3002" name="HBLayer0In10x7f732dbf4c60">
        <volumeref ref="HBLayer0In10x7f732dab7820"/>
        <position name="HBLayer0In10x7f732dbf4c60_pos" unit="mm" x="1781" y="-234.13638425802" z="1541.19480394079"/>
        <rotation name="HBLayer0In10x7f732dbf4c60_rot" unit="deg" x="180" y="-3.2461146750243e-14" z="2.32458640765866e-14"/>
      </physvol>
      <auxiliary auxtype="gammaECut" auxunit="MeV" auxvalue="0.00099"/>
      <auxiliary auxtype="electronECut" auxunit="MeV" auxvalue="0.00099"/>
      <auxiliary auxtype="positronECut" auxunit="MeV" auxvalue="0.00099"/>
      <auxiliary auxtype="protonECut" auxunit="MeV" auxvalue="0.1"/>
    </volume>

@ianna
Copy link
Contributor Author

ianna commented Nov 4, 2019

Left G4 geometry produced with CMS DD, right G4 geometry produced with DD4hep G4 converter:
Screen Shot 2019-11-04 at 17 32 07
Screen Shot 2019-11-04 at 17 33 19
Screen Shot 2019-11-04 at 17 34 27
Original ROOT geometry passed to DD4hep:
Screen Shot 2019-11-04 at 17 46 04
Set visible containers for ROOT geometry and G4 geometry produced from it by DD4hep:
Screen Shot 2019-11-04 at 17 52 32

@ianna
Copy link
Contributor Author

ianna commented Nov 4, 2019

HBLayer0 ROOT geometry on the left and G4 geometry produced from it on the right:
Screen Shot 2019-11-04 at 17 57 25

@ianna ianna changed the title Geant4Converter bug? Geant4Converter bug in dd4hep::Polyhedra Nov 4, 2019
@ianna
Copy link
Contributor Author

ianna commented Nov 8, 2019

ROOT printout of the shape:

*** Shape hcalbarrelalgo:HBLayer0: TGeoPgon ***
    Nedges = 1
*** Shape hcalbarrelalgo:HBLayer0: TGeoPcon ***
    Nz    = 3
    phi1  =   -10.00000
    dphi  =    20.00000
     plane 0: z=    0.00000 Rmin=  177.50000 Rmax=  185.15000
     plane 1: z=  308.23896 Rmin=  177.50000 Rmax=  185.15000
     plane 2: z=  321.54272 Rmin=  185.15000 Rmax=  185.15000
 Bounding box:
*** Shape hcalbarrelalgo:HBLayer0: TGeoBBox ***
    dX =     6.60143
    dY =    32.64694
    dZ =   160.77136
    origin: x=  181.40481 y=    0.00000 z=  160.77136

@ianna
Copy link
Contributor Author

ianna commented Nov 8, 2019

GDML:

*** Shape hcalbarrelalgo_HBLayer0_shape_: TGeoPgon ***
    Nedges = 1
*** Shape hcalbarrelalgo_HBLayer0_shape_: TGeoPcon ***
    Nz    = 3
    phi1  =   350.00000
    dphi  =    10.00000
     plane 0: z=    0.00000 Rmin=  177.50000 Rmax=  185.15000
     plane 1: z=  308.23896 Rmin=  177.50000 Rmax=  185.15000
     plane 2: z=  321.54272 Rmin=  185.15000 Rmax=  185.15000
 Bounding box:
*** Shape hcalbarrelalgo_HBLayer0_shape_: TGeoBBox ***
    dX =     5.52693
    dY =    16.13689
    dZ =   160.77136
    origin: x=  180.33031 y=  -16.13689 z=  160.77136

@MarkusFrankATcernch
Copy link
Contributor

MarkusFrankATcernch commented Nov 8, 2019

I think this is it -- insert for GetPhi1() "-10" degrees....:

  template <> G4VSolid* convertShape<TGeoPgon>(const TGeoShape* shape)  {
    const TGeoPgon* sh = (const TGeoPgon*) shape;
    double phi_start = sh->GetPhi1() * DEGREE_2_RAD;
    double phi_total = (sh->GetDphi() + sh->GetPhi1()) * DEGREE_2_RAD;
    vector<double> rmin, rmax, z;
    for (Int_t i = 0; i < sh->GetNz(); ++i) {
      rmin.emplace_back(sh->GetRmin(i) * CM_2_MM);
      rmax.emplace_back(sh->GetRmax(i) * CM_2_MM);
      z.emplace_back(sh->GetZ(i) * CM_2_MM);
    }
    return new G4Polyhedra(sh->GetName(), phi_start, phi_total, sh->GetNedges(), sh->GetNz(), &z[0], &rmin[0], &rmax[0]);
  }

But I will verify this suspicion.

@petricm petricm added the bug label Nov 8, 2019
MarkusFrankATcernch added a commit to MarkusFrankATcernch/DD4hep that referenced this issue Nov 8, 2019
MarkusFrankATcernch added a commit to MarkusFrankATcernch/DD4hep that referenced this issue Nov 8, 2019
MarkusFrankATcernch added a commit to MarkusFrankATcernch/DD4hep that referenced this issue Nov 8, 2019
MarkusFrankATcernch added a commit to MarkusFrankATcernch/DD4hep that referenced this issue Nov 8, 2019
MarkusFrankATcernch added a commit to MarkusFrankATcernch/DD4hep that referenced this issue Nov 8, 2019
MarkusFrankATcernch added a commit to MarkusFrankATcernch/DD4hep that referenced this issue Nov 8, 2019
@MarkusFrankATcernch
Copy link
Contributor

MarkusFrankATcernch commented Nov 9, 2019

Hi Yana,
please test.
P.S. Thanks for these last 2 dumps. This really clarified the problem!
You apparently were the first ones where start_phi was != NULL....

@petricm
Copy link

petricm commented Nov 10, 2019

@MarkusFrankATcernch you have used BoundingLimits, but G4VSolid does not have this member until Geant4 10.4

@ianna
Copy link
Contributor Author

ianna commented Nov 13, 2019

fixed, thanks!

@ianna ianna closed this as completed Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants