-
Notifications
You must be signed in to change notification settings - Fork 2
/
teste_procura_picos.py
113 lines (91 loc) · 3.23 KB
/
teste_procura_picos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
"""
Created on Mon May 20 15:24:01 2019
@author: Hugo Borges
"""
'''
#parte 1
#codigo estraido de: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks.html
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
from scipy.signal import find_peaks
x = electrocardiogram()[2000:4000]
peaks, _ = find_peaks(x, height=0)
plt.plot(x)
plt.plot(peaks, x[peaks], "x")
plt.plot(np.zeros_like(x), "--", color="gray")
plt.show()
border = np.sin(np.linspace(0, 3 * np.pi, x.size))
peaks, _ = find_peaks(x, height=(-border, border))
plt.plot(x)
plt.plot(-border, "--", color="gray")
plt.plot(border, ":", color="gray")
plt.plot(peaks, x[peaks], "x")
plt.show()
peaks, _ = find_peaks(x, distance=150)
#np.diff(peaks)
plt.plot(x)
plt.plot(peaks, x[peaks], "x")
plt.show()
peaks, properties = find_peaks(x, prominence=(None, 0.6))
properties["prominences"].max()
plt.plot(x)
plt.plot(peaks, x[peaks], "x")
plt.show()
x = electrocardiogram()[17000:18000]
peaks, properties = find_peaks(x, prominence=1, width=20)
properties["prominences"], properties["widths"]
plt.plot(x)
plt.plot(peaks, x[peaks], "x")
plt.vlines(x=peaks, ymin=x[peaks] - properties["prominences"], ymax = x[peaks], color = "C1")
plt.hlines(y=properties["width_heights"], xmin=properties["left_ips"], xmax=properties["right_ips"], color = "C1")
plt.show()
'''
'''
# parte 2
# parte extraida da parte "Making the histogram" do notebbok
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
ds = pd.read_csv('DoubleMuRun2011A.csv')
invariant_mass = np.sqrt(2*ds.pt1*ds.pt2*((np.cosh(ds.eta1-ds.eta2))-(np.cos(ds.phi1-ds.phi2))))
plt.hist(invariant_mass, bins=600, range=(0,110))
print("Valor mínimo = " + str(invariant_mass.min()) + "\nValor máximo = " + str(invariant_mass.max()))
# Let's name the axes and the title. Don't change these.
plt.xlabel('Invariant mass [GeV]')
plt.ylabel('Number of events')
plt.title('Histogram of invariant mass values of two muons. \n')
plt.xscale("log")
plt.yscale("log")
plt.show()
'''
#parte 3
# parte extraida da parte "The histogram of the whole data" do notebbok
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy.signal import find_peaks
ds = pd.read_csv('DoubleMuRun2011A.csv')
invariant_mass_1 = ds['M']
no_bins = 600
# Let's calculate the logarithms of the masses and weighs.
inv_mass_log = np.log10(invariant_mass_1)
weights = []
for a in invariant_mass_1:
weights.append(no_bins/np.log(10)/a)
print("Valor mínimo = " + str(inv_mass_log.min()) + "\nValor máximo = " + str(inv_mass_log.max()))
# Let's plot the weighted histogram.
n_hist, bins_hist, patches = plt.hist(inv_mass_log, bins=no_bins, range=(-0.5,2.5), weights=weights, color="red")
plt.yscale('log')
# Naming the labels and the title.
plt.xlabel('log10(invariant mass) [log10(GeV)]')
plt.ylabel('Number of the events')
plt.title('The histogram of the invariant masses of two muons \n')
plt.show()
peaks, properties = find_peaks(n_hist, distance = 15, height = 14900, width=1)
print(peaks)
print(np.diff(peaks))
plt.plot(n_hist)
plt.plot(peaks, n_hist[peaks], "x")
plt.yscale('log')
plt.show()