*2.1. Jet Dynamics*

After the reverse shock has crossed the ejecta, the dynamics of the blast-wave enters a self-similar regime ([35], BM76 hereafter). In a thin shell approximation, the reverse shock crossing time corresponds to the time when the blast-wave starts decelerating. The deceleration of the jet, caused by the collision with the external medium, becomes significant at the radius *Rdec*, where the energy transferred to the mass *m* collected from the external medium (∼*m*(*Rdec*)*c* 2Γ 2 0 ) is comparable to the initial energy (*E*<sup>0</sup> = *M*0Γ<sup>0</sup> *c* 2 ) carried by the jet. This deceleration radius is typically of the order of *<sup>R</sup>dec*∼1015–10<sup>16</sup> cm, depending on the density of the external medium, the ejecta mass *M*<sup>0</sup> and initial bulk Lorentz factor Γ0. Before reaching this radius, the ejecta expands with constant velocity (coasting phase).

Most analytic estimates of the afterglow evolution with the purpose of modeling data are developed for the deceleration phase, where the self-similar BM76 solution for adiabatic blast-waves is adopted [38,47,54]. Since VHE emission can be detected at quite early times (a few tens of seconds), we are also interested in the description of the coasting phase and in a proper treatment of the transition between coasting and deceleration.

In the following, to derive the evolution of the bulk Lorentz factor, we adopt the approach proposed by [55]. This method allows us to describe the hydrodynamics of a relativistic blast-wave expanding into a medium with an arbitrary density profile *ρ*(*R*) and composition (i.e., enriched by pairs), and the transition from the free expansion of the ejecta to the deceleration phase, taking into account the role of radiative and adiabatic losses. The internal structure is neglected (homogeneous shell approximation), and the Lorentz factor Γ considered is the one of the fluids just behind the shock front. In the deceleration phase, the self-similar solutions derived in BM76 are recovered by this method, both for the adiabatic and the fully radiative cases, and for constant and wind-like density profiles of the external medium. The presented approach also allows us to introduce a timevarying radiative efficiency, either resulting from a change with time of *e*<sup>e</sup> or a change in the radiative efficiency of the electrons. Equations reported here are valid after the reverse shock has crossed the ejecta. Corrections to the hydrodynamics before the reverse-shock crossing time can be found in [55].

#### 2.1.1. Equation Describing the Evolution of the Bulk Lorentz Factor

The aim is to derive an equation describing the change *d*Γ of the bulk Lorentz factor of the fluid just behind the shock in response to the collision with a mass *dm*(*R*) = 4*πR* <sup>2</sup>*ρ*(*R*)*dR* encountered when the shock front moves from a distance *R* to *R* + *dR* and with *ρ* being the mass density. The change in Γ is determined by dissipation of the bulk kinetic energy, the conversion of internal energy back into bulk motion, and injection of energy into the blast-wave. The latter is sometimes invoked to explain plateau phases in the X-ray early afterglow or to explain flux rebrightenings [56–58]. The following treatment neglects energy injection, which, however, can be easily incorporated in this kind of approach.

