Normalize

 

Version Info

Minimum Origin Version Required: Origin 8 SR5

Normalize Multiple Curves in a Graph at User-Specified Point

This example shows how to allow user to pick a particular point in a particular data plot (curve) and then normalize all curves in the layer to the same value at that point.

#include <Origin.h>

void normalize_multiple_curves()
{
        // Assume graph layer with multiple curves is active
        // It is also assumed all curves share same X values, typical in spectroscopy
        GraphLayer gl = Project.ActiveLayer();
        if( !gl )
                return;
        
        // Allow user to click and select one particular point of one particular curve
        GetGraphPoints mypts;
        mypts.SetFollowData(true);
        mypts.GetPoints(1, gl);
        vector vx, vy;
        vector<int> vn;
        if(mypts.GetData(vx, vy, vn) == 1)
        {
                // Save index and y value of picked point
                int nxpicked = vn[0] - 1;
                double dypicked = vy[0];
                // Loop over all data plots in layer
                foreach( DataPlot dp in gl.DataPlots )
                {
                        // Get the data range and then the y column for current plot
                        XYRange xy;
                        Column cy;
                        if(dp.GetDataRange(xy) && xy.GetYColumn(cy))
                        {
                                // Get a vector reference to y values from the y column
                                vectorbase &vycurrent = cy.GetDataObject();
                                // Scale vector so y value matches user-picked point
                                vycurrent *= dypicked/vycurrent[nxpicked];
                        }
                }
        }
}