Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PeakOTron
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UHHDetLab
SiPM
PeakOTron
Commits
01b3ec0a
Commit
01b3ec0a
authored
7 months ago
by
Antonello, Dr. Massimiliano
Browse files
Options
Downloads
Patches
Plain Diff
add an example in user
parent
785a5319
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
user/KETEK-PM1150-EB.py
+105
-0
105 additions, 0 deletions
user/KETEK-PM1150-EB.py
with
105 additions
and
0 deletions
user/KETEK-PM1150-EB.py
0 → 100644
+
105
−
0
View file @
01b3ec0a
import
os
import
numpy
as
np
import
pandas
as
pd
from
PeakOTron
import
PeakOTron
import
re
C_tau
=
lambda
V
,
V_bd
,
V_0
:
(
V
-
V_bd
)
/
V_0
f_tau
=
lambda
V
,
V_bd
,
V_0
:
-
1
/
np
.
log
((
1
-
np
.
exp
(
C_tau
(
V
,
V_bd
,
V_0
)
*
np
.
exp
(
-
1
)))
/
(
1
-
np
.
exp
(
C_tau
(
V
,
V_bd
,
V_0
))))
V_bd_hmt
=
26.1
V_0_hmt
=
1.4
tau
=
146.0
##SLOW COMPONENT OF SIPM PULSE
t_0
=
100.0
## PRE-INTEGRATION TIME
t_gate
=
100.0
## GATE LENGTH
bin_0
=-
100.0
## SELECT FIRST BIN OF SPECTRUM (CAN BE AUTOMATIC)
truncate_nsigma0_up
=
2.0
## SCAN SPECTRUM FROM Q < Q_0 - 4 sigma_0
truncate_nsigma0_do
=
2.0
## EVALUATE SPECTRUM CHI2 IN Q_0 - x*sigma_0 < Q < Q_0 + 2*sigma_0
prefit_only
=
False
## FIT THE WHOLE SPECTRUM
out_dict
=
{}
files_to_fit
=
[]
## Find all histograms in directory
folder
=
'
./data/ketek
'
for
root
,
dirs
,
files
in
os
.
walk
(
folder
):
for
file
in
files
:
if
file
.
endswith
(
"
.Wfm.csv
"
):
files_to_fit
.
append
([
file
,
os
.
path
.
join
(
root
,
file
)])
## Print files.
print
(
"
Files to fit:
"
)
for
i
,
(
file
,
_
)
in
enumerate
(
files_to_fit
):
print
(
'
File {0}: {1}
'
.
format
(
i
,
file
))
## Loop thorough files
for
i
,
(
file
,
path
)
in
enumerate
(
files_to_fit
):
items
=
file
.
split
(
'
_
'
)
print
(
"
\n\n
"
)
print
(
"
===============================================================
"
)
print
(
"
FIT {:d} - {:s}
"
.
format
(
i
,
file
))
print
(
"
===============================================================
"
)
print
(
"
\n\n
"
)
## Load files.
data
=
np
.
loadtxt
(
path
,
skiprows
=
0
)
## Create a PeakOTron Fit Object.
f_data
=
PeakOTron
(
verbose
=
True
)
match
=
re
.
search
(
r
'
scale(\d+)
'
,
file
,
re
.
IGNORECASE
)
if
match
:
number
=
int
(
match
.
group
(
1
))
print
(
"
Extracted number:
"
,
number
)
else
:
print
(
"
No number found in the string.
"
)
V
=
float
(
number
/
100
)
print
(
V
)
# V = 41.0
f_tau_hmt
=
f_tau
(
V
,
V_bd_hmt
,
V_0_hmt
)
## Perform fit.
f_data
.
Fit
(
data
,
tau
=
tau
,
#SLOW PULSE COMPONENT TIME CONSTANT (ns)
t_gate
=
t_gate
,
#GATE LENGTH (ns)
t_0
=
t_0
,
#INTEGRATION TIME BEFORE GATE (ns)
tau_R
=
f_tau_hmt
*
tau
,
bin_0
=
None
,
truncate_nsigma0_up
=
None
,
truncate_nsigma0_do
=
None
)
# f_data.PlotPeaks()
f_data
.
PlotFit
(
xlabel
=
"
$q_0$
"
,
title
=
"
Charge Spectrum {}
"
.
format
(
file
)
)
prefit_val
,
prefit_err
=
f_data
.
GetPrefitResults
(
bin_units
=
False
)
print
(
"
Prefit values
"
,
prefit_val
,
prefit_err
)
fit_val
,
fit_err
=
f_data
.
GetFitResults
(
bin_units
=
False
)
print
(
"
Fit values
"
,
fit_val
,
fit_err
)
fit_out
=
{}
for
key
,
value
in
fit_val
.
items
():
fit_out
[
"
{:s}
"
.
format
(
key
)]
=
value
for
key
,
value
in
fit_err
.
items
():
fit_out
[
"
d_{:s}
"
.
format
(
key
)]
=
value
for
key
,
value
in
prefit_val
.
items
():
fit_out
[
"
prefit_{:s}
"
.
format
(
key
)]
=
value
for
key
,
value
in
prefit_err
.
items
():
fit_out
[
"
prefit_d_{:s}
"
.
format
(
key
)]
=
value
df
=
pd
.
DataFrame
.
from_dict
([
fit_out
])
df
.
to_csv
(
"
{}/fit_results_{:s}.csv
"
.
format
(
folder
,
file
))
# dump(f_data, "{}/dump_{}.csv".format(folder,file))
# break
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