sanity_check_grl.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # usage python sanity_check_grl.py GRLFILE.txt
3 import numpy as np
4 import sys
5 import period_run_lists as pr
6 import pandas as pa
7 
8 the_grl=sys.argv[1]
9 
10 #period10c_start="35331"
11 
12 if (the_grl.find("FD")>-1 ):
13  DET="FD"
14  runs_df = pr.pfd
15 elif (the_grl.find("ND")>-1 ):
16  DET="ND"
17  runs_df = pr.pnd
18 else:
19  print "Expecting a grl name as argument with fd_ or nd_ in the name. Please try again..."
20  exit(0)
21 
22 print "Detector: ",DET
23 
24 # make a list of all the runs in this grl, including duplications due to multiple subruns within a run
25 grl_runs = []
26 with open(the_grl, "r") as f:
27  grl = f.read().split('\n')
28  for row in grl:
29  if len(row)<1:
30  continue
31  run_in_grl = row.split(' ')[0]
32  grl_runs.append(run_in_grl)
33 
34 for i in range(0, len(grl_runs)):
35  grl_runs[i] = np.int64(grl_runs[i])
36 
37 good_runs = pa.DataFrame(grl_runs, columns = ['Runs'])
38 good_runs.drop_duplicates(subset ="Runs",
39  keep = "first", inplace = True)
40 
41 
42 for index, row in runs_df.iterrows():
43  runs = row['Runs'] # a list of runs for this period
44  period_runs = pa.DataFrame(runs, columns = ['Runs'])
45  not_on_grl = list( set(period_runs['Runs'].values) - set(good_runs['Runs'].values) )
46  not_on_grl.sort()
47 
48 
49  nruns = len(period_runs)
50  nruns_not_on_grl = len(not_on_grl)
51  #print "nruns not on grl: ",nruns_not_on_grl
52  #print "not_on_grl",not_on_grl
53 
54  frac_bad = 100.*float(nruns_not_on_grl)/float(nruns)
55  nruns_on_grl = nruns - nruns_not_on_grl
56  frac_good = 100.*float(nruns_on_grl)/float(nruns)
57 
58  print "Percentage (number) of the %d runs from %s that are on this grl: %3.2f %% (%d)"%(nruns,row['Period'],frac_good,nruns_on_grl)
void split(double tt, double *fr)
procfile open("FD_BRL_v0.txt")
exit(0)