Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OrcaSong
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Machine Learning
OrcaSong
Commits
9ce542e5
Commit
9ce542e5
authored
4 years ago
by
Stefan Reck
Browse files
Options
Downloads
Patches
Plain Diff
black
parent
c3ccddf7
No related branches found
No related tags found
1 merge request
!11
Resolve "mc_info_extractor for neutrino reco chain"
This commit is part of merge request
!11
. Comments created here will be created in the context of that merge request.
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
orcasong/mc_info_extr.py
+475
-429
475 additions, 429 deletions
orcasong/mc_info_extr.py
with
475 additions
and
429 deletions
orcasong/mc_info_extr.py
+
475
−
429
Edit
View file @
9ce542e5
...
@@ -13,442 +13,488 @@ import numpy as np
...
@@ -13,442 +13,488 @@ import numpy as np
from
km3pipe.io.hdf5
import
HDF5Header
from
km3pipe.io.hdf5
import
HDF5Header
from
h5py
import
File
from
h5py
import
File
__author__
=
'
Daniel Guderian
'
__author__
=
"
Daniel Guderian
"
def
get_std_reco
(
blob
):
def
get_std_reco
(
blob
):
"""
"""
Function to extract std reco info. The implemented strategy is the following:
Function to extract std reco info. The implemented strategy is the following:
First, look for whether a rec stag has been reached and only then extract the reconstructed
First, look for whether a rec stag has been reached and only then extract the reconstructed
paramater from it. If not, set it to a dummy value (for now 0). This means that for an analysis the events with
paramater from it. If not, set it to a dummy value (for now 0). This means that for an analysis the events with
exactly zero have to be filtered out!
exactly zero have to be filtered out!
The
'
best track
'
is the first (highest lik) while a certain rec stage has to be reached. This might
The
'
best track
'
is the first (highest lik) while a certain rec stage has to be reached. This might
have to be adjusted for other recos than JMuonGandalf chain.
have to be adjusted for other recos than JMuonGandalf chain.
Members of the Tracks:
Members of the Tracks:
dtype([(
'
E
'
,
'
<f8
'
), (
'
JCOPY_Z_M
'
,
'
<f4
'
), (
'
JENERGY_CHI2
'
,
'
<f4
'
), (
'
JENERGY_ENERGY
'
,
'
<f4
'
),
dtype([(
'
E
'
,
'
<f8
'
), (
'
JCOPY_Z_M
'
,
'
<f4
'
), (
'
JENERGY_CHI2
'
,
'
<f4
'
), (
'
JENERGY_ENERGY
'
,
'
<f4
'
),
(
'
JENERGY_MUON_RANGE_METRES
'
,
'
<f4
'
), (
'
JENERGY_NDF
'
,
'
<f4
'
), (
'
JENERGY_NOISE_LIKELIHOOD
'
,
'
<f4
'
),
(
'
JENERGY_MUON_RANGE_METRES
'
,
'
<f4
'
), (
'
JENERGY_NDF
'
,
'
<f4
'
), (
'
JENERGY_NOISE_LIKELIHOOD
'
,
'
<f4
'
),
(
'
JENERGY_NUMBER_OF_HITS
'
,
'
<f4
'
), (
'
JGANDALF_BETA0_RAD
'
,
'
<f4
'
), (
'
JGANDALF_BETA1_RAD
'
,
'
<f4
'
),
(
'
JENERGY_NUMBER_OF_HITS
'
,
'
<f4
'
), (
'
JGANDALF_BETA0_RAD
'
,
'
<f4
'
), (
'
JGANDALF_BETA1_RAD
'
,
'
<f4
'
),
(
'
JGANDALF_CHI2
'
,
'
<f4
'
), (
'
JGANDALF_LAMBDA
'
,
'
<f4
'
), (
'
JGANDALF_NUMBER_OF_HITS
'
,
'
<f4
'
),
(
'
JGANDALF_CHI2
'
,
'
<f4
'
), (
'
JGANDALF_LAMBDA
'
,
'
<f4
'
), (
'
JGANDALF_NUMBER_OF_HITS
'
,
'
<f4
'
),
(
'
JGANDALF_NUMBER_OF_ITERATIONS
'
,
'
<f4
'
), (
'
JSHOWERFIT_ENERGY
'
,
'
<f4
'
), (
'
JSTART_LENGTH_METRES
'
,
'
<f4
'
),
(
'
JGANDALF_NUMBER_OF_ITERATIONS
'
,
'
<f4
'
), (
'
JSHOWERFIT_ENERGY
'
,
'
<f4
'
), (
'
JSTART_LENGTH_METRES
'
,
'
<f4
'
),
(
'
JSTART_NPE_MIP
'
,
'
<f4
'
), (
'
JSTART_NPE_MIP_TOTAL
'
,
'
<f4
'
), (
'
JVETO_NPE
'
,
'
<f4
'
), (
'
JVETO_NUMBER_OF_HITS
'
,
'
<f4
'
),
(
'
JSTART_NPE_MIP
'
,
'
<f4
'
), (
'
JSTART_NPE_MIP_TOTAL
'
,
'
<f4
'
), (
'
JVETO_NPE
'
,
'
<f4
'
), (
'
JVETO_NUMBER_OF_HITS
'
,
'
<f4
'
),
(
'
dir_x
'
,
'
<f8
'
), (
'
dir_y
'
,
'
<f8
'
), (
'
dir_z
'
,
'
<f8
'
), (
'
id
'
,
'
<i4
'
), (
'
idx
'
,
'
<i8
'
), (
'
length
'
,
'
<f8
'
),
(
'
dir_x
'
,
'
<f8
'
), (
'
dir_y
'
,
'
<f8
'
), (
'
dir_z
'
,
'
<f8
'
), (
'
id
'
,
'
<i4
'
), (
'
idx
'
,
'
<i8
'
), (
'
length
'
,
'
<f8
'
),
(
'
likelihood
'
,
'
<f8
'
), (
'
pos_x
'
,
'
<f8
'
), (
'
pos_y
'
,
'
<f8
'
), (
'
pos_z
'
,
'
<f8
'
), (
'
rec_type
'
,
'
<i4
'
),
(
'
likelihood
'
,
'
<f8
'
), (
'
pos_x
'
,
'
<f8
'
), (
'
pos_y
'
,
'
<f8
'
), (
'
pos_z
'
,
'
<f8
'
), (
'
rec_type
'
,
'
<i4
'
),
(
'
t
'
,
'
<f8
'
), (
'
group_id
'
,
'
<i8
'
)])
(
'
t
'
,
'
<f8
'
), (
'
group_id
'
,
'
<i8
'
)])
members of rec stages:
members of rec stages:
.idx (corresponding to the track id),
.idx (corresponding to the track id),
.rec_stage (rec stage identifier, for JMuonGandalf for example: 1=prefit, 2=simplex, 3=gandalf,
.rec_stage (rec stage identifier, for JMuonGandalf for example: 1=prefit, 2=simplex, 3=gandalf,
4=engery, 5=start),
4=engery, 5=start),
.group_id (event id in file)
.group_id (event id in file)
Parameters
Parameters
----------
----------
blob : blob containing the reco info
blob : blob containing the reco info
Returns
Returns
-------
-------
std_reco_info : dict
std_reco_info : dict
Dict with the most common std reco params. Can be expanded.
Dict with the most common std reco params. Can be expanded.
"""
"""
#use this later to identify not reconstructed events
# use this later to identify not reconstructed events
dummy_value
=
0
dummy_value
=
0
#if there was no std reco at all, this will not exist
# if there was no std reco at all, this will not exist
#these are events that stopped at/before prefit
# these are events that stopped at/before prefit
try
:
try
:
rec_stages
=
blob
[
"
RecStages
"
]
rec_stages
=
blob
[
"
RecStages
"
]
#get first track only
# get first track only
rec_stages_best_track
=
rec_stages
.
rec_stage
[
rec_stages
.
idx
==
0
]
rec_stages_best_track
=
rec_stages
.
rec_stage
[
rec_stages
.
idx
==
0
]
# often enough: best track is the first
# often enough: best track is the first
best_track
=
blob
[
"
Tracks
"
][
0
]
best_track
=
blob
[
"
Tracks
"
][
0
]
except
KeyError
:
except
KeyError
:
rec_stages_best_track
=
[]
rec_stages_best_track
=
[]
print
(
"
An event didnt have any reco. Setting everything to
"
+
str
(
dummy_value
)
+
"
.
"
)
print
(
"
An event didnt have any reco. Setting everything to
"
#take the direction only if JGanalf was executed
+
str
(
dummy_value
)
if
3
in
rec_stages_best_track
:
+
"
.
"
)
std_dir_x
=
best_track
[
"
dir_x
"
]
std_dir_y
=
best_track
[
"
dir_y
"
]
# take the direction only if JGanalf was executed
std_dir_z
=
best_track
[
"
dir_z
"
]
if
3
in
rec_stages_best_track
:
std_beta0
=
best_track
[
"
JGANDALF_BETA0_RAD
"
]
std_dir_x
=
best_track
[
"
dir_x
"
]
std_lik
=
best_track
[
"
likelihood
"
]
std_dir_y
=
best_track
[
"
dir_y
"
]
std_n_hits_gandalf
=
best_track
[
"
JGANDALF_NUMBER_OF_HITS
"
]
std_dir_z
=
best_track
[
"
dir_z
"
]
else
:
std_beta0
=
best_track
[
"
JGANDALF_BETA0_RAD
"
]
std_lik
=
best_track
[
"
likelihood
"
]
std_dir_x
=
dummy_value
std_n_hits_gandalf
=
best_track
[
"
JGANDALF_NUMBER_OF_HITS
"
]
std_dir_y
=
dummy_value
std_dir_z
=
dummy_value
else
:
std_beta0
=
dummy_value
std_dir_x
=
dummy_value
std_lik
=
dummy_value
std_dir_y
=
dummy_value
std_n_hits_gandalf
=
dummy_value
std_dir_z
=
dummy_value
#energy fit from JEnergy
std_beta0
=
dummy_value
if
4
in
rec_stages_best_track
:
std_lik
=
dummy_value
std_n_hits_gandalf
=
dummy_value
std_energy
=
best_track
[
"
E
"
]
lik_energy
=
best_track
[
"
JENERGY_CHI2
"
]
# energy fit from JEnergy
if
4
in
rec_stages_best_track
:
else
:
std_energy
=
dummy_value
std_energy
=
best_track
[
"
E
"
]
lik_energy
=
dummy_value
lik_energy
=
best_track
[
"
JENERGY_CHI2
"
]
#vertex and length from JStart
else
:
if
5
in
rec_stages_best_track
:
std_energy
=
dummy_value
lik_energy
=
dummy_value
std_pos_x
=
best_track
[
"
pos_x
"
]
std_pos_y
=
best_track
[
"
pos_y
"
]
# vertex and length from JStart
std_pos_z
=
best_track
[
"
pos_z
"
]
if
5
in
rec_stages_best_track
:
std_length
=
best_track
[
"
JSTART_LENGTH_METRES
"
]
std_pos_x
=
best_track
[
"
pos_x
"
]
std_pos_y
=
best_track
[
"
pos_y
"
]
else
:
std_pos_z
=
best_track
[
"
pos_z
"
]
std_pos_x
=
dummy_value
std_length
=
best_track
[
"
JSTART_LENGTH_METRES
"
]
std_pos_y
=
dummy_value
std_pos_z
=
dummy_value
else
:
std_length
=
dummy_value
std_pos_x
=
dummy_value
std_pos_y
=
dummy_value
std_reco_info
=
{
std_pos_z
=
dummy_value
'
std_dir_x
'
:
std_dir_x
,
'
std_dir_y
'
:
std_dir_y
,
'
std_dir_z
'
:
std_dir_z
,
'
std_beta0
'
:
std_beta0
,
'
std_lik
'
:
std_lik
,
'
std_n_hits_gandalf
'
:
std_n_hits_gandalf
,
std_length
=
dummy_value
'
std_pos_x
'
:
std_pos_x
,
'
std_pos_y
'
:
std_pos_y
,
'
std_pos_z
'
:
std_pos_z
,
std_reco_info
=
{
'
std_energy
'
:
std_energy
,
'
std_lik_energy
'
:
lik_energy
,
'
std_length
'
:
std_length
,
"
std_dir_x
"
:
std_dir_x
,
}
"
std_dir_y
"
:
std_dir_y
,
"
std_dir_z
"
:
std_dir_z
,
return
std_reco_info
"
std_beta0
"
:
std_beta0
,
"
std_lik
"
:
std_lik
,
"
std_n_hits_gandalf
"
:
std_n_hits_gandalf
,
"
std_pos_x
"
:
std_pos_x
,
"
std_pos_y
"
:
std_pos_y
,
"
std_pos_z
"
:
std_pos_z
,
"
std_energy
"
:
std_energy
,
"
std_lik_energy
"
:
lik_energy
,
"
std_length
"
:
std_length
,
}
return
std_reco_info
def
get_real_data_info_extr
(
input_file
):
def
get_real_data_info_extr
(
input_file
):
"""
"""
Wrapper function that includes the actual mc_info_extr
Wrapper function that includes the actual mc_info_extr
for real data. There are no n_gen like in the neutrino case.
for real data. There are no n_gen like in the neutrino case.
Parameters
Parameters
----------
----------
input_file : km3net data file
input_file : km3net data file
Can be online or offline format.
Can be online or offline format.
Returns
Returns
-------
-------
mc_info_extr : function
mc_info_extr : function
The actual mc_info_extr function that holds the extractions.
The actual mc_info_extr function that holds the extractions.
"""
"""
#check if std reco is present
# check if std reco is present
f
=
File
(
input_file
,
"
r
"
)
f
=
File
(
input_file
,
"
r
"
)
has_std_reco
=
"
reco
"
in
f
.
keys
()
has_std_reco
=
"
reco
"
in
f
.
keys
()
def
mc_info_extr
(
blob
):
def
mc_info_extr
(
blob
):
"""
"""
Processes a blob and creates the y with mc_info and, if existing, std reco.
Processes a blob and creates the y with mc_info and, if existing, std reco.
For this real data case it is only general event info, like the id.
For this real data case it is only general event info, like the id.
Parameters
Parameters
----------
----------
blob : dict
blob : dict
The blob from the pipeline.
The blob from the pipeline.
Returns
Returns
-------
-------
track : dict
track : dict
Containing all the specified info the y should have.
Containing all the specified info the y should have.
"""
"""
event_info
=
blob
[
'
EventInfo
'
][
0
]
event_info
=
blob
[
"
EventInfo
"
][
0
]
#add n_hits info for the cut
# add n_hits info for the cut
n_hits
=
len
(
blob
[
'
Hits
'
])
n_hits
=
len
(
blob
[
"
Hits
"
])
track
=
{
track
=
{
'
event_id
'
:
event_info
.
event_id
,
"
event_id
"
:
event_info
.
event_id
,
'
run_id
'
:
event_info
.
run_id
,
"
run_id
"
:
event_info
.
run_id
,
'
trigger_mask
'
:
event_info
.
trigger_mask
,
"
trigger_mask
"
:
event_info
.
trigger_mask
,
'
n_hits
'
:
n_hits
,
"
n_hits
"
:
n_hits
,
}
}
#get all the std reco info
# get all the std reco info
if
has_std_reco
:
if
has_std_reco
:
std_reco_info
=
get_std_reco
(
blob
)
std_reco_info
=
get_std_reco
(
blob
)
track
.
update
(
std_reco_info
)
track
.
update
(
std_reco_info
)
return
track
return
track
return
mc_info_extr
return
mc_info_extr
def
get_random_noise_mc_info_extr
(
input_file
):
def
get_random_noise_mc_info_extr
(
input_file
):
"""
"""
Wrapper function that includes the actual mc_info_extr
Wrapper function that includes the actual mc_info_extr
for random noise simulations. There are no n_gen like in the neutrino case.
for random noise simulations. There are no n_gen like in the neutrino case.
Parameters
Parameters
----------
----------
input_file : km3net data file
input_file : km3net data file
Can be online or offline format.
Can be online or offline format.
Returns
Returns
-------
-------
mc_info_extr : function
mc_info_extr : function
The actual mc_info_extr function that holds the extractions.
The actual mc_info_extr function that holds the extractions.
"""
"""
#
check if std reco is present
#
check if std reco is present
f
=
File
(
input_file
,
"
r
"
)
f
=
File
(
input_file
,
"
r
"
)
has_std_reco
=
"
reco
"
in
f
.
keys
()
has_std_reco
=
"
reco
"
in
f
.
keys
()
def
mc_info_extr
(
blob
):
def
mc_info_extr
(
blob
):
"""
"""
Processes a blob and creates the y with mc_info and, if existing, std reco.
Processes a blob and creates the y with mc_info and, if existing, std reco.
For this random noise case it is only general event info, like the id.
For this random noise case it is only general event info, like the id.
Parameters
Parameters
----------
----------
blob : dict
blob : dict
The blob from the pipeline.
The blob from the pipeline.
Returns
Returns
-------
-------
track : dict
track : dict
Containing all the specified info the y should have.
Containing all the specified info the y should have.
"""
"""
event_info
=
blob
[
'
EventInfo
'
]
event_info
=
blob
[
"
EventInfo
"
]
track
=
{
track
=
{
'
event_id
'
:
event_info
.
event_id
[
0
],
"
event_id
"
:
event_info
.
event_id
[
0
],
'
run_id
'
:
event_info
.
run_id
[
0
],
"
run_id
"
:
event_info
.
run_id
[
0
],
'
particle_type
'
:
0
,
"
particle_type
"
:
0
,
}
}
#
get all the std reco info
#
get all the std reco info
if
has_std_reco
:
if
has_std_reco
:
std_reco_info
=
get_std_reco
(
blob
)
std_reco_info
=
get_std_reco
(
blob
)
track
.
update
(
std_reco_info
)
track
.
update
(
std_reco_info
)
return
track
return
track
return
mc_info_extr
return
mc_info_extr
def
get_neutrino_mc_info_extr
(
input_file
):
def
get_neutrino_mc_info_extr
(
input_file
):
"""
"""
Wrapper function that includes the actual mc_info_extr
Wrapper function that includes the actual mc_info_extr
for neutrino simulations. The n_gen parameter, needed for neutrino weighting
for neutrino simulations. The n_gen parameter, needed for neutrino weighting
is extracted from the header of the file.
is extracted from the header of the file.
Parameters
Parameters
----------
----------
input_file : km3net data file
input_file : km3net data file
Can be online or offline format.
Can be online or offline format.
Returns
Returns
-------
-------
mc_info_extr : function
mc_info_extr : function
The actual mc_info_extr function that holds the extractions.
The actual mc_info_extr function that holds the extractions.
"""
"""
#check if std reco is present
# check if std reco is present
f
=
File
(
input_file
,
"
r
"
)
f
=
File
(
input_file
,
"
r
"
)
has_std_reco
=
"
reco
"
in
f
.
keys
()
has_std_reco
=
"
reco
"
in
f
.
keys
()
#get the n_gen
# get the n_gen
header
=
HDF5Header
.
from_hdf5
(
input_file
)
header
=
HDF5Header
.
from_hdf5
(
input_file
)
n_gen
=
header
.
genvol
.
numberOfEvents
n_gen
=
header
.
genvol
.
numberOfEvents
def
mc_info_extr
(
blob
):
def
mc_info_extr
(
blob
):
"""
"""
Processes a blob and creates the y with mc_info and, if existing, std reco.
Processes a blob and creates the y with mc_info and, if existing, std reco.
For this neutrino case it is the full mc info for the primary neutrino; there are the several
"
McTracks
"
:
For this neutrino case it is the full mc info for the primary neutrino; there are the several
"
McTracks
"
:
check the simulation which index
"
p
"
the neutrino has.
check the simulation which index
"
p
"
the neutrino has.
Parameters
Parameters
----------
----------
blob : dict
blob : dict
The blob from the pipeline.
The blob from the pipeline.
Returns
Returns
-------
-------
track : dict
track : dict
Containing all the specified info the y should have.
Containing all the specified info the y should have.
"""
"""
# get general info about the event
#get general info about the event
event_id
=
blob
[
"
EventInfo
"
].
event_id
[
0
]
event_id
=
blob
[
'
EventInfo
'
].
event_id
[
0
]
run_id
=
blob
[
"
EventInfo
"
].
run_id
[
0
]
run_id
=
blob
[
"
EventInfo
"
].
run_id
[
0
]
# weights for neutrino analysis
#weights for neutrino analysis
weight_w1
=
blob
[
"
EventInfo
"
].
weight_w1
[
0
]
weight_w1
=
blob
[
"
EventInfo
"
].
weight_w1
[
0
]
weight_w2
=
blob
[
"
EventInfo
"
].
weight_w2
[
0
]
weight_w2
=
blob
[
"
EventInfo
"
].
weight_w2
[
0
]
weight_w3
=
blob
[
"
EventInfo
"
].
weight_w3
[
0
]
weight_w3
=
blob
[
"
EventInfo
"
].
weight_w3
[
0
]
# first, look for the particular neutrino index of the production
# first, look for the particular neutrino index of the production
p
=
0
# for ORCA4 (and probably subsequent productions)
p
=
0
#for ORCA4 (and probably subsequent productions)
mc_track
=
blob
[
"
McTracks
"
][
p
]
mc_track
=
blob
[
'
McTracks
'
][
p
]
# some track mc truth info
#some track mc truth info
particle_type
=
mc_track
.
type
particle_type
=
mc_track
.
type
energy
=
mc_track
.
energy
energy
=
mc_track
.
energy
is_cc
=
mc_track
.
cc
is_cc
=
mc_track
.
cc
bjorkeny
=
mc_track
.
by
bjorkeny
=
mc_track
.
by
dir_x
,
dir_y
,
dir_z
=
mc_track
.
dir_x
,
mc_track
.
dir_y
,
mc_track
.
dir_z
dir_x
,
dir_y
,
dir_z
=
mc_track
.
dir_x
,
mc_track
.
dir_y
,
mc_track
.
dir_z
time_interaction
=
(
time_interaction
=
mc_track
.
time
# actually always 0 for primary neutrino, measured in MC time
mc_track
.
time
vertex_pos_x
,
vertex_pos_y
,
vertex_pos_z
=
mc_track
.
pos_x
,
mc_track
.
pos_y
,
mc_track
.
pos_z
)
# actually always 0 for primary neutrino, measured in MC time
vertex_pos_x
,
vertex_pos_y
,
vertex_pos_z
=
(
#add also the nhits info
mc_track
.
pos_x
,
n_hits
=
len
(
blob
[
'
Hits
'
])
mc_track
.
pos_y
,
mc_track
.
pos_z
,
track
=
{
'
event_id
'
:
event_id
,
'
particle_type
'
:
particle_type
,
'
energy
'
:
energy
,
'
is_cc
'
:
is_cc
,
)
'
bjorkeny
'
:
bjorkeny
,
'
dir_x
'
:
dir_x
,
'
dir_y
'
:
dir_y
,
'
dir_z
'
:
dir_z
,
'
time_interaction
'
:
time_interaction
,
'
run_id
'
:
run_id
,
'
vertex_pos_x
'
:
vertex_pos_x
,
# add also the nhits info
'
vertex_pos_y
'
:
vertex_pos_y
,
'
vertex_pos_z
'
:
vertex_pos_z
,
n_hits
=
len
(
blob
[
"
Hits
"
])
'
n_hits
'
:
n_hits
,
'
weight_w1
'
:
weight_w1
,
'
weight_w2
'
:
weight_w2
,
'
weight_w3
'
:
weight_w3
,
track
=
{
'
n_gen
'
:
n_gen
,
"
event_id
"
:
event_id
,
}
"
particle_type
"
:
particle_type
,
print
(
is_cc
)
"
energy
"
:
energy
,
#get all the std reco info
"
is_cc
"
:
is_cc
,
if
has_std_reco
:
"
bjorkeny
"
:
bjorkeny
,
"
dir_x
"
:
dir_x
,
std_reco_info
=
get_std_reco
(
blob
)
"
dir_y
"
:
dir_y
,
"
dir_z
"
:
dir_z
,
track
.
update
(
std_reco_info
)
"
time_interaction
"
:
time_interaction
,
"
run_id
"
:
run_id
,
return
track
"
vertex_pos_x
"
:
vertex_pos_x
,
"
vertex_pos_y
"
:
vertex_pos_y
,
return
mc_info_extr
"
vertex_pos_z
"
:
vertex_pos_z
,
"
n_hits
"
:
n_hits
,
"
weight_w1
"
:
weight_w1
,
"
weight_w2
"
:
weight_w2
,
"
weight_w3
"
:
weight_w3
,
"
n_gen
"
:
n_gen
,
}
print
(
is_cc
)
# get all the std reco info
if
has_std_reco
:
std_reco_info
=
get_std_reco
(
blob
)
track
.
update
(
std_reco_info
)
return
track
return
mc_info_extr
def
get_muon_mc_info_extr
(
input_file
):
def
get_muon_mc_info_extr
(
input_file
):
"""
"""
Wrapper function that includes the actual mc_info_extr
Wrapper function that includes the actual mc_info_extr
for atm. muon simulations. There are no n_gen like in the neutrino case.
for atm. muon simulations. There are no n_gen like in the neutrino case.
Parameters
Parameters
----------
----------
input_file : km3net data file
input_file : km3net data file
Can be online or offline format.
Can be online or offline format.
Returns
Returns
-------
-------
mc_info_extr : function
mc_info_extr : function
The actual mc_info_extr function that holds the extractions.
The actual mc_info_extr function that holds the extractions.
"""
"""
#check if std reco is present
# check if std reco is present
f
=
File
(
input_file
,
"
r
"
)
f
=
File
(
input_file
,
"
r
"
)
has_std_reco
=
"
reco
"
in
f
.
keys
()
has_std_reco
=
"
reco
"
in
f
.
keys
()
#no n_gen here, but needed for concatenation
# no n_gen here, but needed for concatenation
n_gen
=
1
n_gen
=
1
def
mc_info_extr
(
blob
):
def
mc_info_extr
(
blob
):
"""
"""
Processes a blob and creates the y with mc_info and, if existing, std reco.
Processes a blob and creates the y with mc_info and, if existing, std reco.
For this atm. muon case it is the full mc info for the primary; there are the several
"
McTracks
"
:
For this atm. muon case it is the full mc info for the primary; there are the several
"
McTracks
"
:
check the simulation to understand what
"
p
"
you want. Muons come in bundles that have the same direction.
check the simulation to understand what
"
p
"
you want. Muons come in bundles that have the same direction.
For energy: sum of all muons in a bundle,
For energy: sum of all muons in a bundle,
for vertex: weighted (energy) mean of the individual vertices .
for vertex: weighted (energy) mean of the individual vertices .
Parameters
Parameters
----------
----------
blob : dict
blob : dict
The blob from the pipeline.
The blob from the pipeline.
Returns
Returns
-------
-------
track : dict
track : dict
Containing all the specified info the y should have.
Containing all the specified info the y should have.
"""
"""
event_id
=
blob
[
"
EventInfo
"
].
event_id
[
0
]
event_id
=
blob
[
'
EventInfo
'
].
event_id
[
0
]
run_id
=
blob
[
"
EventInfo
"
].
run_id
[
0
]
run_id
=
blob
[
"
EventInfo
"
].
run_id
[
0
]
p
=
0
# for ORCA4 (and probably subsequent productions)
p
=
0
#for ORCA4 (and probably subsequent productions)
mc_track
=
blob
[
"
McTracks
"
][
p
]
mc_track
=
blob
[
'
McTracks
'
][
p
]
particle_type
=
(
particle_type
=
mc_track
.
type
# assumed that this is the same for all muons in a bundle
mc_track
.
type
is_cc
=
mc_track
.
cc
# always 0 actually
)
# assumed that this is the same for all muons in a bundle
bjorkeny
=
mc_track
.
by
is_cc
=
mc_track
.
cc
# always 0 actually
time_interaction
=
mc_track
.
time
# same for all muons in a bundle
bjorkeny
=
mc_track
.
by
time_interaction
=
mc_track
.
time
# same for all muons in a bundle
# sum up the energy of all muons
energy
=
np
.
sum
(
blob
[
'
McTracks
'
].
energy
)
# sum up the energy of all muons
energy
=
np
.
sum
(
blob
[
"
McTracks
"
].
energy
)
# all muons in a bundle are parallel, so just take dir of first muon
dir_x
,
dir_y
,
dir_z
=
mc_track
.
dir_x
,
mc_track
.
dir_y
,
mc_track
.
dir_z
# all muons in a bundle are parallel, so just take dir of first muon
dir_x
,
dir_y
,
dir_z
=
mc_track
.
dir_x
,
mc_track
.
dir_y
,
mc_track
.
dir_z
# vertex is the weighted (energy) mean of the individual vertices
vertex_pos_x
=
np
.
average
(
blob
[
'
McTracks
'
][
p
:].
pos_x
,
weights
=
blob
[
'
McTracks
'
][
p
:].
energy
)
# vertex is the weighted (energy) mean of the individual vertices
vertex_pos_y
=
np
.
average
(
blob
[
'
McTracks
'
][
p
:].
pos_y
,
weights
=
blob
[
'
McTracks
'
][
p
:].
energy
)
vertex_pos_x
=
np
.
average
(
vertex_pos_z
=
np
.
average
(
blob
[
'
McTracks
'
][
p
:].
pos_z
,
weights
=
blob
[
'
McTracks
'
][
p
:].
energy
)
blob
[
"
McTracks
"
][
p
:].
pos_x
,
weights
=
blob
[
"
McTracks
"
][
p
:].
energy
)
#add also the nhits info
vertex_pos_y
=
np
.
average
(
n_hits
=
len
(
blob
[
'
Hits
'
])
blob
[
"
McTracks
"
][
p
:].
pos_y
,
weights
=
blob
[
"
McTracks
"
][
p
:].
energy
)
#this is only relevant for neutrinos, though dummy info is needed for the concatenation
vertex_pos_z
=
np
.
average
(
weight_w1
=
10
blob
[
"
McTracks
"
][
p
:].
pos_z
,
weights
=
blob
[
"
McTracks
"
][
p
:].
energy
weight_w2
=
10
)
weight_w3
=
10
# add also the nhits info
track
=
{
'
event_id
'
:
event_id
,
'
particle_type
'
:
particle_type
,
'
energy
'
:
energy
,
'
is_cc
'
:
is_cc
,
n_hits
=
len
(
blob
[
"
Hits
"
])
'
bjorkeny
'
:
bjorkeny
,
'
dir_x
'
:
dir_x
,
'
dir_y
'
:
dir_y
,
'
dir_z
'
:
dir_z
,
'
time_interaction
'
:
time_interaction
,
'
run_id
'
:
run_id
,
'
vertex_pos_x
'
:
vertex_pos_x
,
# this is only relevant for neutrinos, though dummy info is needed for the concatenation
'
vertex_pos_y
'
:
vertex_pos_y
,
'
vertex_pos_z
'
:
vertex_pos_z
,
weight_w1
=
10
'
n_hits
'
:
n_hits
,
weight_w2
=
10
weight_w3
=
10
'
weight_w1
'
:
weight_w1
,
'
weight_w2
'
:
weight_w2
,
'
weight_w3
'
:
weight_w3
,
'
n_gen
'
:
n_gen
,
track
=
{
}
"
event_id
"
:
event_id
,
"
particle_type
"
:
particle_type
,
#get all the std reco info
"
energy
"
:
energy
,
if
has_std_reco
:
"
is_cc
"
:
is_cc
,
"
bjorkeny
"
:
bjorkeny
,
std_reco_info
=
get_std_reco
(
blob
)
"
dir_x
"
:
dir_x
,
"
dir_y
"
:
dir_y
,
track
.
update
(
std_reco_info
)
"
dir_z
"
:
dir_z
,
"
time_interaction
"
:
time_interaction
,
return
track
"
run_id
"
:
run_id
,
"
vertex_pos_x
"
:
vertex_pos_x
,
return
mc_info_extr
"
vertex_pos_y
"
:
vertex_pos_y
,
"
vertex_pos_z
"
:
vertex_pos_z
,
"
n_hits
"
:
n_hits
,
"
weight_w1
"
:
weight_w1
,
"
weight_w2
"
:
weight_w2
,
"
weight_w3
"
:
weight_w3
,
"
n_gen
"
:
n_gen
,
}
# get all the std reco info
if
has_std_reco
:
std_reco_info
=
get_std_reco
(
blob
)
track
.
update
(
std_reco_info
)
return
track
return
mc_info_extr
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