#!/usr/bin/env python # Copyright (c) 2019, Anthony Latorre # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . from __future__ import print_function, division import yaml import string from os.path import split, splitext, join import uuid from subprocess import check_call CONDOR_TEMPLATE = \ """ # We need the job to run our executable script, with the # input.txt filename as an argument, and to transfer the # relevant input and output files: executable = @executable arguments = @args transfer_input_files = @transfer_input_files transfer_output_files = @transfer_output_files error = @error output = @output log = @log # The below are good base requirements for first testing jobs on OSG, # if you don't have a good idea of memory and disk usage. requirements = (OSGVO_OS_STRING == "RHEL 7") && (OpSys == "LINUX") request_cpus = 1 request_memory = 1 GB request_disk = 1 GB # Queue one job with the above specifications. queue 1 +ProjectName = "SNOplus" """.strip() # all files required to run the fitter (except the DQXX files) INPUT_FILES = ["muE_water_liquid.txt","pmt_response_qoca_d2o_20060216.dat","rsp_rayleigh.dat","e_water_liquid.txt","pmt_pcath_response.dat","pmt.txt","muE_deuterium_oxide_liquid.txt","pmt_response.dat","proton_water_liquid.txt"] # generate a UUID to append to all the filenames so that if we run the same job # twice we don't overwrite the first job ID = uuid.uuid1() class MyTemplate(string.Template): delimiter = '@' def submit_job(filename, run, gtid, dir, dqxx_dir, min_nhit, max_particles): print("submitting job for %s gtid %i" % (filename, gtid)) head, tail = split(filename) root, ext = splitext(tail) # all output files are prefixed with FILENAME_GTID_UUID prefix = "%s_%08i_%s" % (root,gtid,ID.hex) # fit output filename output = "%s.txt" % prefix # condor submit filename condor_submit = "%s.submit" % prefix # set up the arguments for the template executable = join(dir,"fit") args = [tail,"-o",output,"--gtid",gtid,"--min-nhit",min_nhit,"--max-particles",max_particles] transfer_input_files = ",".join([filename,join(dqxx_dir,"DQXX_%010i.dat" % run)] + [join(dir,filename) for filename in INPUT_FILES]) transfer_output_files = ",".join([output]) condor_error = "%s.error" % prefix condor_output = "%s.output" % prefix condor_log = "%s.log" % prefix template = MyTemplate(CONDOR_TEMPLATE) submit_string = template.safe_substitute( executable=executable, args=" ".join(map(str,args)), transfer_input_files=transfer_input_files, transfer_output_files=transfer_output_files, error=condor_error, output=condor_output, log=condor_log) # write out the formatted template with open(condor_submit, "w") as f: f.write(submit_string) # submit the job check_call(["condor_submit",condor_submit]) if __name__ == '__main__': import argparse from subprocess import check_output parser = argparse.ArgumentParser("submit grid jobs") parser.add_argument("filenames", nargs='+', help="input files") parser.add_argument("--dir", type=str, help="fitter directory", required=True) parser.add_argument("--dqxx-dir", type=str, help="dqxx directory", required=True) parser.add_argument("--min-nhit", type=int, help="minimum nhit to fit an event", default=100) parser.add_argument("--max-particles", type=int, help="maximum number of particles to fit for", default=3) parser.add_argument("--skip-second-event", action='store_true', help="only fit the first event after a MAST bank", default=False) args = parser.parse_args() for filename in args.filenames: if args.skip_second_event: output = check_output([join(args.dir,"zdab-cat"),"--skip-second-event",filename]) else: output = check_output([join(args.dir,"zdab-cat"),filename]) data = yaml.load(output) for i, event in enumerate(data['data']): for ev in event['ev']: run = ev['run'] gtid = ev['gtid'] nhit = ev['nhit'] if nhit >= args.min_nhit: submit_job(filename, run, gtid, args.dir, args.dqxx_dir, args.min_nhit, args.max_particles) n72'>72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
*LOG
*---  Standard Titles File: pmt_pcath_response.dat    02 Mar 1998
*---                 Banks: PCAT
*LOG OFF
*DO  PCAT  1    -i(30I -F)         #.  Bank for Photocathode response.
#.         (This bank MDL's PMT_PCATH_R.DAT)
#.
#.    Contact:  S. Biller,  Oxford.
#.
#.       Standard Database Header
#.
19750101        0 20380517 03331900  #.  1..4   Intrinsic validity
       0        0        0           #.  5..7   Data type, Task type, Format no.
       0        0        0           #.  8..10  Creation Date, Time, Source Id.
