Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple bug fixes #7

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion spine/ana/script/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SaveAna(AnaBase):
'reco_fragment': RecoFragment(), 'truth_fragment': TruthFragment(),
'reco_particle': RecoParticle(), 'truth_particle': TruthParticle(),
'reco_interaction': RecoInteraction(),
'truth_particle': TruthInteraction()
'truth_interaction': TruthInteraction()
}

def __init__(self, obj_type, fragment=None, particle=None, interaction=None,
Expand Down
19 changes: 10 additions & 9 deletions spine/build/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,21 @@ def _build_truth(self, truth_particles, neutrinos=None):
p.interaction_id = i

# Append the neutrino information, if it is provided
if neutrinos is not None:
nu_ids = [part.nu_id for part in inter_particles]
assert len(np.unique(nu_ids)) == 1, (
"Interaction made up of particles with different "
"neutrino IDs. Must be unique.")
if nu_ids[0] > -1:
interaction.attach_neutrino(neutrinos[nu_ids[0]])
nu_ids = [part.nu_id for part in inter_particles]
assert len(np.unique(nu_ids)) == 1, (
"Interaction made up of particles with different "
"neutrino IDs. Must be unique.")
interaction.nu_id = nu_ids[0]

if neutrinos is not None and nu_ids[0] > -1:
interaction.attach_neutrino(neutrinos[nu_ids[0]])

else:
anc_pos = [part.ancestor_position for part in inter_particles]
anc_pos = np.unique(anc_pos, axis=0)
assert len(anc_pos) == 1, (
"Particles making up a true interaction have different "
"ancestor positions.")
"Particles making up a true interaction have "
"different ancestor positions.")
interaction.vertex = anc_pos.flatten()

# Append
Expand Down
4 changes: 3 additions & 1 deletion spine/data/out/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class InteractionBase:
_fixed_length_attrs = {'vertex': 3}

# Variable-length attributes as (key, dtype) pairs
_var_length_attrs = {'particle_ids': np.int32}
_var_length_attrs = {
'particles': object, 'particle_ids': np.int32
}

# Attributes specifying coordinates
_pos_attrs = ['vertex']
Expand Down
4 changes: 3 additions & 1 deletion spine/data/out/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ class ParticleBase:
}

# Variable-length attributes as (key, dtype) pairs
_var_length_attrs = {'fragment_ids': np.int32}
_var_length_attrs = {
'fragments': object, 'fragment_ids': np.int32
}

# Attributes specifying coordinates
_pos_attrs = ['start_point', 'end_point']
Expand Down
5 changes: 5 additions & 0 deletions spine/io/write/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ def __call__(self, data, cfg=None):
Dictionary containing the complete SPINE configuration
"""
# If this function has never been called, initialiaze the HDF5 file
# TODO: make this nicer?
if np.isscalar(data['index']):
for k in data:
data[k] = [data[k]]

if (not self.ready and
(not self.append or os.path.isfile(self.file_name))):
self.create(data, cfg)
Expand Down
Loading