-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathread_tree.htm
64 lines (52 loc) · 1.8 KB
/
read_tree.htm
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Reading object from the ROOT file</title>
<link rel="shortcut icon" href="../img/RootIcon.ico"/>
</head>
<body>
<p id="p_start">...</p>
<p id="p_process">...</p>
<p id="p_ready">...</p>
</body>
<script type='module'>
import { openFile } from '../modules/io.mjs';
import { TSelector, treeProcess } from '../modules/tree.mjs';
class TExampleSelector extends TSelector {
/** constructor */
constructor() {
super();
this.cnt = 0;
this.sumpx = 0;
this.sumpy = 0;
this.addBranch('px');
this.addBranch('py');
}
/** function called before reading of TTree starts */
Begin() {
document.getElementById('p_start').innerHTML = 'Start reading TTree';
}
/** function called for every entry */
Process() {
this.sumpx += this.tgtobj.px;
this.sumpy += this.tgtobj.py;
this.cnt++;
document.getElementById('p_process').innerHTML = `Process ${this.cnt} entries`;
}
/** function called when processing finishes */
Terminate(res) {
if (!res || !this.cnt) {
res = 'Fail to process TTree';
} else {
let meanpx = this.sumpx/this.cnt, meanpy = this.sumpy/this.cnt;
res = `MeanPX = ${meanpx.toFixed(4)} MeanPY = ${meanpy.toFixed(4)}`;
}
document.getElementById('p_ready').innerHTML = res;
}
}
let file = await openFile('../../files/hsimple.root');
let tree = await file.readObject('ntuple;1');
treeProcess(tree, new TExampleSelector());
</script>
</html>