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

[DD4hep] Minor size correction of 0.1 to 7 degrees in phi for tube shapes that are non-sensitive TIB pillars and ribs #34088

Merged
merged 5 commits into from Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 37 additions & 19 deletions Geometry/EcalCommonData/plugins/dd4hep/DDEcalBarrelNewAlgo.cc
Expand Up @@ -449,6 +449,11 @@ namespace {
return ns.rotation(ns.prepend(nam));
}

const Rotation3D& myrot(cms::DDNamespace& ns, const string& nam, const Rotation3D& r) {
ns.addRotation(nam, r);
return ns.rotation(ns.prepend(nam));
}

Solid mytrap(const std::string& nam, const EcalTrapezoidParameters& t) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EBGeom") << nam << " Trap " << convertRadToDeg(t.theta()) << ":" << convertRadToDeg(t.phi())
Expand Down Expand Up @@ -1169,10 +1174,12 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
const double yy(radius * sin(phi));
const double xx(radius * cos(phi));
++ptmCopy;
xilyLog.placeVolume(
ilyPTMLog,
ptmCopy,
Transform3D(RotationZ(phi), Position(xx, yy, ily.vecIlyPTMZ[ilyPTM] - ilyLengthHalf)));
xilyLog.placeVolume(ilyPTMLog,
ptmCopy,
Transform3D(myrot(ns,
std::string(ilyPTMLog.name()) + "_rot" + std::to_string(ptmCopy),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo - this is an unnecessary performance bomb. A new object is returned after each +. That means that a new buffer is used each time. You are doing a ton of extra + operations - it is not efficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove these rotation names since they are not strictly necessary.

Rotation3D(RotationZ(phi))),
Position(xx, yy, ily.vecIlyPTMZ[ilyPTM] - ilyLengthHalf)));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EBGeomX")
<< ilyPTMLog.name() << ":" << ptmCopy << " positioned in " << xilyLog.name() << " at ("
Expand All @@ -1189,10 +1196,13 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
const double yy(radius * sin(phi));
const double xx(radius * cos(phi));
++fanOutCopy;
xilyLog.placeVolume(ilyFanOutLog,
fanOutCopy,
Transform3D(RotationZ(phi) * RotationY(180._deg),
Position(xx, yy, ily.vecIlyFanOutZ[ilyFO] - ilyLengthHalf)));
xilyLog.placeVolume(
ilyFanOutLog,
fanOutCopy,
Transform3D(myrot(ns,
std::string(ilyFanOutLog.name()) + "_rot" + std::to_string(fanOutCopy),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

RotationZ(phi) * RotationY(180._deg)),
Position(xx, yy, ily.vecIlyFanOutZ[ilyFO] - ilyLengthHalf)));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EBGeomX")
<< ilyFanOutLog.name() << ":" << fanOutCopy << " positioned in " << xilyLog.name() << " at ("
Expand All @@ -1207,10 +1217,12 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
const double yy(radius * sin(phi));
const double xx(radius * cos(phi));
++femCopy;
xilyLog.placeVolume(
ilyFEMLog,
femCopy,
Transform3D(RotationZ(phi), Position(xx, yy, ily.vecIlyFEMZ[ilyFEM] - ilyLengthHalf)));
xilyLog.placeVolume(ilyFEMLog,
femCopy,
Transform3D(myrot(ns,
std::string(ilyFEMLog.name()) + "_rot" + std::to_string(femCopy),
Rotation3D(RotationZ(phi))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Position(xx, yy, ily.vecIlyFEMZ[ilyFEM] - ilyLengthHalf)));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EBGeomX")
<< ilyFEMLog.name() << ":" << femCopy << " positioned in " << xilyLog.name() << " at ("
Expand Down Expand Up @@ -1242,8 +1254,11 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
xilyLog.placeVolume(
ilyPipeLog[type],
copyNum[type],
Transform3D(Rotation3D(ROOT::Math::AxisAngle(ROOT::Math::AxisAngle::XYZVector(xx, yy, 0), 90._deg)),
Position(xx, yy, zz)));
Transform3D(
myrot(ns,
std::string(ilyPipeLog[type].name()) + "_rot" + std::to_string(ly),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Rotation3D(ROOT::Math::AxisAngle(ROOT::Math::AxisAngle::XYZVector(xx, yy, 0), 90._deg))),
Position(xx, yy, zz)));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EBGeomX") << ilyPipeLog[type].name() << ":" << copyNum[type] << " positioned in "
<< xilyLog.name() << " at (" << cms::convert2mm(xx) << ","
Expand Down Expand Up @@ -1390,7 +1405,7 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext

