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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zhiwen Zhao
fadc_decoder
Commits
80469364
Commit
80469364
authored
4 years ago
by
Chao Peng
Browse files
Options
Downloads
Patches
Plain Diff
update wfanalyzer
parent
f0d140d0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/WfAnalyzer.h
+25
-24
25 additions, 24 deletions
include/WfAnalyzer.h
tools/test_wfanalyzer.cxx
+5
-4
5 additions, 4 deletions
tools/test_wfanalyzer.cxx
with
30 additions
and
28 deletions
include/WfAnalyzer.h
+
25
−
24
View file @
80469364
...
@@ -14,10 +14,6 @@
...
@@ -14,10 +14,6 @@
namespace
wfa
{
namespace
wfa
{
// data structures
// data structures
struct
Pedestal
{
double
mean
,
err
;
};
struct
Peak
{
struct
Peak
{
size_t
pos
,
left
,
right
;
size_t
pos
,
left
,
right
;
double
height
,
integral
;
double
height
,
integral
;
...
@@ -27,6 +23,15 @@ struct Peak {
...
@@ -27,6 +23,15 @@ struct Peak {
}
}
};
};
struct
Pedestal
{
double
mean
,
err
;
};
struct
WFData
{
Pedestal
ped
;
std
::
vector
<
Peak
>
peaks
;
};
// calculate mean and standard deviation of an array
// calculate mean and standard deviation of an array
template
<
typename
T
>
template
<
typename
T
>
inline
void
_calc_mean_err
(
double
&
mean
,
double
&
err
,
T
*
source
,
size_t
npts
)
inline
void
_calc_mean_err
(
double
&
mean
,
double
&
err
,
T
*
source
,
size_t
npts
)
...
@@ -91,10 +96,10 @@ public:
...
@@ -91,10 +96,10 @@ public:
:
thres
(
threshold
),
res
(
resolution
)
{}
:
thres
(
threshold
),
res
(
resolution
)
{}
~
Analyzer
()
{}
~
Analyzer
()
{}
void
Analyze
(
uint32_t
*
samples
,
size_t
nsamples
)
WFData
Analyze
(
uint32_t
*
samples
,
size_t
nsamples
)
{
{
peaks
.
clear
()
;
WFData
data
;
if
(
!
nsamples
)
{
return
;
}
if
(
!
nsamples
)
{
return
data
;
}
auto
buffer
=
ResSpectrum
(
samples
,
nsamples
,
res
);
auto
buffer
=
ResSpectrum
(
samples
,
nsamples
,
res
);
...
@@ -109,7 +114,7 @@ public:
...
@@ -109,7 +114,7 @@ public:
int
tr1
=
trend
(
buffer
[
i
],
buffer
[
i
-
1
]);
int
tr1
=
trend
(
buffer
[
i
],
buffer
[
i
-
1
]);
int
tr2
=
trend
(
buffer
[
i
],
buffer
[
i
+
1
]);
int
tr2
=
trend
(
buffer
[
i
],
buffer
[
i
+
1
]);
// peak at the rising (declining) edge
// peak at the rising (declining) edge
if
((
tr1
*
tr2
>=
0
)
&&
(
std
::
abs
(
tr1
)
>
0
)
&&
std
::
abs
(
buffer
[
i
])
>
ped
.
err
*
3.0
)
{
if
((
tr1
*
tr2
>=
0
)
&&
(
std
::
abs
(
tr1
)
>
0
))
{
size_t
left
=
1
,
right
=
1
;
size_t
left
=
1
,
right
=
1
;
// search the peak range
// search the peak range
while
((
i
>
left
+
1
)
&&
(
trend
(
buffer
[
i
-
left
],
buffer
[
i
-
left
-
1
])
==
tr1
))
{
while
((
i
>
left
+
1
)
&&
(
trend
(
buffer
[
i
-
left
],
buffer
[
i
-
left
-
1
])
==
tr1
))
{
...
@@ -147,51 +152,47 @@ public:
...
@@ -147,51 +152,47 @@ public:
// calculate pedestal
// calculate pedestal
if
(
nped
<=
nsamples
/
4
)
{
if
(
nped
<=
nsamples
/
4
)
{
ped
=
CalcPedestal
(
&
buffer
[
0
],
nsamples
,
1.5
,
3
);
data
.
ped
=
CalcPedestal
(
&
buffer
[
0
],
nsamples
,
1.5
,
3
);
}
else
{
}
else
{
ped
=
CalcPedestal
(
&
ybuf
[
0
],
nped
,
1.2
,
3
);
data
.
ped
=
CalcPedestal
(
&
ybuf
[
0
],
nped
,
1.2
,
3
);
}
}
for
(
auto
&
peak
:
candidates
)
{
for
(
auto
&
peak
:
candidates
)
{
// real sample height
// real sample height
double
sample_height
=
samples
[
peak
.
pos
]
-
ped
.
mean
;
double
sample_height
=
samples
[
peak
.
pos
]
-
data
.
ped
.
mean
;
if
((
sample_height
*
peak
.
height
<
0.
)
||
if
((
sample_height
*
peak
.
height
<
0.
)
||
(
std
::
abs
(
sample_height
)
<
thres
)
||
(
std
::
abs
(
sample_height
)
<
thres
)
||
(
std
::
abs
(
sample_height
)
<
3.0
*
ped
.
err
))
{
(
std
::
abs
(
sample_height
)
<
3.0
*
data
.
ped
.
err
))
{
continue
;
continue
;
}
}
// integrate it over the peak range
// integrate it over the peak range
peak
.
height
=
sample_height
;
peak
.
height
=
sample_height
;
peak
.
integral
=
buffer
[
peak
.
pos
]
-
ped
.
mean
;
peak
.
integral
=
buffer
[
peak
.
pos
]
-
data
.
ped
.
mean
;
for
(
size_t
i
=
1
;
i
<=
peak
.
left
;
++
i
)
{
for
(
size_t
i
=
1
;
i
<=
peak
.
left
;
++
i
)
{
double
val
=
buffer
[
peak
.
pos
-
1
]
-
ped
.
mean
;
double
val
=
buffer
[
peak
.
pos
-
1
]
-
data
.
ped
.
mean
;
if
(
std
::
abs
(
val
)
<
ped
.
err
)
{
break
;
}
// stop when it touches the baseline
if
(
std
::
abs
(
val
)
<
data
.
ped
.
err
)
{
break
;
}
peak
.
integral
+=
val
;
peak
.
integral
+=
val
;
}
}
for
(
size_t
i
=
1
;
i
<=
peak
.
right
;
++
i
)
{
for
(
size_t
i
=
1
;
i
<=
peak
.
right
;
++
i
)
{
double
val
=
buffer
[
peak
.
pos
+
i
]
-
ped
.
mean
;
double
val
=
buffer
[
peak
.
pos
+
i
]
-
data
.
ped
.
mean
;
if
(
std
::
abs
(
val
)
<
ped
.
err
)
{
break
;
}
if
(
std
::
abs
(
val
)
<
data
.
ped
.
err
)
{
break
;
}
peak
.
integral
+=
val
;
peak
.
integral
+=
val
;
}
}
peaks
.
emplace_back
(
peak
);
data
.
peaks
.
emplace_back
(
peak
);
}
}
/*
/*
std::sort(peaks.begin(), peaks.end(),
std::sort(peaks.begin(), peaks.end(),
[] (const Peak &p1, const Peak &p2) { return p1.height > p2.height; });
[] (const Peak &p1, const Peak &p2) { return p1.height > p2.height; });
*/
*/
return
data
;
}
}
const
Pedestal
&
GetPedestal
()
const
{
return
ped
;
}
const
std
::
vector
<
Peak
>
&
GetPeaks
()
const
{
return
peaks
;
}
private
:
private
:
double
thres
;
double
thres
;
size_t
res
;
size_t
res
;
Pedestal
ped
;
std
::
vector
<
Peak
>
peaks
;
public
:
public
:
...
...
This diff is collapsed.
Click to expand it.
tools/test_wfanalyzer.cxx
+
5
−
4
View file @
80469364
...
@@ -40,6 +40,7 @@ void test(size_t res = 3, double thres = 10.0)
...
@@ -40,6 +40,7 @@ void test(size_t res = 3, double thres = 10.0)
wf
->
SetLineWidth
(
1
);
wf
->
SetLineWidth
(
1
);
wf
->
SetLineStyle
(
2
);
wf
->
SetLineStyle
(
2
);
wf
->
Draw
(
"AL"
);
wf
->
Draw
(
"AL"
);
wf
->
GetXaxis
()
->
SetRangeUser
(
0
,
samples
.
size
()
-
1
);
// waveform resolution
// waveform resolution
auto
wf2
=
new
TGraph
(
samples
.
size
());
auto
wf2
=
new
TGraph
(
samples
.
size
());
...
@@ -52,12 +53,12 @@ void test(size_t res = 3, double thres = 10.0)
...
@@ -52,12 +53,12 @@ void test(size_t res = 3, double thres = 10.0)
wf2
->
Draw
(
"L same"
);
wf2
->
Draw
(
"L same"
);
// peak finding
// peak finding
ana
.
Analyze
(
&
samples
[
0
],
samples
.
size
());
auto
data
=
ana
.
Analyze
(
&
samples
[
0
],
samples
.
size
());
auto
ped
=
ana
.
GetPedestal
()
;
auto
ped
=
data
.
ped
;
auto
gr
=
new
TGraph
(
samples
.
size
());
auto
gr
=
new
TGraph
(
samples
.
size
());
gr
->
SetMarkerStyle
(
23
);
gr
->
SetMarkerStyle
(
23
);
for
(
auto
&
peak
:
ana
.
GetP
eaks
()
)
{
for
(
auto
&
peak
:
data
.
p
eaks
)
{
gr
->
SetPoint
(
gr
->
GetN
(),
peak
.
pos
,
peak
.
height
+
ped
.
mean
);
gr
->
SetPoint
(
gr
->
GetN
(),
peak
.
pos
,
peak
.
height
+
data
.
ped
.
mean
);
// gr->SetPoint(gr->GetN(), peak.pos - peak.left, peak.height + peak.base);
// gr->SetPoint(gr->GetN(), peak.pos - peak.left, peak.height + peak.base);
// gr->SetPoint(gr->GetN(), peak.pos + peak.right, peak.height + peak.base);
// gr->SetPoint(gr->GetN(), peak.pos + peak.right, peak.height + peak.base);
std
::
cout
<<
peak
.
pos
<<
", "
<<
peak
.
pos
-
peak
.
left
<<
", "
<<
peak
.
pos
+
peak
.
right
std
::
cout
<<
peak
.
pos
<<
", "
<<
peak
.
pos
-
peak
.
left
<<
", "
<<
peak
.
pos
+
peak
.
right
...
...
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