Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lecture Statistics and Data Analysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Maximilian Vitz
Lecture Statistics and Data Analysis
Commits
bcb67db2
Commit
bcb67db2
authored
3 years ago
by
Maximilian Vitz
Browse files
Options
Downloads
Patches
Plain Diff
Update
parent
cd362d13
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Week8/Solution_8.py
+170
-0
170 additions, 0 deletions
Week8/Solution_8.py
with
170 additions
and
0 deletions
Week8/Solution_8.py
0 → 100644
+
170
−
0
View file @
bcb67db2
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 12 00:00:00 2021
@author: vitz
"""
from
array
import
array
from
numpy
import
sqrt
,
exp
,
pi
import
ctypes
import
numpy
as
np
from
ROOT
import
gROOT
,
gStyle
,
TMinuit
,
TH1F
,
TF1
,
TCanvas
,
TLegend
,
TLatex
,
TMarker
,
TArrow
,
TGraph
########################################################################
def
f1
(
x
,
\
par
):
val
=
0
;
m
=
x
[
0
];
A
=
par
[
0
];
x0
=
par
[
1
];
sigma
=
par
[
2
];
b
=
par
[
3
];
arg
=
(
m
-
x0
)
/
sigma
;
val
=
A
/
(
sqrt
(
2
*
pi
)
*
sigma
)
*
exp
(
-
0.5
*
arg
**
2
)
+
b
;
return
val
########################################################################
def
go
(
nevents
=
10000
,
\
nbins
=
100
,
\
b
=
1
):
npar
=
4
mmin
=
0
mmax
=
2
A
=
3
x0
=
1
sigma
=
0.1
# Create a 1-Dim histogram with fix bins of type float.
h1
=
TH1F
(
"
h1
"
,
\
""
,
\
nbins
,
\
mmin
,
\
mmax
);
h1
.
SetXTitle
(
"
x
"
);
h1
.
SetYTitle
(
"
nb. of events
"
);
gStyle
.
SetOptFit
(
111111
);
# A TF1 object is a 1-Dim function defined between a lower and upper limit.
ff1
=
TF1
(
"
ff1
"
,
\
f1
,
\
mmin
,
\
mmax
,
\
npar
)
ff1
.
SetParameter
(
0
,
A
)
ff1
.
SetParameter
(
1
,
x0
)
ff1
.
SetParameter
(
2
,
sigma
)
ff1
.
SetParameter
(
3
,
b
)
ff1
.
SetMinimum
(
0
)
h1
.
FillRandom
(
"
ff1
"
,
\
int
((
A
+
2
*
b
)
*
nevents
))
# Create a new canvas with a predefined size form.
c1
=
TCanvas
(
"
c1
"
,
\
""
,
\
1000
,
\
400
)
ff1
.
SetParameter
(
0
,
A
*
0.7
)
ff1
.
SetParameter
(
1
,
x0
*
1.1
)
ff1
.
SetParameter
(
2
,
sigma
*
1.5
)
ff1
.
SetParameter
(
3
,
0
)
h1
.
SetMinimum
(
0
)
ff1
.
FixParameter
(
0
,
\
500
)
h1
.
Fit
(
"
ff1
"
)
ff1
.
ReleaseParameter
(
0
)
h1
.
Fit
(
"
ff1
"
)
print
(
'
Espected number of signal events:
'
,
h1
.
GetBinWidth
(
1
)
*
A
*
nevents
)
########################################################################
bgd
=
np
.
array
(
[
0.0
,
\
0.5
,
\
1.0
,
\
2.0
,
\
5.0
,
\
10
,
\
30
,
\
50
])
bgd
=
array
(
"
d
"
,
\
bgd
)
errA
=
np
.
array
(
[
3.49543e+00
,
\
3.71073e+00
,
\
3.91263e+00
,
\
4.28512e+00
,
\
5.20164e+00
,
\
6.46264e+00
,
\
1.01335e+01
,
\
1.26267e+01
])
errA
=
array
(
"
d
"
,
\
errA
)
# Create a new canvas with a predefined size form.
c2
=
TCanvas
(
"
c2
"
,
\
""
,
\
1000
,
\
400
)
# A TGraph is an object made of two arrays X and Y with npoints each.
gr1
=
TGraph
(
len
(
bgd
)
,
\
bgd
,
\
errA
)
gr1
.
SetMarkerStyle
(
20
)
gr1
.
Draw
(
"
ap
"
)
input
(
"
Hit to return
"
)
########################################################################
def
main
():
go
()
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