Solid fawSolid = SubtractionSolid(fawSolid1,
fawCutBox,
Transform3D(myrot(ns, fawCutName + "R", fawCutForm.getRotation()),
Transform3D(myrot(ns, fawCutName + "_rot", fawCutForm.getRotation()),
Position(fawCutForm.getTranslation().x(),
fawCutForm.getTranslation().y(),
fawCutForm.getTranslation().z())));
Expand All @@ -1413,7 +1428,7 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
ns.assembly(alvWedge.hawRName),
copyOne,
Transform3D(
myrot(ns, alvWedge.hawRName + "R", hawRform.getRotation()),
myrot(ns, alvWedge.hawRName + "_rot", hawRform.getRotation()),
Position(hawRform.getTranslation().x(), hawRform.getTranslation().y(), hawRform.getTranslation().z())));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EBGeomX") << ns.assembly(alvWedge.hawRName).name() << ":" << copyOne << " positioned in "
Expand All @@ -1426,7 +1441,10 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
ns.assembly(alvWedge.hawRName),
copyTwo,
Transform3D(
Rotation3D(1., 0., 0., 0., 1., 0., 0., 0., -1.) * RotationY(M_PI), // rotate about Y after refl thru Z
myrot(
ns,
alvWedge.hawRName + "R2",
Rotation3D(1., 0., 0., 0., 1., 0., 0., 0., -1.) * RotationY(M_PI)), // rotate about Y after refl thru Z
Position(-hawRform.getTranslation().x(), -hawRform.getTranslation().y(), -hawRform.getTranslation().z())));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EBGeomX") << ns.assembly(alvWedge.hawRName).name() << ":" << copyTwo << " positioned in "
Expand Down Expand Up @@ -1489,7 +1507,7 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
ns.assembly(alvWedge.hawRName)
.placeVolume(gridLog,
copyOne,
Transform3D(myrot(ns, grid.name + "R", gridForm.getRotation()),
Transform3D(myrot(ns, grid.name + "_rot", gridForm.getRotation()),
Position(gridForm.getTranslation().x(),
gridForm.getTranslation().y(),
gridForm.getTranslation().z())));
Expand Down Expand Up @@ -1559,7 +1577,7 @@ static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext
);

const string cryDDName(cry.name + sType);
Solid crySolid = mytrap(cry.name, trapCry);
Solid crySolid = mytrap(cryDDName, trapCry);
Volume cryLog = Volume(cryDDName, crySolid, ns.material(cry.mat));

//++++++++++++++++++++++++++++++++++ APD ++++++++++++++++++++++++++++++++++
Expand Down
Expand Up @@ -11,7 +11,7 @@
<!-- support ring solids - refer to outer disk comments -->
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardInnerDiskOuterRing"/>
<String name="SolidName" value="PixelForwardInnerDiskOuterRingZminus"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo - identical names are intentional. They are distinguished by a copy number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue relates to namespaces. In old DD, all components have names qualified by namespaces, so these duplicated names were not a problem since they were in different namespaces. With DD4hep, namespaces are used most, but not all, of the time. These pixel names happen to lack namespaces.

With old DD, these solids are Unions with unique names:

<UnionSolid name="pixfwdInnerDiskZplus:PixelForwardInnerDiskOuterRing">
<UnionSolid name="pixfwdInnerDiskZminus:PixelForwardInnerDiskOuterRing">

With DD4hep, without my fix, these solids get the same names because the namespace is missing (they are CutTubs with DD4hep):

<CutTubs name="PixelForwardInnerDiskOuterRing" dz="10.2500*mm" rMin="114.8500*mm" rMax="117.3500*mm" startPhi="265.0503*deg" deltaPhi="7.9068*deg" lx="-0.0000" ly="-0.0000" lz="-1.0000" tx="0.3970" ty="-0.0069" tz="0.9178"/>
<CutTubs name="PixelForwardInnerDiskOuterRing" dz="10.2500*mm" rMin="114.8500*mm" rMax="117.3500*mm" startPhi="265.0503*deg" deltaPhi="7.9068*deg" lx="0.3970" ly="-0.0069" lz="-0.9178" tx="0.0000" ty="0.0000" tz="1.0000"/>

Note the two solids have the same names but slightly different parameters. With my fix, the definitions become:

