fcs-proj / FastCaloSim

An experiment-independent library for fast calorimeter simulation
Apache License 2.0
2 stars 0 forks source link

New geometry implementation #35

Closed jbeirer closed 1 month ago

jbeirer commented 2 months ago

This pull request fully redesigns the way we handle the gometry in FastCaloSim, especially the hit to cell matching. Previously, complex detector maps were built that allowed for a fast cell lookup based on the η-φ and x-y (FCAL) positions. This has in many cases a direct dependence on the ATLAS geometry. Now, the cell data is loaded into RTree's (one per layer) that allow for a fast cell lookup given a position in the detector. This massively simplifies the geometry handling. Simulation remains largely unchanged, but some differences are unavoidable:

As expected, the R-tree lookup is significantly slower $O(\log(n))$ than the old approach (x100), but this is not expected to become a bottleneck:

Screenshot 2024-09-23 at 16 55 41

The hit-to-cell matching assumes regular cuboid cells. If this approximation is not sufficient or experiments want to implement a faster lookup such as for the ATLAS FCal, this can be done via setting alternative geo handlers to the geometry:

// Create alternative geometry handler for FCal
std::shared_ptr<FCal> fcal_geo = std::make_shared<FCal>();
// Load the FCal geometry from the files
fcal_geo->load(AtlasGeoTestsConfig::FCAL_ELECTRODE_FILES);
// Cast the FCal geometry handler to the geo interface
std::shared_ptr<CaloGeo> fcal_geo_handler =
std::static_pointer_cast<CaloGeo>(fcal_geo);
// Set the alternative geometry handler for the FCal layers (21 - 23)
geo->set_alt_geo_handler(21, 23, fcal_geo_handler);

Currently we use an std::map for mapping the cell id to the energy depositions to be able to have a consistent CI comparison. This will change to std::unorderd_map to allow for faster average lookup times of $O(1)$.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 84.74903% with 79 lines in your changes missing coverage. Please review.

Project coverage is 36.48%. Comparing base (d58256e) to head (4a758b5). Report is 1 commits behind head on main.

:white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
include/FastCaloSim/Geometry/Cell.h 51.42% 17 Missing :warning:
source/Core/TFCSExtrapolationState.cxx 7.14% 13 Missing :warning:
source/Geometry/CaloGeo.cxx 87.96% 13 Missing :warning:
source/Core/TFCSPredictExtrapWeights.cxx 0.00% 12 Missing :warning:
include/FastCaloSim/Geometry/FCal.h 94.21% 7 Missing :warning:
...ce/Core/TFCSLateralShapeParametrizationHitBase.cxx 0.00% 4 Missing :warning:
source/Core/TFCSEnergyAndHitGANV2.cxx 0.00% 3 Missing :warning:
source/Core/TFCSHitCellMappingFCal.cxx 83.33% 2 Missing :warning:
source/Core/TFCSSimulationState.cxx 66.66% 2 Missing :warning:
include/FastCaloSim/Core/TFCSEnergyAndHitGANV2.h 0.00% 1 Missing :warning:
... and 5 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #35 +/- ## ========================================== - Coverage 38.54% 36.48% -2.07% ========================================== Files 223 211 -12 Lines 10641 9476 -1165 Branches 1516 1334 -182 ========================================== - Hits 4102 3457 -645 + Misses 6539 6019 -520 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.