AIDASoft / DD4hep

Detector Description Toolkit for High Energy Physics
http://dd4hep.cern.ch
GNU Lesser General Public License v3.0
53 stars 100 forks source link

Controlling Geant4 smart voxelization from the detector constructor #1361

Open atolosadelgado opened 10 hours ago

atolosadelgado commented 10 hours ago

Hi,

If I understand correctly, the DD4hep class Volume [link] is the equivalent to Logical Volume in Geant4. I was wondering if it would be possible to expose the following functions [link] of G4LogicalVolume from the DD4hep Volume:

    // File: source/geometry/management/include/G4LogicalVolume.hh, line 294 
    inline G4double GetSmartless() const;
    inline void SetSmartless(G4double s);
    inline G4bool IsToOptimise() const;
    inline void SetOptimisation(G4bool optim);

In my case I am dealing with the full stereo drift chamber, which may be very extreme when creating the voxelization because of the twisted geometry. I would like to investigate if it is possible to fine tune the granularity of the voxelization so it can be a better option to using hyperboloids as layers. With the Geant4 default settings, the voxelization causes the memory to explode: 4GB (60k wires placed directly into the main volume) [1] vs 2.7GB (60k placed in 112 different layers) [2].

Without the possibility of tuning the granularity of the smart voxelization, I guess the use of hyperboloids is preferred because of the smaller memory consumption, even if the tracking is slower.

Thank you for your time.

Best, Alvaro

[1] When placing wires directly into the main gas volume, so the geometry tree looks like "main gas, cylinder" -> "wires" x60000

G4GeometryManager::ReportVoxelStats -- Voxel Statistics

    Total memory consumed for geometry optimisation:   1476755 kByte
    Total CPU time elapsed for geometry optimisation: 92 seconds

    Voxelisation: top CPU users:
    Percent   Total CPU    System CPU       Memory  Volume
    -------   ----------   ----------     --------  ----------
      99.74        91.32         0.64      1476756k DCH_v2_gas

    Voxelisation: top memory users:
    Percent     Memory      Heads    Nodes   Pointers    Total CPU    Volume
    -------   --------     ------   ------   --------   ----------    ----------
     100.00    1476755k    892233 23403932   40571076        91.32    DCH_v2_gas

[2] When using hyperboloids as layers, so the geometry tree looks like "main gas, cylinder" -> "gas layer, hyperboloid" x112 -> "wires" x60000

G4GeometryManager::ReportVoxelStats -- Voxel Statistics

    Total memory consumed for geometry optimisation:   539877 kByte
    Total CPU time elapsed for geometry optimisation: 27 seconds

    Voxelisation: top CPU users:
    Percent   Total CPU    System CPU       Memory  Volume
    -------   ----------   ----------     --------  ----------
       2.12         0.58         0.01        11597k DCH_v2_layer109
       2.12         0.58         0.01        11626k DCH_v2_layer111
       2.12         0.58         0.00        11544k DCH_v2_layer107
       2.04         0.56         0.01        11550k DCH_v2_layer105
       1.93         0.53         0.01        10561k DCH_v2_layer99
       1.82         0.50         0.00        10623k DCH_v2_layer103
       1.82         0.50         0.00        10577k DCH_v2_layer101
       1.79         0.49         0.00         8578k DCH_v2_layer112
       1.79         0.49         0.01         9983k DCH_v2_layer91
       1.79         0.49         0.01         9979k DCH_v2_layer93

    Voxelisation: top memory users:
    Percent     Memory      Heads    Nodes   Pointers    Total CPU    Volume
    -------   --------     ------   ------   --------   ----------    ----------
       2.15      11625k      5651   189804     298392         0.58    DCH_v2_layer111
       2.15      11596k      5665   189230     297988         0.58    DCH_v2_layer109
       2.14      11549k      5713   188264     297336         0.56    DCH_v2_layer105
       2.14      11543k      5679   188248     296992         0.58    DCH_v2_layer107
       1.97      10623k      4919   174206     270288         0.50    DCH_v2_layer103
       1.96      10577k      4933   173348     269412         0.50    DCH_v2_layer101
       1.96      10561k      4951   173008     269256         0.53    DCH_v2_layer99
       1.95      10506k      4951   171986     268388         0.49    DCH_v2_layer97
       1.86      10020k      4333   164900     254204         0.49    DCH_v2_layer95
       1.85       9994k      4375   164290     254212         0.47    DCH_v2_layer89
andresailer commented 10 hours ago

At what phase of Geant4 do these values have to be set?

atolosadelgado commented 9 hours ago

At what phase of Geant4 do these values have to be set?

These values are set when instantiating the logical volumes [link]. There is no UI command for later modification.

andresailer commented 7 hours ago

Why do you need to access

?

Is the ability to SetSmartless(G4double s), enough?

andresailer commented 6 hours ago

The problem is to pass all that information from DD4hep volumes to G4LogicalVolumes, and maybe needing to expose more functions...

So maybe we can try this:

Create your own G4LogicalVolume plugin to create G4LogicalVolumes that you fully control. See https://github.com/AIDASoft/DD4hep/blob/master/examples/DDG4/src/ChannelingCrystalVolume.cpp as an example, e.g. SmartlessLogicalVolume

In the c++ where you create your volumes then put something like this

    Volume vol = Volume("Volume", solid, material);
    // ...
    vol.addProperty("Geant4-plugin", "SmartlessLogicalVolume");

Then the Geant4Converter will use your code to create the G4LogicalVolume

https://github.com/AIDASoft/DD4hep/blob/960cfa063b0ad2b90d6b5211ba52ff7f4dae9087/DDG4/src/Geant4Converter.cpp#L787-L795

See the release notes entry https://github.com/AIDASoft/DD4hep/blob/960cfa063b0ad2b90d6b5211ba52ff7f4dae9087/doc/ReleaseNotes.md?plain=1#L1065