<CutTubs name="PixelForwardInnerDiskOuterRingZplus" dz="10.2500*mm" rMin="114.8500*mm" rMax="117.3500*mm" startPhi="265.0503*deg" deltaPhi="7.9068*deg" lx="-0.0000" ly="-0.0000" lz="-1.0000" tx="0.3970" ty="-0.0069" tz="0.9178"/>
<CutTubs name="PixelForwardInnerDiskOuterRingZminus" dz="10.2500*mm" rMin="114.8500*mm" rMax="117.3500*mm" startPhi="265.0503*deg" deltaPhi="7.9068*deg" lx="0.3970" ly="-0.0069" lz="-0.9178" tx="0.0000" ty="0.0000" tz="1.0000"/>

These names are the basis for several solids and logical volumes, so without the fix, there are a set of different components that share the same names.
I suspect that this problem may be related to Gabrielle's PR #32843, where she talks about removing the namespace from Tracker names, but I don't see a direct cause in that PR.
I think it is important to avoid duplicate names for different solids.

<String name="Material" value="pixfwdMaterials:C_C_InnerOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskOuterRingRMin]"/>
Expand All @@ -22,7 +22,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardInnerDiskCFOuterRing"/>
<String name="SolidName" value="PixelForwardInnerDiskCFOuterRingZminus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_InnerOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskOuterRingCFRMin]"/>
Expand All @@ -33,7 +33,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardInnerDiskInnerRing"/>
<String name="SolidName" value="PixelForwardInnerDiskInnerRingZminus"/>
<String name="Material" value="pixfwdMaterials:C_C_InnerInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskInnerRingRMin]"/>
Expand All @@ -44,7 +44,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardInnerDiskCFInnerRing"/>
<String name="SolidName" value="PixelForwardInnerDiskCFInnerRingZminus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_InnerInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskInnerRingCFRMin]"/>
Expand Down
Expand Up @@ -11,7 +11,7 @@
<!-- support ring solids - refer to outer disk comments -->
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardInnerDiskOuterRing"/>
<String name="SolidName" value="PixelForwardInnerDiskOuterRingZplus"/>
<String name="Material" value="pixfwdMaterials:C_C_InnerOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskOuterRingRMin]"/>
Expand All @@ -22,7 +22,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardInnerDiskCFOuterRing"/>
<String name="SolidName" value="PixelForwardInnerDiskCFOuterRingZplus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_InnerOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskOuterRingCFRMin]"/>
Expand All @@ -33,7 +33,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardInnerDiskInnerRing"/>
<String name="SolidName" value="PixelForwardInnerDiskInnerRingZplus"/>
<String name="Material" value="pixfwdMaterials:C_C_InnerInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskInnerRingRMin]"/>
Expand All @@ -44,7 +44,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardInnerDiskCFInnerRing"/>
<String name="SolidName" value="PixelForwardInnerDiskCFInnerRingZplus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_InnerInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:InnerDiskInnerRingCFRMin]"/>
Expand Down
Expand Up @@ -20,7 +20,7 @@
-->
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardOuterDiskOuterRing"/>
<String name="SolidName" value="PixelForwardOuterDiskOuterRingZminus"/>
<String name="Material" value="pixfwdMaterials:C_C_OuterOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskOuterRingRMin]"/>
Expand All @@ -31,7 +31,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardOuterDiskCFOuterRing"/>
<String name="SolidName" value="PixelForwardOuterDiskCFOuterRingZminus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_OuterOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskOuterRingCFRMin]"/>
Expand All @@ -42,7 +42,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardOuterDiskInnerRing"/>
<String name="SolidName" value="PixelForwardOuterDiskInnerRingZminus"/>
<String name="Material" value="pixfwdMaterials:C_C_OuterInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskInnerRingRMin]"/>
Expand All @@ -53,7 +53,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZminus"/>
<String name="SolidName" value="PixelForwardOuterDiskCFInnerRing"/>
<String name="SolidName" value="PixelForwardOuterDiskCFInnerRingZminus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_OuterInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskInnerRingCFRMin]"/>
Expand Down
Expand Up @@ -20,7 +20,7 @@
-->
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardOuterDiskOuterRing"/>
<String name="SolidName" value="PixelForwardOuterDiskOuterRingZplus"/>
<String name="Material" value="pixfwdMaterials:C_C_OuterOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskOuterRingRMin]"/>
Expand All @@ -31,7 +31,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardOuterDiskCFOuterRing"/>
<String name="SolidName" value="PixelForwardOuterDiskCFOuterRingZplus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_OuterOuterRing"/>
<Numeric name="zPos" value="[OuterRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskOuterRingCFRMin]"/>
Expand All @@ -42,7 +42,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardOuterDiskInnerRing"/>
<String name="SolidName" value="PixelForwardOuterDiskInnerRingZplus"/>
<String name="Material" value="pixfwdMaterials:C_C_OuterInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskInnerRingRMin]"/>
Expand All @@ -53,7 +53,7 @@
</Algorithm>
<Algorithm name="track:DDCutTubsFromPoints">
<rParent name="pixfwdDisks:PixelForwardDiskZplus"/>
<String name="SolidName" value="PixelForwardOuterDiskCFInnerRing"/>
<String name="SolidName" value="PixelForwardOuterDiskCFInnerRingZplus"/>
<String name="Material" value="pixfwdMaterials:FPix_CFSkin_OuterInnerRing"/>
<Numeric name="zPos" value="[InnerRingZ]"/>
<Numeric name="rMin" value="[pixfwdSupportRingParameters:OuterDiskInnerRingCFRMin]"/>
Expand Down
2 changes: 2 additions & 0 deletions Geometry/TrackerCommonData/plugins/dd4hep/DDTECModuleAlgo.cc
Expand Up @@ -409,6 +409,7 @@ static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt,
dy = 0.5 * pitchThick;
dz = 0.5 * pitchHeight;
solid = Box(dx, dy, dz);
name += "Box";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo - why? It’s a Box and you can always check it by type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem relates to namespaces. In the old DD, all component names are qualified by namespaces, so these definitions result:

