babymaker  e95a6a9342d4604277fe7cc6149b6b5b24447d89
nev_check.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import os, sys, re
3 import glob
4 import string
5 from pprint import pprint
6 import ROOT
7 import argparse
8 
9 parser = argparse.ArgumentParser()
10 parser.add_argument("-t","--timestamp")
11 args = parser.parse_args()
12 
13 if (args.timestamp):
14  timestamp = args.timestamp
15 else:
16  sys.exit("Please provide a timestamp either as, e.g. 151019_011440")
17 
18 
19 bdir = os.getcwd()
20 
21 if ('babymaker' not in bdir.split("/").pop()):
22  sys.exit("Execute from babymaker directory")
23 
24 outdir = os.path.join(bdir,'out',timestamp)
25 print outdir
26 if not os.path.exists(outdir):
27  sys.exit("Can't find out directory %s" %outdir)
28 
29 #one line to get list of unique dataset names in outdir
30 datasets = set([x.split("_mf")[0].split("/").pop() for x in glob.glob(outdir+"/*.root")])
31 
32 mismatch = 0
33 match = 0
34 totalsuccess = 0
35 totaltotal = 0 #awesomename
36 for dset in datasets:
37  print "Let's take a look at " + dset
38  ch = ROOT.TChain("tree")
39  chglob = ROOT.TChain("treeglobal")
40  if("T1tttt" in dset): # for now just checking mass skims
41  ch.Add(outdir+"/"+dset+"_mf*mlsp*.root")
42  chglob.Add(outdir+"/"+dset+"_mf*mlsp*.root")
43  else:
44  ch.Add(outdir+"/"+dset+"_mf*.root")
45  chglob.Add(outdir+"/"+dset+"_mf*.root")
46 
47  #make sure all root files agree how many events there should be
48  nev_list = []
49  for entry in chglob:
50  nev_list.append(entry.nev_sample)
51  if len(set(nev_list)) > 1:
52  print "incompatible root files combined"
53 
54  nsuccess = ch.GetEntries()
55  ntotal = nev_list[0]
56  totaltotal += ntotal
57  totalsuccess +=nsuccess
58 
59  if ntotal == nsuccess:
60  print "COMPLETE: "+str(nsuccess)+" / "+str(ntotal)+" events made it. Great job."
61  match+=1
62  elif ntotal > nsuccess:
63  print "NOT COMPLETE:"+str(nsuccess)+" / "+str(ntotal)+" events made it. Looks like you can't go play in the mountains after all."
64  mismatch+=1
65 
66  elif ntotal < nsuccess:
67  print "OVER COMPLETE:"+str(nsuccess)+" / "+str(ntotal)+" events made it. Looks like you can't go play in the mountains after all."
68  mismatch+=1
69 
70  print ""
71 
72 print "Attempted "+str(totaltotal)+" events. Completed "+str(totalsuccess)
73 print "Completed "+str(match) +"/"+str(match+mismatch)+" datasets."
74 
75 
76 
77