Hamiltonian for a massless particle - formal definition of energy Given a Lagrangian, is possible to calculate momenta and from them the Hamiltonian, if the system is regular enough.
Today, I have realized that the Lagrangian of a massless particle in a gravitational field is singular, and described by a constraint Hamiltonian.
Here is my problem: given this Lagrangian, the Hamiltonian always vanishes; if it's always zero, how is it possible to talk of a "energy" associated with a massless particle?
 A: Comments to the post (v3):


*

*The notion of Hamiltonian and the notion of total energy do not need to coincide, cf. this Phys.SE post and links therein. Total energy is the Noether charge associated with time translations. In relativity theory, the notion of time (and thereby the notion of energy) depend on the chosen coordinate system. In particular the notion total energy (unlike the notion of rest energy) is not an invariant. See also above comments by ACuriousMind & JamalS. 

*In the context of e.g. the Minkowski metric or the FLRW metric
$$ ds^2~=~\sum_{\mu,\nu=0}^3g_{(4)\mu\nu}\mathrm{d}x^{\mu}\odot \mathrm{d}x^{\nu}~=~-\mathrm{d}x^0\odot \mathrm{d}x^0+a(x^0)^2\sum_{i,j=1}^3g_{(3)ij}\mathrm{d}x^i\odot \mathrm{d}x^j ,\tag{1}$$ 
it is possible to make the Hamiltonian $H$ for a massless point particle equal to the total energy 
$$c|{\bf p}|~:=~c\sqrt{\sum_{i,j=1}^3 p_i g^{(4)ij}p_j}~=~\frac{c}{a(x^0)}\sqrt{\sum_{i,j=1}^3 p_i g^{(3)ij}p_j} \tag{2}$$ 
by choosing the static gauge condition $x^0=c\tau$, where $\tau$ is the world-line parameter (which is not the proper time). For details, see e.g. this Phys.SE post. Note that the total energy (2) is not conserved in the FLRW case due to the scale factor $a(x^0)$ with explicit time dependence.
