3 from __future__
import print_function
4 import os, sys, re, optparse, math
7 for i
in range(len(copyargs)):
10 if copyargs[i].
find(
" ") != -1:
11 copyargs[i] =
"\"%s\"" % copyargs[i]
12 commandline =
" ".
join(copyargs)
14 usage =
"""./%prog DIRNAME PATTERN INITIALGEOM INPUTFILES [options] 16 Creates (overwrites) a directory for each word in PATTERN and creates 17 (overwrites) submitJobs.sh with the submission sequence and 20 DIRNAME directories will be named DIRNAME01, DIRNAME02, etc. 21 PATTERN a quoted combination of "phiy", "phipos", "phiz" 22 INITIALGEOM SQLite file containing muon geometry with tag names 23 CSCAlignmentRcd, CSCAlignmentErrorExtendedRcd 24 INPUTFILES Python file defining 'fileNames', a list of input files as 27 parser = optparse.OptionParser(usage)
28 parser.add_option(
"-j",
"--jobs",
29 help=
"approximate number of \"gather\" subjobs",
33 parser.add_option(
"-s",
"--submitJobs",
34 help=
"alternate name of submitJobs.sh script (please include .sh extension); a file with this name will be OVERWRITTEN",
36 default=
"submitJobs.sh",
38 parser.add_option(
"-b",
"--big",
39 help=
"if invoked, subjobs will also be run on cmscaf1nd",
42 parser.add_option(
"-u",
"--user_mail",
43 help=
"if invoked, send mail to a specified email destination. If \"-u\" is not present, the default destination LSB_MAILTO in lsf.conf will be used",
46 parser.add_option(
"--globalTag",
47 help=
"GlobalTag for calibration conditions",
49 default=
"GR_R_42_V14::All",
51 parser.add_option(
"--photogrammetry",
52 help=
"if invoked, alignment will be constrained to photogrammetry",
54 dest=
"photogrammetry")
55 parser.add_option(
"--photogrammetryOnlyholes",
56 help=
"if invoked, only missing data will be constrained to photogrammetry",
58 dest=
"photogrammetryOnlyholes")
59 parser.add_option(
"--photogrammetryOnlyOnePerRing",
60 help=
"if invoked, only one chamber per ring will be constrained to photogrammetry",
62 dest=
"photogrammetryOnlyOnePerRing")
63 parser.add_option(
"--photogrammetryScale",
64 help=
"scale factor for photogrammetry constraint: 1 is default and 10 *weakens* the constraint by a factor of 10",
67 dest=
"photogrammetryScale")
68 parser.add_option(
"--slm",
69 help=
"if invoked, apply SLM constraint",
72 parser.add_option(
"--fillME11holes",
73 help=
"use CollisionsOct2010 data to fill holes in ME1/1",
76 parser.add_option(
"--disks",
77 help=
"align whole disks, rather than individual rings",
81 parser.add_option(
"--minP",
82 help=
"minimum track momentum (measured via radial component of fringe fields)",
86 parser.add_option(
"--minHitsPerChamber",
87 help=
"minimum number of hits per chamber",
90 dest=
"minHitsPerChamber")
91 parser.add_option(
"--maxdrdz",
92 help=
"maximum dr/dz of tracklets (anti-cosmic cut)",
96 parser.add_option(
"--maxRedChi2",
97 help=
"maximum reduced chi^2 of tracks",
101 parser.add_option(
"--fiducial",
102 help=
"if invoked, select only segments within the good region of the chamber (for all 6 layers)",
105 parser.add_option(
"--useHitWeights",
106 help=
"if invoked, use hit weights in tracklet fits",
108 dest=
"useHitWeights")
109 parser.add_option(
"--truncateSlopeResid",
110 help=
"maximum allowed slope residual in mrad (like the histograms in a phiy job)",
113 dest=
"truncateSlopeResid")
114 parser.add_option(
"--truncateOffsetResid",
115 help=
"maximum allowed offset residual in mm (like the histograms in a phipos or phiz job)",
118 dest=
"truncateOffsetResid")
119 parser.add_option(
"--combineME11",
120 help=
"if invoked, combine ME1/1a and ME1/1b chambers",
123 parser.add_option(
"--useTrackWeights",
124 help=
"if invoked, weight residuals by track uncertainties",
126 dest=
"useTrackWeights")
127 parser.add_option(
"--errorFromRMS",
128 help=
"if invoked, determine residuals uncertainties from the RMS of the residuals distribution",
131 parser.add_option(
"--minTracksPerOverlap",
132 help=
"minimum number of tracks needed for an overlap constraint to be valid",
135 dest=
"minTracksPerOverlap")
136 parser.add_option(
"--slopeFromTrackRefit",
137 help=
"if invoked, determine direction of tracklets by refitting track to all other stations",
139 dest=
"slopeFromTrackRefit")
140 parser.add_option(
"--minStationsInTrackRefits",
141 help=
"minimum number of stations in a full track refit (slopeFromTrackRefit)",
144 dest=
"minStationsInTrackRefits")
145 parser.add_option(
"--inputInBlocks",
146 help=
"if invoked, assume that INPUTFILES provides a list of files already groupped into job blocks, -j has no effect in that case",
148 dest=
"inputInBlocks")
149 parser.add_option(
"--json",
150 help=
"If present with JSON file as argument, use JSON file for good lumi mask. "+\
151 "The latest JSON file is available at /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions10/7TeV/StreamExpress/",
156 if len(sys.argv) < 5:
157 raise SystemError(
"Too few arguments.\n\n"+parser.format_help())
159 DIRNAME = sys.argv[1]
160 PATTERN = re.split(
"\s+", sys.argv[2])
161 INITIALGEOM = sys.argv[3]
162 INPUTFILES = sys.argv[4]
164 options, args = parser.parse_args(sys.argv[5:])
165 user_mail = options.user_mail
166 globaltag = options.globaltag
167 photogrammetry = options.photogrammetry
168 photogrammetryOnlyholes = options.photogrammetryOnlyholes
169 photogrammetryOnlyOnePerRing = options.photogrammetryOnlyOnePerRing
170 photogrammetryScale = options.photogrammetryScale
172 fillME11holes = options.fillME11holes
173 disks = options.disks
175 minHitsPerChamber = options.minHitsPerChamber
176 maxdrdz = options.maxdrdz
177 maxRedChi2 = options.maxRedChi2
178 fiducial = options.fiducial
179 useHitWeights = options.useHitWeights
180 truncateSlopeResid = options.truncateSlopeResid
181 truncateOffsetResid = options.truncateOffsetResid
182 combineME11 = options.combineME11
183 useTrackWeights = options.useTrackWeights
184 errorFromRMS = options.errorFromRMS
185 minTracksPerOverlap = options.minTracksPerOverlap
186 slopeFromTrackRefit = options.slopeFromTrackRefit
187 minStationsInTrackRefits = options.minStationsInTrackRefits
189 if options.inputInBlocks: inputInBlocks =
"--inputInBlocks" 190 json_file = options.json
196 njobs = options.subjobs
197 if (options.inputInBlocks):
198 njobs = len(fileNamesBlocks)
200 print(
"while --inputInBlocks is specified, the INPUTFILES has no blocks!")
203 stepsize =
int(math.ceil(1.*len(fileNames)/options.subjobs))
206 bsubfile = [
"#!/bin/sh",
""]
211 for i, mode
in enumerate(PATTERN):
214 inputdb = INITIALGEOM
215 inputdbdir = directory[:]
217 inputdb = director +
".db" 218 inputdbdir = directory[:]
220 directory =
"%s%02d/" % (DIRNAME, iteration)
221 director = directory[:-1]
222 os.system(
"rm -rf %s; mkdir %s" % (directory, directory))
223 os.system(
"cp gatherBH_cfg.py %s" % directory)
224 os.system(
"cp alignBH_cfg.py %s" % directory)
226 bsubfile.append(
"cd %s" % directory)
228 constraints =
"""echo \"\" > constraints_cff.py 230 if photogrammetry
and (mode ==
"phipos" or mode ==
"phiz"):
232 if disks: diskswitch =
"--disks " 234 constraints +=
"""export ALIGNMENT_CONVERTXML=%(inputdb)s 235 cmsRun $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/python/convertToXML_global_cfg.py 236 python $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/scripts/relativeConstraints.py %(inputdb)s_global.xml $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/data/Photogrammetry2007.%(mode)s PGFrame --scaleErrors %(photogrammetryScale)s %(diskswitch)s>> constraints_cff.py 239 elif photogrammetryOnlyholes
and (mode ==
"phipos" or mode ==
"phiz"):
241 if disks: diskswitch =
"--disks " 243 constraints +=
"""export ALIGNMENT_CONVERTXML=%(inputdb)s 244 cmsRun $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/python/convertToXML_global_cfg.py 245 python $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/scripts/relativeConstraints.py %(inputdb)s_global.xml $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/data/Photogrammetry2007_onlyOct2010holes.%(mode)s PGFrame --scaleErrors %(photogrammetryScale)s %(diskswitch)s>> constraints_cff.py 248 elif photogrammetryOnlyOnePerRing
and (mode ==
"phipos" or mode ==
"phiz"):
250 if disks: diskswitch =
"--disks " 252 constraints +=
"""export ALIGNMENT_CONVERTXML=%(inputdb)s 253 cmsRun $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/python/convertToXML_global_cfg.py 254 python $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/scripts/relativeConstraints.py %(inputdb)s_global.xml $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/data/Photogrammetry2007_onlyOnePerRing.%(mode)s PGFrame --scaleErrors %(photogrammetryScale)s %(diskswitch)s>> constraints_cff.py 257 if slm
and (mode ==
"phipos" or "phiz"):
259 if disks: diskswitch =
"--disks " 261 constraints +=
"""export ALIGNMENT_CONVERTXML=%(inputdb)s 262 cmsRun $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/python/convertToXML_global_cfg.py 263 python $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/scripts/relativeConstraints.py %(inputdb)s_global.xml $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/data/SLM_test.%(mode)s SLMFrame --scaleErrors 1.0 %(diskswitch)s>> constraints_cff.py 266 if fillME11holes
and (mode ==
"phipos" or mode ==
"phiz"):
268 if disks: diskswitch =
"--disks " 270 constraints +=
"""export ALIGNMENT_CONVERTXML=%(inputdb)s 271 cmsRun $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/python/convertToXML_global_cfg.py 272 python $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/scripts/relativeConstraints.py %(inputdb)s_global.xml $ALIGNMENT_AFSDIR/Alignment/MuonAlignmentAlgorithms/data/CollisionsOct2010_ME11holes.%(mode)s TKFrame --scaleErrors 1. %(diskswitch)s>> constraints_cff.py 275 for jobnumber
in range(njobs):
276 gather_fileName =
"%sgather%03d.sh" % (directory, jobnumber)
277 if not options.inputInBlocks:
278 inputfiles =
" ".
join(fileNames[jobnumber*stepsize:(jobnumber+1)*stepsize])
280 inputfiles =
" ".
join(fileNamesBlocks[jobnumber])
282 if len(inputfiles) > 0:
283 file(gather_fileName,
"w").
write(
"""#/bin/sh 286 export ALIGNMENT_CAFDIR=`pwd` 290 export SCRAM_ARCH=slc5_amd64_gcc434 291 echo INFO: SCRAM_ARCH $SCRAM_ARCH 293 eval `scramv1 run -sh` 295 source /afs/cern.ch/cms/caf/setup.sh 296 echo INFO: CMS_PATH $CMS_PATH 297 echo INFO: STAGE_SVCCLASS $STAGE_SVCCLASS 298 echo INFO: STAGER_TRACE $STAGER_TRACE 300 export ALIGNMENT_AFSDIR=`pwd` 302 export ALIGNMENT_INPUTFILES='%(inputfiles)s' 303 export ALIGNMENT_ITERATION=%(iteration)d 304 export ALIGNMENT_MODE=%(mode)s 305 export ALIGNMENT_JOBNUMBER=%(jobnumber)d 306 export ALIGNMENT_INPUTDB=%(inputdb)s 307 export ALIGNMENT_GLOBALTAG=%(globaltag)s 308 export ALIGNMENT_PHOTOGRAMMETRY='%(photogrammetry)s or %(photogrammetryOnlyholes)s or %(photogrammetryOnlyOnePerRing)s' 309 export ALIGNMENT_SLM=%(slm)s 310 export ALIGNMENT_FILLME11HOLES='%(fillME11holes)s' 311 export ALIGNMENT_DISKS=%(disks)s 312 export ALIGNMENT_minP=%(minP)s 313 export ALIGNMENT_minHitsPerChamber=%(minHitsPerChamber)s 314 export ALIGNMENT_maxdrdz=%(maxdrdz)s 315 export ALIGNMENT_maxRedChi2=%(maxRedChi2)s 316 export ALIGNMENT_fiducial=%(fiducial)s 317 export ALIGNMENT_useHitWeights=%(useHitWeights)s 318 export ALIGNMENT_truncateSlopeResid=%(truncateSlopeResid)s 319 export ALIGNMENT_truncateOffsetResid=%(truncateOffsetResid)s 320 export ALIGNMENT_combineME11=%(combineME11)s 321 export ALIGNMENT_useTrackWeights=%(useTrackWeights)s 322 export ALIGNMENT_errorFromRMS=%(errorFromRMS)s 323 export ALIGNMENT_minTracksPerOverlap=%(minTracksPerOverlap)s 324 export ALIGNMENT_slopeFromTrackRefit=%(slopeFromTrackRefit)s 325 export ALIGNMENT_minStationsInTrackRefits=%(minStationsInTrackRefits)s 327 cp -f %(directory)sgatherBH_cfg.py %(inputdbdir)s%(inputdb)s inertGlobalPositionRcd.db $ALIGNMENT_CAFDIR/ 328 cd $ALIGNMENT_CAFDIR/ 333 cmsRun gatherBH_cfg.py 335 cp -f *.tmp *.root $ALIGNMENT_AFSDIR/%(directory)s 337 os.system(
"chmod +x %s" % gather_fileName)
338 bsubfile.append(
"echo %sgather%03d.sh" % (directory, jobnumber))
340 if last_align
is None: waiter =
"" 341 else: waiter =
"-w \"ended(%s)\"" % last_align
342 if options.big: queue =
"cmscaf1nd" 343 else: queue =
"cmscaf1nh" 345 if user_mail: bsubfile.append(
"bsub -R \"type==SLC5_64\" -q %s -J \"%s_gather%03d\" -u %s %s gather%03d.sh" % (queue, director, jobnumber, user_mail, waiter, jobnumber))
346 else: bsubfile.append(
"bsub -R \"type==SLC5_64\" -q %s -J \"%s_gather%03d\" %s gather%03d.sh" % (queue, director, jobnumber, waiter, jobnumber))
348 bsubnames.append(
"ended(%s_gather%03d)" % (director, jobnumber))
350 file(
"%sconvert-db-to-xml_cfg.py" % directory,
"w").
write(
"""from Alignment.MuonAlignment.convertSQLitetoXML_cfg import * 351 process.PoolDBESSource.connect = \"sqlite_file:%(directory)s%(director)s.db\" 352 process.MuonGeometryDBConverter.outputXML.fileName = \"%(directory)s%(director)s.xml\" 353 process.MuonGeometryDBConverter.outputXML.relativeto = \"ideal\" 354 process.MuonGeometryDBConverter.outputXML.suppressDTChambers = True 355 process.MuonGeometryDBConverter.outputXML.suppressDTSuperLayers = True 356 process.MuonGeometryDBConverter.outputXML.suppressDTLayers = True 357 process.MuonGeometryDBConverter.outputXML.suppressCSCChambers = False 358 process.MuonGeometryDBConverter.outputXML.suppressCSCLayers = True 360 process.MuonGeometryDBConverter.getAPEs = True 361 process.PoolDBESSource.toGet = cms.VPSet( 362 cms.PSet(record = cms.string(\"DTAlignmentRcd\"), tag = cms.string(\"DTAlignmentRcd\")), 363 cms.PSet(record = cms.string(\"DTAlignmentErrorExtendedRcd\"), tag = cms.string(\"DTAlignmentErrorExtendedRcd\")), 364 cms.PSet(record = cms.string(\"CSCAlignmentRcd\"), tag = cms.string(\"CSCAlignmentRcd\")), 365 cms.PSet(record = cms.string(\"CSCAlignmentErrorExtendedRcd\"), tag = cms.string(\"CSCAlignmentErrorExtendedRcd\")), 369 constraints +=
"""\ncp -f constraints_cff.py $ALIGNMENT_AFSDIR/%(directory)sconstraints_cff.py""" % vars()
371 file(
"%salign.sh" % directory,
"w").
write(
"""#!/bin/sh 374 export ALIGNMENT_CAFDIR=`pwd` 378 export SCRAM_ARCH=slc5_amd64_gcc434 379 echo INFO: SCRAM_ARCH $SCRAM_ARCH 381 eval `scramv1 run -sh` 383 source /afs/cern.ch/cms/caf/setup.sh 384 echo INFO: CMS_PATH $CMS_PATH 385 echo INFO: STAGE_SVCCLASS $STAGE_SVCCLASS 386 echo INFO: STAGER_TRACE $STAGER_TRACE 388 export ALIGNMENT_AFSDIR=`pwd` 390 export ALIGNMENT_ITERATION=%(iteration)d 391 export ALIGNMENT_MODE=%(mode)s 392 export ALIGNMENT_INPUTDB=%(inputdb)s 393 export ALIGNMENT_GLOBALTAG=%(globaltag)s 394 export ALIGNMENT_PHOTOGRAMMETRY='%(photogrammetry)s or %(photogrammetryOnlyholes)s or %(photogrammetryOnlyOnePerRing)s' 395 export ALIGNMENT_SLM=%(slm)s 396 export ALIGNMENT_FILLME11HOLES='%(fillME11holes)s' 397 export ALIGNMENT_DISKS=%(disks)s 398 export ALIGNMENT_minP=%(minP)s 399 export ALIGNMENT_minHitsPerChamber=%(minHitsPerChamber)s 400 export ALIGNMENT_maxdrdz=%(maxdrdz)s 401 export ALIGNMENT_maxRedChi2=%(maxRedChi2)s 402 export ALIGNMENT_fiducial=%(fiducial)s 403 export ALIGNMENT_useHitWeights=%(useHitWeights)s 404 export ALIGNMENT_truncateSlopeResid=%(truncateSlopeResid)s 405 export ALIGNMENT_truncateOffsetResid=%(truncateOffsetResid)s 406 export ALIGNMENT_combineME11=%(combineME11)s 407 export ALIGNMENT_useTrackWeights=%(useTrackWeights)s 408 export ALIGNMENT_errorFromRMS=%(errorFromRMS)s 409 export ALIGNMENT_minTracksPerOverlap=%(minTracksPerOverlap)s 410 export ALIGNMENT_slopeFromTrackRefit=%(slopeFromTrackRefit)s 411 export ALIGNMENT_minStationsInTrackRefits=%(minStationsInTrackRefits)s 413 cp -f %(directory)salignBH_cfg.py %(directory)sconvert-db-to-xml_cfg.py %(inputdbdir)s%(inputdb)s %(directory)s*.tmp inertGlobalPositionRcd.db $ALIGNMENT_CAFDIR/ 414 cd $ALIGNMENT_CAFDIR/ 415 export ALIGNMENT_ALIGNMENTTMP=`ls alignment*.tmp` 420 cmsRun alignBH_cfg.py 421 cp -f report.py $ALIGNMENT_AFSDIR/%(directory)s%(director)s_report.py 422 cp -f outputdb.db $ALIGNMENT_AFSDIR/%(directory)s%(director)s.db 423 cp -f plotting.root $ALIGNMENT_AFSDIR/%(directory)s%(director)s.root 426 cmsRun %(directory)sconvert-db-to-xml_cfg.py 428 export ALIGNMENT_PLOTTINGTMP=`ls %(directory)splotting0*.root 2> /dev/null` 429 if [ \"zzz$ALIGNMENT_PLOTTINGTMP\" != \"zzz\" ]; then 430 hadd -f1 %(directory)s%(director)s_plotting.root %(directory)splotting0*.root 431 #if [ $? == 0 ] && [ \"$ALIGNMENT_CLEANUP\" == \"True\" ]; then rm %(directory)splotting0*.root; fi 435 os.system(
"chmod +x %salign.sh" % directory)
437 bsubfile.append(
"echo %salign.sh" % directory)
439 if user_mail: bsubfile.append(
"bsub -R \"type==SLC5_64\" -q cmscaf1nd -J \"%s_align\" -u %s -w \"%s\" align.sh" % (director, user_mail,
" && ".
join(bsubnames)))
440 else: bsubfile.append(
"bsub -R \"type==SLC5_64\" -q cmscaf1nd -J \"%s_align\" -w \"%s\" align.sh" % (director,
" && ".
join(bsubnames)))
442 bsubfile.append(
"cd ..")
444 last_align =
"%s_align" % director
448 os.system(
"chmod +x %s" % options.submitJobs)
S & print(S &os, JobReport::InputFile const &f)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static std::string join(char **cmd)