private void calcG(int choice) {
        /* calculates the g values. choice parameter is the stage selection */
        int index, grstep, i;
        double d2;

        switch (choice) {
            case 1:// initialization
                for (i = 0; i < ngr; i++) {
                    g[i] = 0.0;
                }
                break;

            case 2: // Compute g of r
                for (i = 0; i < numberOfParticles - 1; i++) {
                    for (int j = i + 1; j < numberOfParticles; j++) {
                        dx = getParticleX(i) - getParticleX(j);
                        dy = getParticleY(i) - getParticleY(j);

                        // Handle Images for Periodic Boundary Conditions
                        pbclParticles();
                        // Calculate the 2D distance
                        d2 = Math.sqrt(dx * dx + dy * dy);
                        // Check if outside range
                        if (d2 <= grange) {
                            index = (int) (d2 / dr);
                            g[index] += 2.0;
                        }
                    }
                }
                break;

            case 3:
                grstep = (numberOfSteps - noneq) / dataDump;
                double dV;
                for (i = 1; i < ngr; i++) {
                    r[i] = i * dr;
                    dV = 2.0 * Math.PI * ((r[i] + dr) * (r[i] + dr) - r[i] * r[i]);
                    // generalize
                    g[i] = g[i] / (dV * grstep * numberOfParticles * (numberOfParticles - 1) / (2.0 * volume));
                }

                for (i = 0; i < ngr; i++) {
                    r[i] += 0.5 * dr;
                }
                break;

            default:
                System.out.println("error in g[r] calculation");
                break;
        }
    }