8000 Remove code duplication for relativistic factor · Issue #451 · desy-ml/cheetah · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Remove code duplication for relativistic factor #451
Open
@Hespe

Description

@Hespe

There are currently two independent implementations that calculate the relativistic factors $\gamma$ and $\beta$. It would probably be best to reconsile them to avoid inconsistencies down the line.

@property
def relativistic_gamma(self) -> torch.Tensor:
"""Reference relativistic gamma of the beam."""
return self.energy / self.species.mass_eV
@property
def relativistic_beta(self) -> torch.Tensor:
"""Reference relativistic beta of the beam."""
relativistic_beta = torch.ones_like(self.relativistic_gamma)
relativistic_beta[torch.abs(self.relativistic_gamma) > 0] = torch.sqrt(
1 - 1 / (self.relativistic_gamma[self.relativistic_gamma > 0] ** 2)
)
return relativistic_beta

def compute_relativistic_factors(
energy: torch.Tensor, particle_mass_eV: torch.Tensor
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""
Computes the relativistic factors gamma, inverse gamma squared and beta for
particles.
:param energy: Energy in eV.
:param particle_mass_eV: Mass of the particle in eV.
:return: gamma, igamma2, beta.
"""
gamma = energy / particle_mass_eV
igamma2 = torch.where(gamma == 0.0, 0.0, 1 / gamma**2)
beta = torch.sqrt(1 - igamma2)
return gamma, igamma2, beta

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0