- jwebb's home page
- Posts
- 2019
- 2018
- 2017
- 2016
- 2015
- 2014
- 2013
- November (1)
- October (1)
- September (1)
- July (1)
- June (1)
- April (1)
- March (3)
- February (1)
- January (1)
- 2012
- 2011
- December (2)
- September (3)
- August (5)
- July (6)
- June (6)
- May (1)
- April (5)
- March (5)
- February (2)
- January (2)
- 2010
- December (3)
- October (3)
- September (2)
- August (2)
- June (2)
- May (4)
- April (4)
- March (2)
- February (4)
- January (10)
- 2009
- 2008
- 2007
- 2006
- July (1)
- My blog
- Post new blog entry
- All blogs
HOWTO: Check for overlaps / extrusions in a geometry using TGeoChecker
Root's TGeoChecker class provides some useful functions to check for errors in geometries. A simple example (in pseudocode) would look like:
# Create a new manager
TGeoManager *manager = new TGeoManager()
buildTheGeometry();
# Create the checker code
TGeoChecker *checker = new TGeoChecker( manager );
# Check for overlap between top-level and daughters to a tolerance
# of 0.001 cm. And provide a "f"ull check of the volume.
TGeoVolume *top = manager->GetTopVolume();
checker->CheckOverlaps( top, 0.001, "f" )
# Finally print a list of the overlaps and extrusions
checker->PrintOverlaps();
A much more sophisticated (and working) example is included below. It takes as input the name of the volume you want to examine, then recursively follows the daughter volumes to examine the full geometry. It should be noted that many of the overlaps which this code will find will likely be intended in the geometry... one typically uses two or more overlapping volumes to construct shapes more complicated than what root/geant/etc... provides by default. Extrusions are a different matter. When a volume extrudes it's mother volume, the offending volume will never be seen by particles traversing the geometry.
TGeoChecker *gGeoChecker = 0;
Double_t gTolerance = 0.0001;
Int_t gRecurseLevel = 0;
void checker( const Char_t *toplevel = "TPCE" )
{
gROOT->LoadMacro("y2006h.h");
y2006h();
// Set the top volume we are interested in checking, and
// punt if it wasn't found in the geometry
TGeoVolume *top = gGeoManager->GetVolume( toplevel );
if ( !top )
{
std::cout << Form("%s was not found",toplevel) << std::endl;
return;
}
gGeoManager->SetTopVolume(top);
// Instance of the handy but little known TGeoChecker
gGeoChecker = new TGeoChecker( gGeoManager );
// Check for overlaping / extruding volumes in the specified
// volume, and recursively descend into all sub volumes
checkForOverlaps( top );
std::cout << std::endl;
std::cout << std::endl;
// Print out any overlaps found
gGeoChecker->PrintOverlaps();
}
void checkForOverlaps( TGeoVolume *volume )
{
if ( gRecurseLevel < 2 )
std::cout << Form("\nExamining: %s ",volume->GetName());
gRecurseLevel++; // increment recursion level on call
// Check for overlaps in this volume
gGeoChecker->CheckOverlaps( volume, gTolerance, "f" );
TObjArray *nodes = volume->GetNodes();
TIter next(nodes);
TGeoNode *node;
//
// Iterate over all nodes in this volume, calling checkForOverlaps
// on each corresponding daughter volume. This may take a while,
// so the top-level daughters get a printout.
//
while ( node = (TGeoNode*)next() )
{
volume = node->GetVolume();
assert(volume);
// std::cout << Form(".");
checkForOverlaps( volume );
}
gRecurseLevel--; // decrement recursion level on exit
}
- jwebb's blog
- Login or register to post comments