forked from GRIFFINCollaboration/efficiencyCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
366 lines (320 loc) · 13.8 KB
/
main.js
File metadata and controls
366 lines (320 loc) · 13.8 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
function setup(){
var i, nodes,
HPGeSwitch = document.getElementById('enableHPGe'),
LaBr3Switch = document.getElementById('enableLaBr3'),
SiLiSwitch = document.getElementById('enableSiLi'),
detailMessage = 'HPGe GEANT4 Simulation: 8th order polynomial fit including SCEPTAR and Delrin vacuum chamber.<br><br>';
detailMessage +='LaBr3 GEANT4 Simulation: 8th order polynomial fit above 40 keV including SCEPTAR and<br>Delrin vacuum chamber.<br><br>'
detailMessage +='Si(Li) Simulation: Relative Efficiency curve shape based on formalism referenced in<br>Radiation Detection & Measurement (G.F. Knoll, Wiley 2000).<br>'
detailMessage +='An absolute normalization is applied per Masters Thesis of Ryan Dunlop, University of Guelph, 2012,<br>High-precision branching ratio measurement for the superallowed beta+ emitter 74Rb, based on<br>the analysis of in-beam 80Rb decay.<br><br>'
detailMessage +='The following five configuration efficiencies are based on solid angle coverage of detectors:<br>'
detailMessage +='DESCANT: 27% efficient between 1 and 5 MeV; efficiency lower outside this range, and no value is<br>reported here.<br>'
detailMessage +='SCEPTAR: 80% efficient.<br>'
detailMessage +='SCEPTAR + ZDS: 65% efficient.<br>'
detailMessage +='SCEPTAR + PACES: 40% efficient.<br>'
detailMessage +='PACES + ZDS: 25% efficient.'
//call the parameter dump
loadParameters();
loadLaBrParameters();
//SiLi parameters taken from CITATION NEEDED
//last parameter is an overall normalization to fix eff(603keV) = 0.0342, per
//Masters Thesis of Ryan Dunlop, University of Guelph, 2012,
//High-precision branching ratio measurement for the superallowed beta+ emitter 74Rb
SiLiCoef = {};
SiLiCoef['detector'] = [71.131, 7.97308, -0.474268, -0.00120224, 1.40317, .0342/104.30174050118521];
//Set up color codes
colorCodes = {};
colorCodes['HPGe'] = '#449944';
colorCodes['LaBr3'] = '#e67e22';
colorCodes['SiLi'] = '#2980b9';
colorCodes['DESCANT'] = '#8e44ad';
colorCodes['SCEPTAR'] = '#c0392b';
colorCodes['SCEPTARZDS'] = '#c0392b';
colorCodes['SCEPTARPACES'] = '#c0392b';
colorCodes['PACESZDS'] = '#f1c40f';
//set up control panel//////////////////////////////////////
HPGeSwitch.enabled = 0;
HPGeSwitch.onclick = function(event){
if (this.enabled){
this.style.backgroundColor = '#444444';
this.enabled = 0;
} else{
this.style.backgroundColor = '#449944';
this.enabled = 1;
}
toggleHPGeControls();
chooseGraphs();
}
LaBr3Switch.enabled = 0;
LaBr3Switch.onclick = function(event){
if (this.enabled){
this.style.backgroundColor = '#444444';
this.enabled = 0;
} else{
this.style.backgroundColor = '#e67e22';
this.enabled = 1;
}
chooseGraphs();
}
SiLiSwitch.enabled = 0;
SiLiSwitch.onclick = function(event){
if (this.enabled){
this.style.backgroundColor = '#444444';
this.enabled = 0;
} else{
this.style.backgroundColor = '#2980b9';
this.enabled = 1;
}
chooseGraphs();
}
//make sure the file name for image saving gets passed around:
document.getElementById('filename').onchange = function(){
//set the filename to whatever the user has requested:
document.getElementById('savePlot').download = this.value;
}
//plot range control//////////////////////////////////////
document.getElementById('xMin').onchange = chooseGraphs;
document.getElementById('xMax').onchange = chooseGraphs;
document.getElementById('yMin').onchange = chooseGraphs;
document.getElementById('yMax').onchange = chooseGraphs;
document.getElementById('yScale').onchange = chooseGraphs;
//default No. HPGe to 12:
document.getElementById('nHPGeSwitch').value = 12;
//default summing to per clover:
document.getElementById('summingScheme').value = 'clover';
//repaint the plot when anything in the form changes:
document.getElementById('plotOptions').onchange = chooseGraphs.bind(null);
//button setup//////////////////////////////////////////////
document.getElementById('wikiLink').onclick = function(){
window.open('https://www.triumf.info/wiki/tigwiki/index.php/GRIFFIN_User%27s_Web_Toolkit','wikiTab');
};
document.getElementById('yieldDB').onclick = function(){
window.open('http://mis.triumf.ca/science/planning/yield/beam', 'yieldTab');
};
document.getElementById('ENSDF').onclick = function(){
window.open('http://www.nndc.bnl.gov/ensdf/', 'ENSDFtab');
};
document.getElementById('BrIcc').onclick = function(){
window.open('http://bricc.anu.edu.au/', 'BrIcctab');
};
document.getElementById('details').onclick = function(){
confirm('GRIFFIN Simulated Efficiency Calculator', detailMessage)
};
//make sure the plot area is a sane size:
document.getElementById('graphDiv').style.width = (window.innerWidth - document.getElementById('controlPanel').offsetWidth)*0.95;
document.getElementById('graphDiv').style.height = document.getElementById('controlPanel').offsetHeight*1.05;
//Set up widgets///////////////////////////////////////////////////////////////////////
//Singles
document.getElementById('singlesForm').onchange = computeSingles.bind(null);
//Coincidences
document.getElementById('coincidenceWidget').whichInput = 0;
document.getElementById('coincForm').onchange = computeCoincidence.bind(null);
//Triples
document.getElementById('triplesWidget').whichInput = 0;
document.getElementById('triplesForm').onchange = computeTriples.bind(null);
//must validate by hand until FF implements number-type inputs:
nodes = document.querySelectorAll('input.widgetInput')
for(i=0; i<nodes.length; i++ ){
nodes[i].onchange = validateNumber.bind(null, nodes[i].id);
}
/*
document.getElementById('singlesInputEnergy').onchange = validateNumber.bind(null, 'singlesInputEnergy');
document.getElementById('singlesBR').onchange = validateNumber.bind(null, 'singlesBR');
document.getElementById('singlesIntensity').onchange = validateNumber.bind(null, 'singlesIntensity');
document.getElementById('singlesDutyCycle').onchange = validateNumber.bind(null, 'singlesDutyCycle');
document.getElementById('nSingles').onchange = validateNumber.bind(null, 'nSingles');
document.getElementById('coincInputEnergy1').onchange = validateNumber.bind(null, 'coincInputEnergy1');
document.getElementById('coincInputEnergy2').onchange = validateNumber.bind(null, 'coincInputEnergy2');
document.getElementById('coincBR1').onchange = validateNumber.bind(null, 'coincBR1');
document.getElementById('coincBR2').onchange = validateNumber.bind(null, 'coincBR2');
document.getElementById('singlesIntensity').onchange = validateNumber.bind(null, 'singlesIntensity');
document.getElementById('singlesDutyCycle').onchange = validateNumber.bind(null, 'singlesDutyCycle');
document.getElementById('nSingles').onchange = validateNumber.bind(null, 'nSingles');
document.getElementById('singlesInputEnergy').onchange = validateNumber.bind(null, 'singlesInputEnergy');
document.getElementById('singlesBR').onchange = validateNumber.bind(null, 'singlesBR');
document.getElementById('singlesIntensity').onchange = validateNumber.bind(null, 'singlesIntensity');
document.getElementById('singlesDutyCycle').onchange = validateNumber.bind(null, 'singlesDutyCycle');
document.getElementById('nSingles').onchange = validateNumber.bind(null, 'nSingles');
*/
//default to on for demo:
HPGeSwitch.onclick();
LaBr3Switch.onclick();
SiLiSwitch.onclick();
//evaluate all widgets at defaults
computeSingles();
computeCoincidence();
computeTriples();
}
//decide which plots to send to a call to deployGraph
function chooseGraphs(){
var funcs = [],
titles = [],
colors = [],
min = parseFloat(document.getElementById('xMin').value),
max = parseFloat(document.getElementById('xMax').value),
HPGeMinCoef = {},
HPGeMaxCoef = {},
HPGeString, LaBrString, SiLiString, i;
HPGeMinCoef['dummy'] = [0, 0, 0, 0, 0, 0, 0, 0, 0];
HPGeMaxCoef['dummy'] = [0, 0, 0, 0, 0, 0, 0, 0, 0];
//make sure specified plot maxima aren't silly:
document.getElementById('xMax').min = parseFloat(document.getElementById('xMin').value);
document.getElementById('yMax').min = parseFloat(document.getElementById('yMin').value);
if(document.getElementById('enableHPGe').enabled){
HPGeString = constructPlotKey();
window.HPGeFunc = HPGeEfficiency.bind(null, HPGeCoef[HPGeString], HPGeMinCoef['dummy'], HPGeMaxCoef['dummy']);
funcs[funcs.length] = window.HPGeFunc;
titles[titles.length] = 'HPGe';
colors[colors.length] = '#449944';
}
if(document.getElementById('enableLaBr3').enabled){
LaBrString = constructLaBrPlotKey();
window.LaBrFunc = LaBrEfficiency.bind(null, LaBrCoef[LaBrString], HPGeMinCoef['dummy'], HPGeMaxCoef['dummy']);
funcs[funcs.length] = window.LaBrFunc;
titles[titles.length] = 'LaBr3';
colors[colors.length] = '#e67e22';
}
if(document.getElementById('enableSiLi').enabled){
SiLiString = constructSiLiPlotKey();
window.SiLiFunc = SiLiEfficiency.bind(null, SiLiCoef[SiLiString], HPGeMinCoef['dummy'], HPGeMaxCoef['dummy']);
funcs[funcs.length] = window.SiLiFunc;
titles[titles.length] = 'Si(Li)';
colors[colors.length] = '#2980b9';
}
deployGraph(funcs, titles, colors, min, max);
}
//deploy graphs of [func]tions with [titles]
function deployGraph(func, titles, colors, min, max){
var i, j, logx, deltaLow, deltaHigh, eff,
data = 'Energy[keV]',
nPoints = 1000,
scaleSelect = document.getElementById("xScale"),
scale = scaleSelect.options[scaleSelect.selectedIndex].value;
yScaleSelect = document.getElementById("yScale"),
yScale = yScaleSelect.options[yScaleSelect.selectedIndex].value;
if(yScale=='true') yScale = true;
else yScale = false;
//don't let the user switch to log scale with a 0 min
if(yScale && parseFloat(document.getElementById('yMin').value)==0 )
document.getElementById('yMin').value = 0.001;
for(i=0; i<titles.length; i++){
data += ', '+titles[i];
}
data += '\n';
for(i=0; i<nPoints+1; i++){
if(scale=='lin'){
logx = (max-min)/nPoints*i+min;
data += logx;
logx = Math.log(logx);
} else{
logx = (Math.log(max)-Math.log(min))/nPoints*i+Math.log(min);
data += logx;
}
for(j=0; j<func.length; j++){
data+=',';
eff = func[j].bind(null, logx)();
data += eff;
}
data += '\n';
}
g = new Dygraph(document.getElementById('graphDiv'), data, {
title: 'Simulated Efficiency v. Energy',
xlabel: 'Energy [keV]',
ylabel: 'Efficiency',
sigFigs: 2,
strokeWidth: 4,
colors: colors,
highlightCircleSize: 6,
labelsSeparateLines : true,
clickCallback : passClickToWidget,
legend: 'always',
customBars: true,
logscale: yScale,
titleHeight: 30,
xLabelHeight: 24,
yLabelWidth: 24,
yAxisLabelWidth: 75,
axes:{
x: {
valueFormatter: function(number, opts, dygraph){
if(scale=='log')
return Math.exp(number).toFixed() + ' keV';
else
return number.toFixed() + ' keV';
},
axisLabelFormatter: function(number, gran, opts, dygraph){
if(scale=='lin')
return Math.round(number);
else
return Math.round(Math.exp(number));
}
},
y: {
axisLabelFormatter: function(number, gran, opts, dygraph){
if(number<0.1){
return number.toExponential(1)
} else
return number.toFixed(2);
}
}
}
});
g.updateOptions({
drawCallback: repaint,
});
repaint(g);
}
//construct the correct plot key based on whatever is selected in the plot options
//HPGeCoef holds the coefficients for all HPGe fits in a key value store
//where the key is the string concatenation of all the control panel values in
//the order:
//summing scheme + nDetectors + HPGe Distance + Delrin thickness
//so 'clover1214.520' is 12 detectors at 14.5cm with 20mm delrin and per-clover summing.
//HPGeCoef['clover811.00'] = [-8.0309801002962706e+02, 1.1187177193972436e+03, -6.7413427087340233e+02, 2.2869743662093572e+02, -4.7716717011091916e+01, 6.2669769394841666e+00, -5.0603869584892447e-01, 2.2979902406689505e-02, -4.4966824986778788e-04];
//HPGeMinCoef and HPGeMaxCoef are packed the same way as HPGeCoef, but hold the 1-sigma extrema for the coefficients:
function constructPlotKey(){
var summingOptions = document.getElementById('summingScheme'),
summing = summingOptions.options[summingOptions.selectedIndex].value,
nHPGeOptions = document.getElementById('nHPGeSwitch'),
nHPGe = nHPGeOptions.options[nHPGeOptions.selectedIndex].value,
HPGeDistanceOptions = document.getElementById('HPGeDistanceSwitch'),
HPGeDistance = HPGeDistanceOptions.options[HPGeDistanceOptions.selectedIndex].value,
absorberOptions = document.getElementById('delrinSwitch'),
absorber = absorberOptions.options[absorberOptions.selectedIndex].value,
plotKey = summing + nHPGe + HPGeDistance + absorber;
return plotKey;
}
//LaBr's only option is summing per detector or over the whole array, and we're not interested in the array option.
function constructLaBrPlotKey(){
return 'detector';
}
function constructSiLiPlotKey(){
return 'detector';
}
//callback to run every time the function repaints
function repaint(dygraph){
var xMin = document.getElementById('xMin'),
xMax = document.getElementById('xMax'),
yMin = document.getElementById('yMin'),
yMax = document.getElementById('yMax'),
scaleSelect = document.getElementById("xScale"),
scale = scaleSelect.options[scaleSelect.selectedIndex].value;
prepImageSave(dygraph);
if(scale=='lin'){
xMin.value = g.xAxisRange()[0].toFixed();
xMax.value = g.xAxisRange()[1].toFixed();
}else{
xMin.value = Math.exp(g.xAxisRange()[0]).toFixed();
xMax.value = Math.exp(g.xAxisRange()[1]).toFixed();
}
yMin.value = g.yAxisRange()[0].toFixed(2);
yMax.value = g.yAxisRange()[1].toFixed(2);
//FF form validation shenanigans again:
validateNumber('xMin');
validateNumber('xMax');
validateNumber('yMin');
validateNumber('yMax');
computeSingles();
computeCoincidence();
computeTriples();
}