Geometry validation

Once the desired geometry is implemented in DD4hep, one need a way to compare it with the existing descriptions from Mokka or GeomConverter. This wiki describes several options for doing this. Lots of thanks to Andrei Gheață and Nikiforos Nikiforou for demonstrating how various tools work.

Visual validation

First step is of course visual validation.To compare by eye an existing geometry with the newly implemented geometry in DD4hep, one should use the visualisation tools described in the VisuDet wiki.

Checking overlaps

Let's say we start with the examples/CLICSiD geometry and we remove everything except the ECal Barrel and EndCap components.

Running ./geoDisplay compact/ECal.xml as described here, we load this geometry in memory and display it using the TGeo class from ROOT:


To check overlaps or extrusions, from ROOT prompt run

root [0]  gGeoManager->CheckOverlaps(0.01);
where the precision is given in cm. This will report any overlaps/extrusions:
Info in <TGeoNodeMatrix::CheckOverlaps>: Number of illegal overlaps/extrusions : 31
To visualise the overlaps/extrusions, navigate in the ROOT TBrowser to worldIllegal overlaps and you will be able to see something like this:


The offending subvolumes are highlighted in red. Some other useful commands:

gGeoManager->cd(/path/to/volume/); // to check only a subvolume
gGeoManager->GetPath();   // to see current path

Shooting particles with Geant4/SLIC

One can shoot particles using SLIC MC, and save output to a slcio file, then use anajob or dumpevent to compare hit positions.

To do this, setup ilcsoft to get access to SLIC and the LCIO libraries (for later processing of slcio files). Then create a file, e.g. particleGun.mac, containing something like this:

/generator/select gps
/gps/pos/type Point
/gps/pos/centre 0. 0. 0.
/gps/ang/type iso
/gps/ang/mintheta 90 deg
/gps/ang/maxtheta 90 deg
/gps/ang/minphi 10 deg
/gps/ang/maxphi 10 deg
/gps/ene/type Mono
/gps/ene/mono 99.8944 GeV
/gps/ene/gradient 0
/gps/ene/intercept 1
/gps/particle mu-
/random/seed 123456789
/run/beamOn 1 

Run SLIC, loading the geometry and running this macro:

slic -g geometry.lcdd -m particleGun.mac

This will create a file named outfile.slcio. Now run:

anajob outfile.slcio
to see hit counts, or
dumpevent outfile.slcio 1
or use (attached, modify at will) to print various hit parameters. For this to run, SLIC must be built with BUILD_ROOTDICT=ON.

Stress tests

There is a TGeo tool for checking geometries. Although written for testing actual TGeo class implementations, one could use this to compare for example two descriptions produced let's say via different frameworks, and spot if any differences were introduced. A good description of how it actually works can be found in the header of the C++ source file

Go to directory $ROOTSYS/test and edit stressGeometry.cxx to add a custom entry. In my case a diff shows these changes:

[protopop@ppelx ECal]$ diff $ROOTSYS/test/stressGeometry.cxx.orig $ROOTSYS/test/stressGeometry.cxx
< const Int_t NG = 33;
> const Int_t NG = 34;
>                         "clicd",
>               1, //clicd - added by
>                               0.4,  //clicd
>                          {900,900,1400},    // clicd
>       if(i==4)
>    TGeoManager::Import(Form("", fname.Data()));
>       else
where the original geometry file clicd.root was created with gGeoManager->Export("clicd.root"); after importing it from another format, e.g. GDML (and removing for this example everything but the ECal).

We recompile

source /afs/
cd $ROOTSYS/test/
make stressGeometry
and run
./stressGeometry clicd
This will generate a file called clicd_ref_1.root and put it in $ROOTSYS/test/files. This is the reference that will be used for all our subsequent comparisons.

Now let's say we want to compare our newly implemented geometry with the original. We save our new geometry with

and we put it in the same location as above (, e.g. cp ECal_new.root ~/web/clic/clicd.root

For example, if we have changed EcalEndcap_zmin from 165.70cm to 164.70cm between the two models, we get


[protopop@ppelx test]$ ./stressGeometry clicd
Info in <TFile::OpenFromCache>: using local cache copy of [./files/clicd_ref_1.root]
Reference file found
 ==>Point 45 differs with diff = 35.4858, x=47.3349, y=4.26597, z=-370.913
    p.nbound=112, p.length=907.019,, p.rad=724.119
      nbound=116,   length=907.019,   safe=129.087,   rad=759.605
 ==>Point 1057 differs with diff = 63.411, x=-39.6917, y=-27.223, z=166.572
    p.nbound=75, p.length=795.659,, p.rad=574.564
      nbound=80,   length=795.659,   safe=0.0221592,   rad=637.975
*Tree    :TD        : TGeo stress diff                                       *
*Entries :      160 : Total =           10359 bytes  File  Size =       5420 *
*        :          : Tree compression factor =   1.00                       *
*Br    0 :p         : x/D:y/D:z/D:theta/D:phi/D:rad[4]/F                     *
*Entries :      160 : Total  Size=       9993 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*     stress clicd            found    80 bad points ............. failed
The statistics can be adjusted by changing Npoints = 10000; from its default.

And here's the optimised version of stressGeometry.cxx which I've been using lately. Easier to use in conjunction with this script:


If you don't have that already, then install your own version of ROOT, so that you can customise it.

You might have to delete ROOT's local cache of the geometry file (clicd.root in the above example), or simply store it locally in order to make sure the newest version is loaded for comparison with the reference. Once created, the reference remains in $ROOTSYS/test/files/ and you will have to delete it to force the creation of a new one.

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng ECal1.png r1 manage 17.7 K 2014-06-19 - 14:00 DanProtopopescu ECal visualised in geoDisplay
Unix shell scriptsh r1 manage 0.6 K 2014-12-10 - 11:53 DanProtopopescu Shell script to use in conjunction with stressGeometry
Texttxt r2 r1 manage 1.1 K 2014-06-24 - 14:27 DanProtopopescu Script used to extract hit positions from slcio file
PNGpng extrusion.png r1 manage 32.2 K 2014-06-19 - 14:01 DanProtopopescu Extrusion detected by CheckOverlaps()
Unknown file formatcxx stressGeometry.cxx r1 manage 23.4 K 2014-12-10 - 11:44 DanProtopopescu Modified stressGeompetry.cxx source file
Topic revision: r12 - 2014-12-10 - DanProtopopescu
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback