Opening a file in update mode causes Error in <TBasket::Streamer>: The value of fNbytes is incorrect

Indeed. The geant4 reimplementation has a flaw that makes the file not update-able. Instead you need to first copy the file with ROOT (hadd -f output_updatable.root output_good.root) then update the copy.

Namely the problem is that TFile meta data record stored by the Geant4 is shorter than expected. Hence when ROOT write the TFile meta data it inadvertently overwrites enough of the data to make the file unusable.

See https://gitlab.cern.ch/geant4/geant4-dev/-/blob/master/source/analysis/g4tools/include/tools/rroot/directory#L85
vs
ROOT: TDirectoryFile Class Reference

Cheers,
Philippe.