Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
KM3io.jl
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
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
common
KM3io.jl
Commits
e480396c
Commit
e480396c
authored
2 months ago
by
Tamas Gal
Browse files
Options
Downloads
Plain Diff
Merge branch 'calibration_helpers' into 'main'
Calibration helpers See merge request
!50
parents
7999721a
c02614de
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!50
Calibration helpers
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/hardware.jl
+22
-3
22 additions, 3 deletions
src/hardware.jl
src/root/offline.jl
+1
-1
1 addition, 1 deletion
src/root/offline.jl
src/types.jl
+1
-0
1 addition, 0 deletions
src/types.jl
test/hardware.jl
+6
-1
6 additions, 1 deletion
test/hardware.jl
with
30 additions
and
5 deletions
src/hardware.jl
+
22
−
3
View file @
e480396c
...
@@ -280,6 +280,7 @@ struct Detector
...
@@ -280,6 +280,7 @@ struct Detector
locations
::
Dict
{
Tuple
{
Int
,
Int
},
DetectorModule
}
locations
::
Dict
{
Tuple
{
Int
,
Int
},
DetectorModule
}
strings
::
Vector
{
Int
}
strings
::
Vector
{
Int
}
comments
::
Vector
{
String
}
comments
::
Vector
{
String
}
_pmt_id_module_map
::
Dict
{
Int
,
DetectorModule
}
end
end
"""
"""
Return a vector of all modules of a given detector.
Return a vector of all modules of a given detector.
...
@@ -324,7 +325,15 @@ Return the detector module for a given location.
...
@@ -324,7 +325,15 @@ Return the detector module for a given location.
"""
"""
Return the `PMT` for a given hit.
Return the `PMT` for a given hit.
"""
"""
@inline
getpmt
(
d
::
Detector
,
hit
)
=
getpmt
(
getmodule
(
d
,
hit
.
dom_id
),
hit
.
channel_id
)
@inline
getpmt
(
d
::
Detector
,
hit
::
AbstractDAQHit
)
=
getpmt
(
getmodule
(
d
,
hit
.
dom_id
),
hit
.
channel_id
)
"""
Return the detector module for a given DAQ hit.
"""
@inline
getmodule
(
d
::
Detector
,
hit
::
AbstractDAQHit
)
=
getmodule
(
d
,
hit
.
dom_id
)
"""
Return the detector module for a given MC hit.
"""
@inline
getmodule
(
d
::
Detector
,
hit
::
AbstractMCHit
)
=
d
.
_pmt_id_module_map
[
hit
.
pmt_id
]
Base
.
getindex
(
d
::
Detector
,
string
::
Int
,
::
Colon
)
=
sort!
(
filter
(
m
->
m
.
location
.
string
==
string
,
modules
(
d
)))
Base
.
getindex
(
d
::
Detector
,
string
::
Int
,
::
Colon
)
=
sort!
(
filter
(
m
->
m
.
location
.
string
==
string
,
modules
(
d
)))
Base
.
getindex
(
d
::
Detector
,
string
::
Int
,
floors
::
T
)
where
T
<:
Union
{
AbstractArray
,
UnitRange
}
=
[
d
[
string
,
floor
]
for
floor
in
sort
(
floors
)]
Base
.
getindex
(
d
::
Detector
,
string
::
Int
,
floors
::
T
)
where
T
<:
Union
{
AbstractArray
,
UnitRange
}
=
[
d
[
string
,
floor
]
for
floor
in
sort
(
floors
)]
Base
.
getindex
(
d
::
Detector
,
::
Colon
,
floor
::
Int
)
=
sort!
(
filter
(
m
->
m
.
location
.
floor
==
floor
,
modules
(
d
)))
Base
.
getindex
(
d
::
Detector
,
::
Colon
,
floor
::
Int
)
=
sort!
(
filter
(
m
->
m
.
location
.
floor
==
floor
,
modules
(
d
)))
...
@@ -422,6 +431,7 @@ function read_datx(io::IO)
...
@@ -422,6 +431,7 @@ function read_datx(io::IO)
modules
=
Dict
{
Int32
,
DetectorModule
}()
modules
=
Dict
{
Int32
,
DetectorModule
}()
locations
=
Dict
{
Tuple
{
Int
,
Int
},
DetectorModule
}()
locations
=
Dict
{
Tuple
{
Int
,
Int
},
DetectorModule
}()
strings
=
Int
[]
strings
=
Int
[]
_pmt_id_module_map
=
Dict
{
Int
,
DetectorModule
}()
for
_
in
1
:
n_modules
for
_
in
1
:
n_modules
module_id
=
read
(
io
,
Int32
)
module_id
=
read
(
io
,
Int32
)
location
=
Location
(
read
(
io
,
Int32
),
read
(
io
,
Int32
))
location
=
Location
(
read
(
io
,
Int32
),
read
(
io
,
Int32
))
...
@@ -443,10 +453,13 @@ function read_datx(io::IO)
...
@@ -443,10 +453,13 @@ function read_datx(io::IO)
push!
(
pmts
,
PMT
(
pmt_id
,
pmt_pos
,
pmt_dir
,
pmt_t₀
,
pmt_status
))
push!
(
pmts
,
PMT
(
pmt_id
,
pmt_pos
,
pmt_dir
,
pmt_t₀
,
pmt_status
))
end
end
m
=
DetectorModule
(
module_id
,
module_pos
,
location
,
n_pmts
,
pmts
,
q
,
module_status
,
module_t₀
)
m
=
DetectorModule
(
module_id
,
module_pos
,
location
,
n_pmts
,
pmts
,
q
,
module_status
,
module_t₀
)
for
pmt
in
pmts
_pmt_id_module_map
[
pmt
.
id
]
=
m
end
modules
[
module_id
]
=
m
modules
[
module_id
]
=
m
locations
[(
location
.
string
,
location
.
floor
)]
=
m
locations
[(
location
.
string
,
location
.
floor
)]
=
m
end
end
Detector
(
version
,
det_id
,
validity
,
utm_position
,
utm_ref_grid
,
n_modules
,
modules
,
locations
,
strings
,
comments
)
Detector
(
version
,
det_id
,
validity
,
utm_position
,
utm_ref_grid
,
n_modules
,
modules
,
locations
,
strings
,
comments
,
_pmt_id_module_map
)
end
end
@inline
_readstring
(
io
)
=
String
(
read
(
io
,
read
(
io
,
Int32
)))
@inline
_readstring
(
io
)
=
String
(
read
(
io
,
read
(
io
,
Int32
)))
...
@@ -481,6 +494,7 @@ function read_detx(io::IO)
...
@@ -481,6 +494,7 @@ function read_detx(io::IO)
modules
=
Dict
{
Int32
,
DetectorModule
}()
modules
=
Dict
{
Int32
,
DetectorModule
}()
locations
=
Dict
{
Tuple
{
Int
,
Int
},
DetectorModule
}()
locations
=
Dict
{
Tuple
{
Int
,
Int
},
DetectorModule
}()
strings
=
Int8
[]
strings
=
Int8
[]
_pmt_id_module_map
=
Dict
{
Int
,
DetectorModule
}()
# a counter to work around the floor == -1 bug in some older DETX files
# a counter to work around the floor == -1 bug in some older DETX files
floor_counter
=
1
floor_counter
=
1
...
@@ -556,10 +570,14 @@ function read_detx(io::IO)
...
@@ -556,10 +570,14 @@ function read_detx(io::IO)
m
=
DetectorModule
(
module_id
,
pos
,
Location
(
string
,
floor
),
n_pmts
,
pmts
,
q
,
status
,
t₀
)
m
=
DetectorModule
(
module_id
,
pos
,
Location
(
string
,
floor
),
n_pmts
,
pmts
,
q
,
status
,
t₀
)
modules
[
module_id
]
=
m
modules
[
module_id
]
=
m
locations
[(
string
,
floor
)]
=
m
locations
[(
string
,
floor
)]
=
m
for
pmt
in
pmts
_pmt_id_module_map
[
pmt
.
id
]
=
m
end
idx
+=
n_pmts
+
1
idx
+=
n_pmts
+
1
end
end
Detector
(
version
,
det_id
,
validity
,
utm_position
,
utm_ref_grid
,
n_modules
,
modules
,
locations
,
strings
,
comments
)
Detector
(
version
,
det_id
,
validity
,
utm_position
,
utm_ref_grid
,
n_modules
,
modules
,
locations
,
strings
,
comments
,
_pmt_id_module_map
)
end
end
...
@@ -607,6 +625,7 @@ The `version` parameter can be a version number or `:same`, which is the default
...
@@ -607,6 +625,7 @@ The `version` parameter can be a version number or `:same`, which is the default
and writes the same version as the provided detector has.
and writes the same version as the provided detector has.
"""
"""
function
write
(
filename
::
AbstractString
,
d
::
Detector
;
version
=:
same
)
function
write
(
filename
::
AbstractString
,
d
::
Detector
;
version
=:
same
)
!
endswith
(
filename
,
".detx"
)
&&
error
(
"Only DETX is supported for detector writing."
)
isfile
(
filename
)
&&
@warn
"File '
$(filename)
' already exists, overwriting."
isfile
(
filename
)
&&
@warn
"File '
$(filename)
' already exists, overwriting."
open
(
filename
,
"w"
)
do
fobj
open
(
filename
,
"w"
)
do
fobj
write
(
fobj
,
d
;
version
=
version
)
write
(
fobj
,
d
;
version
=
version
)
...
...
This diff is collapsed.
Click to expand it.
src/root/offline.jl
+
1
−
1
View file @
e480396c
...
@@ -25,7 +25,7 @@ A calibrated MC hit of the offline dataformat. Caveat: the `position` and
...
@@ -25,7 +25,7 @@ A calibrated MC hit of the offline dataformat. Caveat: the `position` and
the offline format (one class for all).
the offline format (one class for all).
"""
"""
struct
CalibratedMCHit
struct
CalibratedMCHit
<:
AbstractCalibratedMCHit
pmt_id
::
Int32
pmt_id
::
Int32
t
::
Float64
# MC truth
t
::
Float64
# MC truth
a
::
Float64
# amplitude (in p.e.)
a
::
Float64
# amplitude (in p.e.)
...
...
This diff is collapsed.
Click to expand it.
src/types.jl
+
1
−
0
View file @
e480396c
...
@@ -50,6 +50,7 @@ abstract type AbstractHit end
...
@@ -50,6 +50,7 @@ abstract type AbstractHit end
abstract type
AbstractDAQHit<:AbstractHit
end
abstract type
AbstractDAQHit<:AbstractHit
end
abstract type
AbstractMCHit<:AbstractHit
end
abstract type
AbstractMCHit<:AbstractHit
end
abstract type
AbstractCalibratedHit
<:
AbstractDAQHit
end
abstract type
AbstractCalibratedHit
<:
AbstractDAQHit
end
abstract type
AbstractCalibratedMCHit
<:
AbstractMCHit
end
"""
"""
...
...
This diff is collapsed.
Click to expand it.
test/hardware.jl
+
6
−
1
View file @
e480396c
...
@@ -8,6 +8,9 @@ const SAMPLES_DIR = joinpath(@__DIR__, "samples")
...
@@ -8,6 +8,9 @@ const SAMPLES_DIR = joinpath(@__DIR__, "samples")
@testset
"DETX parsing"
begin
@testset
"DETX parsing"
begin
mchit_sample
=
KM3io
.
CalibratedMCHit
(
7636
,
0
,
0
,
0
,
0
,
Position
(
0.0
,
0.0
,
0.0
),
Direction
(
0.0
,
0.0
,
0.0
))
daqhit_sample
=
KM3io
.
SnapshotHit
(
808966287
,
0
,
0
,
0
)
for
version
∈
1
:
5
for
version
∈
1
:
5
d
=
Detector
(
joinpath
(
SAMPLES_DIR
,
"v
$(version)
.detx"
))
d
=
Detector
(
joinpath
(
SAMPLES_DIR
,
"v
$(version)
.detx"
))
...
@@ -72,6 +75,8 @@ const SAMPLES_DIR = joinpath(@__DIR__, "samples")
...
@@ -72,6 +75,8 @@ const SAMPLES_DIR = joinpath(@__DIR__, "samples")
@test
817287557
==
getmodule
(
d
,
30
,
18
)
.
id
@test
817287557
==
getmodule
(
d
,
30
,
18
)
.
id
@test
817287557
==
getmodule
(
d
,
(
30
,
18
))
.
id
@test
817287557
==
getmodule
(
d
,
(
30
,
18
))
.
id
@test
817287557
==
getmodule
(
d
,
Location
(
30
,
18
))
.
id
@test
817287557
==
getmodule
(
d
,
Location
(
30
,
18
))
.
id
@test
808966287
==
getmodule
(
d
,
daqhit_sample
)
.
id
@test
808966287
==
getmodule
(
d
,
mchit_sample
)
.
id
@test
19
==
length
(
d
[
:
,
18
])
@test
19
==
length
(
d
[
:
,
18
])
for
m
in
d
[
:
,
17
]
for
m
in
d
[
:
,
17
]
...
@@ -153,7 +158,7 @@ end
...
@@ -153,7 +158,7 @@ end
detx
=
Detector
(
datapath
(
"detx"
,
"KM3NeT_00000133_20221025.detx"
))
detx
=
Detector
(
datapath
(
"detx"
,
"KM3NeT_00000133_20221025.detx"
))
datx
=
Detector
(
datapath
(
"datx"
,
"KM3NeT_00000133_20221025.datx"
))
datx
=
Detector
(
datapath
(
"datx"
,
"KM3NeT_00000133_20221025.datx"
))
for
field
in
fieldnames
(
Detector
)
for
field
in
fieldnames
(
Detector
)
field
==
:
modules
&&
continue
field
in
(
:
modules
,
:
_pmt_id_module_map
)
&&
continue
if
field
==
:
locations
if
field
==
:
locations
detx_locs
=
getfield
(
detx
,
field
)
detx_locs
=
getfield
(
detx
,
field
)
datx_locs
=
getfield
(
datx
,
field
)
datx_locs
=
getfield
(
datx
,
field
)
...
...
This diff is collapsed.
Click to expand it.
Tamas Gal
@tgal
mentioned in commit
5f3b6f38
·
2 months ago
mentioned in commit
5f3b6f38
mentioned in commit 5f3b6f388d55b2bde55044b19b01db6c687c8d6e
Toggle commit list
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