|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<title>KCl Detector Count Calculator</title> |
|
<style> |
|
body { |
|
font-family: Arial, sans-serif; |
|
margin: 2rem; |
|
max-width: 36rem; |
|
} |
|
label { |
|
display: block; |
|
margin-top: 1rem; |
|
} |
|
input { |
|
width: 6rem; |
|
} |
|
button { |
|
margin-top: 1.25rem; |
|
} |
|
#result { |
|
margin-top: 1.5rem; |
|
font-weight: bold; |
|
font-size: 1.1rem; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<h1>KCl Detector Count Calculator</h1> |
|
<p>Enter a measuring <strong>time</strong> (0–60 s) and <strong>mass</strong> of KCl (0–3 g). Each click simulates a new run according to the Poisson distribution.</p> |
|
|
|
<label>Measuring time (s): |
|
<input type="number" id="time" min="0" max="10000" step="0.1" value="10"> |
|
</label> |
|
|
|
<label>Mass of KCl (g): |
|
<input type="number" id="mass" min="0" max="3" step="0.5" value="1.0"> |
|
</label> |
|
|
|
<button id="calcBtn">Simulate</button> |
|
|
|
<div id="result"></div> |
|
|
|
<script type="module"> |
|
import poisson from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-poisson@esm/index.mjs'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const BASE_RATE = 2.8672; |
|
const ABS_COEFF = 0.15; |
|
const BACKGROUND_RATE = 0.8; |
|
|
|
const numberInput = document.getElementById('mass'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const timeInput = document.getElementById('time'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function simulate() { |
|
const t = parseFloat(document.getElementById('time').value); |
|
const m = parseFloat(document.getElementById('mass').value); |
|
|
|
if (!(t >= 0 && t <= 10000 && m >= 0 && m <= 3 )) { |
|
document.getElementById('result').textContent = 'Please enter time ≤ 10000 s and mass ≤ 3 g (both not negative).'; |
|
return; |
|
} |
|
if((parseFloat(timeInput.value) * 10) % 1 >= 1e-8){ |
|
document.getElementById('result').textContent = 'Time has to be a multiple of 0.1s'; |
|
return; |
|
} |
|
if((parseFloat(numberInput.value) * 10) % 5 >= 1e-8){ |
|
document.getElementById('result').textContent = 'Mass has to be a multiple of 0.5g'; |
|
return; |
|
} |
|
|
|
|
|
const rateSample = BASE_RATE * m * Math.exp(-ABS_COEFF * m); |
|
const rateTotal = rateSample + BACKGROUND_RATE; |
|
|
|
|
|
const lambda = rateTotal * t; |
|
|
|
|
|
console.log("using lambda",lambda) |
|
const counts = poisson(lambda); |
|
|
|
document.getElementById('result').textContent = `Detector counts: ${counts}`; |
|
} |
|
|
|
document.getElementById('calcBtn').addEventListener('click', simulate); |
|
</script> |
|
</body> |
|
</html> |
|
|