Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3mon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
km3mon
Commits
c4afee8e
Commit
c4afee8e
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Remove old script
parent
863ff6f6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/event_hits.py
+0
-173
0 additions, 173 deletions
scripts/event_hits.py
with
0 additions
and
173 deletions
scripts/event_hits.py
deleted
100755 → 0
+
0
−
173
View file @
863ff6f6
#!/usr/bin/env python
# coding=utf-8
# Filename: event_hits.py
# Author: Tamas Gal <tgal@km3net.de>
# vim: ts=4 sw=4 et
"""
Monitors hits and triggered hits on each DOM, based on events.
Usage:
event_hits.py [options]
event_hits.py (-h | --help)
Options:
-l LIGIER_IP The IP of the ligier [default: 127.0.0.1].
-p LIGIER_PORT The port of the ligier [default: 5553].
-d DET_ID Detector ID [default: 29].
-o PLOT_DIR The directory to save the plot [default: www/plots].
-h --help Show this screen.
"""
from
__future__
import
division
from
datetime
import
datetime
from
collections
import
deque
,
defaultdict
from
functools
import
partial
import
math
import
os
import
shutil
import
time
import
threading
from
io
import
BytesIO
import
matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib
.
use
(
'
Agg
'
)
import
matplotlib.pyplot
as
plt
import
matplotlib.ticker
as
ticker
import
matplotlib.dates
as
md
from
matplotlib.colors
import
LogNorm
from
matplotlib
import
pylab
import
seaborn
as
sns
import
pandas
as
pd
import
numpy
as
np
from
km3pipe
import
Pipeline
,
Module
,
Geometry
from
km3pipe.dataclasses
import
HitSeries
from
km3pipe.common
import
Queue
,
Empty
from
km3pipe.hardware
import
Detector
from
km3pipe.io
import
CHPump
from
km3pipe.io.daq
import
(
DAQProcessor
,
DAQPreamble
,
DAQSummaryslice
,
DAQEvent
)
from
km3pipe.time
import
tai_timestamp
import
km3pipe.style
km3pipe
.
style
.
use
(
'
km3pipe
'
)
PLOTS_PATH
=
'
km3web/plots
'
N_DOMS
=
18
N_DUS
=
2
geometry
=
Geometry
(
det_id
=
29
)
detector
=
geometry
.
detector
xfmt
=
md
.
DateFormatter
(
'
%Y-%m-%d %H:%M
'
)
class
DOMHits
(
Module
):
def
configure
(
self
):
self
.
run
=
True
self
.
max_events
=
1000
self
.
hits
=
deque
(
maxlen
=
1000
)
self
.
triggered_hits
=
deque
(
maxlen
=
1000
)
self
.
lock
=
threading
.
Lock
()
self
.
thread
=
threading
.
Thread
(
target
=
self
.
plot
).
start
()
def
process
(
self
,
blob
):
tag
=
str
(
blob
[
'
CHPrefix
'
].
tag
)
if
not
tag
==
'
IO_EVT
'
:
return
blob
data
=
blob
[
'
CHData
'
]
data_io
=
BytesIO
(
data
)
preamble
=
DAQPreamble
(
file_obj
=
data_io
)
event
=
DAQEvent
(
file_obj
=
data_io
)
with
self
.
lock
:
hits
=
np
.
zeros
(
N_DOMS
*
N_DUS
)
for
dom_id
,
_
,
_
,
_
in
event
.
snapshot_hits
:
du
,
floor
,
_
=
detector
.
doms
[
dom_id
]
hits
[(
du
-
1
)
*
N_DOMS
+
floor
-
1
]
+=
1
self
.
hits
.
append
(
hits
)
triggered_hits
=
np
.
zeros
(
N_DOMS
*
N_DUS
)
for
dom_id
,
_
,
_
,
_
,
_
in
event
.
triggered_hits
:
du
,
floor
,
_
=
detector
.
doms
[
dom_id
]
triggered_hits
[(
du
-
1
)
*
N_DOMS
+
floor
-
1
]
+=
1
self
.
triggered_hits
.
append
(
triggered_hits
)
return
blob
def
plot
(
self
):
while
self
.
run
:
with
self
.
lock
:
self
.
create_plots
()
time
.
sleep
(
50
)
def
create_plots
(
self
):
if
len
(
self
.
hits
)
>
0
:
self
.
create_plot
(
self
.
hits
,
"
Hits on DOMs
"
,
'
hits_on_doms
'
)
if
len
(
self
.
triggered_hits
)
>
0
:
self
.
create_plot
(
self
.
triggered_hits
,
"
Triggered Hits on DOMs
"
,
'
triggered_hits_on_doms
'
)
def
create_plot
(
self
,
hits
,
title
,
filename
):
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
16
,
8
))
ax
.
grid
(
True
)
ax
.
set_axisbelow
(
True
)
hit_matrix
=
np
.
array
([
np
.
array
(
x
)
for
x
in
hits
]).
transpose
()
im
=
ax
.
matshow
(
hit_matrix
,
interpolation
=
'
nearest
'
,
filternorm
=
None
,
cmap
=
'
plasma
'
,
aspect
=
'
auto
'
,
origin
=
'
lower
'
,
zorder
=
3
,
norm
=
LogNorm
(
vmin
=
1
,
vmax
=
np
.
amax
(
hit_matrix
)))
yticks
=
np
.
arange
(
N_DOMS
*
N_DUS
)
ytick_labels
=
[
"
DU{0:0.0f}-DOM{1:02d}
"
.
format
(
np
.
ceil
((
y
+
1
)
/
N_DOMS
),
y
%
(
N_DOMS
)
+
1
)
\
for
y
in
yticks
]
ax
.
set_yticks
(
yticks
);
ax
.
set_yticklabels
(
ytick_labels
);
ax
.
tick_params
(
labelbottom
=
False
)
ax
.
tick_params
(
labeltop
=
False
)
ax
.
set_xlabel
(
"
event (latest on the right)
"
)
ax
.
set_title
(
"
{0} - via the last {1} Events
\n
{2} UTC
"
.
format
(
title
,
self
.
max_events
,
datetime
.
utcnow
().
strftime
(
"
%c
"
)))
cb
=
fig
.
colorbar
(
im
,
pad
=
0.05
)
cb
.
set_label
(
"
number of hits
"
)
fig
.
tight_layout
()
f
=
os
.
path
.
join
(
PLOTS_PATH
,
filename
+
'
.png
'
)
f_tmp
=
os
.
path
.
join
(
PLOTS_PATH
,
filename
+
'
_tmp.png
'
)
plt
.
savefig
(
f_tmp
,
dpi
=
120
,
bbox_inches
=
"
tight
"
)
plt
.
close
(
'
all
'
)
shutil
.
move
(
f_tmp
,
f
)
def
finish
(
self
):
self
.
run
=
False
if
self
.
thread
is
not
None
:
self
.
thread
.
stop
()
def
main
():
from
docopt
import
docopt
args
=
docopt
(
__doc__
,
version
=
VERSION
)
det_id
=
int
(
args
[
'
-d
'
])
plots_path
=
args
[
'
-o
'
]
ligier_ip
=
args
[
'
-l
'
]
ligier_port
=
int
(
args
[
'
-p
'
])
pipe
=
kp
.
Pipeline
()
pipe
.
attach
(
kp
.
io
.
ch
.
CHPump
,
host
=
ligier_ip
,
port
=
ligier_port
,
tags
=
'
IO_EVT, IO_SUM
'
,
timeout
=
60
*
60
*
24
*
7
,
max_queue
=
2000
)
pipe
.
attach
(
kp
.
io
.
daq
.
DAQProcessor
)
pipe
.
attach
(
DOMHits
,
det_id
=
det_id
,
plots_path
=
plots_path
)
pipe
.
drain
()
if
__name__
==
'
__main__
'
:
main
()
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