SND@LHC Software
Loading...
Searching...
No Matches
MufluxMuonTaggerDrifttubesCombo.py
Go to the documentation of this file.
1from __future__ import print_function
2__author__ = 'Mikhail Hushchyn'
3
4import numpy as np
5from sklearn.linear_model import LinearRegression
6
7
8def initialize(fgeo):
9 pass
10
11
12
13def execute(muon_tagger_track_hits, drifttubes_track_hits, debug=0):
14
15 track_hits = {}
16 i_track = 0
17
18 for i_muon_tagger_track in muon_tagger_track_hits.keys():
19
20 one_muon_tagger_track = muon_tagger_track_hits[i_muon_tagger_track]
21
22 for i_drifttubes_track in drifttubes_track_hits.keys():
23
24 one_drifttubes_track = drifttubes_track_hits[i_drifttubes_track]
25
26 # Get linear model quality
27 rmse = linear_fit_in_zx_plane(one_muon_tagger_track, one_drifttubes_track, debug)
28
29 # Create tracks combination
30 if rmse < 2.0:
31 atrack = {}
32 atrack['drifttubes_track'] = one_drifttubes_track
33 atrack['muon_tagger_track'] = one_muon_tagger_track
34 track_hits[i_track] = atrack
35 i_track += 1
36
37 if debug:
38 print('rmse: ', rmse)
39 print('i_muon_tagger_track: ', i_muon_tagger_track)
40 print('i_drifttubes_track: ', i_drifttubes_track)
41
42
43 return track_hits
44
45
46
48 pass
49
50
51
52from sklearn.metrics import mean_squared_error
53
54
55def linear_fit_in_zx_plane(muon_tagger_track, drifttubes_track, debug):
56
57 # Collect hit coordinates
58 z_coords = []
59 x_coords = []
60
61 for ahit in muon_tagger_track['hits_x']:
62 z_coords.append([ahit['z']])
63 x_coords.append(ahit['xtop'])
64
65 for ahit in drifttubes_track['34']:
66 z_coords.append([ahit['z']])
67 x_coords.append(ahit['xtop'])
68
69 if debug:
70 print('z_coords:', z_coords)
71 print('x_coords:', x_coords)
72
73 # Fit linear regression model
74 reg = LinearRegression()
75 reg.fit(z_coords, x_coords)
76
77 # Make prediction
78 x_coords_pred = reg.predict(z_coords)
79
80 # Calculate model's quality metric
81 rmse = np.sqrt(mean_squared_error(x_coords, x_coords_pred))
82
83
84 return rmse
85
86
87
88
89
execute(muon_tagger_track_hits, drifttubes_track_hits, debug=0)
linear_fit_in_zx_plane(muon_tagger_track, drifttubes_track, debug)