Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 2 additions & 77 deletions spine/ana/base.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove these spurious new line changes? I am guessing this is something your editor does by default? If there is a reason to operate this change repo wise it would make sense to do it globally and in a separate PR.

Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,8 @@ class AnaBase(ABC):
# Valid run modes
_run_modes = ('reco', 'truth', 'both', 'all')

# List of known point modes for true particles and their corresponding keys
_point_modes = (
('points', 'points_label'),
('points_adapt', 'points'),
('points_g4', 'points_g4')
)

def __init__(self, obj_type=None, run_mode=None, truth_point_mode=None,
append=False, overwrite=False, log_dir=None, prefix=None):
def __init__(self, obj_type=None, run_mode=None, append=False,
overwrite=False, log_dir=None, prefix=None):
"""Initialize default anlysis script object properties.

Parameters
Expand All @@ -63,10 +56,6 @@ def __init__(self, obj_type=None, run_mode=None, truth_point_mode=None,
If specified, tells whether the analysis script must run on
reconstructed ('reco'), true ('true') or both objects
('both' or 'all')
truth_point_mode : str, optional
If specified, tells which attribute of the :class:`TruthFragment`,
:class:`TruthParticle` or :class:`TruthInteraction` object to use
to fetch its point coordinates
append : bool, default False
If True, appends existing CSV files instead of creating new ones
overwrite : bool, default False
Expand Down Expand Up @@ -125,14 +114,6 @@ def __init__(self, obj_type=None, run_mode=None, truth_point_mode=None,
# Update underlying keys, if needed
self.update_keys({k:True for k in self.obj_keys})

# If a truth point mode is specified, store it
if truth_point_mode is not None:
assert truth_point_mode in self.point_modes, (
"The `truth_point_mode` argument must be one of "
f"{self.point_modes.keys()}. Got `{truth_point_mode}` instead.")
self.truth_point_mode = truth_point_mode
self.truth_index_mode = truth_point_mode.replace('points', 'index')

# Store the append flag
self.append_file = append
self.overwrite_file = overwrite
Expand Down Expand Up @@ -186,18 +167,6 @@ def keys(self, keys):
"""
self._keys = tuple(keys.items())

@property
def point_modes(self):
"""Dictionary which makes the correspondance between the name of a true
object point attribute with the underlying point tensor it points to.

Returns
-------
Dict[str, str]
Dictionary of (attribute, key) mapping for point coordinates
"""
return dict(self._point_modes)

def update_keys(self, update_dict):
"""Update the underlying set of keys and their necessity in place.

Expand Down Expand Up @@ -280,50 +249,6 @@ def __call__(self, data, entry=None):
# Run the analysis script
return self.process(data_filter)

def get_index(self, obj):
"""Get a certain pre-defined index attribute of an object.

The :class:`TruthFragment`, :class:`TruthParticle` and
:class:`TruthInteraction` objects index are obtained using the
`truth_index_mode` attribute of the class.

Parameters
----------
obj : Union[FragmentBase, ParticleBase, InteractionBase]
Fragment, Particle or Interaction object

Results
-------
np.ndarray
(N) Object index
"""
if not obj.is_truth:
return obj.index
else:
return getattr(obj, self.truth_index_mode)

def get_points(self, obj):
"""Get a certain pre-defined point attribute of an object.

The :class:`TruthFragment`, :class:`TruthParticle` and
:class:`TruthInteraction` objects points are obtained using the
`truth_point_mode` attribute of the class.

Parameters
----------
obj : Union[FragmentBase, ParticleBase, InteractionBase]
Fragment, Particle or Interaction object

Results
-------
np.ndarray
(N, 3) Point coordinates
"""
if not obj.is_truth:
return obj.points
else:
return getattr(obj, self.truth_point_mode)

@abstractmethod
def process(self, data):
"""Place-holder method to be defined in each analysis script.
Expand Down
2 changes: 0 additions & 2 deletions spine/ana/diag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
This submodule is use to run basic diagnostics analyses such as:
- Track dE/dx profile
- Track energy reconstruction
- Track completeness
- Shower start dE/dx
- ...
'''

from .shower import *
from .track import *
189 changes: 0 additions & 189 deletions spine/ana/diag/track.py

This file was deleted.

4 changes: 2 additions & 2 deletions spine/ana/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from spine.utils.factory import module_dict, instantiate

from . import diag, metric, script
from . import metric, script

# Build a dictionary of available calibration modules
ANA_DICT = {}
for module in [diag, metric, script]:
for module in [metric, script]:
ANA_DICT.update(**module_dict(module))


Expand Down
1 change: 1 addition & 0 deletions spine/ana/script/__init__.py
Copy link
Member

@francois-drielsma francois-drielsma Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this import to spine/ana/diag/__init__.py or spine/ana/metric/__init__.py depending on the answer to the question in the other comment?

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .event import *
from .metrics import *
from .colinear_tracks import *
from .fmatch_performance import *
Loading
Loading