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
world →
Illegal 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
gGeoManager->getCurrentNode()->CheckOverlaps(0.01);
gGeoManager->PrintOverlaps();
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:
/run/initialize
/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
dumpHits.py
(
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
78c78
< const Int_t NG = 33;
---
> const Int_t NG = 34;
82a83
> "clicd",
116a118
> 1, //clicd - added by protopop@cern.ch
150a153
> 0.4, //clicd
184a188
> {900,900,1400}, // clicd
255a260,262
> if(i==4)
> TGeoManager::Import(Form("http://www.ppe.gla.ac.uk/~protopop/clic/%s", 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/phas.gla.ac.uk/data/ilc/software/ilcsoft/v01-17/init_ilcsoft.sh
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
gGeoManager->Export("ECal_new.root");
and we put it in the same location as above (
http://www.ppe.gla.ac.uk/~protopop/clic/clicd.root), 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 http://root.cern.ch/files/clicd_ref_1.root [./files/clicd_ref_1.root]
Reference file http://root.cern.ch/files/clicd_ref_1.root 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.safe=129.087, 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.safe=0.0221592, 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:
compare.sh.
Troubleshooting
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.