-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathalice_esd.js
58 lines (43 loc) · 1.81 KB
/
alice_esd.js
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
// function to extract tracks from ALICE_ESD tree
// tracks are in https://root.cern/files/alice_ESDs.root
// geometry in https://root.cern/files/alice_ESDgeometry.root
// Have to return Promise with list of objects which can be drawn on geometry
async function extract_geo_tracks(tree, opt) {
// as first argument, tree should be provided
console.log('CALL async function extract_geo_tracks');
let handle = await import(JSROOT.source_dir + 'modules/tree.mjs');
const selector = new handle.TSelector();
selector.addBranch('ESDfriend.fTracks.fPoints', 'pnts');
let lst = JSROOT.create('TList'), numentry = 0, numtracks = 0;
selector.Process = function() {
// function called for every entry
const pnts = this.tgtobj.pnts;
numentry++;
// now converts AliTrackPointArray into TGeoTrack
for (let p = 0; p < pnts.length; ++p) {
numtracks++;
const arr = pnts[p];
if (!arr.fNPoints) continue;
const track = JSROOT.create('TGeoTrack');
track.fNpoints = arr.fNPoints*4;
track.fPoints = new Float32Array(track.fNpoints*4);
for (let k = 0; k < arr.fNPoints; ++k) {
track.fPoints[k*4] = arr.fX[k];
track.fPoints[k*4+1] = arr.fY[k];
track.fPoints[k*4+2] = arr.fZ[k];
}
track.fLineWidth = 2;
track.fLineColor = 3;
lst.Add(track);
if (numtracks > 100) return this.Abort(); // do not accumulate too many tracks
}
}
selector.Terminate = function() {
// function called when processing finishes
console.log(`Read done num entries ${numentry} tracks ${numtracks}`);
}
await handle.treeProcess(tree, selector);
console.log('FINISH extract_geo_tracks');
return lst;
}
console.log(`LOAD alice_esd.js with JSROOT ${JSROOT.version}`);