Display units on root file

I would like to know what the energy scale my root file is displaying in the TBrowser.
Is there a way to assign units to the histogram x-axis so that I could see what this looks like, for example, on the keV scale? Can I do this within the Geant4 application?

Have you tried defining the unit when creating the histogram? No idea if the TBrowser respects this, but I think it’s worth the try :slight_smile:


G4int CreateH1(const G4String& name, const G4String& title,
               G4int nbins, G4double xmin, G4double xmax,
               const G4String& unitName = "none", // <- define unit here 
               const G4String& fcnName = "none", 
               const G4String& binSchemeName = "linear");


If you define a unit in CreateH1, then this unit will be applied to all filled values and a label with this unit will appear on the H1 x-axis; eg. [keV] in your case. But you should be careful and not apply the unit when filling your histogram.

There is also a possibility to define the axis title using

G4bool SetH1XAxisTitle(G4int id, const G4String& title);
G4bool SetH1YAxisTitle(G4int id, const G4String& title);

or corresponding UI commands.

Best regards,

I am currently using Ntuples to gather data, and I am storing them as G4doubles. I am not sure if G4doubles store some sort of unit data, as I am able to call G4BestUnit on the double I am storing.


I’m pretty sure, though, that this function just looks at the order of magnitude of the double and assigns the unit based on the string I provide.

I also found that there are Ntuples that can be formed with strings, but I do not know if specific values from S columns can be accessed to display information about the graph.

G4bool FillNtupleSColumn(G4int id, const G4String& value);

They don’t.



If you don’t divide by a specific unit before filling the value into the ntuple (not recommended), you will likely have MeV as the unit for energies, as that is the base unit according to the manual.

Ok, that’s what I expected. Thank you for your help!