|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 7 | + |
| 8 | + <title>Reading object from the ROOT file</title> |
| 9 | + |
| 10 | + <script src="../scripts/JSRootCore.min.js" type="text/javascript"></script> |
| 11 | + |
| 12 | + <script type='text/javascript'> |
| 13 | + // absolute file path can be used as well |
| 14 | + var filename = "../../files/hsimple.root"; |
| 15 | + JSROOT.OpenFile(filename, function(file) { |
| 16 | + file.ReadObject("ntuple;1", function(tree) { |
| 17 | + |
| 18 | + var selector = new JSROOT.TSelector(); |
| 19 | + |
| 20 | + selector.AddBranch("px"); |
| 21 | + selector.AddBranch("py"); |
| 22 | + |
| 23 | + var cnt = 0, sumpx = 0, sumpy = 0; |
| 24 | + |
| 25 | + selector.Begin = function() { |
| 26 | + // function called before reading of TTree starts |
| 27 | + document.getElementById('p_start').innerHTML = "Start reading TTree"; |
| 28 | + } |
| 29 | + |
| 30 | + selector.Process = function() { |
| 31 | + // function called for every entry |
| 32 | + sumpx += this.tgtobj.px; |
| 33 | + sumpy += this.tgtobj.py; |
| 34 | + cnt++; |
| 35 | + document.getElementById('p_process').innerHTML = "Process " + cnt + " entries"; |
| 36 | + } |
| 37 | + |
| 38 | + selector.Terminate = function(res) { |
| 39 | + // function called when processing finishes |
| 40 | + if (!res || (cnt===0)) res = "Fail to process TTree"; |
| 41 | + else res = 'MeanPX = ' + (sumpx/cnt).toFixed(4) + ' MeanPY = ' + (sumpy/cnt).toFixed(4); |
| 42 | + document.getElementById('p_ready').innerHTML = res; |
| 43 | + } |
| 44 | + |
| 45 | + tree.Process(selector); |
| 46 | + }); |
| 47 | + }); |
| 48 | + </script> |
| 49 | + |
| 50 | +</head> |
| 51 | + |
| 52 | +<body> |
| 53 | + <p id="p_start">...</p> |
| 54 | + <p id="p_process">...</p> |
| 55 | + <p id="p_ready">...</p> |
| 56 | +</body> |
| 57 | + |
| 58 | +</html> |
| 59 | + |
0 commit comments