Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
runCondor_beamspot.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file runCondor_beamspot.py
1 from optparse import OptionParser
2 import time
3 import os
4 import pwd
5 import sys
6 import re
7 
8 def dir_empty(dir_path):
9  return not any((True for _ in os.scandir(dir_path)))
10 
11 
12 if __name__ == '__main__':
13  # python runCondor_TrackletAna.py -m /sphenix/user/hjheng/TrackletAna/minitree/INTT/VtxEvtMap_ana398_zvtx-20cm_dummyAlignParams/INTTVtxZ.root -i /sphenix/user/hjheng/TrackletAna/data/INTT/ana398_zvtx-20cm_dummyAlignParams/sim/INTTRecoClusters_sim_merged.root -o TrackletMinitree_ana398_zvtx-20cm_dummyAlignParams -e 200 -s 400 -r 0.5
14  parser = OptionParser(usage="usage: %prog ver [options -h]")
15  parser.add_option("-d", "--isdata", dest="isdata", action="store_true", default=False, help="Is data")
16  parser.add_option("-i", "--infiledir", dest="infiledir", default='/sphenix/user/hjheng/TrackletAna/data/INTT/HIJING_ana398_xvtx-0p04cm_yvtx0p24cm_zvtx-20cm_dummyAlignParams', help="Input file")
17  parser.add_option("-o", "--outfiledir", dest="outfiledir", default='BeamspotMinitree_HIJING_ana398_xvtx-0p04cm_yvtx0p24cm_zvtx-20cm_dummyAlignParams', help="Output file directory (under /sphenix/user/hjheng/TrackletAna/minitree/INTT/)")
18  parser.add_option("-p", "--dphicut", dest="dphicut", default=0.05, help="Delta phi cut")
19  parser.add_option("-j", "--nJob", dest="nJob", default=400, help="nJob")
20  parser.add_option("-s", "--submitcondor", dest="submitcondor", action="store_true", default=False, help="Submit condor jobs")
21 
22  (opt, args) = parser.parse_args()
23  print('opt: {}'.format(opt))
24 
25  isdata = opt.isdata
26  infiledir = opt.infiledir
27  outfiledir = opt.outfiledir
28  dphicut = float(opt.dphicut)
29  nJob = int(opt.nJob)
30  submitcondor = opt.submitcondor
31  username = pwd.getpwuid(os.getuid())[0]
32  print ('username: {}'.format(username))
33  # subdir = 'data' if isdata else 'sim'
34  finaloutfiledir = '/sphenix/user/{}/TrackletAna/minitree/INTT/{}'.format(username, outfiledir)
35  os.makedirs(finaloutfiledir, exist_ok=True)
36 
37  os.makedirs('./log_beamspot/', exist_ok=True)
38  if not dir_empty('./log_beamspot/'):
39  os.system('rm ./log_beamspot/*')
40 
41 
42  condorFileName = "submitCondor_BeamspotReco_{}.job".format('data' if isdata else 'sim')
43  condorFile = open("{}".format(condorFileName), "w")
44  condorFile.write("Universe = vanilla\n")
45  condorFile.write("InitialDir = /sphenix/user/{}/TrackletAna/analysis_INTT\n".format(username))
46  condorFile.write("Executable = $(InitialDir)/condor_BeamspotReco.sh\n")
47  condorFile.write("PeriodicHold = (NumJobStarts>=1 && JobStatus == 1)\n")
48  condorFile.write("request_memory = 4GB\n")
49  condorFile.write("Priority = 20\n")
50  condorFile.write("job_lease_duration = 3600\n")
51  condorFile.write("inputfile = {}/ntuple_$(Process).root\n".format(infiledir))
52  condorFile.write("dphicut = {}\n".format(dphicut))
53  condorFile.write("outputfile = {}/minitree_$(Process).root\n".format(finaloutfiledir))
54  condorFile.write("Output = $(Initialdir)/condor/log_beamspot/condorlog_$(Process).out\n")
55  condorFile.write("Error = $(Initialdir)/condor/log_beamspot/condorlog_$(Process).err\n")
56  condorFile.write("Log = $(Initialdir)/condor/log_beamspot/condorlog_$(Process).log\n")
57  condorFile.write("Arguments = \"$(inputfile) $(outputfile) $(dphicut)\"\n")
58  condorFile.write("Queue {}\n".format(nJob))
59  condorFile.close() # Close the file before submitting the job
60 
61  if submitcondor:
62  cmd = 'condor_submit ' + condorFileName
63  os.system(cmd)