Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fadc_decoder
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zhiwen Zhao
fadc_decoder
Commits
0b3fe142
Commit
0b3fe142
authored
Apr 19, 2020
by
Chao Peng
Browse files
Options
Downloads
Patches
Plain Diff
add a analysis script
parent
e084e395
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
scripts/analyze_waveform.py
+64
-0
64 additions, 0 deletions
scripts/analyze_waveform.py
scripts/draw_events.py
+14
-6
14 additions, 6 deletions
scripts/draw_events.py
src/esb_analyze.cpp
+1
-1
1 addition, 1 deletion
src/esb_analyze.cpp
with
79 additions
and
7 deletions
scripts/analyze_waveform.py
0 → 100644
+
64
−
0
View file @
0b3fe142
import
ROOT
import
os
import
json
import
numpy
as
np
import
pandas
as
pd
import
argparse
from
matplotlib
import
pyplot
as
plt
from
scipy
import
signal
from
collections.abc
import
Iterable
def
branch_to_array1d
(
br
,
t
):
return
np
.
ndarray
((
len
(
br
),
),
dtype
=
t
,
buffer
=
br
)
def
get_channels
(
json_path
):
dbf
=
open
(
json_path
)
db
=
json
.
load
(
dbf
)
channels
=
dict
()
for
mod
,
mod_prop
in
db
.
items
():
for
ch
in
mod_prop
[
'
channels
'
]:
channels
[
ch
[
'
name
'
]]
=
ch
[
'
type
'
]
return
channels
parser
=
argparse
.
ArgumentParser
(
'
Raw waveform analysis
'
)
parser
.
add_argument
(
'
root_file
'
,
help
=
'
a root file of waveform data
'
)
parser
.
add_argument
(
'
module_file
'
,
help
=
'
a json database of modules and channels
'
)
parser
.
add_argument
(
'
output_file
'
,
help
=
'
Output csv file
'
)
parser
.
add_argument
(
'
--peak-thres
'
,
dest
=
'
pthres
'
,
help
=
'
sigma threshold for finding the peak, default 8
'
,
type
=
float
,
default
=
8
)
parser
.
add_argument
(
'
--peak-min
'
,
dest
=
'
pmin
'
,
help
=
'
lower limit of the peak adc value, default 10
'
,
type
=
int
,
default
=
10
)
parser
.
add_argument
(
'
--peak-max
'
,
dest
=
'
pmax
'
,
help
=
'
upper limit of the peak adc value, default 8000
'
,
type
=
int
,
default
=
8000
)
parser
.
add_argument
(
'
--time-min
'
,
dest
=
'
tmin
'
,
help
=
'
lower limit of the time window, default 0
'
,
type
=
int
,
default
=
0
)
parser
.
add_argument
(
'
--time-max
'
,
dest
=
'
tmax
'
,
help
=
'
upper limit of the time window, default 63
'
,
type
=
int
,
default
=
63
)
args
=
parser
.
parse_args
()
f
=
ROOT
.
TFile
.
Open
(
args
.
root_file
,
'
read
'
)
tree
=
f
.
EvTree
ch
=
get_channels
(
args
.
module_file
)
res
=
pd
.
DataFrame
(
columns
=
[
c
+
'
_peak
'
for
c
in
list
(
ch
)]
+
[
c
+
'
_pos
'
for
c
in
list
(
ch
)])
for
iev
in
np
.
arange
(
0
,
tree
.
GetEntries
()):
tree
.
GetEntry
(
iev
)
if
iev
%
100
==
0
:
print
(
'
processed {}
'
.
format
(
iev
),
end
=
'
\r
'
)
evpeaks
,
evposes
=
[],
[]
for
c
in
ch
:
br_peak
=
branch_to_array1d
(
tree
.
__getattr__
(
c
+
'
_Ppeak
'
),
np
.
float32
)
br_pos
=
branch_to_array1d
(
tree
.
__getattr__
(
c
+
'
_Ptime
'
),
np
.
float32
)
ch_peak
,
ch_pos
=
0
,
0
for
peak
,
pos
in
zip
(
br_peak
,
br_pos
):
if
pos
<
args
.
tmax
and
pos
>
args
.
tmin
and
peak
>
ch_peak
:
ch_peak
=
peak
ch_pos
=
pos
evpeaks
.
append
(
ch_peak
)
evposes
.
append
(
ch_pos
)
res
.
loc
[
iev
,
:]
=
evpeaks
+
evposes
res
.
to_csv
(
args
.
output_file
)
This diff is collapsed.
Click to expand it.
scripts/draw_events.py
+
14
−
6
View file @
0b3fe142
...
@@ -25,7 +25,7 @@ def fit_pedestal(bk, outlier_thres=2.0, min_lengths=10):
...
@@ -25,7 +25,7 @@ def fit_pedestal(bk, outlier_thres=2.0, min_lengths=10):
return
ped_mean
,
ped_err
return
ped_mean
,
ped_err
def
get_peak
(
vals
,
thres
=
8.0
,
twindow
=
(
0
,
192
),
zero_thres
=
5.0
):
def
get_peak
(
vals
,
thres
=
8.0
,
twindow
=
(
0
,
63
),
zero_thres
=
5.0
):
if
len
(
vals
)
<
1
:
if
len
(
vals
)
<
1
:
return
0
,
0
,
0
,
0
return
0
,
0
,
0
,
0
# find peaks
# find peaks
...
@@ -70,13 +70,21 @@ tree = f.EvTree
...
@@ -70,13 +70,21 @@ tree = f.EvTree
# alignment of channels
# alignment of channels
figsize
=
(
16
,
16
)
figsize
=
(
16
,
16
)
nrows
,
ncols
=
4
,
4
nrows
,
ncols
=
4
,
4
# ch = [
# 'Cer11_5', 'Cer12_5', 'Cer13_5', 'Cer14_5',
# 'Cer21_5', 'Cer22_5', 'Cer23_5', 'Cer24_5',
# 'Cer31_5', 'Cer32_5', 'Cer33_5', 'Cer34_5',
# 'Cer41_5', 'Cer42_5', 'Cer43_5', 'Cer44_5',
# ]
ch
=
[
ch
=
[
'
Cer11_
5
'
,
'
Cer1
2_5
'
,
'
Cer1
3_5
'
,
'
Cer1
4_5
'
,
'
Cer11_
1
'
,
'
Cer1
1_2
'
,
'
Cer1
1_3
'
,
'
Cer1
1_4
'
,
'
Cer
21_5
'
,
'
Cer
2
2_
5
'
,
'
Cer
23_5
'
,
'
Cer
24_5
'
,
'
Cer
12_1
'
,
'
Cer
1
2_
2
'
,
'
Cer
12_3
'
,
'
Cer
12_4
'
,
'
Cer
31_5
'
,
'
Cer
32_5
'
,
'
Cer
3
3_
5
'
,
'
Cer
34_5
'
,
'
Cer
13_1
'
,
'
Cer
13_2
'
,
'
Cer
1
3_
3
'
,
'
Cer
13_4
'
,
'
Cer
41_5
'
,
'
Cer
42_5
'
,
'
Cer
43_5
'
,
'
Cer
4
4_
5
'
,
'
Cer
14_1
'
,
'
Cer
14_2
'
,
'
Cer
14_3
'
,
'
Cer
1
4_
4
'
,
]
]
pmt
=
[
pmt
=
[
'
A
'
,
'
A
'
,
'
A
'
,
'
A
'
,
'
A
'
,
'
A
'
,
'
A
'
,
'
A
'
,
'
B
'
,
'
B
'
,
'
B
'
,
'
B
'
,
'
B
'
,
'
B
'
,
'
B
'
,
'
B
'
,
...
@@ -117,6 +125,7 @@ for iev in evs:
...
@@ -117,6 +125,7 @@ for iev in evs:
)
)
fig
,
axs
=
plt
.
subplots
(
nrows
,
ncols
,
figsize
=
figsize
)
fig
,
axs
=
plt
.
subplots
(
nrows
,
ncols
,
figsize
=
figsize
)
lines
,
labels
=
[],
[]
for
(
i
,
ax
)
in
enumerate
(
axs
.
flat
):
for
(
i
,
ax
)
in
enumerate
(
axs
.
flat
):
box
=
dict
(
boxstyle
=
'
round
'
,
facecolor
=
'
white
'
,
alpha
=
0.5
)
box
=
dict
(
boxstyle
=
'
round
'
,
facecolor
=
'
white
'
,
alpha
=
0.5
)
ax
.
text
(
0.68
,
0.83
,
ch
[
i
],
transform
=
ax
.
transAxes
,
fontsize
=
16
,
verticalalignment
=
'
top
'
,
bbox
=
box
)
ax
.
text
(
0.68
,
0.83
,
ch
[
i
],
transform
=
ax
.
transAxes
,
fontsize
=
16
,
verticalalignment
=
'
top
'
,
bbox
=
box
)
...
@@ -124,7 +133,6 @@ for iev in evs:
...
@@ -124,7 +133,6 @@ for iev in evs:
ax
.
patch
.
set_alpha
(
pmt_colors
[
pmt
[
i
]][
1
])
ax
.
patch
.
set_alpha
(
pmt_colors
[
pmt
[
i
]][
1
])
sp
=
samples
[
ch
[
i
]]
sp
=
samples
[
ch
[
i
]]
lines
,
labels
=
[],
[]
if
len
(
sp
)
>
0
:
if
len
(
sp
)
>
0
:
pp
=
pprops
[
ch
[
i
]]
pp
=
pprops
[
ch
[
i
]]
ax
.
plot
(
np
.
arange
(
len
(
sp
)),
sp
,
label
=
'
Waveform Data
'
)
ax
.
plot
(
np
.
arange
(
len
(
sp
)),
sp
,
label
=
'
Waveform Data
'
)
...
...
This diff is collapsed.
Click to expand it.
src/esb_analyze.cpp
+
1
−
1
View file @
0b3fe142
...
@@ -315,7 +315,7 @@ void waveform_analysis(const std::vector<uint32_t> &raw, BranchData &res)
...
@@ -315,7 +315,7 @@ void waveform_analysis(const std::vector<uint32_t> &raw, BranchData &res)
// find peaks
// find peaks
TSpectrum
s
;
TSpectrum
s
;
s
.
SetResolution
(
0.5
);
s
.
SetResolution
(
0.5
);
int
npeaks
=
s
.
SearchHighRes
(
wfbuf
,
bkbuf
,
res
.
nraw
,
2
.0
,
5
,
false
,
3
,
true
,
3
);
int
npeaks
=
s
.
SearchHighRes
(
wfbuf
,
bkbuf
,
res
.
nraw
,
3
.0
,
10
,
false
,
5
,
true
,
3
);
// fill branch data
// fill branch data
double
*
pos
=
s
.
GetPositionX
();
double
*
pos
=
s
.
GetPositionX
();
...
...
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