Commit 935c1a2a authored by Frank Siegert's avatar Frank Siegert
Browse files

Add example for common include files.

parent 87b6dae4
# MC16 Stop-Stau Simplified Model Grid, JIRA: ATLMCPROD-7163
include('MadGraphControl/SimplifiedModel_TT_stau.py')
# This comes after all Simplified Model setup files
from MadGraphControl.MadGraphUtils import SUSY_SM_Generation
from MadGraphControl.MadGraphUtils import build_param_card
try:
from MadGraphControl.MadGraphUtils import update_lhe_file
except ImportError:
print "Will not be able to update LHE file using this release"
try:
from MadGraphControl.MadGraphUtils import run_madspin
except ImportError:
print "Will not be able to run madspin on existing LHE file using this release"
# Set maximum number of events if the event multiplier has been modified
if evt_multiplier>0:
if runArgs.maxEvents>0:
nevts=runArgs.maxEvents*evt_multiplier
else:
nevts=5000*evt_multiplier
if njets<0:
evgenLog.fatal('njets is not set')
raise RuntimeError('njet is not set')
# systematic variation
if 'scup' in runArgs.jobConfig[0]:
syst_mod=dict_index_syst[0]
elif 'scdw' in runArgs.jobConfig[0]:
syst_mod=dict_index_syst[1]
elif 'alup' in runArgs.jobConfig[0]:
syst_mod=dict_index_syst[2]
elif 'aldw' in runArgs.jobConfig[0]:
syst_mod=dict_index_syst[3]
elif 'qcup' in runArgs.jobConfig[0]:
syst_mod=dict_index_syst[6]
elif 'qcdw' in runArgs.jobConfig[0]:
syst_mod=dict_index_syst[7]
# Set up for grid pack running
gridpackDirName=None
if hasattr(runArgs, "inputGenConfFile"):
gridpackDirName='madevent/'
if 'writeGridpack' not in dir():
writeGridpack=False
# Pass arguments as a dictionary: the "decays" argument is not accepted in older versions of MadGraphControl
argdict = {'runArgs' : runArgs,
'process' : process,
'gentype' : gentype,
'decaytype': decaytype,
'masses' : masses,
'decays' : decays,
'madspin_card' : madspin_card,
}
if not SLHAonly and (not hasattr(runArgs,'inputGeneratorFile') or runArgs.inputGeneratorFile is None):
# If it has not been set explicitly, set it now
if not 'ickkw' in extras: extras['ickkw'] = 0
argdict.update({'nevts' : nevts,
'syst_mod' : syst_mod,
'xqcut' : xqcut,
'writeGridpack' : writeGridpack,
'gridpackDirName': gridpackDirName,
'keepOutput' : keepOutput,
'pdlabel' : "'nn23lo1'",
'lhaid' : 247000,
'extras' : extras,
})
try:
[qcut,outputDS] = SUSY_SM_Generation(**argdict)
except TypeError:
# Older version of MadGraphControl
try:
del argdict['extras']
[qcut,outputDS] = SUSY_SM_Generation(**argdict)
except TypeError:
del argdict['decays']
[qcut,outputDS] = SUSY_SM_Generation(**argdict)
elif not hasattr(runArgs,'inputGeneratorFile') or runArgs.inputGeneratorFile is None:
argdict.update({'nevts' : 10000,
'syst_mod' : None,
'xqcut' : xqcut,
'SLHAonly' : True,
'keepOutput': keepOutput,
'extras' : extras,
})
try:
[qcut,outputDS] = SUSY_SM_Generation(**argdict)
except TypeError:
# Older version of MadGraphControl
try:
del argdict['extras']
[qcut,outputDS] = SUSY_SM_Generation(**argdict)
except TypeError:
del argdict['decays']
[qcut,outputDS] = SUSY_SM_Generation(**argdict)
else:
build_param_card(param_card_old='param_card.SM.%s.%s.dat'%(gentype,decaytype),param_card_new='param_card_updated.dat',decays=decays)
param_card_old = 'param_card_updated.dat'
#param_card_old = 'param_card.SM.%s.%s.dat'%(gentype,decaytype)
qcut = -1
import tarfile
myTarball = tarfile.open(runArgs.inputGeneratorFile)
myEvents = None
for afile in myTarball.getnames():
if afile.endswith('.events'): myEvents = afile
if myEvents is None:
print 'No input events file found!'
else:
events_file = myTarball.extractfile( myEvents )
try:
lhe_file_new_tmp = update_lhe_file(myEvents,param_card_old=param_card_old,lhe_file_new=None,masses=masses)
print lhe_file_new_tmp
except NameError:
print "WARNING: Will not overwrite LHE file - make sure the LHE file you're using is specific to the model you're generating!"
for aline in events_file:
if 'ktdurham' in aline and "=" in aline:
qcut = float(aline.split('=')[0].strip())
break
myTarball.close()
if madspin_card is not None: run_madspin(madspin_card,runArgs,keepOutput)
outputDS = runArgs.inputGeneratorFile
from __main__ import opts
if ((qcut<0 and njets>0) or outputDS is None or ''==outputDS) and not opts.config_only:
evgenLog.warning('Looks like something went wrong with the MadGraph generation - bailing out!')
raise RuntimeError('Error in MadGraph generation')
import os
if 'ATHENA_PROC_NUMBER' in os.environ:
evgenLog.info('Noticed that you have run with an athena MP-like whole-node setup. Will re-configure now to make sure that the remainder of the job runs serially.')
njobs = os.environ.pop('ATHENA_PROC_NUMBER')
# Try to modify the opts underfoot
if not hasattr(opts,'nprocs'): mglog.warning('Did not see option!')
else: opts.nprocs = 0
print opts
runArgs.qcut = qcut
runArgs.inputGeneratorFile = outputDS
if 'syst_mod' in dir():
runArgs.syst_mod = syst_mod
runArgs.decaytype = decaytype
runArgs.gentype = gentype
# Pythia8 setup
genSeq.Pythia8.Commands += ["Init:showAllParticleData = on",
"Next:numberShowLHA = 10",
"Next:numberShowEvent = 10",
]
if njets>0:
genSeq.Pythia8.Commands += ["Merging:mayRemoveDecayProducts = on",
"Merging:nJetMax = "+str(njets),
"Merging:doKTMerging = on",
"Merging:TMS = "+str(qcut),
"Merging:ktType = 1",
"Merging:Dparameter = 0.4",
"Merging:nQuarksMerge = 4"]
# Configuration for EvgenJobTransforms
#--------------------------------------------------------------
evgenConfig.generators += ["EvtGen"]
if not hasattr(runArgs,'inputGeneratorFile'):
print 'ERROR: something wasnt write in file name transfer from the fragment.'
runArgs.inputGeneratorFile='madgraph.*._events.tar.gz'
evgenConfig.keywords += ["SUSY"]
if not opts.config_only:
evgenConfig.inputfilecheck = runArgs.inputGeneratorFile.split('._0')[0]
# Generator transform pre-include
# Gets us ready for on-the-fly SUSY SM generation
# Simple variable setups
njets = -1
masses = {}
decays = {}
# Event multipliers for getting more events out of madgraph to feed through athena (esp. for filters)
evt_multiplier = 2.0
# Useful definitions
squarks = []
squarksl = []
for anum in [1,2,3,4]:
squarks += [str(1000000+anum),str(-1000000-anum),str(2000000+anum),str(-2000000-anum)]
squarksl += [str(1000000+anum),str(-1000000-anum)]
dict_index_syst = {0:'scalefactup',
1:'scalefactdown',
2:'alpsfactup',
3:'alpsfactdown',
4:'moreFSR',
5:'lessFSR',
6:'qup',
7:'qdown'}
# Basic settings for production and filters
SLHAonly = False
syst_mod = None
xqcut = None
madspin_card = None
try:
from MadGraphControl.MadGraphUtils import getMadGraphVersion
version = getMadGraphVersion()
if int(version.split('.')[1])<5 and int(version.split('.')[0])<3:
extras = {}
else:
extras = {'event_norm':'sum', # Fix normalization issues when SysCalc runs
}
except ImportError:
print "WARNING: you are running a really old version of MadGraph now!"
extras={}
if hasattr(runArgs,'EventMultiplier'): evt_multiplier=runArgs.EventMultiplier
if runArgs.maxEvents>0:
nevts=runArgs.maxEvents*evt_multiplier
else:
nevts=5000*evt_multiplier
evt_multiplier=-1
# in case someone needs to be able to keep the output directory for testing
keepOutput = False
if 'py1up' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var1Up_EvtGen_Common.py")
elif 'py1dw' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var1Down_EvtGen_Common.py")
elif 'py2up' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var2Up_EvtGen_Common.py")
elif 'py2dw' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var2Down_EvtGen_Common.py")
elif 'py3aup' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var3aUp_EvtGen_Common.py")
elif 'py3adw' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var3aDown_EvtGen_Common.py")
elif 'py3bup' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var3bUp_EvtGen_Common.py")
elif 'py3bdw' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var3bDown_EvtGen_Common.py")
elif 'py3cup' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var3cUp_EvtGen_Common.py")
elif 'py3cdw' in runArgs.jobConfig[0]:
include("Pythia8_iPythia8_A14_NNPDF23LO_Var3cDown_EvtGen_Common.py")
else:
include("Pythia8_iPythia8_A14_NNPDF23LO_EvtGen_Common.py")
include("Pythia8_i/Pythia8_MadGraph.py")
include('MadGraphControl/SimplifiedModelPreInclude.py')
### parse options from MC job-options filename
tokens = runArgs.jobConfig[0].replace(".py","").split('_')
gentype, decaytype = tokens[2], tokens[3]
mstop, mstau = int(tokens[4]), int(tokens[5])
### production defaults
njets = 2
madspindecays = True
pythiadecays = False
for arg in tokens[6:]:
if arg == "noMadSpin":
madspindecays = False
elif arg == "PythiaDecay":
madspindecays = False
pythiadecays = True
elif arg.startswith("njets"):
njets = int(arg[5:])
if njets > 2:
raise RuntimeError("Cannot do more than 2 jets (%d requested)" % njets)
### SUSY masses
masses['1000006'] = mstop # stop
masses['1000015'] = mstau # stau
masses['1000022'] = 0.5 # "massless" neutralino
### MadGraph commands
# the following lines tell Madgraph to generate stop-pairs with 0,1,2 extra jets.
process = "generate p p > t1 t1~ {decay} @1\n"
if njets > 0:
process += "add process p p > t1 t1~ j {decay} @2\n"
if njets > 1:
process += "add process p p > t1 t1~ j j {decay} @3\n"
if madspindecays or pythiadecays:
process = process.format(decay="$ go susylq susylq~ b1 b2 t2 b1~ b2~ t2~")
else:
# do decay in MadGraph (takes very long, need to use gridpacks)
process = process.format(decay=", (t1 > b ta1+ vt), (t1~ > b~ ta1- vt~) $ go susylq susylq~ b1 b2 t2 b1~ b2~ t2~")
### MadSpin card
if madspindecays:
madspin_card='madspin_card_TT_stau.dat'
card = """
set seed {randomSeed}
set max_weight_ps_point 400 # default
set spinmode none # necessary for 3-body decay!
decay t1 > b ta1+ vt
decay t1~ > b~ ta1- vt~
# also do stau decay in MadSpin
decay ta1+ > ta+ n1
decay ta1- > ta- n1
# will run the actual code
launch
""".format(randomSeed = runArgs.randomSeed)
with open(madspin_card, 'w') as outf:
outf.write(card)
### evgenConfig
evgenConfig.contact = [ "mann@cern.ch" ]
evgenConfig.keywords += ['simplifiedModel', 'stop']
evgenConfig.description = 'stop direct pair production, stop->stau+nu+b, stau->tau+neutralino in simplified model, m_stop = %s GeV, m_stau = %s GeV, m_N1 = %s GeV, njets = %i.' % (masses['1000006'], masses['1000015'], masses['1000022'], njets)
if madspindecays:
evgenConfig.description += " Uses MadSpin for stop and stau decays."
if pythiadecays:
evgenConfig.description += " Uses Pythia for all decays."
#evgenConfig.inputconfcheck = "MadGraph_NNPDF23LO_TT_stau_%03i_%03i" % (mstop, mstau)
### post-include stuff
if njets > 0:
genSeq.Pythia8.Commands += ["Merging:Process = pp>{t1,1000006}{t1~,-1000006}"] # do not need Pythia's guess option (https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/SUSYMcRequestProcedure#AGENE_1511_Pythia_guess_Option_f)
# https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/SUSYMcRequestProcedure#PDG_merging_cuts_in_MG_2_6_2
extras['pdgs_for_merging_cut']='1, 2, 3, 4, 21, 1000001, 1000002, 1000003, 1000004, 1000021, 2000001, 2000002, 2000003, 2000004'
# last line
include('MadGraphControl/SimplifiedModelPostInclude.py')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment