I think you are missing a large input filter capacitor. This thing is two blocks.
The first block involving Q3 is a capacitance multiplier that reduces the ripple (mains frequency times two) coming from the missing filter capacitor.
The second is a 5V regulator sitting on top of a 36V zener diode that regulates the output voltage to 36V+5V = 42V. The zener is mostly biased by the GND current from the regulator with a bit of bootstrapped current through the 5.1K resistor. D16 is to protect the regulator in case the input is shorted.
The regulator has its "GND" reference at +36V so it is regulating the output to 5V relative to GND which gives a total of 42V out.
You can test this with a 78x05 by wiring a diode, LED or zener diode from the GND terminal to circuit ground. Say you use a 3.1V (@ a few mA) white LED. The LED will glow with fairly constant brightness and the regulator output will be 8.1V, assuming the input is more than about 10V and less than the maximum voltage for the regulator plus 3.1V.