1868 def run(self):
1869 """
1870 Run ``basf2_mva_evaluate.py`` subprocess to evaluate QE MVA.
1871
1872 The MVA weight file created from training on the training data set is
1873 evaluated on separate test data.
1874 """
1875 weightfile_details = create_fbdt_option_string(self.fast_bdt_option)
1876 evaluation_pdf_output_basename = self.teacher_task.weightfile_identifier_basename + weightfile_details + ".pdf"
1877
1878 evaluation_pdf_output_path = self.get_output_file_name(evaluation_pdf_output_basename)
1879
1880 if 'USEREC' in self.process_type:
1881 if 'USERECBB' in self.process_type:
1882 process = 'BBBAR'
1883 elif 'USERECEE' in self.process_type:
1884 process = 'BHABHA'
1885 datafiles = 'datafiles/qe_records_N' + str(self.n_events_testing) + '_' + \
1886 process + '_test_' + self.task_acronym + '.root'
1887 else:
1888 datafiles = self.get_input_file_names(
1889 self.data_collection_task.get_records_file_name(
1890 self.data_collection_task,
1891 n_events=self.n_events_testing,
1892 random_seed=self.process + '_test_' +
1893 self.task_acronym))[0]
1894 cmd = [
1895 "basf2_mva_evaluate.py",
1896 "--identifiers",
1897 self.get_input_file_names(
1898 self.teacher_task.get_weightfile_xml_identifier(
1899 self.teacher_task,
1900 fast_bdt_option=self.fast_bdt_option))[0],
1901 "--datafiles",
1902 datafiles,
1903 "--treename",
1904 self.teacher_task.tree_name,
1905 "--outputfile",
1906 evaluation_pdf_output_path,
1907 ]
1908
1909
1910 log_file_dir = get_log_file_dir(self)
1911
1912
1913 try:
1914 os.makedirs(log_file_dir, exist_ok=True)
1915
1916
1917 except FileExistsError:
1918 print('Directory ' + log_file_dir + 'already exists.')
1919 stderr_log_file_path = log_file_dir + "stderr"
1920 stdout_log_file_path = log_file_dir + "stdout"
1921 with open(stdout_log_file_path, "w") as stdout_file:
1922 stdout_file.write(f'stdout output of the command:\n{" ".join(cmd)}\n\n')
1923 if os.path.exists(stderr_log_file_path):
1924
1925 os.remove(stderr_log_file_path)
1926
1927
1928 with open(stdout_log_file_path, "a") as stdout_file:
1929 with open(stderr_log_file_path, "a") as stderr_file:
1930 try:
1931 subprocess.run(cmd, check=True, stdin=stdout_file, stderr=stderr_file)
1932 except subprocess.CalledProcessError as err:
1933 stderr_file.write(f"Evaluation failed with error:\n{err}")
1934 raise err
1935
1936