-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.py
44 lines (33 loc) · 1.22 KB
/
output.py
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
#!/usr/bin/env python
from analysis_utils.root import pytree
import ROOT as r
class reco_output:
def __init__(self, output_filename, min_hits, **kwargs):
self.outfile = r.TFile(output_filename, 'recreate')
self.min_hits = min_hits
for arg in ('eff','density','energy','theta','phi'):
setattr(self, arg, kwargs.get(arg, 0))
t = pytree.PyTree('reco', 'reco')
self.t = t
self.h = r.TH1I('nhits', 'nhits', 1000, 0, 1000)
#self.write_result([])
def write_result(self, hits):
nhits = len(hits)
self.h.Fill(nhits)
if nhits < self.min_hits:
return
t = self.t
t.reset()
t.write_branch(self.eff, 'eff', float)
t.write_branch(self.density, 'density', float)
t.write_branch(self.energy, 'energy', float)
t.write_branch(self.theta, 'theta', float)
t.write_branch(self.phi, 'phi', float)
t.write_branch(nhits, 'hit_n', float)
t.write_branch(hits[:,0], 'hit_x', [int])
t.write_branch(hits[:,1], 'hit_y', [int])
t.write_branch(hits[:,2], 'hit_val', [int])
t.fill()
def close(self):
self.outfile.Write()
self.outfile.Close()