-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnewGainMatcher.html
More file actions
393 lines (343 loc) · 17.9 KB
/
newGainMatcher.html
File metadata and controls
393 lines (343 loc) · 17.9 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<html>
<head>
<title>GRIFFIN GainMatcher</title>
<script src='scripts/HTMLImports.min.js' type="text/javascript"></script>
<script src='scripts/mustache.js' type="text/javascript"></script>
<script src='scripts/easeljs-0.7.0.min.js' type="text/javascript"></script>
<script src='scripts/dygraphs.1.1.1.min.js' type="text/javascript"></script>
<script src='scripts/regression.min.js' type="text/javascript"></script>
<script src='scripts/gammaSpectrum.js' type="text/javascript"></script>
<script src='scripts/fitit.js' type="text/javascript"></script>
<script src="scripts/jquery1-11-3.min.js"></script>
<script src="scripts/bootstrap3-3-5.min.js"></script>
<script src="scripts/plotly-1.5.0.min.js"></script>
<script src='scripts/helpers.js' type="text/javascript"></script>
<script src='scripts/newGainMatcher.js' type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap3-3-5.min.css">
<link rel="stylesheet" type="text/css" href="css/custom.css">
<!--HTML imports-->
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link id='header' rel="import" href="templates/header/header.html">
<link id='paginationMenu' rel="import" href="templates/paginationMenu/paginationMenu.html">
<link id='newGainMatcherReport' rel="import" href="templates/newGainMatcherReport/newGainMatcherReport.html">
<link id='newGainMatcherReportTable' rel="import" href="templates/newGainMatcherReport/newGainMatcherReportTable.html">
<link id='newGainMatcherFitsReportTable' rel="import" href="templates/newGainMatcherReport/newGainMatcherReportTable.html">
<link id='plotGrid' rel="import" href="templates/plotGrid/plotGrid.html">
<link id='plotControl' rel="import" href="templates/plotControl/plotControl.html">
<link id='plotListLite' rel="import" href="templates/plotList/plotListLite.html">
<link id='dataplot' rel="import" href="templates/dataplot/dataplot.html">
<link id='footer' rel="import" href="templates/footer/footer.html">
</head>
<body>
<div id='head'></div>
<div id='messageDiv' class='col-md-12'>
<div id='messageDivText'></div><div id='messageDivButton'></div>
</div>
<div id='progressDiv' class="container progress hidden">
<div id='newGainMatcherProgress' class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">Initializing App...
</div>
</div>
<!--helpful hints-->
<div class='col-md-6'>
<div id='welcomeMessage' class="alert alert-warning" role="alert">
<span class="glyphicon glyphicon-check" aria-hidden="false"></span>
This app will gain match spectra.
</div>
<div id='fetchingMessage' class="alert alert-warning hidden" role="alert">
<span class="glyphicon glyphicon-check" aria-hidden="true"></span>
Spectra are downloading from the server...
</div>
<div id='roughGainMatchMessage' class="alert alert-warning hidden" role="alert">
<span class="glyphicon glyphicon-check" aria-hidden="true"></span>
Performing a rough Gain Matching of the spectra before attempting peak fitting...
</div>
<div id='fittingSinglesMessage' class="alert alert-warning hidden" role="alert">
<span class="glyphicon glyphicon-check" aria-hidden="true"></span>
Fitting the peaks in the 1d spectra...
</div>
<div id='fittingProjectionsMessage' class="alert alert-warning hidden" role="alert">
<span class="glyphicon glyphicon-check" aria-hidden="true"></span>
Fitting the peaks in the projected spectra from the 2d spectra...
</div>
<div id='reviewMessage' class="alert alert-warning hidden" role="alert">
<span class="glyphicon glyphicon-check" aria-hidden="true"></span>
Analysis complete. Review the results in the table below. Results can be downloaded as CSV or Cal files.
</div>
</div>
<div id='error-messages-for-drop-area' class='col-md-6 error-text'></div>
<div id="peakFitterDivContainer" class='col-md-12 hidden'>
<div id='inputsHistosContainerDiv' class='col-md-12'>
<div class='col-md-12'>
<label for="inputHistogramFiles" class='col-md-4'>List of Histogram files (.tar):</label>
<div id='histo-list-menu-div' class='col-md-4'>
<label for="HistoListSelect">Select files to add them:</label>
</div>
<div class='col-md-6'>
<textarea id="inputHistogramFiles" name="inputHistogramFiles" rows="4" cols="50"></textarea>
</div>
</div>
</div>
<div id='inputs1dContainerDiv' class='col-md-12'>
<div class='col-md-4'>
<label for="input1dSpectrumNames" class='col-md-12'>List of 1d spectra:</label>
<textarea id="input1dSpectrumNames" name="input1dSpectrumNames" rows="4" cols="50"></textarea>
</div>
<div class='col-md-4'>
<label for="input1dPeaks" class='col-md-12'>List of peaks to fit in all 1d spectra:</label>
<textarea id="input1dPeaks" name="input1dPeaks" rows="4" cols="50"></textarea>
</div>
</div>
<div id='inputs2dContainerDiv' class='col-md-12'>
<div class='col-md-4'>
<label for="input2dSpectrumNames" class='col-md-12'>List of 2d spectra:</label>
<textarea id="input2dSpectrumNames" name="input2dSpectrumNames" rows="4" cols="50"></textarea>
</div>
<div class='col-md-4'>
<label for="input2dGates" class='col-md-12'>List of gates to make projections for all 2d spectra:</label>
<textarea id="input2dGates" name="input2dGates" rows="4" cols="50"></textarea>
</div>
<div class='col-md-4'>
<label for="input2dPeaks" class='col-md-12'>List of peaks to fit in all projections:</label>
<textarea id="input2dPeaks" name="input2dPeaks" rows="4" cols="50"></textarea>
</div>
</div>
</div>
<div id='buttonsContainerDiv' class='col-md-12'>
<div id='launchSubmitDiv' class='col-md-6 hidden'></div>
<div id='saveCalDiv' class='col-md-3 hidden'>
<button type="button" class="btn btn-primary btn-lg" id='saveCal'>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Save Cal file
</button>
<input id='saveCalname' type='text' value='GRIFFIN-Cal-File.cal' width='500px'></input>
</div>
<div id='saveJSONDiv' class='col-md-3 hidden'>
<button type="button" class="btn btn-primary btn-lg" id='saveJSON'>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Save JSON file
</button>
</div>
<div id='saveCSVDiv' class='col-md-3 hidden'>
<button type="button" class="btn btn-primary btn-lg" id='saveCSV'>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>Download results as CSV
</button>
</div>
<div id='saveScriptDiv' class='col-md-3 hidden'>
<button type="button" class="btn btn-primary btn-lg" id='saveScript'>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>Download input script
</button>
</div>
</div>
</div>
<!-- Histogram Choice Div -->
<div id='histoChoiceBar' class='col-md-12'>
<div id='histoChoiceDir' class='col-md-8'></div>
<div id='histoChoiceSubmitDiv' class='col-md-4'></div>
</div>
<div id='detectorChoiceBar' class='col-md-12'></div>
<div id='decisionBarAuto' class='col-md-12 hidden'></div>
<div id='customPeaksContainerDiv' class='col-md-12 hidden'>
<div class='col-md-4'>
<label for="customInput1dPeakEnergy" class='col-md-12'>Enter a comma-separated list of peak calibrated energies for gain-matching:</label>
<textarea id="customInput1dPeakEnergy" name="customInput1dPeakEnergy" rows="4" cols="50"></textarea>
</div>
<div class='col-md-4'>
<label for="customInput1dPeakPulseHeight" class='col-md-12'>Enter a comma-separated list of peak uncalibrated centroids:</label>
<textarea id="customInput1dPeakPulseHeight" name="customInput1dPeakPulseHeight" rows="4" cols="50"></textarea>
</div>
<div id='customPeaksButtonDiv' class='col-md-4'></div>
</div>
<!-- Pagination menu Div -->
<div id='menu' class='col-md-12'></div>
<!-- Spectrum Plotting -->
<div id='plotRegion' class='sectionWrapper'>
<div id='plotWrap' class='col-md-9 plotRegion item'>
<div id='plottingGrid'></div>
<div class='col-md-8' id='plotCtrl'></div>
<div class='sectionWrapper refitButtons'>
<div class='col-md-12'>
<select id="refitSelect"></select>
<button type="button" class="btn btn-default btn-lg" id='refitButton' engaged='0'>
<span id='refitButtonBadge' class="glyphicon glyphicon-equalizer" aria-hidden="true"></span>
<span id='refitButtonText'>Refit this Peak</span>
</button>
</div>
</div>
</div>
<div class='col-md-2 item'>
<div id='plotList' style='overflow-y:scroll; height:400px;'></div>
</div>
</div>
<!-- Peak-Fitting results table -->
<div id='resultsTableRegion' class='col-md-12 hidden'>
<div id='newGainMatcherFits' class='col-md-12'></div>
</div>
<!--Table of calculations and results-->
<div id='detectorReportRegion' class='col-md-12'>
<div id='tableMenuDiv' class='col-md-12'></div>
<div id='reportCardDiv' class='col-md-12'></div>
<div id='newGainMatcher' class='col-md-6'></div>
<div id='detectorReportPlot' class='col-md-6'></div>
</div>
<!-- Plot of all curves together -->
<div id='resultsPlotRegion' class='col-md-12'>
<div id='newGainMatcherPlot' class='col-md-12 plotlyDiv'></div>
<div id='newGainMatcherResidualsByPeakPlots' class='col-md-12 plotlyDiv'>
<h3>These new calibration coefficients for each peak:</h3>
</div>
<div id='newGainMatcherResidualsByDetectorPlots' class='col-md-12 plotlyDiv'>
<h3>These new calibration coefficients for each detector:</h3>
</div>
</div>
<div id='foot'></div>
<script>
window.addEventListener('HTMLImportsLoaded', function(e) {
dataStore._plotGrid = new plotGrid('plottingGrid');
dataStore._plotControl = new plotControl('plotCtrl', 'horizontal');
dataStore.templates = prepareTemplates(['header', 'paginationMenu', 'newGainMatcherReport', 'newGainMatcherReportTable', 'newGainMatcherFitsReportTable', 'plotGrid', 'plotControl', 'plotListLite', 'dataplot', 'footer']);
setupHeader('head', 'new Gain Matcher');
setupPaginationMenu('menu');
dataStore._plotGrid.setup();
dataStore._plotControl.setup();
//set up spectrum cell
dataStore._plotGrid.manageCellCreation(null, dataStore.plots[0]);
setupFooter('foot');
//don't want additional plots in this app
deleteNode('plottingGridnewPlotButton');
// Inject the dismiss button to the server messageDiv
newButton = document.createElement('button');
newButton.setAttribute('id', 'messageDivDismissButton');
newButton.setAttribute('class', 'btn btn-default btn-lg');
newButton.innerHTML = "Dismiss";
newButton.onclick = function(){
ClearErrorConnectingToAnalyzerServer();
}.bind(newButton);
document.getElementById('messageDivButton').appendChild(newButton);
// Create the text input for the Histogram file directory and file inputs
var newLabel = document.createElement("label");
newLabel.for = 'HistoDirectoryInput';
newLabel.innerHTML = 'Directory of Histogram files: ';
document.getElementById('histoChoiceDir').appendChild(newLabel);
newInput = document.createElement('input');
newInput.id = 'HistoDirectoryInput';
newInput.type = 'text';
newInput.style.width = '400px';
newInput.value = dataStore.histoFileDirectoryPath;
newInput.onchange = function(){
dataStore.histoFileDirectoryPath = this.value;
getHistoFileListFromServer();
}.bind(newInput);
document.getElementById('histoChoiceDir').appendChild(newInput);
// Grab the histogram list for the default directory
getHistoFileListFromServer();
getMidasFileListFromServer(); // The request for details follows this. Needed for adding run titles to selects
// Set up event listener for adding run titles to selects
listener('histoChoiceBar', 'midasFileDetailsAvailable', addTitlesToHistoListSelect);
// Set up the refit button
document.getElementById('refitButton').onclick = function(){ toggleRefitMode(); }
document.getElementById('refitButton').disabled = true; // Disabled until there are peaks to refit
// Set up the CSV file button
document.getElementById('saveCSV').onclick = function(){ buildCSVfile(); }
// Set up the Script download file button
document.getElementById('saveScript').onclick = function(){ buildScriptfile(); }
//make sure the file name for Cal file download gets passed around:
document.getElementById('saveCalname').onchange = function(){
//set the filename to whatever the user has requested:
document.getElementById('saveCal').download = this.value;
}
// Set up the Cal file button
document.getElementById('saveCal').onclick = function(){ buildCalfile(); }
// Set up the JSON file button
document.getElementById('saveJSON').onclick = function(){ buildJSONfile(); }
// Create Detector choice buttons
for(var i=0; i<dataStore.detectorChoice.length; i++){
newButton = document.createElement('button');
newButton.setAttribute('id', 'detectorChoice-'+dataStore.detectorChoice[i].name);
newButton.setAttribute('class', 'btn btn-default');
newButton.setAttribute('engaged', '0');
newButton.value = dataStore.detectorChoice[i].name;
newButton.innerHTML = 'Calibrate '+dataStore.detectorChoice[i].name;
newButton.onclick = function(){
dataStore.detectorType = this.value;
//plug in source decision controls
document.getElementById('decisionBarAuto').innerHTML = '';
var keys = Object.keys(dataStore.peaksList[dataStore.detectorType]);
for(var i=0; i<keys.length; i++){
if(keys[i].includes("Table")){ continue; }
// Create Auto calibrate source Submit button
newButton = document.createElement('button');
newButton.setAttribute('id', 'automaticCalibration-'+keys[i]);
newButton.setAttribute('class', 'btn btn-default');
newButton.setAttribute('engaged', '0');
newButton.value = keys[i];
newButton.innerHTML = '<span id=\'autoCalibBadge-'+keys[i]+'\' class=\'glyphicon glyphicon-equalizer\' aria-hidden=\'true\'></span><span id=\'autoText\'>'+keys[i]+'</span>';
if(keys[i].includes("Custom")){
newButton.onclick = function(){
document.getElementById('customPeaksContainerDiv').classList.remove('hidden');
// Fetch a single spectrum to use as the reference
dataStore.currentTask = 'Setup';
// Set the dataStore.histoFileName to this source so that constructQueries requests the correct spectrum
dataStore.histoFileName = dataStore.currentHistoFileName = document.getElementById('HistoListSelectGRIFFIN').value;
// Plug in the active spectra names for the 1d histograms
dataStore._plotControl.activeSpectra = [];
dataStore._plotControl.activeSpectra.push(dataStore.peakFitterScriptTemplate[dataStore.detectorType]['spectrumList1d'][0]);
dataStore._plotControl.refreshAll();
}.bind(newButton);
}else{
newButton.onclick = function(){
setupnewGainMatcher(dataStore.detectorType,this.value);
}.bind(newButton);
}
document.getElementById('decisionBarAuto').appendChild(newButton);
}
// Add the button for the Custom peak list entry
if(keys.includes("Custom")){
document.getElementById('customPeaksButtonDiv').innerHTML = "";
newButton = document.createElement('button');
newButton.setAttribute('id', 'automaticCalibration-CustomGo');
newButton.setAttribute('class', 'btn btn-default');
newButton.setAttribute('engaged', '0');
newButton.value = "CustomGo";
newButton.innerHTML = '<span id=\'autoCalibBadge-'+'CustomGo'+'\' class=\'glyphicon glyphicon-equalizer\' aria-hidden=\'true\'></span><span id=\'autoText\'>'+'CustomGo'+'</span>';
newButton.onclick = function(){
// Save the peak list as a Custom source entry for this detector type
dataStore.peaksList[dataStore.detectorType]["Custom"] = [];
var valuesArrayEnergy = document.getElementById('customInput1dPeakEnergy').value.split(",").map(Number);
dataStore.peaksList[dataStore.detectorType]["Custom"] = valuesArrayEnergy;
dataStore.peaksList[dataStore.detectorType]["CustomTable"] = valuesArrayEnergy.slice(0,4);
var valuesArrayPulseHeight = document.getElementById('customInput1dPeakPulseHeight').value.split(",").map(Number);
console.log(dataStore);
// Construct the data array needed by regression.polynomial
var data = [];
for(j=0; j<valuesArrayEnergy.length; j++){ data.push([valuesArrayPulseHeight[j],valuesArrayEnergy[j]]); }
// Linear fit
// Hats off to Tom Alexander, https://github.com/Tom-Alexander/regression-js
var result = regression.polynomial(data, { order: 1, precision: 20 });
optimalGain = result.equation[0];
console.log("OptimalGain found to be: "+optimalGain);
// Roughly gain-match this spectrum to become the referenceSpectrum for all spectra
var keys = Object.keys(dataStore.rawData);
var testSpectrum = []; testSpectrum.fillN(0,2000);
for(j=0; j<testSpectrum.length; j++){
var bin = parseInt(j*optimalGain);
if(bin>0 && bin<testSpectrum.length){
testSpectrum[bin] += dataStore.rawData[keys[0]][j];
}
}
dataStore.referenceSpectrum[dataStore.detectorType]["Custom"] = testSpectrum;
// Start the auto peak fitting process
setupnewGainMatcher(dataStore.detectorType,"Custom");
}.bind(newButton);
document.getElementById('customPeaksButtonDiv').appendChild(newButton);
}
document.getElementById('decisionBarAuto').classList.remove('hidden');
}.bind(newButton);
document.getElementById('detectorChoiceBar').appendChild(newButton);
}
// Reveal the progress bar
document.getElementById('progressDiv').classList.remove('hidden');
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
});
</script>
</body>
</html>