How to get the number of real electrons generated and the electrons collected

Maybe you need to add ROOT::MathMore to the list of libraries in your CMakeLists.txt?

add_executable(gem gem.C)
target_link_libraries(gem Garfield::Garfield ROOT::MathMore)