To write the equation for energy conservation, from which *d*Γ/*dR* can be derived, we first need to recall how the energy density transforms under Lorentz transformations. In the following, we denote quantities measured in the frame comoving with the shocked fluid (comoving frame), with a prime, to distinguish them from quantities measured in the frame of the progenitor star (rest frame, without a prime).

The energy density in the comoving frame is *u* 0 = *u* 0 int + *ρ* 0 *c* 2 , where *u* 0 int is the comoving internal energy and *ρ* 0 is the comoving mass density. Applying Lorentz transformations, *u* = (*u* 0 + *p* 0 )Γ <sup>2</sup> <sup>−</sup> *<sup>p</sup>* 0 , where *p* 0 is the pressure and is related to the internal energy density by the equation of state, and *p* <sup>0</sup> = (*γ*ˆ − 1) *u* 0 int = (*γ*ˆ − 1) (*u* <sup>0</sup> − *ρ* 0 *c* 2 ), where *γ*ˆ is the adiabatic index of the shocked plasma. The energy density is then given by: *u* = *u* 0 int(*γ*ˆΓ <sup>2</sup> <sup>−</sup> *<sup>γ</sup>*<sup>ˆ</sup> <sup>+</sup> <sup>1</sup>) + *<sup>ρ</sup>* 0 *c* 2Γ 2 , which shows how the internal energy and rest mass density transform. The total energy in the progenitor frame will be *E* = *uV* = *uV*0/Γ, where *V* is the shell volume in the progenitor frame, and can be expressed as:

*E* = Γ*Mc*<sup>2</sup> + Γeff*E* 0 int , (1)

where:

$$
\Gamma\_{\rm eff} \equiv \frac{\gamma \Gamma^2 - \gamma + 1}{\Gamma} \,, \tag{2}
$$

which properly describes the Lorentz transformation of the internal energy. Here, *M* = *M*<sup>0</sup> + *m* = *ρ* 0*V* 0 is the sum of the ejecta mass *M*<sup>0</sup> = *E*0/Γ0*c* <sup>2</sup> and of the swept-up mass *m*(*R*), and *E* 0 *int* = (*u* <sup>0</sup> − *ρ* 0 *c* 2 )*V* 0 is the comoving internal energy. The adiabatic index can be parameterized as *γ*ˆ = (4 + Γ −1 )/3 to obtain the expected limits *γ*ˆ ' 4/3 for Γ 1 and *γ*ˆ ' 5/3 for Γ → 1. The majority of analytical treatments use Γ instead of Γ*eff* , which implies an error up to a factor of 4/3 in the ultra-relativistic limit [55].

The blast-wave energy *E* in Equation (1) can change due to (*i*), the rest mass energy *dm c*<sup>2</sup> collected from the medium, (*ii*) radiative losses *dErad* = Γ*eff dE*<sup>0</sup> *rad* and (*iii*) injection of energy. Ignoring possible episodes of energy injections into the blast-wave, the equation of energy conservation in the progenitor frame is:

$$d\left[\Gamma(M\_0 + m)c^2 + \Gamma\_{\rm eff}E\_{\rm int}^{\prime}\right] = dm\,c^2 + \Gamma\_{\rm eff}dE\_{\rm rad}^{\prime}\,. \tag{3}$$

The overall change in the comoving internal energy *dE*0 *int* results from the sum of three contributions:

$$dE'\_{\rm int} = dE'\_{\rm sh} + dE'\_{ad} + dE'\_{rad} \; . \tag{4}$$

The first contribution, *dE*0 *sh* = (<sup>Γ</sup> <sup>−</sup> <sup>1</sup>) *dm c*<sup>2</sup> , is the random kinetic energy produced at the shock as a result of the interaction with an element *dm* of circum-burst material: as pointed out by BM76, in the post-shock frame, the average kinetic energy per unit mass *dE*0 *sh*/*dm* is constant across the shock, and equal to (Γ − 1)*c* 2 . The second term in Equation (4), *dE*0 *ad*, is the internal energy lost due to adiabatic expansion, that leads to a conversion of random energy back to bulk kinetic energy. The third term, *dE*0 *rad*, accounts for radiative losses.

From Equation (3), it follows that the variation of the Lorentz factor is:

$$\frac{d\Gamma}{dR} = -\frac{(\Gamma\_{\rm eff} + 1)(\Gamma - 1)}{(M\_0 + m)} \frac{c^2 \frac{dm}{d\Gamma} + \Gamma\_{\rm eff} \frac{dE'\_{ad}}{d\Gamma}}{c^2 + E'\_{int} \frac{d\Gamma\_{\rm eff}}{d\Gamma}}\,,\tag{5}$$

from which the evolution Γ(*R*) of the bulk Lorentz factor of the fluid just behind the shock as a function of the shock front radius can be derived.

The term Γeff *dE*<sup>0</sup> *ad*/*dR*, accounting for adiabatic losses, allows us to describe the reacceleration of the fireball: this contribution, usually neglected, becomes important only when the density decreases faster than *ρ* ∝ *R* −3 . To evaluate Equation (5), it is necessary to first specify *dE*0 *ad* and *E* 0 *int*.
