Hello,
I suggest to take a look at the slides on the Analysis presented at the Orsay Geant4 tutorial:
https://groups.ijclab.in2p3.fr/ED-geant4/2020-session-6/
and to the section on Analysis in the Application Developer Guide:
https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/Analysis/analysis.html
Best regards.