Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3io
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
km3py
km3io
Commits
3df6826c
Commit
3df6826c
authored
4 years ago
by
Zineb Aly
Browse files
Options
Downloads
Patches
Plain Diff
rename best_Jmuon to best_track
parent
7358a963
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!45
Adapt best track root access
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
km3io/tools.py
+63
-63
63 additions, 63 deletions
km3io/tools.py
with
63 additions
and
63 deletions
km3io/tools.py
+
63
−
63
View file @
3df6826c
...
...
@@ -272,68 +272,68 @@ def mask(rec_stages, stages):
return
builder
.
snapshot
()
==
1
def
best_track
(
tracks
,
strategy
=
"
default
"
,
rec_type
=
None
):
"""
best track selection based on different strategies
Parameters
----------
tracks : class km3io.offline.OfflineBranch
a subset of reconstructed tracks where `events.n_tracks > 0` is always true.
strategy : str
the trategy desired to select the best tracks. It is either:
-
"
first
"
: to select the first tracks.
-
"
default
"
: to select the best tracks (the first ones) corresponding to a specific
reconstruction algorithm (JGandalf, Jshowerfit, etc). This requires rec_type input.
Example: best_track(my_tracks, strategy=
"
default
"
, rec_type=
"
JPP_RECONSTRUCTION_TYPE
"
).
rec_type : str, optional
reconstruction type as defined in the official KM3NeT-Dataformat.
Returns
-------
class km3io.offline.OfflineBranch
tracks class with the desired
"
best tracks
"
selection.
Raises
------
ValueError
ValueError raised when:
- an invalid strategy is requested.
- a subset of events with empty tracks is used.
"""
options
=
[
'
first
'
,
'
default
'
]
if
strategy
not
in
options
:
raise
ValueError
(
"
{} not in {}
"
.
format
(
strategy
,
options
))
n_events
=
1
if
tracks
.
is_single
else
len
(
tracks
)
if
n_events
>
1
and
any
(
count_nested
(
tracks
.
lik
,
axis
=
1
)
==
0
):
raise
ValueError
(
"'
events
'
should not contain empty tracks. Consider applying the mask: events.n_tracks>0
"
)
if
strategy
==
"
first
"
:
if
n_events
==
1
:
out
=
tracks
[
0
]
else
:
out
=
tracks
[:,
0
]
if
strategy
==
"
default
"
and
rec_type
is
None
:
raise
ValueError
(
"
rec_type must be provided when the default strategy is used.
"
)
if
strategy
==
"
default
"
and
rec_type
is
not
None
:
if
n_events
==
1
:
rec_types
=
tracks
[
tracks
.
rec_type
==
krec
[
rec_type
]]
len_stages
=
count_nested
(
rec_types
.
rec_stages
,
axis
=
1
)
longest
=
rec_types
[
len_stages
==
ak1
.
max
(
len_stages
,
axis
=
0
)]
out
=
longest
[
longest
.
lik
==
ak1
.
max
(
longest
.
lik
,
axis
=
0
)]
else
:
rec_types
=
tracks
[
tracks
.
rec_type
==
krec
[
rec_type
]]
len_stages
=
count_nested
(
rec_types
.
rec_stages
,
axis
=
2
)
longest
=
rec_types
[
len_stages
==
ak1
.
max
(
len_stages
,
axis
=
1
)]
out
=
longest
[
longest
.
lik
==
ak1
.
max
(
longest
.
lik
,
axis
=
1
)]
return
out
#
def best_track(tracks, strategy="default", rec_type=None):
#
"""best track selection based on different strategies
#
Parameters
#
----------
#
tracks : class km3io.offline.OfflineBranch
#
a subset of reconstructed tracks where `events.n_tracks > 0` is always true.
#
strategy : str
#
the trategy desired to select the best tracks. It is either:
#
- "first" : to select the first tracks.
#
- "default": to select the best tracks (the first ones) corresponding to a specific
#
reconstruction algorithm (JGandalf, Jshowerfit, etc). This requires rec_type input.
#
Example: best_track(my_tracks, strategy="default", rec_type="JPP_RECONSTRUCTION_TYPE").
#
rec_type : str, optional
#
reconstruction type as defined in the official KM3NeT-Dataformat.
#
Returns
#
-------
#
class km3io.offline.OfflineBranch
#
tracks class with the desired "best tracks" selection.
#
Raises
#
------
#
ValueError
#
ValueError raised when:
#
- an invalid strategy is requested.
#
- a subset of events with empty tracks is used.
#
"""
#
options = ['first', 'default']
#
if strategy not in options:
#
raise ValueError("{} not in {}".format(strategy, options))
#
n_events = 1 if tracks.is_single else len(tracks)
#
if n_events > 1 and any(count_nested(tracks.lik, axis=1) == 0):
#
raise ValueError(
#
"'events' should not contain empty tracks. Consider applying the mask: events.n_tracks>0"
#
)
#
if strategy == "first":
#
if n_events == 1:
#
out = tracks[0]
#
else:
#
out = tracks[:, 0]
#
if strategy == "default" and rec_type is None:
#
raise ValueError(
#
"rec_type must be provided when the default strategy is used.")
#
if strategy == "default" and rec_type is not None:
#
if n_events == 1:
#
rec_types = tracks[tracks.rec_type == krec[rec_type]]
#
len_stages = count_nested(rec_types.rec_stages, axis=1)
#
longest = rec_types[len_stages == ak1.max(len_stages, axis=0)]
#
out = longest[longest.lik == ak1.max(longest.lik, axis=0)]
#
else:
#
rec_types = tracks[tracks.rec_type == krec[rec_type]]
#
len_stages = count_nested(rec_types.rec_stages, axis=2)
#
longest = rec_types[len_stages == ak1.max(len_stages, axis=1)]
#
out = longest[longest.lik == ak1.max(longest.lik, axis=1)]
#
return out
def
get_multiplicity
(
tracks
,
rec_stages
):
...
...
@@ -444,7 +444,7 @@ def _reco_stages(reco):
return
stages
def
best_
JMuon
(
tracks
,
reco
,
start
=
None
,
end
=
None
,
stages
=
[]):
def
best_
track
(
tracks
,
reco
,
start
=
None
,
end
=
None
,
stages
=
[]):
valid_stages
=
_reco_stages
(
reco
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment