How to create 2D Histogram with energy units

Hi all,

I have two different energy spectrum waves (x=Counts vs y=Energy) that I want to plot.  Individually, the waves have been XY paired with the correct energy scaling.  I need to plot the two waves in a 2D histogram to find different characteristics at specific energies.  Here is my code snippet to create a 2D histogram

function TwoDHist(X,Y, XRange, YRange, XBinNum,YBinNum, runtime, trialnum)
    wave X, Y
    variable XBinNum, YBinNum, XRange, YRange, runtime
    String TrialNum
    variable i, N=numpnts(Y), XIndex, YIndex
    Make/N=(XBinNum+1,YBinNum+1)/O wave2D
   
    for (i=0; i<N; i+=1)
        XIndex = (X[i]/(XRange/XBinNum)) // divided by bin widths
        YIndex = Y[i]/(YRange/YBinNum)
        if ((0 < XIndex) && (XIndex < XBinNum) && (0 < YIndex) && (YIndex < YBinNum))
            wave2D [XIndex][Yindex] +=1  // Add a value of 1 to specified coordinate
        endif
    endfor

wave2D = wave2D/runtime //Normalize by run time

String WaveTwoD     // Rename wave
WaveTwoD = "Wave2D" + Trialnum
Rename Wave2D $WaveTwoD

end

With this code, it will only plot counts versus counts, whereas I need to have the histogram as energy versus energy. I hope I'm not misunderstanding my own code.  Thanks in advance!

Perhaps you should be using the JointHistogram operation.

But if you make a 2D histogram of two data sets with counts and energy, shouldn't the result be counts vs energy?

I am little curious on the choice of wave names specifically X and Y since they are reserved for scaling functionality.

Would there use cause a compilation issue?  Do you get the same result choosing other names?

 

Andy

In reply to by johnweeks

I don't believe so. In my case, the X[i]/(Xrange/BinNum) is indexing the counts, which are assigned to a specific energy, and using that as the parameter to fill the 2D Histogram.  I may be misunderstanding this though.

Yes, X and Y are Igor functions to return X and Y values when used on the right-hand-side of a wave assignment. But in what was probably a historical design error, you are allowed to create variables that hide those functions. It is not good code, however, even though you will find WaveMetrics examples that use X this way.

In my first posting above, I think I misunderstood your question at the very end. I think perhaps your question is really the fact that as written, when you make an image plot using your 2D wave the axes run from [0, N-1]. But you want something that represents some range of energy. To do that, set the X and Y scaling of the 2D wave to appropriate ranges.