Skip to content

Commit

Permalink
Revert run, subrun, and event attribute change, remove hard-coded mas…
Browse files Browse the repository at this point in the history
…king in singlep.py
  • Loading branch information
dkoh0207 committed Mar 1, 2024
1 parent ade558e commit 997c8d2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 54 deletions.
10 changes: 1 addition & 9 deletions analysis/classes/Interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ def __init__(self,
is_fiducial: bool = False,
is_ccrosser: bool = False,
coffset: float = -np.inf,
units: str = 'px',
run: int = -1,
subrun: int = -1,
event: int = -1, **kwargs):
units: str = 'px', **kwargs):

# Initialize attributes
self.id = int(interaction_id)
Expand Down Expand Up @@ -139,11 +136,6 @@ def __init__(self,
self.crthit_matched = crthit_matched
self.crthit_matched_particle_id = crthit_matched_particle_id
self.crthit_id = crthit_id

# Run Info
self.run = int(run)
self.subrun = int(subrun)
self.event = int(event)

@property
def size(self):
Expand Down
10 changes: 1 addition & 9 deletions analysis/classes/Particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ def __init__(self,
is_valid: bool = True,
is_ccrosser: bool = False,
coffset: float = -np.inf,
units: str = 'px',
run: int = -1,
subrun: int = -1,
event: int = -1, **kwargs):
units: str = 'px', **kwargs):

# Initialize private attributes to be assigned through setters only
self._num_fragments = None
Expand Down Expand Up @@ -176,11 +173,6 @@ def __init__(self,
self._match_overlap = kwargs.get('match_overlap', OrderedDict())
if not isinstance(self._match_overlap, dict):
raise ValueError(f"{type(self._match_overlap)}")

# Run Info
self.run = int(run)
self.subrun = int(subrun)
self.event = int(event)

def merge(self, particle):
'''
Expand Down
35 changes: 1 addition & 34 deletions analysis/classes/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,6 @@ def _build_reco(self,
pid_scores = softmax(type_logits, axis=1)
primary_scores = softmax(primary_logits, axis=1)

run, subrun, event = -1, -1, -1

if 'run_info' in data:
run = data['run_info'][entry]['run']
subrun = data['run_info'][entry]['subrun']
event = data['run_info'][entry]['event']

for i, p in enumerate(particles):
volume_id, cts = np.unique(volume_labels[p], return_counts=True)
volume_id = int(volume_id[cts.argmax()])
Expand All @@ -363,10 +356,7 @@ def _build_reco(self,
pid_scores=pid_scores[i],
primary_scores=primary_scores[i],
start_point = np.ascontiguousarray(particle_start_points[i], dtype=np.float32),
end_point = np.ascontiguousarray(particle_end_points[i], dtype=np.float32),
run=run,
subrun=subrun,
event=event)
end_point = np.ascontiguousarray(particle_end_points[i], dtype=np.float32))
out.append(part)

return out
Expand Down Expand Up @@ -422,14 +412,6 @@ def _build_truth(self,

# point_labels = data['point_labels'][entry]
# unit_convert = lambda x: pixel_to_cm_1d(x, meta) if self.convert_to_cm == True else x

# Add run info
run, subrun, event = -1, -1, -1

if 'run_info' in data:
run = data['run_info'][entry]['run']
subrun = data['run_info'][entry]['subrun']
event = data['run_info'][entry]['event']

# For debugging
voxel_counts = 0
Expand Down Expand Up @@ -460,10 +442,6 @@ def _build_truth(self,
particle.start_point = particle.first_step
if particle.semantic_type == TRACK_SHP:
particle.end_point = particle.last_step

particle.run = run
particle.subrun = subrun
particle.event = event

out.append(particle)
continue
Expand Down Expand Up @@ -522,9 +500,6 @@ def _build_truth(self,
points=coords,
sources=input_source[mask] if len(input_source) else input_source,
depositions=depositions,
run=run,
subrun=subrun,
event=event,
is_primary=bool(is_primary),
depositions_MeV=np.empty(0, dtype=np.float32),
truth_index=true_voxel_indices,
Expand Down Expand Up @@ -716,14 +691,6 @@ def decorate_truth_interactions(self, entry, data, interactions):
for ia in interactions:
if ia.truth_id in vertices:
ia.truth_vertex = vertices[ia.truth_id]

if 'run_info' in data:
run = data['run_info'][entry]['run']
subrun = data['run_info'][entry]['subrun']
event = data['run_info'][entry]['event']
ia.run = run
ia.subrun = subrun
ia.event = event

if 'neutrinos' in data and ia.nu_id > -1:
neutrinos = data['neutrinos'][entry]
Expand Down
5 changes: 3 additions & 2 deletions mlreco/models/singlep.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, cfg, name='particle_image_classifier'):
model_cfg = cfg.get(name, {})
self.batch_col = model_cfg.get('batch_col', 0)
self.split_col = model_cfg.get('split_col', 6)
self.num_classes = model_cfg.get('num_classes', 5)

self.skip_invalid = model_cfg.get('skip_invalid', True)
self.target_col = model_cfg.get('target_col', 9)
Expand Down Expand Up @@ -130,7 +131,7 @@ def forward(self, input, clusts=None):
# It is possible that pid = 5 appears in the 9th column.
# In that case, it is observed that the training crashses with a
# integer overflow numel error.
mask = point_cloud[:, 9] <= 4
mask = point_cloud[:, 9] < self.num_classes
valid_points = point_cloud[mask]

if self.split_input_mode:
Expand Down Expand Up @@ -430,7 +431,7 @@ def forward_tg(self, out, valid_labels):

def forward(self, out, type_labels):

valid_labels = type_labels[0][type_labels[0][:, 9] <= 4]
valid_labels = type_labels[0][type_labels[0][:, 9] < self.num_classes]

if self.split_input_mode:
logits, labels = self.forward_tg(out, valid_labels)
Expand Down

0 comments on commit 997c8d2

Please sign in to comment.