Filling histogram with G4AnalysisManager from sensitive detector

I have been trying to fill a histogram with a energy spectrum of incident neutrons hitting a target.

I have defined a target volume, defined a sensitive detector, defined a primitive scorer (G4PSFlatSurfaceCurrent) with a particle filter, assigned that scorer to the sensitive detector and that sensitive detector to the target volume.

I have instanced G4AnalysisManager at the beginning of the run, and created a 1D histogram and a G4TScoreHistFiller.

At the end of an event, I instance G4AnalysisManager and G4SDManager, get a HCofThisEvent, and assign the values of the primitive scorer’s hit collection to a map, then assign the value of the map to a variable with fills the histogram.

but when I G4cout that variable that fills the histogram at the end, it outputs zeroes only, so one of the necessary steps is broken or missing. If any of you have any insight, I would greatly appreciate it.


I think that G4TScoreHistFiller is useful when you use command-based scoring (see Command-based scoring — Book For Application Developers 11.1 documentation)

In your use case, you can rather follow the basic example B4d, which demonstrates how to fill the scorers data in histograms using G4AnalysisManager.

Best regards,