19750101        0 20380517 03331900  #. 11..14  Effective validity
       0        0                    #. 15..16  Entry Date Time
4*0                                  #. 17..20  Spare
10*0                                 #. 21..30  Temporary data (not in database)
#.
#.    End of Standard Database Header
#.
#.    Revision History:-
#.    ================
#.
#.    3.01  M.Thorman  New data - obtained from the NPL measurements of PMT
#.                     efficiency.
#.
#.    User Data.
#. 
#.    Wavelength table of probability of an absorbed photon causing
#.    a hit.  In one nm steps from 230 to 700.
 
0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00
0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00  0.0000E+00
0.0000E+00  0.4909E-03  0.9818E-03  0.1473E-02  0.1964E-02
0.2454E-02  0.2945E-02  0.3436E-02  0.3927E-02  0.4418E-02
0.4909E-02  0.5510E-02  0.6111E-02  0.6713E-02  0.7314E-02
0.7915E-02  0.8516E-02  0.9117E-02  0.9719E-02  0.1032E-01
0.1092E-01  0.1269E-01  0.1446E-01  0.1622E-01  0.1799E-01
0.1976E-01  0.2153E-01  0.2329E-01  0.2506E-01  0.2683E-01
0.2860E-01  0.3169E-01  0.3478E-01  0.3788E-01  0.4097E-01
0.4406E-01  0.4716E-01  0.5025E-01  0.5334E-01  0.5644E-01
0.5953E-01  0.6295E-01  0.6636E-01  0.6978E-01  0.7320E-01
0.7661E-01  0.8003E-01  0.8344E-01  0.8686E-01  0.9028E-01
0.9369E-01  0.9680E-01  0.9991E-01  0.1030      0.1061    
0.1092      0.1123      0.1154      0.1185      0.1217    
0.1248      0.1275      0.1302      0.1330      0.1357    
0.1385      0.1412      0.1439      0.1467      0.1494    
0.1522      0.1541      0.1561      0.1580      0.1600    
0.1619      0.1639      0.1658      0.1678      0.1697    
0.1717      0.1725      0.1734      0.1742      0.1751    
0.1759      0.1767      0.1776      0.1784      0.1793    
0.1801      0.1810      0.1819      0.1827      0.1836    
0.1844      0.1853      0.1862      0.1870      0.1879    
0.1888      0.1890      0.1893      0.1896      0.1898    
0.1901      0.1903      0.1906      0.1909      0.1911    
0.1914      0.1917      0.1921      0.1924      0.1928    
0.1931      0.1935      0.1938      0.1942      0.1945    
0.1949      0.1952      0.1954      0.1957      0.1960    
0.1963      0.1966      0.1969      0.1972      0.1975    
0.1978      0.1978      0.1978      0.1978      0.1979    
0.1979      0.1979      0.1979      0.1980      0.1980    
0.1980      0.1983      0.1985      0.1988      0.1990    
0.1993      0.1996      0.1998      0.2001      0.2003    
0.2006      0.2008      0.2010      0.2013      0.2015    
0.2017      0.2019      0.2022      0.2024      0.2026    
0.2029      0.2033      0.2038      0.2042      0.2047    
0.2052      0.2056      0.2061      0.2065      0.2070    
0.2075      0.2078      0.2082      0.2085      0.2089    
0.2092      0.2096      0.2099      0.2103      0.2106    
0.2110      0.2113      0.2116      0.2119      0.2123    
0.2126      0.2129      0.2132      0.2135      0.2139    
0.2142      0.2142      0.2143      0.2144      0.2144    
0.2145      0.2146      0.2146      0.2147      0.2148    
0.2148      0.2147      0.2145      0.2144      0.2142    
0.2141      0.2139      0.2138      0.2136      0.2135    
0.2133      0.2131      0.2128      0.2126      0.2124    
0.2121      0.2119      0.2117      0.2114      0.2112    
0.2110      0.2103      0.2097      0.2090      0.2084    
0.2077      0.2071      0.2064      0.2058      0.2051    
0.2045      0.2038      0.2032      0.2025      0.2018    
0.2012      0.2005      0.1999      0.1992      0.1986    
0.1979      0.1975      0.1971      0.1967      0.1962    
0.1958      0.1954      0.1950      0.1946      0.1941    
0.1937      0.1933      0.1929      0.1925      0.1921    
0.1917      0.1913      0.1908      0.1904      0.1900    
0.1896      0.1892      0.1887      0.1883      0.1879    
0.1874      0.1870      0.1866      0.1861      0.1857    
0.1852      0.1835      0.1818      0.1801      0.1784    
0.1766      0.1749      0.1732      0.1715      0.1698    
0.1681      0.1651      0.1622      0.1593      0.1564    
0.1535      0.1506      0.1477      0.1448      0.1419    
0.1390      0.1366      0.1342      0.1318      0.1294    
0.1270      0.1246      0.1222      0.1198      0.1174    
0.1150      0.1143      0.1136      0.1129      0.1122    
0.1115      0.1107      0.1100      0.1093      0.1086    
0.1079      0.1062      0.1046      0.1029      0.1013    
0.9965E-01  0.9801E-01  0.9636E-01  0.9472E-01  0.9308E-01
0.9143E-01  0.9060E-01  0.8977E-01  0.8895E-01  0.8812E-01
0.8729E-01  0.8646E-01  0.8563E-01  0.8480E-01  0.8398E-01
0.8315E-01  0.8224E-01  0.8133E-01  0.8041E-01  0.7950E-01
0.7859E-01  0.7768E-01  0.7677E-01  0.7586E-01  0.7495E-01
0.7404E-01  0.7297E-01  0.7190E-01  0.7083E-01  0.6976E-01
0.6869E-01  0.6762E-01  0.6655E-01  0.6548E-01  0.6441E-01
0.6334E-01  0.6223E-01  0.6111E-01  0.5999E-01  0.5887E-01
0.5775E-01  0.5663E-01  0.5552E-01  0.5440E-01  0.5328E-01
0.5216E-01  0.5092E-01  0.4967E-01  0.4843E-01  0.4719E-01
0.4594E-01  0.4470E-01  0.4345E-01  0.4221E-01  0.4097E-01
0.3972E-01  0.3884E-01  0.3795E-01  0.3707E-01  0.3618E-01
0.3530E-01  0.3441E-01  0.3353E-01  0.3264E-01  0.3176E-01
0.3087E-01  0.2996E-01  0.2906E-01  0.2815E-01  0.2724E-01
0.2634E-01  0.2543E-01  0.2452E-01  0.2361E-01  0.2271E-01
0.2180E-01  0.2109E-01  0.2038E-01  0.1967E-01  0.1897E-01
0.1826E-01  0.1755E-01  0.1684E-01  0.1613E-01  0.1542E-01
0.1471E-01  0.1412E-01  0.1353E-01  0.1293E-01  0.1234E-01
0.1175E-01  0.1115E-01  0.1056E-01  0.9967E-02  0.9374E-02
0.8781E-02  0.8416E-02  0.8052E-02  0.7687E-02  0.7323E-02
0.6958E-02  0.6594E-02  0.6229E-02  0.5865E-02  0.5500E-02
0.5136E-02  0.4899E-02  0.4663E-02  0.4427E-02  0.4191E-02
0.3955E-02  0.3718E-02  0.3482E-02  0.3246E-02  0.3010E-02
0.2774E-02  0.2650E-02  0.2527E-02  0.2404E-02  0.2281E-02
0.2157E-02  0.2034E-02  0.1911E-02  0.1788E-02  0.1665E-02
0.1541E-02  0.1459E-02  0.1377E-02  0.1295E-02  0.1213E-02
0.1131E-02  0.1049E-02  0.9665E-03  0.8844E-03  0.8023E-03
0.7201E-03  0.6944E-03  0.6686E-03  0.6429E-03  0.6171E-03
0.5914E-03  0.5656E-03  0.5399E-03  0.5141E-03  0.4884E-03
0.4626E-03