-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountbins.py
More file actions
33 lines (23 loc) · 821 Bytes
/
countbins.py
File metadata and controls
33 lines (23 loc) · 821 Bytes
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
import ROOT,sys
def main(argv):
if len(argv)-1<1:
raise RuntimeError('usage: python countins.py file.root')
filename = argv[1]
f = ROOT.TFile.Open(filename,'READ')
if not f: raise RuntimeError(filename+' doesnt exist')
nbins_dict = {}
for tkey in f.GetListOfKeys():
if tkey.GetClassName().count('TH1'):
histoname = tkey.GetName()
h = f.Get(histoname)
if not h: raise RuntimeError(histoname+' doesnt exist in '+filename)
nbins = h.GetNbinsX()
try:
nbins_dict[nbins] += [histoname]
except:
nbins_dict[nbins] = [histoname]
for n in sorted(nbins_dict.keys(),reverse=True):
for histo in nbins_dict[n]:
print n, histo
if __name__ == '__main__':
main(sys.argv)