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
bf432120
Commit
bf432120
authored
4 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Fix tracks example
parent
a7e7244b
No related branches found
No related tags found
1 merge request
!47
Resolve "uproot4 integration"
Pipeline
#16347
failed
4 years ago
Stage: test
Stage: coverage
Stage: doc
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/plot_offline_tracks.py
+34
-70
34 additions, 70 deletions
examples/plot_offline_tracks.py
with
34 additions
and
70 deletions
examples/plot_offline_tracks.py
+
34
−
70
View file @
bf432120
...
...
@@ -2,8 +2,7 @@
Reading Offline tracks
======================
The following example shows how to access tracks data in an offline ROOT file, which is
written by aanet software.
The following example shows how to access tracks data in an offline ROOT file.
Note: the offline files used here were intentionaly reduced to 10 events.
"""
...
...
@@ -11,16 +10,20 @@ import km3io as ki
from
km3net_testdata
import
data_path
#####################################################
# To access offline tracks/mc_tracks data:
# We open the file using the
f
=
ki
.
OfflineReader
(
data_path
(
"
offline/numucc.root
"
))
mc_tracks
=
ki
.
OfflineReader
(
data_path
(
"
offline/numucc.root
"
)).
events
.
mc_tracks
tracks
=
ki
.
OfflineReader
(
data_path
(
"
offline/km3net_offline.root
"
)).
events
.
tracks
#####################################################
# To access offline tracks/mc_tracks data:
f
.
tracks
f
.
mc_tracks
#####################################################
# Note that no
t all
data is loaded in memory, so printing
# tracks will only return how many
elements (events) were fou
nd
in
#
the tracks branch of the file
.
# Note that no data is loaded in memory
at this point
, so printing
# tracks will only return how many
sub-branches (correspo
ndin
g to
#
events) were found
.
print
(
tracks
)
...
...
@@ -32,86 +35,47 @@ print(mc_tracks)
#####################################################
# Accessing the tracks/mc_tracks keys
# -----------------------------------
# to explore the tracks
key
s:
# to explore the
reconstructed
tracks
field
s:
keys
=
tracks
.
keys
()
print
(
keys
)
print
(
f
.
tracks
.
fields
)
#####################################################
# t
o explore the mc_tracks keys:
# t
he same for MC tracks
mc_keys
=
mc_tracks
.
keys
()
print
(
mc_keys
)
print
(
f
.
mc_tracks
.
fields
)
#####################################################
# Accessing tracks data
# ---------------------
# to access data in `E` (tracks energy):
# each field will return a nested `awkward.Array` and load everything into
# memory, so be careful if you are working with larger files.
E
=
tracks
.
E
print
(
E
)
print
(
f
.
tracks
.
E
)
print
(
f
.
tracks
.
dir_z
)
print
(
f
.
tracks
.
lik
)
#####################################################
# to access the likelihood:
likelihood
=
tracks
.
lik
print
(
likelihood
)
#####################################################
# That's it! you can access any key of your interest in the tracks
# keys in the exact same way.
# To select just a single event or a subset of events, use the indices or slices.
# The following will access all tracks and their fields
# of the third event (0 is the first):
#####################################################
# Accessing the mc_tracks data
# ----------------------------
# similarly, you can access mc_tracks data in any key of interest by
# following the same procedure as for tracks:
cos_zenith
=
mc_tracks
.
dir_z
print
(
cos_zenith
)
#####################################################
# or:
dir_y
=
mc_tracks
.
dir_y
print
(
dir_y
)
print
(
f
[
2
].
tracks
)
print
(
f
[
2
].
tracks
.
dir_z
)
#####################################################
# item selection in tracks data
# -----------------------------
# tracks data can be selected as you would select an item from a numpy array.
# for example, to select E (energy) in the tracks corresponding to the first event:
# while here, we select the first 3 events. Notice that all fields will return
# nested arrays, as we have seem above where all events were selected.
print
(
tracks
[
0
].
E
)
print
(
f
[:
3
])
print
(
f
[:
3
].
tracks
)
print
(
f
[:
3
].
tracks
.
dir_z
)
#####################################################
# or:
print
(
tracks
.
E
[
0
])
# or events from 3 and 5 (again, 0 indexing):
#####################################################
# slicing of tracks
# -----------------
# to select a slice of tracks data:
print
(
tracks
[
0
:
3
].
E
)
#####################################################
# or:
print
(
tracks
.
E
[
0
:
3
])
#####################################################
# you can apply masks to tracks data as you would do with numpy arrays:
mask
=
tracks
.
lik
>
100
print
(
tracks
.
lik
[
mask
])
#####################################################
# or:
print
(
tracks
.
dir_z
[
mask
])
print
(
f
[
2
:
5
])
print
(
f
[
2
:
5
].
tracks
)
print
(
f
[
2
:
5
].
tracks
.
dir_z
)
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