<Box name="tecmodule0r:TECModule0PA" dx="43.9000*mm" dy="0.3325*mm" dz="6.5000*mm"/>
<Trapezoid name="tecmodule0s:TECModule0PA" dz="43.9000*mm" theta="2.8576*deg" phi="0.0000*deg" h1="0.3325*mm" bl1="9.3663*mm" tl1="9.3663*mm" alp1="0.0000*deg" h2="0.3325*mm" bl2="4.9837*mm" tl2="4.9837*mm" alp2="0.0000*deg"/>

but with DD4hep, there is no namespace for these names, so WITHOUT this fix these solid definitions result :

<Box name="TECModule0PA" dx="43.9000*mm" dy="0.3325*mm" dz="6.5000*mm"/>
<Trapezoid name="TECModule0PA" dz="43.9000*mm" theta="2.8576*deg" phi="0.0000*deg" h1="0.3325*mm" bl1="9.3663*mm" tl1="9.3663*mm" alp1="0.0000*deg" h2="0.3325*mm" bl2="4.9837*mm" tl2="4.9837*mm" alp2="0.0000*deg"/>

Here are two different solids with the same name. I don't see how that could work correctly. Running the code with the appended names gives:

<Box name="TECModule0PABox" dx="43.9000*mm" dy="0.3325*mm" dz="6.5000*mm"/>
<Trapezoid name="TECModule0PATrap" dz="43.9000*mm" theta="2.8576*deg" phi="0.0000*deg" h1="0.3325*mm" bl1="9.3663*mm" tl1="9.3663*mm" alp1="0.0000*deg" h2="0.3325*mm" bl2="4.9837*mm" tl2="4.9837*mm" alp2="0.0000*deg"/>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not accidental that one is a Box and the other a Trapezoid?
BTW: what the box is used for in reconstruction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why these two solids were defined as a Box and a Trapezoid. I can only say that this feature is in the old DD and has been there for a long time.

