def run_chain(self, chain, physics, rootfile=None, move=False): """ Runs a chain of steps. The first step is considered the input step (it is not ran). If rootfile is specified, it is copied into the svj_path. If move=True, it is moved instead (only possible for local filenames). """ inpres = chain[:-1] outpres = chain[1:] # Copy/move the input rootfile if it's given if rootfile: expected_infile = osp.join(self.svj_path, svj_filename(inpres[0], physics)) if move: logger.info("Moving %s -> %s", rootfile, expected_infile) os.rename(rootfile, expected_infile) else: seutils.cp(rootfile, expected_infile) # Run steps for inpre, outpre in zip(inpres, outpres): expected_outfile = self.run_step( inpre, outpre, physics, n_attempts=3 if ("RECO" in outpre or "DIGI" in outpre) else 1, ) return expected_outfile
def download_mg_tarball(mz, rinv, boost=0., dst=None, **kwargs): dst = osp.join( os.getcwd() if dst is None else dst, get_mg_tarball_name(mz, rinv, boost=boost) ) # Tarballs on SE will not have the boost tag but it's irrelevant for mg tarballs, so just set boost to 0 src = osp.join(MG_TARBALL_PATH, get_mg_tarball_name(mz, rinv, boost=0.)) if osp.isfile(dst): logger.info('File %s already exists', dst) else: logger.info('Downloading %s --> %s', src, dst) seutils.cp(src, dst)
def from_tarball(cls, tarball, scram_arch=None, outdir=None): if seutils.has_protocol(tarball): logger.info("Tarball %s seems to be located remote; copying", tarball) dst = osp.abspath(osp.basename(tarball)) if osp.isfile(dst): logger.warning("Using pre-existing tarball %s", dst) else: seutils.cp(tarball, dst) tarball = dst cmssw_src = cls.extract_tarball(tarball, outdir) # See if the tarball was already compiled with some scram_arch, if so use it if scram_arch is None: compiled_arches = glob.glob(osp.join(cmssw_src, "../bin/slc*")) if compiled_arches: scram_arch = osp.basename(compiled_arches[0]) logger.warning( "Detected tarball was compiled with arch %s, using it", scram_arch ) return cls(cmssw_src, scram_arch)
def download_madgraph_tarball(physics, dst=None): """Downloads tarball from the storage element""" dst = osp.join(os.getcwd() if dst is None else dst, madgraph_tarball_filename(physics)) if osp.isfile(dst): logger.info("File %s already exists", dst) else: for mg_tarball_path in MG_TARBALL_PATHS: # Tarballs on SE will not have the boost tag and have postfix "_n-1" src = osp.join( mg_tarball_path, madgraph_tarball_filename( Physics(physics, boost=0.0, max_events=1, part=None)), ) if seutils.isfile(src): logger.info("Downloading %s --> %s", src, dst) seutils.cp(src, dst) break else: raise Exception( "Cannot download tarball {0} for Physics {1}".format( madgraph_tarball_filename(physics), physics))
import qondor, seutils cmssw = qondor.init_cmssw() cmssw.run_commands([ 'cd TreeMaker/Production/test', 'cmsRun runMakeTreeFromMiniAOD_cfg.py' ' numevents=-1' ' outfile=outfile' ' scenario=Autumn18sig' ' lostlepton=0' ' doZinv=0' ' systematics=0' ' deepAK8=0' ' deepDoubleB=0' ' doPDFs=0' ' nestedVectors=False' ' debugjets=1' ' splitLevel=99' + (' dump=1' if args.dump else '') + (' inputFiles=' + ','.join(qondor.get_item())) ]) expected_outfile = osp.join(cmssw.cmssw_src, 'TreeMaker/Production/test', 'outfile_RA2AnalysisTree.root') seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/treemaker/ht1000_nonested_{date}_mz{mz}/{part}.root' .format(date=qondor.get_submission_time().strftime('%b%d'), mz=qondor.get_var('mz'), part=qondor.get_proc_id()))
seutils.debug() cmssw = qondor.init_cmssw() mz = int(qondor.get_var('mz')) max_events = 10000 # runSVJ wants maxEvents to be passed, just set it large enough physics = { 'year': 2018, 'mz': mz, 'mdark': 20., 'rinv': 0.3, 'boost': 1000., } part = qondor.get_proc_id() + 1 for i_rootfile, rootfile in enumerate(qondor.get_item()): # Ensure unique part name per rootfile across jobs; Not sure if necessary for SIM>MINIAOD svjpart = 1000 * part + i_rootfile qondor.logger.info('Job %s: Processing %s', qondor.get_proc_id(), rootfile) expected_outfile = svjqondor.run_sim_reco_miniaod(cmssw, part=svjpart, rootfile=rootfile, **physics) seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/miniaod/ht1000_{date}_mz{mz}_Aug07genonly/{part}_{i_rootfile}.root' .format(date=qondor.get_submission_time().strftime('%b%d'), mz=mz, part=part, i_rootfile=i_rootfile))
parser = argparse.ArgumentParser() parser.add_argument('--dump', action='store_true') args = parser.parse_args() import qondor, seutils cmssw = qondor.init_cmssw() cmssw.run_commands([ 'cd TreeMaker/Production/test', 'cmsRun runMakeTreeFromMiniAOD_cfg.py' ' numevents=-1' ' outfile=outfile' ' scenario=Autumn18sig' ' lostlepton=0' ' doZinv=0' ' systematics=0' ' deepAK8=0' ' deepDoubleB=0' ' doPDFs=0' ' nestedVectors=False ' ' debugjets=1 ' + (' dump=1' if args.dump else '') + (' inputFiles=' + ','.join(qondor.get_item())) ]) expected_outfile = osp.join(cmssw.cmssw_src, 'TreeMaker/Production/test', 'outfile_RA2AnalysisTree.root') seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/klijnsma/semivis/treemakerht1000_nonested/mz{0}_{1}.root' .format(qondor.get_var('mz'), qondor.get_proc_id()))
'year': 2018, 'mz': mz, 'mdark': 20., 'rinv': 0.3, 'boost': 0., } svjqondor.download_mg_tarball(dst=osp.join(cmssw.cmssw_src, 'SVJ/Production/test'), **physics) gen_outfile = svjqondor.run_step_cmd(cmssw, inpre='step0_GRIDPACK', outpre='step1_LHE-GEN', part=part_for_svj, max_events=entries_per_file, **physics) expected_outfile = svjqondor.run_sim_reco_miniaod(cmssw, part=part_for_svj, rootfile=gen_outfile, **physics) seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/miniaod/nohtcutfromscratch_{date}_mz{mz}_epf{epf}_series{series}/{part}.root' .format(date=qondor.get_submission_time().strftime('%b%d'), mz=mz, epf=entries_per_file, series=series, part=part_for_svj))
htcondor( 'cmsconnect_blacklist', ['*_RU_*', '*FNAL*', '*IFCA*', '*KIPT*', 'T3_IT_Trieste', 'T2_TR_METU', 'T2_US_Vanderbilt', 'T2_PK_NCP'] ) for mz in [150, 250, 450, 650]: for rinv in [ 0.001, 0.1, 0.3, 0.5 ]: submit(mz=mz, mdark=10., rinv=rinv) """# endsubmit import qondor, seutils, os.path as osp cmssw = qondor.svj.init_cmssw('root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/svjproduction-tarballs/CMSSW_10_2_21_latest_el7_gen_2018.tar.gz') physics = qondor.svj.Physics({ 'year' : 2018, 'mz' : qondor.scope.mz, 'mdark' : qondor.scope.mdark, 'rinv' : qondor.scope.rinv, 'max_events' : 1, }) expected_outfile = cmssw.make_madgraph_tarball(physics) if not qondor.BATCHMODE: seutils.drymode() dst = osp.join( 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/mg_tarballs_2021', osp.basename(expected_outfile) ) seutils.cp(expected_outfile, dst)
def main(): parser = argparse.ArgumentParser() parser.add_argument( 'action', type=str, choices=['setup', 'pull', 'tarball', 'stageout', 'status'], help= ('setup: Sets up a CMSSW environment; ' 'pull: Updates an existing CMSSW environment; ' 'tarball: Makes a tarball out of an existing CMSSW environment; ' 'stageout: Copies all created tarballs to the storage element (at {0}) ' '(year and step arguments are ignored)'.format(STAGEOUTDIR))) parser.add_argument( 'year', type=str, nargs='?', choices=[str(y) for y in YEARS] + ['treemaker', '*'], help='Specify which year (each year may have different CMSSW versions)' ) parser.add_argument( 'step', type=str, nargs='?', choices=STEPS + ['*'], help= 'Specify which step (different steps may have different CMSSW versions)' ) parser.add_argument( '-o', '--out', type=str, help= 'Path to where CMSSW should be set up (default is where this script is)' ) parser.add_argument( '-d', '--dry', action='store_true', help='Only prints what would be done, but does not run anything') args = parser.parse_args() if args.out: global THISDIR THISDIR = osp.abspath(args.out) qondor.logger.info('Working directory: %s', THISDIR) if args.dry: drymode() if args.action == 'stageout': for tarball in glob.glob(osp.join(TARBALLDIR, '*.tar.gz')): dst = osp.join(STAGEOUTDIR, osp.basename(tarball)) force = ('latest' in dst) if not force and seutils.isfile(dst): qondor.logger.info('%s already exists', dst) else: qondor.logger.info('Staging out %s --> %s', tarball, dst) seutils.cp(tarball, STAGEOUTDIR, force=force) return for year, step in iter_years_steps(args.year, args.step): if args.action == 'setup': setup(year, step) elif args.action == 'pull': pull(year, step) elif args.action == 'tarball': make_tarball(year, step) elif args.action == 'status': status(year, step)
cmssw.run_commands([ 'cd TreeMaker/Production/test', 'cmsRun runMakeTreeFromMiniAOD_cfg.py' ' nstart={}' ' nfiles=1' ' outfile=outfile' ' scenario={}' ' inputFilesConfig={}' ' lostlepton=0' ' doZinv=0' ' systematics=0' ' deepAK8=0' ' deepDoubleB=0' ' doPDFs=0' ' nestedVectors=False' ' splitLevel=99' ' numevents=5' # ONLY FOR TESTING, remove this option if you're really producing something .format(i_file, scenario, bkg) ]) # Copy the output root file to a storage element expected_outfile = osp.join(cmssw.cmssw_src, 'TreeMaker/Production/test', 'outfile_RA2AnalysisTree.root') seutils.cp( expected_outfile, 'gsiftp://hepcms-gridftp.umd.edu//mnt/hadoop/cms/store/user/thomas.klijnsma/qcdtest3/' 'bkg_{date}_year{year}/{bkg}/{part}.root'.format( date=qondor.get_submission_timestr(), year=year, bkg=bkg, part=i_file), env=qondor.BARE_ENV, implementation='gfal')
# # $ items b=20 ls(root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/miniaod/nohtcutfromscratch_Aug25_mz650/5*.root) # #$ endset import qondor, seutils, os.path as osp cmssw = qondor.init_cmssw() cmssw.run_commands([ 'cd TreeMaker/Production/test', 'cmsRun runMakeTreeFromMiniAOD_cfg.py' ' numevents=-1' ' outfile=outfile' ' scenario=Autumn18sig' ' lostlepton=0' ' doZinv=0' ' systematics=0' ' deepAK8=0' ' deepDoubleB=0' ' doPDFs=0' ' nestedVectors=False' ' debugjets=1' ' splitLevel=99' + (' inputFiles=' + ','.join(qondor.get_item())) ]) expected_outfile = osp.join(cmssw.cmssw_src, 'TreeMaker/Production/test', 'outfile_RA2AnalysisTree.root') seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/treemaker/nohtcutfromscratch_{date}_mz{mz}_epf640_series8000/{part}.root' .format(date=qondor.get_submission_time().strftime('%b%d'), mz=qondor.get_var('mz'), part=qondor.get_proc_id()), )
for i in range(1,41): for rinv in [0.001, 0.1, 0.3]: submit(i=i, mz=mz, mdark=10., rinv=rinv) """# endsubmit import qondor, seutils, os.path as osp cmssw = qondor.svj.init_cmssw( 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/svjproduction-tarballs/CMSSW_10_2_21_latest_el7_gen_2018.tar.gz' ) physics = qondor.svj.Physics({ 'year': 2018, 'mz': qondor.scope.mz, 'mdark': qondor.scope.mdark, 'rinv': qondor.scope.rinv, 'mingenjetpt': 250., 'max_events': 30000, 'part': qondor.scope.i }) cmssw.download_madgraph_tarball(physics) expected_outfile = cmssw.run_step('step0_GRIDPACK', 'step1_LHE-GEN', physics) if not qondor.BATCHMODE: seutils.drymode() seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/gen/' 'genjetpt250_{date}_mz{mz:.0f}_mdark{mdark:.0f}_rinv{rinv}/{i}.root'. format(date=qondor.get_submission_timestr(), i=qondor.scope.i, **physics))
genfiles = seutils.ls_wildcard( 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/gen/' 'genjetpt250_Jan25_mz{mz:.0f}_mdark10_rinv{rinv}/*.root'.format( mz=qondor.scope.mz, rinv=qondor.scope.rinv)) cmssw = qondor.svj.init_cmssw( 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/svjproduction-tarballs/' 'CMSSW_10_2_21_efb554a_el7_gen_2018_Feb02_ecfntupler.tar.gz') rundir = osp.join(cmssw.cmssw_src, 'SVJ/Production/test') processed_genfiles = [] for i, genfile in enumerate(genfiles): if args.test and i == 2: break local_rootfile = osp.join(rundir, 'step1.root') if osp.isfile(local_rootfile): os.remove(local_rootfile) seutils.cp(genfile, local_rootfile) cmssw.run_commands([ 'cd {0}'.format(rundir), 'cmsRun runSVJ.py' ' config=genJetSubstructure' ' outpre=gensub' ' part={i}' ' channel=s' ' mMediator={mz:.0f}' ' mDark=10' ' rinv={rinv}' ' {maxEvents}'.format(mz=qondor.scope.mz, rinv=qondor.scope.rinv, i=i + 1, maxEvents='maxEvents=10' if args.test else '') ]) processed_genfiles.append(
mz = int(qondor.get_var('mz')) # CMSSW files with ~18k events are hard to manage # Run in blocks of 400 max_events, ~200 evts net per output entries_per_file = 400 n_blocks = 40 physics = { 'year' : 2018, 'mz' : mz, 'mdark' : 20., 'rinv' : 0.3, 'boost' : 0., } svjqondor.download_mg_tarball(dst=osp.join(cmssw.cmssw_src, 'SVJ/Production/test'), **physics) ijob = qondor.get_proc_id() + 1000 for i_block in range(n_blocks): part_for_svj = 100*ijob + i_block # Also need to ensure uniqueness per block expected_outfile = svjqondor.run_step_cmd( cmssw, inpre='step0_GRIDPACK', outpre='step1_LHE-GEN', part=part_for_svj, max_events=entries_per_file, **physics ) seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/lpcsusyhad/SVJ2017/boosted/gen/nohtcut_{date}_mz{mz}/{part}_{i_block}.root' .format(date=qondor.get_submission_time().strftime('%b%d'), mz=mz, part=part, i_block=i_block) )
mz = int(qondor.get_var('mz')) max_events = int(qondor.get_var('max_events')) offset = 2000 # apply an offset to the part to generate new events part = qondor.get_proc_id( ) + 1 + offset # proc_id starts at 0, runSVJ expects starting at 1 physics = { 'year': 2018, 'mz': mz, 'mdark': 20., 'rinv': 0.3, 'boost': 1000., } svjqondor.download_mg_tarball(dst=osp.join(cmssw.cmssw_src, 'SVJ/Production/test'), **physics) expected_outfile = svjqondor.run_step_cmd(cmssw, inpre='step0_GRIDPACK', outpre='step1_LHE-GEN', part=part, max_events=max_events, **physics) seutils.cp( expected_outfile, 'root://cmseos.fnal.gov//store/user/klijnsma/semivis/genht1000/Jul16_mz{mz}/{part}.root' .format(mz=mz, part=part))
'mdark': 20., 'rinv': 0.3, 'boost': 1000., } rootfiles = qondor.get_item() qondor.logger.info('Job %s: Processing %s', qondor.get_proc_id(), rootfiles) for rootfile in rootfiles: part = int(osp.basename(rootfile).replace( '.root', '')) # Get part from the gen step extended_physics = dict(physics, part=part, max_events=max_events) expected_infile = osp.join( cmssw.cmssw_src, 'SVJ/Production/test', svjqondor.formatted_filename('step1_LHE-GEN', **extended_physics)) if not osp.isfile(expected_infile): seutils.cp(rootfile, expected_infile) svjqondor.run_step_cmd(cmssw, inpre='step1_LHE-GEN', outpre='step1_SIM', **extended_physics) svjqondor.run_step_cmd(cmssw, inpre='step1_SIM', outpre='step3_DIGI-RECO', **extended_physics) expected_outfile = svjqondor.run_step_cmd(cmssw, inpre='step3_DIGI-RECO', outpre='step4_MINIAOD', **extended_physics)