Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-03 02:23:12

0001 #! /usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 from builtins import range
0005 import os, sys, optparse, math
0006 
0007 copyargs = sys.argv[:]
0008 for i in range(len(copyargs)):
0009     if copyargs[i] == "":
0010         copyargs[i] = "\"\""
0011     if copyargs[i].find(" ") != -1:
0012         copyargs[i] = "\"%s\"" % copyargs[i]
0013 commandline = " ".join(copyargs)
0014 
0015 prog = sys.argv[0]
0016 
0017 usage = """./%(prog)s DIRNAME ITERATIONS INITIALGEOM INPUTFILES [options]
0018 
0019 Creates (overwrites) a directory for each of the iterations and creates (overwrites)
0020 submitJobs.sh with the submission sequence and dependencies.
0021 
0022 DIRNAME        directories will be named DIRNAME01, DIRNAME02...
0023 ITERATIONS     number of iterations
0024 INITIALGEOM    SQLite file containing muon geometry with tag names
0025                DTAlignmentRcd, DTAlignmentErrorExtendedRcd, CSCAlignmentRcd, CSCAlignmentErrorExtendedRcd
0026 INPUTFILES     Python file defining 'fileNames', a list of input files as
0027                strings (create with findQualityFiles.py)""" % vars()
0028 
0029 parser = optparse.OptionParser(usage)
0030 parser.add_option("--validationLabel",
0031                   help="[REQUIRED] the label to be used to mark a run; the results will be put into a LABEL_DATESTAMP.tgz tarball",
0032                   type="string",
0033                   default="",
0034                   dest="validationLabel")
0035 parser.add_option("-j", "--jobs",
0036                    help="approximate number of \"gather\" subjobs",
0037                    type="int",
0038                    default=50,
0039                    dest="subjobs")
0040 parser.add_option("-s", "--submitJobs",
0041                    help="alternate name of submitJobs.sh script (please include .sh extension); a file with this name will be OVERWRITTEN",
0042                    type="string",
0043                    default="submitJobs.sh",
0044                    dest="submitJobs")
0045 parser.add_option("-b", "--big",
0046                   help="if invoked, subjobs will also be run on cmscaf1nd",
0047                   action="store_true",
0048                   dest="big")
0049 parser.add_option("--globalTag",
0050                   help="GlobalTag for alignment/calibration conditions (typically all conditions except muon and tracker alignment)",
0051                   type="string",
0052                   default="CRAFT0831X_V1::All",
0053                   dest="globaltag")
0054 parser.add_option("--trackerconnect",
0055                   help="connect string for tracker alignment (frontier://... or sqlite_file:...)",
0056                   type="string",
0057                   default="",
0058                   dest="trackerconnect")
0059 parser.add_option("--trackeralignment",
0060                   help="name of TrackerAlignmentRcd tag",
0061                   type="string",
0062                   default="Alignments",
0063                   dest="trackeralignment")
0064 parser.add_option("--trackerAPEconnect",
0065                   help="connect string for tracker APEs (frontier://... or sqlite_file:...)",
0066                   type="string",
0067                   default="",
0068                   dest="trackerAPEconnect")
0069 parser.add_option("--trackerAPE",
0070                   help="name of TrackerAlignmentErrorExtendedRcd tag (tracker APEs)",
0071                   type="string",
0072                   default="AlignmentErrorsExtended",
0073                   dest="trackerAPE")
0074 parser.add_option("--gprcdconnect",
0075                   help="connect string for GlobalPositionRcd (frontier://... or sqlite_file:...)",
0076                   type="string",
0077                   default="",
0078                   dest="gprcdconnect")
0079 parser.add_option("--gprcd",
0080                   help="name of GlobalPositionRcd tag",
0081                   type="string",
0082                   default="GlobalPosition",
0083                   dest="gprcd")
0084 parser.add_option("--iscosmics",
0085                   help="if invoked, use cosmic track refitter instead of the standard one",
0086                   action="store_true",
0087                   dest="iscosmics")
0088 parser.add_option("--station123params",
0089                   help="alignable parameters for DT stations 1, 2, 3 (see SWGuideAlignmentAlgorithms#Selection_of_what_to_align)",
0090                   type="string",
0091                   default="111111",
0092                   dest="station123params")
0093 parser.add_option("--station4params",
0094                   help="alignable parameters for DT station 4",
0095                   type="string",
0096                   default="100011",
0097                   dest="station4params")
0098 parser.add_option("--cscparams",
0099                   help="alignable parameters for CSC chambers",
0100                   type="string",
0101                   default="100011",
0102                   dest="cscparams")
0103 parser.add_option("--minTrackPt",
0104                   help="minimum allowed track transverse momentum (in GeV)",
0105                   type="string",
0106                   default="0",
0107                   dest="minTrackPt")
0108 parser.add_option("--maxTrackPt",
0109                   help="maximum allowed track transverse momentum (in GeV)",
0110                   type="string",
0111                   default="1000",
0112                   dest="maxTrackPt")
0113 parser.add_option("--minTrackP",
0114                   help="minimum allowed track momentum (in GeV)",
0115                   type="string",
0116                   default="0",
0117                   dest="minTrackP")
0118 parser.add_option("--maxTrackP",
0119                   help="maximum allowed track momentum (in GeV)",
0120                   type="string",
0121                   default="10000",
0122                   dest="maxTrackP")
0123 parser.add_option("--minTrackerHits",
0124                   help="minimum number of tracker hits",
0125                   type="int",
0126                   default=15,
0127                   dest="minTrackerHits")
0128 parser.add_option("--maxTrackerRedChi2",
0129                   help="maximum tracker chi^2 per degrees of freedom",
0130                   type="string",
0131                   default="10",
0132                   dest="maxTrackerRedChi2")
0133 parser.add_option("--notAllowTIDTEC",
0134                   help="if invoked, do not allow tracks that pass through the tracker's TID||TEC region (not recommended)",
0135                   action="store_true",
0136                   dest="notAllowTIDTEC")
0137 parser.add_option("--twoBin",
0138                   help="if invoked, apply the \"two-bin method\" to control charge-antisymmetric errors",
0139                   action="store_true",
0140                   dest="twoBin")
0141 parser.add_option("--weightAlignment",
0142                   help="if invoked, segments will be weighted by ndf/chi^2 in the alignment",
0143                   action="store_true",
0144                   dest="weightAlignment")
0145 parser.add_option("--minAlignmentSegments",
0146                   help="minimum number of segments required to align a chamber",
0147                   type="int",
0148                   default=5,
0149                   dest="minAlignmentHits")
0150 parser.add_option("--notCombineME11",
0151                   help="if invoked, treat ME1/1a and ME1/1b as separate objects",
0152                   action="store_true",
0153                   dest="notCombineME11")
0154 parser.add_option("--maxEvents",
0155                   help="maximum number of events",
0156                   type="string",
0157                   default="-1",
0158                   dest="maxEvents")
0159 parser.add_option("--skipEvents",
0160                   help="number of events to be skipped",
0161                   type="string",
0162                   default="0",
0163                   dest="skipEvents")
0164 parser.add_option("--maxResSlopeY",
0165                   help="maximum residual slope y component",
0166                   type="string",
0167                   default="10",
0168                   dest="maxResSlopeY")
0169 parser.add_option("--ring2only",
0170                   help="if invoked, use only ring 2 results to align all rings in corresponding disks",
0171                   action="store_true",
0172                   dest="ring2only")
0173 parser.add_option("--createMapNtuple",
0174                   help="if invoked while mapplots are switched on, a special ntuple would be created",
0175                   action="store_true",
0176                   dest="createMapNtuple")
0177 parser.add_option("--inputInBlocks",
0178                   help="if invoked, assume that INPUTFILES provides a list of files already groupped into job blocks, -j has no effect in that case",
0179                   action="store_true",
0180                   dest="inputInBlocks")
0181 parser.add_option("--json",
0182                   help="If present with JSON file as argument, use JSON file for good lumi mask. "+\
0183                   "The latest JSON file is available at /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions11/7TeV/Prompt/",
0184                   type="string",
0185                   default="",
0186                   dest="json")
0187 parser.add_option("--preFilter",
0188                   help="if invoked, MuonAlignmentPreFilter module would be invoked in the Path's beginning. Can significantly speed up gather jobs.",
0189                   action="store_true",
0190                   dest="preFilter")
0191 parser.add_option("--useTrackerMuons",
0192                   help="use tracker muons approach instead of the default global muons tracks based one",
0193                   action="store_true",
0194                   dest="useTrackerMuons")
0195 parser.add_option("--muonCollectionTag",
0196                   help="InputTag of muons collection to use in tracker muons based approach",
0197                   type="string",
0198                   default="newmuons",
0199                   dest="muonCollectionTag")
0200 parser.add_option("--maxDxy",
0201                   help="maximum track impact parameter with relation to beamline",
0202                   type="string",
0203                   default="1000.",
0204                   dest="maxDxy")
0205 parser.add_option("--minNCrossedChambers",
0206                   help="minimum number of muon chambers that a track is required to cross",
0207                   type="string",
0208                   default="2",
0209                   dest="minNCrossedChambers")
0210 
0211 if len(sys.argv) < 5:
0212     raise SystemError("Too few arguments.\n\n"+parser.format_help())
0213 
0214 DIRNAME = sys.argv[1]
0215 ITERATIONS = int(sys.argv[2])
0216 INITIALGEOM = sys.argv[3]
0217 INPUTFILES = sys.argv[4]
0218 
0219 options, args = parser.parse_args(sys.argv[5:])
0220 globaltag = options.globaltag
0221 trackerconnect = options.trackerconnect
0222 trackeralignment = options.trackeralignment
0223 trackerAPEconnect = options.trackerAPEconnect
0224 trackerAPE = options.trackerAPE
0225 gprcdconnect = options.gprcdconnect
0226 gprcd = options.gprcd
0227 iscosmics = str(options.iscosmics)
0228 station123params = options.station123params
0229 station4params = options.station4params
0230 cscparams = options.cscparams
0231 muonCollectionTag = options.muonCollectionTag
0232 minTrackPt = options.minTrackPt
0233 maxTrackPt = options.maxTrackPt
0234 minTrackP = options.minTrackP
0235 maxTrackP = options.maxTrackP
0236 maxDxy = options.maxDxy
0237 minTrackerHits = str(options.minTrackerHits)
0238 maxTrackerRedChi2 = options.maxTrackerRedChi2
0239 minNCrossedChambers = options.minNCrossedChambers
0240 allowTIDTEC = str(not options.notAllowTIDTEC)
0241 twoBin = str(options.twoBin)
0242 weightAlignment = str(options.weightAlignment)
0243 minAlignmentHits = str(options.minAlignmentHits)
0244 combineME11 = str(not options.notCombineME11)
0245 maxEvents = options.maxEvents
0246 skipEvents = options.skipEvents
0247 validationLabel = options.validationLabel
0248 maxResSlopeY = options.maxResSlopeY
0249 preFilter = not not options.preFilter
0250 useTrackerMuons = options.useTrackerMuons
0251 
0252 createMapNtuple=False
0253 if options.createMapNtuple: createMapNtuple=True
0254 
0255 ring2only = ""
0256 if options.ring2only: ring2only = "--ring2only"
0257 inputInBlocks = ""
0258 if options.inputInBlocks: inputInBlocks = "--inputInBlocks"
0259 
0260 json_file = options.json
0261 
0262 if validationLabel == '':
0263   print("\nOne or more of REQUIRED options is missing!\n")
0264   parser.print_help()
0265   sys.exit()
0266 
0267 fileNames=[]
0268 fileNamesBlocks=[]
0269 execfile(INPUTFILES)
0270 njobs = options.subjobs
0271 if (options.inputInBlocks):
0272   njobs = len(fileNamesBlocks)
0273   if njobs==0:
0274     print("while --inputInBlocks is specified, the INPUTFILES has no blocks!")
0275     sys.exit()
0276 
0277 stepsize = int(math.ceil(1.*len(fileNames)/njobs))
0278 
0279 pwd = str(os.getcwd())
0280 
0281 bsubfile = ["#!/bin/sh", ""]
0282 bsubnames = []
0283 last_align = None
0284 
0285 #####################################################################
0286 # step 0: convert initial geometry to xml
0287 INITIALXML = INITIALGEOM + '.xml'
0288 if INITIALGEOM[-3:]=='.db':
0289   INITIALXML = INITIALGEOM[:-3] + '.xml'
0290 print("Converting",INITIALGEOM,"to",INITIALXML," ...will be done in several seconds...")
0291 exit_code = os.system("./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py  %s %s" % (INITIALGEOM,INITIALXML))
0292 if exit_code>0:
0293   print("problem: conversion exited with code:", exit_code)
0294   sys.exit()
0295 
0296 
0297 #####################################################################
0298 # do two iterations of gather + align jobs
0299 directory = ""
0300 for iteration in range(1, ITERATIONS+1):
0301     if iteration == 1:
0302         inputdb = INITIALGEOM
0303         inputdbdir = directory[:]
0304         inputxml = INITIALXML
0305     else:
0306         inputdb = director + ".db"
0307         inputdbdir = directory[:]
0308         inputxml = director + ".xml"
0309 
0310     directory = "%s%02d/" % (DIRNAME, iteration)
0311     director = directory[:-1]
0312     directory1 = "%s01/" % DIRNAME
0313     director1 = directory1[:-1]
0314     os.system("rm -rf %s; mkdir %s" % (directory, directory))
0315     os.system("cp gather_cfg.py %s" % directory)
0316     #os.system("cp align_cfg.py %s" % directory)
0317 
0318     bsubfile.append("cd %s" % directory)
0319 
0320     for jobnumber in range(njobs):
0321         gather_fileName = "%sgather%03d.sh" % (directory, jobnumber)
0322         if not options.inputInBlocks:
0323           inputfiles = " ".join(fileNames[jobnumber*stepsize:(jobnumber+1)*stepsize])
0324         else:
0325           inputfiles = " ".join(fileNamesBlocks[jobnumber])
0326 
0327         copyplots = "plotting*.root"
0328 
0329         copytrackerdb = ""
0330         if trackerconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerconnect[12:]
0331         if trackerAPEconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerAPEconnect[12:]
0332         if gprcdconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % gprcdconnect[12:]
0333 
0334         if len(inputfiles) > 0:
0335             file(gather_fileName, "w").write("""#/bin/sh
0336 # %(commandline)s
0337 
0338 export ALIGNMENT_CAFDIR=`pwd`
0339 
0340 cd %(pwd)s
0341 eval `scramv1 run -sh`
0342 export ALIGNMENT_AFSDIR=`pwd`
0343 
0344 export ALIGNMENT_INPUTFILES='%(inputfiles)s'
0345 export ALIGNMENT_ITERATION=%(iteration)d
0346 export ALIGNMENT_JOBNUMBER=%(jobnumber)d
0347 export ALIGNMENT_MAPPLOTS=True
0348 export ALIGNMENT_SEGDIFFPLOTS=True
0349 export ALIGNMENT_CURVATUREPLOTS=False
0350 export ALIGNMENT_GLOBALTAG=%(globaltag)s
0351 export ALIGNMENT_INPUTDB=%(inputdb)s
0352 export ALIGNMENT_TRACKERCONNECT=%(trackerconnect)s
0353 export ALIGNMENT_TRACKERALIGNMENT=%(trackeralignment)s
0354 export ALIGNMENT_TRACKERAPECONNECT=%(trackerAPEconnect)s
0355 export ALIGNMENT_TRACKERAPE=%(trackerAPE)s
0356 export ALIGNMENT_GPRCDCONNECT=%(gprcdconnect)s
0357 export ALIGNMENT_GPRCD=%(gprcd)s
0358 export ALIGNMENT_ISCOSMICS=%(iscosmics)s
0359 export ALIGNMENT_STATION123PARAMS=%(station123params)s
0360 export ALIGNMENT_STATION4PARAMS=%(station4params)s
0361 export ALIGNMENT_CSCPARAMS=%(cscparams)s
0362 export ALIGNMENT_MUONCOLLECTIONTAG=%(muonCollectionTag)s
0363 export ALIGNMENT_MINTRACKPT=%(minTrackPt)s
0364 export ALIGNMENT_MAXTRACKPT=%(maxTrackPt)s
0365 export ALIGNMENT_MINTRACKP=%(minTrackP)s
0366 export ALIGNMENT_MAXTRACKP=%(maxTrackP)s
0367 export ALIGNMENT_MAXDXY=%(maxDxy)s
0368 export ALIGNMENT_MINTRACKERHITS=%(minTrackerHits)s
0369 export ALIGNMENT_MAXTRACKERREDCHI2=%(maxTrackerRedChi2)s
0370 export ALIGNMENT_MINNCROSSEDCHAMBERS=%(minNCrossedChambers)s
0371 export ALIGNMENT_ALLOWTIDTEC=%(allowTIDTEC)s
0372 export ALIGNMENT_TWOBIN=%(twoBin)s
0373 export ALIGNMENT_WEIGHTALIGNMENT=%(weightAlignment)s
0374 export ALIGNMENT_MINALIGNMENTHITS=%(minAlignmentHits)s
0375 export ALIGNMENT_COMBINEME11=%(combineME11)s
0376 export ALIGNMENT_MAXEVENTS=%(maxEvents)s
0377 export ALIGNMENT_SKIPEVENTS=%(skipEvents)s
0378 export ALIGNMENT_MAXRESSLOPEY=%(maxResSlopeY)s
0379 export ALIGNMENT_DO_DT='False'
0380 export ALIGNMENT_DO_CSC='True'
0381 export ALIGNMENT_JSON=%(json_file)s
0382 export ALIGNMENT_CREATEMAPNTUPLE=%(createMapNtuple)s
0383 export ALIGNMENT_PREFILTER=%(preFilter)s
0384 export ALIGNMENT_USETRACKERMUONS=%(useTrackerMuons)s
0385 
0386 if [ \"zzz$ALIGNMENT_JSON\" != \"zzz\" ]; then
0387   cp -f $ALIGNMENT_JSON $ALIGNMENT_CAFDIR/
0388 fi
0389 
0390 cp -f %(directory)sgather_cfg.py %(inputdbdir)s%(inputdb)s %(copytrackerdb)s $ALIGNMENT_CAFDIR/
0391 cd $ALIGNMENT_CAFDIR/
0392 ls -l
0393 cmsRun gather_cfg.py
0394 ls -l
0395 cp -f %(copyplots)s $ALIGNMENT_AFSDIR/%(directory)s
0396 """ % vars())
0397             os.system("chmod +x %s" % gather_fileName)
0398             bsubfile.append("echo %sgather%03d.sh" % (directory, jobnumber))
0399 
0400             if last_align is None: waiter = ""
0401             else: waiter = "-w \"ended(%s)\"" % last_align
0402             if options.big: queue = "cmscaf1nd"
0403             else: queue = "cmscaf1nh"
0404 
0405             bsubfile.append("bsub -R \"type==SLC5_64\" -q %s -J \"%s_gather%03d\" %s gather%03d.sh" % (queue, director, jobnumber, waiter, jobnumber))
0406 
0407             bsubnames.append("ended(%s_gather%03d)" % (director, jobnumber))
0408 
0409     copytrackerdb = ""
0410     if trackerconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerconnect[12:]
0411     if trackerAPEconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerAPEconnect[12:]
0412     if gprcdconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % gprcdconnect[12:]
0413 
0414     file("%salign.sh" % directory, "w").write("""#!/bin/sh
0415 # %(commandline)s
0416 
0417 export ALIGNMENT_CAFDIR=`pwd`
0418 mkdir files
0419 mkdir out
0420 
0421 cd %(pwd)s
0422 eval `scramv1 run -sh`
0423 export ALIGNMENT_AFSDIR=`pwd`
0424 
0425 # combine _plotting.root files into one:
0426 nfiles=$(ls %(directory)splotting0*.root 2> /dev/null | wc -l)
0427 if [ \"$nfiles\" != \"0\" ]; then
0428   flist=""
0429   for fn in %(directory)splotting0*.root
0430   do
0431     FILESIZE=$(stat -c%%s "$fn")
0432     if [ $FILESIZE -gt 1000 ]; then
0433       echo $fn, $FILESIZE
0434       flist="$flist $fn"
0435     fi
0436   done
0437   echo $flist
0438   #hadd -f1 %(directory)s%(director)s_plotting.root %(directory)splotting0*.root
0439   hadd -f1 %(directory)s%(director)s_plotting.root $flist
0440   #if [ $? == 0 ]; then rm %(directory)splotting0*.root; fi
0441 fi
0442 
0443 # copy plotting and db files to CAFDIR
0444 cp -f %(directory)s%(director)s_plotting.root  $ALIGNMENT_CAFDIR/files
0445 cp -f inertGlobalPositionRcd.db %(inputdbdir)s%(inputdb)s  %(inputdbdir)s%(inputxml)s  %(copytrackerdb)s  $ALIGNMENT_CAFDIR/
0446 
0447 # copy the scripts to CAFDIR
0448 cd Alignment/MuonAlignmentAlgorithms/scripts/
0449 cp -f plotscripts.py $ALIGNMENT_CAFDIR/
0450 cp -f mutypes.py $ALIGNMENT_CAFDIR/
0451 cp -f alignmentValidation.py $ALIGNMENT_CAFDIR/
0452 cp -f phiedges_fitfunctions.C $ALIGNMENT_CAFDIR/
0453 cp -f convertSQLiteXML.py $ALIGNMENT_CAFDIR/
0454 cp -f alignCSCRings.py $ALIGNMENT_CAFDIR/
0455 cp -f signConventions.py $ALIGNMENT_CAFDIR/
0456 cd -
0457 
0458 cd $ALIGNMENT_CAFDIR/
0459 ls -l
0460 
0461 # run alignment validation to produce map plots and sin fit results
0462 ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out  --csc --map --segdiff --createDirSructure
0463 
0464 # align CSC rings using the fit results from the previous step
0465 ./alignCSCRings.py -d $ALIGNMENT_CAFDIR/out -l %(validationLabel)s -x %(inputxml)s %(ring2only)s
0466 
0467 # convert ring-aligned xml geometry into sqlite
0468 ./convertSQLiteXML.py %(inputxml)s.ring.xml %(director)s.db
0469 
0470 # convert the new sqlite into proper chambers and layers xml
0471 ./convertSQLiteXML.py %(director)s.db %(director)s.xml
0472 
0473 #copy all good stuff to $ALIGNMENT_AFSDIR/%(directory)s
0474 tar czf %(director)s_%(validationLabel)s.tgz out
0475 cp -f %(director)s_%(validationLabel)s.tgz $ALIGNMENT_AFSDIR/%(directory)s
0476 cp -f out/tmp_test_results_map__%(validationLabel)s.pkl  $ALIGNMENT_AFSDIR/%(directory)s%(director)s.pkl
0477 cp -f %(inputxml)s.ring.xml  $ALIGNMENT_AFSDIR/%(directory)s
0478 cp -f %(director)s.xml  $ALIGNMENT_AFSDIR/%(directory)s
0479 cp -f %(director)s.db  $ALIGNMENT_AFSDIR/%(directory)s
0480 
0481 # if it's last iteration, apply chamber motion policy
0482 #if [ \"$ALIGNMENT_ITERATION\" == 2 ]; then
0483 #  #nfiles=$(ls %(directory)splotting0*.root 2> /dev/null | wc -l)
0484 #fi
0485 
0486 """ % vars())
0487     os.system("chmod +x %salign.sh" % directory)
0488 
0489     bsubfile.append("echo %salign.sh" % directory)
0490     if options.big: queue = "cmscaf1nd"
0491     else: queue = "cmscaf1nh"
0492     bsubfile.append("bsub -R \"type==SLC5_64\" -q %s -J \"%s_align\" -w \"%s\" align.sh" % (queue, director, " && ".join(bsubnames)))
0493     bsubnames = []
0494     last_align = "%s_align" % director
0495     
0496     # after the last iteration do diagnostics run for putting into a browser
0497     if iteration == ITERATIONS:
0498         # do we have plotting files created?
0499         directory1 = "%s01/" % DIRNAME
0500         director1 = directory1[:-1]
0501 
0502         file("%svalidation.sh" % directory, "w").write("""#!/bin/sh
0503 # %(commandline)s
0504 
0505 export ALIGNMENT_CAFDIR=`pwd`
0506 #mkdir files
0507 mkdir out
0508 mkdir tmp
0509 
0510 cd %(pwd)s
0511 eval `scramv1 run -sh`
0512 ALIGNMENT_AFSDIR=`pwd`
0513 
0514 # copy the scripts to CAFDIR
0515 cd Alignment/MuonAlignmentAlgorithms/scripts/
0516 cp -f plotscripts.py $ALIGNMENT_CAFDIR/
0517 cp -f mutypes.py $ALIGNMENT_CAFDIR/
0518 cp -f alignmentValidation.py $ALIGNMENT_CAFDIR/
0519 cp -f phiedges_fitfunctions.C $ALIGNMENT_CAFDIR/
0520 cp -f createTree.py $ALIGNMENT_CAFDIR/
0521 cp -f signConventions.py $ALIGNMENT_CAFDIR/
0522 cd -
0523 cp Alignment/MuonAlignmentAlgorithms/test/browser/tree* $ALIGNMENT_CAFDIR/out/
0524 
0525 # copy the results to CAFDIR
0526 cp -f %(directory1)s%(director1)s_%(validationLabel)s.tgz $ALIGNMENT_CAFDIR/tmp/
0527 cp -f %(directory)s%(director)s_%(validationLabel)s.tgz $ALIGNMENT_CAFDIR/tmp/
0528 
0529 cd $ALIGNMENT_CAFDIR/
0530 tar xzvf tmp/%(director1)s_%(validationLabel)s.tgz
0531 mv tmp/out/* out/
0532 mv out/iterN out/iter1
0533 mv out/tmp_test_results_map__%(validationLabel)s.pkl out/tmp_test_results_map__%(validationLabel)s_1.pkl
0534 tar xzvf tmp/%(director)s_%(validationLabel)s.tgz
0535 mv tmp/out/* out/
0536 
0537 echo \" ### Start running ###\"
0538 date
0539 
0540 # run simple diagnostic
0541 ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out --csc --diagnostic
0542 
0543 # fill the tree browser structure: 
0544 ./createTree.py -i $ALIGNMENT_CAFDIR/out
0545 
0546 timestamp=`date \"+%%y-%%m-%%d %%H:%%M:%%S\"`
0547 echo \"%(validationLabel)s.plots (${timestamp})\" > out/label.txt
0548 
0549 ls -l out/
0550 timestamp=`date +%%Y%%m%%d%%H%%M%%S`
0551 tar czf %(validationLabel)s_${timestamp}.tgz out
0552 cp -f %(validationLabel)s_${timestamp}.tgz $ALIGNMENT_AFSDIR/
0553 
0554 """ % vars())
0555         os.system("chmod +x %svalidation.sh" % directory)
0556         
0557         bsubfile.append("echo %svalidation.sh" % directory)
0558         bsubfile.append("bsub -R \"type==SLC5_64\" -q cmscaf1nd -J \"%s_validation\" -w \"ended(%s)\" validation.sh" % (director, last_align))
0559 
0560     bsubfile.append("cd ..")
0561     bsubfile.append("")
0562 
0563 
0564 file(options.submitJobs, "w").write("\n".join(bsubfile))
0565 os.system("chmod +x %s" % options.submitJobs)
0566