exp / index.html
user93729's picture
Update index.html
9fb6e88 verified
<!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&nbsp;s) and <strong>mass</strong> of KCl (0–3&nbsp;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';
/* ---------------------------------------------------------
* Load Poisson PRNG. We try the @stdlib library first; if
* loading or ESM interop fails, we fall back to a simple
* Knuth‑style algorithm so the page always works.
* ------------------------------------------------------- */
// let poisson;
// // Top‑level await works in modern browsers (Chrome ≥ 89, FF ≥ 115 ESR, Safari ≥ 15)
// const mod = await import('https://cdn.jsdelivr.net/npm/@stdlib/random-base-poisson@0.1.1/+esm');
// // For CJS packages transpiled to ESM, the export might be under `default` or the namespace itself
// poisson = (typeof mod === 'function') ? mod : (typeof mod.default === 'function' ? mod.default : undefined);
// if (typeof poisson !== 'function') throw new Error('Poisson export not found');
/* ---------------------------------------------------------
* Adjustable physical constants (tweak as needed)
* ------------------------------------------------------- */
const BASE_RATE = 2.8672; // counts · g⁻¹ · s⁻¹ (unattenuated activity seen by detector) 16*0.896*0.20 (nominal,branching ratio, efficiency)
const ABS_COEFF = 0.15; // self‑absorption coefficient (g⁻¹) in exp(−k·m)
const BACKGROUND_RATE = 0.8; // background counts · s⁻¹
const numberInput = document.getElementById('mass');
// let oldvalue = numberInput.value;
// numberInput.addEventListener('input', function() {
// const value = this.value;
// // Check if the value is not empty and is not a valid multiple of 0.5
// if (value !== '' && (parseFloat(value) * 10) % 5 >= 1e-8) {
// // Set a custom error message
// console.log("here1")
// this.value = oldvalue;
// }
// else{
// oldvalue=value;
// }
// });
const timeInput = document.getElementById('time');
// let oldtime = timeInput.value;
// timeInput.addEventListener('input', function() {
// const value = this.value;
// // Check if the value is not empty and is not a valid multiple of 0.5
// if (value !== '' && (parseFloat(value) * 10) % 1 >= 1e-8) {
// // Set a custom error message
// console.log("here1")
// this.value = oldtime;
// }
// else{
// oldtime=value;
// }
// });
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;
}
// Expected count rate (counts/s) after self‑absorption
const rateSample = BASE_RATE * m * Math.exp(-ABS_COEFF * m);
const rateTotal = rateSample + BACKGROUND_RATE;
// Expected counts over measuring time
const lambda = rateTotal * t;
// Simulated detector counts with Poisson noise
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>