ns.addSolidNS(name, solid);
edm::LogVerbatim("TECGeom") << "Solid:\t" << name << " " << solid.name() << " Box made of " << pitchMat
<< " of dimensions " << dx << ", " << dy << ", " << dz;
Expand All @@ -419,6 +420,7 @@ static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt,
bl2 = 0.5 * pitchHeight - 0.5 * dz * sin(detTilt);
thet = atan((bl1 - bl2) / (2. * dz));
solid = Trap(dz, thet, 0, h1, bl1, bl1, 0, h1, bl2, bl2, 0);
name += "Trap";
ns.addSolidNS(name, solid);
edm::LogVerbatim("TECGeom") << "Solid:\t" << name << " " << solid.name() << " Trap made of " << pitchMat
<< " of dimensions " << dz << ", " << convertRadToDeg(thet) << ", 0, " << h1 << ", "
Expand Down
4 changes: 2 additions & 2 deletions Geometry/TrackerCommonData/plugins/dd4hep/DDTIBLayerAlgo.cc
Expand Up @@ -252,7 +252,7 @@ static long algorithm(Detector& /* description */, cms::DDParsingContext& contex
double dz = 0.5 * layerL - 2. * fillerDz;
double _rmi = std::min(rin + 0.5 * dd4hep::mm, rout - 0.5 * dd4hep::mm);
double _rma = std::max(rin + 0.5 * dd4hep::mm, rout - 0.5 * dd4hep::mm);
solid = ns.addSolidNS(name, Tube(_rmi, _rma, dz, -0.5 * width, width));
solid = ns.addSolidNS(name, Tube(_rmi, _rma, dz, -0.5 * width, 0.5 * width));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo - it is strange that this did not come out in validation. Could you, please, share a snapshot of the geometry fragment before and after? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will reproduce the bug and post the before and after. It is a very small difference, so that is maybe why it wasn't detected earlier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo, I suspect, that old variant of the Tube was correct. The signature of the Tube:
rmin, rmax, dz, phi1, phi2. Problem is in badly chosen name "width", it should be "phiWidth". It is correct to have "-0.5*phiwidth, phiwidth".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can compare old DD with DD4hep for these tubes. Here is old DD:

<Tubs name="tiblayer0:TIBLayer0Rib0" rMin="254.0000*mm" rMax="258.0000*mm" dz="696.0000*mm" startPhi="-3.9167*deg" deltaPhi="7.8334*deg"/>

Here is DD4hep WITHOUT the fix:

<Tubs name="tiblayer0:TIBLayer0Rib0" rMin="254.0000*mm" rMax="258.0000*mm" dz="696.0000*mm" startPhi="-3.9167*deg" deltaPhi="11.7501*deg"/>

The problem comes from the change in the Tube constructor between old DD and DD4hep. In old DD, the last parameter is deltaPhi:

tubs(const DDName& name, double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)

and the corresponding line of code is:

tubs(DDName(name, idNameSpace), dz, rin + 0.5 * CLHEP::mm, rout -0.5* CLHEP::mm, -0.5* width, width);

but with DD4hep the last parameter is endPhi:

Tube (double rmin, double rmax, double dz, double startPhi, double endPhi)

so the last the last parameter with DD4hep needs to be endPhi = startPhi + deltaPhi. As long as startPhi is 0, the old and new parameters are the same, but in this case, startPhi is not 0.
With the fix, DD4hep gives the correct values:

<Tubs name="tiblayer0:TIBLayer0Rib0" rMin="254.0000*mm" rMax="258.0000*mm" dz="696.0000*mm" startPhi="-3.9167*deg" deltaPhi="7.8334*deg"/>

It is unfortunate that this bug was not found until now. I think it affects about 20 solids. I would think we would want to fix it now, rather than leaving it for all of Run 3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo , thank you for the explanation but in my view what DD4Hep did is a scandal - they change signature in a place which is very difficult to debug. We may have thousands similar places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@civanch I did a systematic comparison of all solids between old DD and DD4hep. That's how I discovered the minor discrepancies discussed in this PR. I don't think there are any more. Probably, in most cases for tubes, startPhi is 0, so there is no chance of problem, and in the other cases, endPhi is set correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo - it would be good to see a snapshot before and after the fix. I'd assume there would be an overlap detected with a double delta phi. Also, it is not obvious what DD4hep is doing when constructing the shape. Sometimes the arguments may differ.

LogDebug("TIBGeom") << solid.name() << " Tubs made of " << ribMat << " from " << -0.5 * convertRadToDeg(width)
<< " to " << 0.5 * convertRadToDeg(width) << " with Rin " << rin + 0.5 * dd4hep::mm << " Rout "
<< rout - 0.5 * dd4hep::mm << " ZHalf " << dz;
Expand Down Expand Up @@ -490,7 +490,7 @@ static long algorithm(Detector& /* description */, cms::DDParsingContext& contex
break;
}

solid = ns.addSolidNS(name, Tube(pillarRin, pillarRout, pillarDz, -pillarDPhi, 2. * pillarDPhi));
solid = ns.addSolidNS(name, Tube(pillarRin, pillarRout, pillarDz, -pillarDPhi, pillarDPhi));
Volume Pillar = ns.addVolumeNS(Volume(name, solid, ns.material(pillarMaterial)));
LogDebug("TIBGeom") << solid.name() << " Tubs made of " << pillarMaterial << " from " << -pillarDPhi << " to "
<< pillarDPhi << " with Rin " << pillarRin << " Rout " << pillarRout << " ZHalf " << pillarDz;
Expand Down