CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
mps_parse_pedechi2hist Namespace Reference

Functions

def get_all_ids_names
 
def get_his_data
 
def get_used_binaries
 
def main
 

Function Documentation

def mps_parse_pedechi2hist.get_all_ids_names (   mps_db)
Returns two lists containing the mille job IDs and the associated names.

Arguments:
- `mps_db`: path to the MPS database file

Definition at line 77 of file mps_parse_pedechi2hist.py.

Referenced by main().

77 
78 def get_all_ids_names(mps_db):
79  """Returns two lists containing the mille job IDs and the associated names.
80 
81  Arguments:
82  - `mps_db`: path to the MPS database file
83  """
84 
85  lib = mpslib.jobdatabase()
86  lib.read_db(mps_db)
87 
88  ids = lib.JOBNUMBER[:lib.nJobs]
89  names = lib.JOBSP3[:lib.nJobs]
90 
91  return ids, names
92 
def mps_parse_pedechi2hist.get_his_data (   his_file)
Parse the pede histogram file.

Arguments:
- `his_file`: pede histogram file

Definition at line 117 of file mps_parse_pedechi2hist.py.

Referenced by main().

118 def get_his_data(his_file):
119  """Parse the pede histogram file.
120 
121  Arguments:
122  - `his_file`: pede histogram file
123  """
124 
125  his_data = []
126  with open(his_file, "r") as his:
127  found_chi2_start = False;
128 
129  for line in his:
130  if r"final <Chi^2/Ndf> from accepted local fits vs file number" in line:
131  found_chi2_start = True
132  if not found_chi2_start:
133  continue
134  else:
135  if r"end of xy-data" in line: break
136  if not re.search("\d", line): continue
137  if re.search(r"[a-z]", line): continue
138  splitted = line.split()
139  his_data.append(splitted[-1])
140 
141  return his_data
142 
def mps_parse_pedechi2hist.get_used_binaries (   cfg,
  no_binary_check 
)
Returns list of used binary IDs.

Arguments:
- `cfg`: python config used to run the pede job
- `no_binary_check`: if 'True' a check for file existence is skipped

Definition at line 93 of file mps_parse_pedechi2hist.py.

Referenced by main().

93 
94 def get_used_binaries(cfg, no_binary_check):
95  """Returns list of used binary IDs.
96 
97  Arguments:
98  - `cfg`: python config used to run the pede job
99  - `no_binary_check`: if 'True' a check for file existence is skipped
100  """
101 
102  cms_process = mps_tools.get_process_object(cfg)
103 
104  binaries = cms_process.AlignmentProducer.algoConfig.mergeBinaryFiles
105  if no_binary_check:
106  used_binaries = binaries
107  else:
108  # following check works only if 'args.cfg' was run from the same directory:
109  used_binaries = [b for b in binaries
110  if os.path.exists(os.path.join(os.path.dirname(cfg), b))]
111 
112  used_binaries = [int(re.sub(r"milleBinary(\d+)\.dat", r"\1", b))
113  for b in used_binaries]
114 
115  return used_binaries
116 
def mps_parse_pedechi2hist.main (   argv = None)
Main routine of the script.

Arguments:
- `argv`: arguments passed to the main routine

Definition at line 29 of file mps_parse_pedechi2hist.py.

References get_all_ids_names(), get_his_data(), get_used_binaries(), join(), and print().

29 
30 def main(argv = None):
31  """Main routine of the script.
32 
33  Arguments:
34  - `argv`: arguments passed to the main routine
35  """
36 
37  if argv == None:
38  argv = sys.argv[1:]
39 
40  parser = argparse.ArgumentParser(description="Analysis pede histogram file")
41  parser.add_argument("-d", "--mps-db", dest="mps_db", required=True,
42  metavar="PATH", help="MPS database file ('mps.db')")
43  parser.add_argument("--his", dest="his_file", required=True,
44  metavar="PATH", help="pede histogram file")
45  parser.add_argument("-c", "--cfg", dest="cfg", metavar="PATH", required=True,
46  help="python configuration file of pede job")
47  parser.add_argument("-b", "--no-binary-check", dest="no_binary_check",
48  default=False, action="store_true",
49  help=("skip check for existing binaries "
50  "(possibly needed if used interactively)"))
51  args = parser.parse_args(argv)
52 
53 
54  for input_file in (args.mps_db, args.his_file, args.cfg):
55  if not os.path.exists(input_file):
56  print("Could not find input file:", input_file)
57  sys.exit(1)
58 
59  ids, names = get_all_ids_names(args.mps_db)
60  used_binaries = get_used_binaries(args.cfg, args.no_binary_check)
61  his_data = get_his_data(args.his_file)
62 
63  if len(his_data) != len(used_binaries):
64  print("The number of used binaries is", len(used_binaries), end=' ')
65  print("whereas in contrast, however, the <chi2/ndf> histogram in Pede has", end=' ')
66  print(len(his_data), "bins (Pede version >= rev92 might help if #bins < #binaries).", end=' ')
67  print("Exiting.")
68  sys.exit(1)
69 
70  with open("chi2pedehis.txt", "w") as f:
71  for i, b in enumerate(used_binaries):
72  index = ids.index(b)
73  name = names[index]
74  f.write(" ".join([name, "{:03d}".format(b), his_data[i]])+"\n")
75 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19