-
Notifications
You must be signed in to change notification settings - Fork 1
/
oscapp.js
170 lines (134 loc) · 5.02 KB
/
oscapp.js
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"use strict";
const kUNKNOWN = 0;
const kPLOTS = 1;
const kTABLE = 2;
class oscapp {
constructor() {
this.oschelp = new OscHelper();
this.Widgets = {};
this.Widgets.OscProbPlot_mu_El = document.getElementById("OscProbPlot_mu");
this.Widgets.OscProbPlot_e_El = document.getElementById("OscProbPlot_e");
this.Widgets.ConstraintControls =
document.getElementById("ConstraintControls");
this.Widgets.OscParamTable = document.getElementById("OscParamTable");
this.Controls = {};
this.Controls.OscProbPlotAddBtn = document.getElementById("add_btn");
this.Controls.OscProbPlotClearBtn = document.getElementById("clear_btn");
this.Controls.neutrino_selector =
document.getElementById("neutrino_selector");
this.Controls.baseline_input = document.getElementById("baseline_input");
this.Expt = {};
this.Expt.IsMatter = 1;
this.Expt.pdg_from = 14;
this.Expt.pdg_to = 14;
this.Expt.baseline_km = 1300;
}
AddCurve(plot, Expt, params, index) {
this.oschelp.SetOscillation(Expt.pdg_from, Expt.baseline_km, params);
let osc_curve = {
meta : {id : index, name : "osc_curve"},
data : [],
};
let EMin = 0;
let EMax = 5;
let ESteps = 1000;
let EStep = (EMax - EMin) / ESteps;
for (let i = 0; i < ESteps; ++i) {
let p = [];
p[0] = EMin + i * EStep;
p[1] = this.oschelp.GetProb(p[0], Expt.pdg_to);
if (!isNaN(p[1])) {
osc_curve.data.push(p);
}
}
plot.SetCurve(index, osc_curve);
}
OscProbInit() {
this.HookupExptControls();
this.InitializeConstraintControls();
this.HookupOscParamControls();
this.Widgets.OscProbPlot_mu = new OscProbPlot();
this.Widgets.OscProbPlot_mu.DrawAxes(
this.Widgets.OscProbPlot_mu_El, 0.1, 5, 0, 1,
"\\(P(\\nu_{\\mu}\\rightarrow\\nu_{\\mu})\\)");
this.Widgets.OscProbPlot_e = new OscProbPlot();
this.Widgets.OscProbPlot_e.DrawAxes(
this.Widgets.OscProbPlot_e_El, 0.1, 5, 0, 0.2,
"\\(P(\\nu_{\\mu}\\rightarrow\\nu_{e})\\)");
this.NotifyOscParamChange(0, new OscParams(), kUNKNOWN);
}
NotifyExptChange() {
this.Widgets.OscProbPlot_mu.ClearAll();
this.Widgets.OscProbPlot_e.ClearAll();
for (let [key, value] of Object.entries(GetAllChosenParameters())) {
let idx = parseInt(key);
let expt = this.Expt;
expt.pdg_to = 14 * expt.IsMatter;
this.AddCurve(this.Widgets.OscProbPlot_mu, this.Expt, value, idx);
expt.pdg_to = 12 * expt.IsMatter;
this.AddCurve(this.Widgets.OscProbPlot_e, this.Expt, value, idx);
}
}
HookupExptControls() {
this.Controls.neutrino_selector.querySelectorAll("p").forEach((el) => {
el.addEventListener("click", () => {
let chosen = el.innerHTML;
el.parentNode.parentNode.querySelector("button").innerHTML = chosen;
let nutype = el.dataset.nutype;
if (nutype === "nu") {
this.Expt.IsMatter = 1;
this.Expt.pdg_from = Math.abs(this.Expt.pdg_from);
this.Expt.pdg_to = Math.abs(this.Expt.pdg_to);
} else if (nutype === "nubar") {
this.Expt.IsMatter = -1;
this.Expt.pdg_from = -Math.abs(this.Expt.pdg_from);
this.Expt.pdg_to = -Math.abs(this.Expt.pdg_to);
}
this.NotifyExptChange();
});
});
this.Controls.baseline_input.addEventListener("change", () => {
this.Expt.baseline_km = parseFloat(this.Controls.baseline_input.value);
this.NotifyExptChange();
});
}
NotifyOscParamChange(idx, osc_params, notifier) {
let expt = this.Expt;
expt.pdg_to = 14 * expt.IsMatter;
this.AddCurve(this.Widgets.OscProbPlot_mu, expt, osc_params, idx);
expt.pdg_to = 12 * expt.IsMatter;
this.AddCurve(this.Widgets.OscProbPlot_e, expt, osc_params, idx);
SetConstraintWidgetPoints(idx, osc_params);
if (notifier != kTABLE) { // Don't update table row as you are changing it
SetOscParamRow(idx, osc_params);
}
}
RemoveOscParamIndex(idx) {
ClearConstrainWidgetPoint(idx);
ClearOscParamRow(idx);
this.Widgets.OscProbPlot_mu.RemoveCurve(idx);
this.Widgets.OscProbPlot_e.RemoveCurve(idx);
}
InitializeConstraintControls() { // On click
InitializeConstraintWidgets(
this.Widgets.ConstraintControls,
(idx, chg_par) => { this.NotifyOscParamChange(idx, chg_par, kPLOTS); });
InitializeOscParamTable(
this.Widgets.OscParamTable,
(idx, chg_par) => { this.NotifyOscParamChange(idx, chg_par, kTABLE); },
(idx) => {this.RemoveOscParamIndex(idx)},
(idx) => {ConstraintWidgetSetIndex(idx)});
}
HookupOscParamControls() {
this.Controls.OscProbPlotAddBtn.addEventListener("click", () => {
let NI = IncrementConstrainWidgetNPoints();
this.NotifyOscParamChange(NI, new OscParams());
});
this.Controls.OscProbPlotClearBtn.addEventListener("click", () => {
this.Widgets.OscProbPlot_mu.ClearAll();
this.Widgets.OscProbPlot_e.ClearAll();
ClearConstrainWidgetPoints();
ClearOscParamRows();
});
}
};