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

feat: support TGeoTessellated volumes in DetectorChecksum #1141

Merged
merged 12 commits into from
Jul 13, 2023
Merged
50 changes: 49 additions & 1 deletion DDCore/src/plugins/DetectorChecksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,48 @@ const DetectorChecksum::entry_t& DetectorChecksum::handleSolid(Solid solid) cons
else if ( shape->IsA() == TGeoShapeAssembly::Class() ) {
log << "<shape_assembly " << nam << "\"/>";
}
else if ( shape->IsA() == TGeoTessellated::Class() ) {
if ( hash_meshes ) {
const TGeoTessellated* sh = (TGeoTessellated*)shape;
log << "<define>" << newline;
if ( sh->IsClosedBody() == false ) {
except("DetectorChecksum","+++ TGeoTessellated volume is not closed: %s", solid.name());
}
for (int ivertex = 0; ivertex < sh->GetNvertices(); ivertex++) {
// Note: const_cast since TGeoTessellated::GetVertex not marked const in ROOT <= 6.28
const auto& vtx = const_cast<TGeoTessellated*>(sh)->GetVertex(ivertex);
log << "<position name\"" << nam << "_v" << ivertex
<< " lunit=\"" << m_len_unit_nam << "\""
<< " x=\"" << vtx.x()/m_len_unit << "\""
<< " y=\"" << vtx.y()/m_len_unit << "\""
<< " z=\"" << vtx.z()/m_len_unit << "\""
<< "/>" << newline;
}
log << "</define>" << newline;
log << "<tessellated name=\"" << nam << "\">" << newline;
for (int ifacet = 0; ifacet < sh->GetNfacets(); ifacet++) {
// Note: const_cast since TGeoTessellated::GetFacet not marked const in ROOT <= 6.28
const auto& facet = const_cast<TGeoTessellated*>(sh)->GetFacet(ifacet);
if ( facet.GetNvert() == 3 ) {
log << "<triangular";
}
else if ( facet.GetNvert() == 4 ) {
log << "<quadrangular";
}
else {
except("DetectorChecksum","+++ TGeoTessellated volume with unsupported number of vertices: %s", solid.name());
}
for (int ivertex = 0; ivertex < facet.GetNvert(); ivertex++) {
log << " vertex" << ivertex + 1 << "=\"" << nam << "_v" << facet.GetVertexIndex(ivertex) << "\"";
}
log << " type=\"ABSOLUTE\"/>" << newline;
}
log << "</tessellated>" << newline;
}
else {
log << "<tessellated></tessellated>" << newline;
}
}
else {
except("DetectorChecksum","+++ Unknown shape: %s", solid.name());
}
Expand Down Expand Up @@ -1269,7 +1311,7 @@ void DetectorChecksum::dump_sensitives() const {

static long create_checksum(Detector& description, int argc, char** argv) {
std::vector<std::string> detectors;
int precision = 6, newline = 1, level = 1, readout = 0, debug = 0;
int precision = 6, newline = 1, level = 1, meshes = 0, readout = 0, debug = 0;
int dump_elements = 0, dump_materials = 0, dump_solids = 0, dump_volumes = 0;
int dump_placements = 0, dump_detelements = 0, dump_sensitives = 0;
int dump_iddesc = 0, dump_segmentations = 0;
Expand All @@ -1296,6 +1338,8 @@ static long create_checksum(Detector& description, int argc, char** argv) {
debug = ::atol(argv[++i]);
else if ( 0 == ::strncmp("+newline",argv[i],5) )
newline = 0;
else if ( 0 == ::strncmp("-meshes",argv[i],5) )
meshes = 1;
else if ( 0 == ::strncmp("-readout",argv[i],5) )
readout = 1;
else if ( 0 == ::strncmp("-dump_elements",argv[i],10) )
Expand All @@ -1320,6 +1364,9 @@ static long create_checksum(Detector& description, int argc, char** argv) {
std::cout <<
"Usage: -plugin DD4hepDetectorChecksum -arg [-arg] \n\n"
" -detector <string> Top level DetElement path. Default: '/world' \n"
" -meshes also hash the detector's meshed solids \n"
" (may be sensitive to changes due to rounding) \n"
" default: false \n"
" -readout also hash the detector's readout properties \n"
" (sensitive det, id desc, segmentation) \n"
" default: false \n"
Expand Down Expand Up @@ -1359,6 +1406,7 @@ static long create_checksum(Detector& description, int argc, char** argv) {
if ( !dens_unit.empty() ) wr.m_densunit_nam = dens_unit;
if ( !atom_unit.empty() ) wr.m_atomunit_nam = atom_unit;
if ( newline ) wr.newline = "\n";
wr.hash_meshes = meshes;
wr.hash_readout = readout;
wr.max_level = level;
wr.debug = debug;
Expand Down
2 changes: 2 additions & 0 deletions DDCore/src/plugins/DetectorChecksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ namespace dd4hep {

/// Property: precision of hashed printouts
mutable int precision { 6 };
/// Property: Include meshed solids in detector hash
int hash_meshes { 0 };
/// Property: Include readout property in detector hash
int hash_readout { 0 };
/// Property: maximum depth level for printouts
Expand Down
18 changes: 18 additions & 0 deletions examples/ClientTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,24 @@ dd4hep_add_test_reg( MiniTel_check_checksum_full
REGEX_FAIL "Exception;EXCEPTION;ERROR"
)
#
# Checksum test of a tessellated solid (default, without meshes)
dd4hep_add_test_reg( Check_Shape_Tessellated_check_checksum
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
EXEC_ARGS geoPluginRun -input ${ClientTestsEx_INSTALL}/compact/Check_Shape_Tessellated.xml
-plugin DD4hepDetectorChecksum
REGEX_PASS "Combined hash code c8eb13dd1d4d9ca1 \\(13 sub-codes\\)"
REGEX_FAIL "Exception;EXCEPTION;ERROR"
)
#
# Checksum test of a tessellated solid (with meshes)
dd4hep_add_test_reg( Check_Shape_Tessellated_check_checksum_with_meshes
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
EXEC_ARGS geoPluginRun -input ${ClientTestsEx_INSTALL}/compact/Check_Shape_Tessellated.xml
-plugin DD4hepDetectorChecksum -meshes -precision 3
REGEX_PASS "Combined hash code ada64a13764bb466 \\(13 sub-codes\\)"
REGEX_FAIL "Exception;EXCEPTION;ERROR"
)
#
# Test the sequential processing of two xml files
dd4hep_add_test_reg( minitel_config_plugins_include_command_line
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
Expand Down
Loading