SUSY_SimplifiedModel_PostInclude.py 5.3 KB
Newer Older
1
# This comes after all Simplified Model setup files
Zach Marshall's avatar
Zach Marshall committed
2
from MadGraphControl.MadGraphUtils import SUSY_Generation,modify_param_card,check_reset_proc_number
3
4
5
6
7
8
from MadGraphControl.MadGraphUtilsHelpers import get_physics_short

phys_short = get_physics_short()

if 'rpv' in phys_short.lower() and not 'import ' in process:
    raise RuntimeError('Please import a model when using an RPV decay; these are not handled by the standard MSSM model in MadGraph')
9
10
11
12
13
14

# 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:
15
        nevts=evgenConfig.nEventsPerJob*evt_multiplier
16
17
else:
    # Sensible default
18
    nevts=evgenConfig.nEventsPerJob*2.
Zach Marshall's avatar
Zach Marshall committed
19
run_settings.update({'nevents':int(nevts)})
20

21
22
23
# Only needed for something non-standard (not 1/4 heavy mass)
if ktdurham is not None:
    run_settings.update({'ktdurham':ktdurham})
24
25

# systematic variation
26
if 'scup' in phys_short:
27
    syst_mod=dict_index_syst[0]
28
elif 'scdw' in phys_short:
29
    syst_mod=dict_index_syst[1]
30
elif 'alup' in phys_short:
31
    syst_mod=dict_index_syst[2]
32
elif 'aldw' in phys_short:
33
    syst_mod=dict_index_syst[3]
34
elif 'qcup' in phys_short:
35
    syst_mod=dict_index_syst[6]
36
elif 'qcdw' in phys_short:
37
38
39
    syst_mod=dict_index_syst[7]

# Pass arguments as a dictionary: the "decays" argument is not accepted in older versions of MadGraphControl
40
41
if 'mass' in [x.lower() for x in param_blocks]:
    raise RuntimeError('Do not provide masses in param_blocks; use the masses variable instead')
Giordon Holtsberg Stark's avatar
Giordon Holtsberg Stark committed
42
param_blocks['MASS']=masses
43
44
# Add decays in if needed
if len(decays)>0: param_blocks['DECAY']=decays
45
46
argdict = {'runArgs'        : runArgs,
           'process'        : process,
47
           'params'         : param_blocks,
48
           'fixEventWeightsForBridgeMode': fixEventWeightsForBridgeMode,
49
50
51
52
53
           'madspin_card'   : madspin_card,
           'keepOutput'     : keepOutput, # Should only ever be true for testing!
           'run_settings'   : run_settings, # All goes into the run card
           'writeGridpack'  : writeGridpack,
           'syst_mod'       : syst_mod,
54
55
           'param_card'     : param_card, # Only set if you *can't* modify the default param card to get your settings
            'add_lifetimes_lhe' : add_lifetimes_lhe
56
57
           }

58
59
# First the standard case: No input LHE file
if not hasattr(runArgs,'inputGeneratorFile') or runArgs.inputGeneratorFile is None:
Zach Marshall's avatar
Zach Marshall committed
60
61
    # Note that for gridpack generation, the job will exit after this command
    ktdurham = SUSY_Generation(**argdict)
62
63

else:
64
    # These manipulations require a dummy SUSY process
Zach Marshall's avatar
Zach Marshall committed
65
    from MadGraphControl.MadGraphUtils import new_process,update_lhe_file,add_madspin,arrange_output,SUSY_process
66
67
68
69
    process_dir = new_process(SUSY_process('generate p p > go go'))
    modify_param_card(process_dir=process_dir,params={'MASS':masses,'DECAY':decays})
    param_card_old = process_dir+'/Cards/param_card.dat'
    ktdurham = -1
70
71
    import tarfile
    if tarfile.is_tarfile(runArgs.inputGeneratorFile):
72
73
74
75
76
77
78
79
80
81
82
83
84
85
        myTarball = tarfile.open(runArgs.inputGeneratorFile)
        myEvents = None
        for afile in myTarball.getnames():
            if afile.endswith('.events'): myEvents = afile
        if myEvents is None:
            raise RuntimeError('No input events file found!')
        else:
            events_file = myTarball.extractfile( myEvents )
            update_lhe_file(lhe_file_old=myEvents,param_card_old=param_card_old,masses=masses)
            for aline in events_file:
                if 'ktdurham' in aline and "=" in aline:
                    ktdurham = float(aline.split('=')[0].strip())
                    break
        myTarball.close()
86
    else:
87
88
89
90
91
92
93
        # Assume this is already an unzipped file -- happens when we run on multiple LHEs
        update_lhe_file(lhe_file_old=runArgs.inputGeneratorFile,param_card_old=param_card_old,masses=masses)
        with open(runArgs.inputGeneratorFile,'r') as events_file:
            for aline in events_file:
                if 'ktdurham' in aline and "=" in aline:
                    ktdurham = float(aline.split('=')[0].strip())
                    break
94

95
96
97
98
    if madspin_card is not None:
        # Do a stupid addition of madspin - requires a dummy process
        add_madspin(madspin_card,process_dir=process_dir)
        arrange_output(process_dir=process_dir,saveProcDir=keepOutput,runArgs=runArgs,fixEventWeightsForBridgeMode=fixEventWeightsForBridgeMode)
99

100
101
# Check if we were running multi-core, and if so move back to single core for Pythia8
check_reset_proc_number(opts)
102

103
104
# Pythia8 setup for matching if necessary
njets=max([l.count('j') for l in process.split('\n')])
105
106
njets_min=min([l.count('j') for l in process.split('\n') if 'generate ' in l or 'add process' in l])
if njets>0 and njets!=njets_min and hasattr(genSeq,'Pythia8'):
107
108
109
    genSeq.Pythia8.Commands += ["Merging:mayRemoveDecayProducts = on",
                                "Merging:nJetMax = "+str(njets),
                                "Merging:doKTMerging = on",
110
                                "Merging:TMS = "+str(ktdurham),
111
112
113
114
115
116
117
                                "Merging:ktType = 1",
                                "Merging:Dparameter = 0.4",
                                "Merging:nQuarksMerge = 4"]

# Configuration for EvgenJobTransforms
#--------------------------------------------------------------
evgenConfig.keywords += ["SUSY"]