How to use Z axis of hmc5883l?The data for tilt compensation?

I find out some code from github.But it seems just use x and y axis data.This code work fine only the hmc5883l module horizontal placement.I think it’s not use Z axis reason right?

  // Calculate heading
  float heading = atan2(norm.YAxis, norm.XAxis);

  // Set declination angle on your location and fix heading
  // You can find your declination on: http://magnetic-declination.com/
  // (+) Positive or (-) for negative
  // For Bytom / Poland declination angle is 4'26E (positive)
  // Formula: (deg + (min / 60.0)) / (180 / M_PI);
  float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
  heading += declinationAngle;

  // Correct for heading < 0deg and heading > 360deg
  if (heading < 0)
  {
    heading += 2 * PI;
  }
 
  if (heading > 2 * PI)
  {
    heading -= 2 * PI;
  }

  // Convert to degrees
  float headingDegrees = heading * 180/M_PI;

For tilt compensation you need to use all three magnetometer axes and to measure the tilt, a 3D accelerometer.

Pololu has good tilt compensation code, which can be used with their better performing LSM303D magnetometer/accelerometer module, or adapted to other sensors.

Now I have a question:
Where it is used the z axis.To my understanding,it is used for tilt compensation.

All three axes of the magnetometer are needed to measure the strength and direction of the Earth's (or some other) magnetic field.

Yes, the magnetometer Z axis is used in tilt compensation, but the magnetometer alone does not provide enough information to make a tilt compensated compass. You can read about the theory here: NXP® Semiconductors Official Site | Home.

Thank all of you