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