3 from __future__
import print_function
16 if e.errno == errno.EEXIST
and os.path.isdir(path):
22 return os.path.realpath(os.path.abspath(os.path.expanduser(path)))
28 run_dir = os.path.join(output_dir,
"run")
31 cmssw_dir = os.path.join(os.environ[
"CMSSW_BASE"],
"src")
36 input_files = [
fullPath(f)
for f
in glob.glob(os.path.join(input_dir,
"*SMS*")) ]
37 num_files = len(input_files)
38 input_files = numpy.array_split(numpy.array(input_files), num_jobs)
42 for sublist
in input_files:
45 job_files = sublist.tolist()
46 run_path = os.path.join(run_dir,
"wspace_sig_{}.sh".format(num_submitted))
47 with open(run_path,
"w")
as run_file:
48 os.fchmod(run_file.fileno(), 0755)
49 run_file.write(
"#! /bin/bash\n\n")
51 run_file.write(
"DIRECTORY=`pwd`\n")
52 run_file.write(
"cd {}\n".format(cmssw_dir))
53 run_file.write(
". /net/cms2/cms2r0/babymaker/cmsset_default.sh\n")
54 run_file.write(
"eval `scramv1 runtime -sh`\n")
55 run_file.write(
"cd $DIRECTORY\n\n")
57 for ifile
in range(len(job_files)):
59 cmd =
"./run/wspace_sig.exe -f {} -o {} --sig_strength {} -u all -l 35.9 -p".format(
60 f, output_dir, (injection_strength
if injection_strength >= 0.
else 0.))
61 if injection_strength >= 0.:
62 cmd +=
" --unblind none" 63 if injection_model !=
"":
64 cmd +=
" --inject "+injection_model
65 run_file.write(
"echo Starting to process file {} of {}\n".format(ifile+1, len(job_files)))
66 run_file.write(cmd+
"\n\n")
68 subprocess.check_call([
"JobSubmit.csh",run_path])
71 print(
"\nSubmitted {} files in {} jobs. Output will be sent to {}.\n".format(
72 num_files, num_submitted, output_dir))
74 if __name__ ==
"__main__":
75 parser = argparse.ArgumentParser(description =
"Submits batch jobs to produce workspaces for each signal mass point",
76 formatter_class = argparse.ArgumentDefaultsHelpFormatter)
77 parser.add_argument(
"output_dir", nargs=
"?", default =
"/net/cms2/cms2r0/babymaker/wspaces/2016_08_10/T1tttt",
78 help=
"Directory in which to store output workspaces.")
79 parser.add_argument(
"input_dir", nargs=
"?", default =
"/net/cms29/cms29r0/babymaker/babies/2016_08_10/T1tttt/skim_abcd",
80 help=
"Directory containing input ntuples.")
81 parser.add_argument(
"--num_jobs",
"-n", type=int, default=50,
82 help=
"Maximum number of jobs into which to split the mass points")
83 parser.add_argument(
"--injection_strength", type=float, default=-1.,
84 help=
"Amount of signal to inject. Negative values turn off signal injection. Note that signal injection replaces the data with MC yields, even at injection strength of 0.")
85 parser.add_argument(
"--injection_model", default=
"",
86 help=
"Path to signal ntuple to use for signal injection. If unspecified, uses the same signal model as used to construct the likelihood function")
87 args = parser.parse_args()
89 SendSignalWorkspaces(args.input_dir, args.output_dir, args.num_jobs, args.injection_strength, args.injection_model)
def SendSignalWorkspaces(input_dir, output_dir, num_jobs, injection_strength, injection_model)