Need advise with parsing of CSV file

Hello all!

I have trouble when I manually parse the “.csv” file with a 2D histogram. Unfortunately, I have not found any information about “.CSV” file format in the official GEANT4 documentation. I hope in future versions somebody will add it.

I create analysis manager in a standard way:

using G4AnalysisManager = G4CsvAnalysisManager;
G4int id2d2 = man->CreateH2(“X_Y”, “Energy distribution X-Y plane (cm, MeV)”, 200, -1, 1, 500, 0., 5.);

at the end, I get file which contains data like this:

#class tools::histo::h2d
#title Energy distribution X-Y plane (cm, MeV)
#dimension 2
#axis fixed 200 -1 1
#axis fixed 500 0 5
#planes_Sxyw -1.71347
#annotation axis_x.title
#annotation axis_y.title
#bin_number 101404

How correctly restore grid of X, Y - axis from this data and find corresponding Z value?

here is my interpretation, hope someone can confirm:

there are 2 extra bins per dimension, collecting overflow and underflow (values smaller/larger than your limits)
hence in your example (200+2)*(500+2)=101404

x/y axis is given by equal spacing from -1 to 1 in N+1 steps (linspace(-1,1,201) in matlab for the first axis), but this defines the edges of each bin. center of each bin you have to calculate on your own :wink:
z-value is the second column in the csv (if you have a weight factor of 1 this is identical to the first column).

assemble the data into a matrix in the same order as the “axis fixed …”-lines, then you can use e.g. matrix(2:end-1,2:end-1) for the values without over/underflow