Skip to content

Commit

Permalink
Prevent NaNs in emittance computation
Browse files Browse the repository at this point in the history
  • Loading branch information
jank324 committed Jan 7, 2024
1 parent df48d85 commit 5283bd1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cheetah/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ def sigma_yyp(self) -> torch.Tensor:
@property
def emittance_x(self) -> torch.Tensor:
"""Emittance of the beam in x direction in m*rad."""
return torch.sqrt(self.sigma_x**2 * self.sigma_xp**2 - self.sigma_xxp**2)
return torch.sqrt(
torch.clamp_min(
self.sigma_x**2 * self.sigma_xp**2 - self.sigma_xxp**2, 0.0
)
)

@property
def normalized_emittance_x(self) -> torch.Tensor:
Expand All @@ -283,7 +287,11 @@ def alpha_x(self) -> torch.Tensor:
@property
def emittance_y(self) -> torch.Tensor:
"""Emittance of the beam in y direction in m*rad."""
return torch.sqrt(self.sigma_y**2 * self.sigma_yp**2 - self.sigma_yyp**2)
return torch.sqrt(
torch.clamp_min(
self.sigma_y**2 * self.sigma_yp**2 - self.sigma_yyp**2, 0.0
)
)

@property
def normalized_emittance_y(self) -> torch.Tensor:
Expand Down

0 comments on commit 5283bd1

Please sign in to comment.