Skip to content

Commit a5b738d

Browse files
committed
Add boolean flag for whether or not to use an small epsilon on charge
1 parent 05fb659 commit a5b738d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/graphnet/models/detector/magic.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""MAGIC-specific `Detector` class(es)."""
22

3-
from typing import Dict, Callable
3+
from typing import Dict, Callable, Any
44
import torch
55
import os
66

@@ -18,6 +18,17 @@ class MAGIC(Detector):
1818
# By default, treat the telescope ID as a spatial-like z-coordinate
1919
xyz = ["x_cam", "y_cam", "tel_id"]
2020

21+
def __init__(self, use_charge_epsilon: bool = True, **kwargs: Any) -> None:
22+
"""Construct detector for the MAGIC telescopes.
23+
24+
Args:
25+
use_charge_epsilon: Whether to add a small epsilon value to charge
26+
before taking log10 to avoid log(0). Defaults to True (uses
27+
1e-6). Set to False if data is guaranteed to have zero-padding.
28+
"""
29+
super().__init__(**kwargs)
30+
self._charge_epsilon = 1e-6 if use_charge_epsilon else 0.0
31+
2132
def feature_map(self) -> Dict[str, Callable]:
2233
"""Map standardization functions to each dimension.
2334
@@ -47,5 +58,4 @@ def _time(self, x: torch.tensor) -> torch.tensor:
4758

4859
def _charge(self, x: torch.tensor) -> torch.tensor:
4960
"""Add a small epsilon to avoid log(0)."""
50-
epsilon = 1e-6
51-
return torch.log10(x + epsilon)
61+
return torch.log10(x + self._charge_epsilon)

0 commit comments

Comments
 (0)