ATLAS Offline Software
Loading...
Searching...
No Matches
SUSY_SimplifiedModel_PostInclude.py
Go to the documentation of this file.
1# This comes after all Simplified Model setup files
2from MadGraphControl.MadGraphUtils import modify_param_card
3from MadGraphControl.SUSY_Helpers import SUSY_Generation
4from MCJobOptionUtils.JOsupport import get_physics_short,check_reset_proc_number
5
6phys_short = get_physics_short()
7
8if 'rpv' in phys_short.lower() and not 'import ' in process:
9 raise RuntimeError('Please import a model when using an RPV decay; these are not handled by the standard MSSM model in MadGraph')
10
11# Set maximum number of events if the event multiplier has been modified
12if evt_multiplier>0:
13 if runArgs.maxEvents>0:
14 nevts=runArgs.maxEvents*evt_multiplier
15 else:
16 nevts=evgenConfig.nEventsPerJob*evt_multiplier
17else:
18 # Sensible default
19 nevts=evgenConfig.nEventsPerJob*2.
20run_settings.update({'nevents':int(nevts)})
21
22# Only needed for something non-standard (not 1/4 heavy mass)
23if ktdurham is not None:
24 run_settings.update({'ktdurham':ktdurham})
25
26if flavourScheme not in [4,5]:
27 raise RuntimeError('flavourScheme must be 4 or 5.')
28
29if flavourScheme == 4:
30 run_settings.update({
31 'pdgs_for_merging_cut': '1, 2, 3, 4, 21' # Terrible default in MG
32 })
33 PYTHIA8_nQuarksMerge = 5 if finalStateB else 4
34else:
35 run_settings.update({
36 'pdgs_for_merging_cut': '1, 2, 3, 4, 5, 21',
37 'asrwgtflavor': 5,
38 'maxjetflavor': 5
39 })
40 PYTHIA8_nQuarksMerge = 5
41 if define_pj_5FS:
42 # Add the 5FS p and j definition to the beginning of the process string
43 process = "define p = g u c d s b u~ c~ d~ s~ b~\ndefine j = g u c d s b u~ c~ d~ s~ b~\n" + process
44 # Check that if p and j get redefined that it is consistent with 5FS otherwise raise error
45 for l in process.split('\n'):
46 l_nocomment = l.split('#')[0]
47 if ("define p" in l_nocomment or "define j" in l_nocomment) and l_nocomment.count("=") == 1:
48 l_equals = (l_nocomment.split("=")[-1]).split(" ")
49 if not set(['g', 'u', 'c', 'd', 's', 'b', 'u~', 'c~', 'd~', 's~', 'b~']) <= set(l_equals):
50 raise RuntimeError('Invalid definition found for p or j in process string while using 5FS')
51 if force_nobmass_5FS:
52 if masses.get('5',0.0) != 0.0:
53 raise RuntimeError('Non-zero mass found for b while using 5FS')
54 masses['5'] = 0.0
55
56# systematic variation
57if '_msup' in phys_short:
58 syst_mod='msup'
59elif '_msdw' in phys_short:
60 syst_mod='msdw'
61if syst_mod not in ['msup','msdw',None]:
62 raise RuntimeError(f'Systematic variation {syst_mod=} unknown; allowed values are "msup" or "msdw" for matching scale up/down variations')
63
64# Pass arguments as a dictionary: the "decays" argument is not accepted in older versions of MadGraphControl
65if 'mass' in [x.lower() for x in param_blocks]:
66 raise RuntimeError('Do not provide masses in param_blocks; use the masses variable instead')
67param_blocks['MASS']=masses
68# Add decays in if needed
69if len(decays)>0: param_blocks['DECAY']=decays
70argdict = {'runArgs' : runArgs,
71 'process' : process,
72 'params' : param_blocks,
73 'fixEventWeightsForBridgeMode': fixEventWeightsForBridgeMode,
74 'madspin_card' : madspin_card,
75 'keepOutput' : keepOutput, # Should only ever be true for testing!
76 'run_settings' : run_settings, # All goes into the run card
77 'writeGridpack' : writeGridpack,
78 'syst_mod' : syst_mod,
79 'param_card' : param_card, # Only set if you *can't* modify the default param card to get your settings
80 'add_lifetimes_lhe' : add_lifetimes_lhe,
81 'usePMGSettings' : usePMGSettings,
82 'plugin' : plugin,
83 }
84
85# First the standard case: No input LHE file
86if not hasattr(runArgs,'inputGeneratorFile') or runArgs.inputGeneratorFile is None:
87 # Note that for gridpack generation, the job will exit after this command
88 ktdurham = SUSY_Generation(**argdict)
89
90else:
91 # These manipulations require a dummy SUSY process
92 from MadGraphControl.MadGraphUtils import new_process,update_lhe_file,add_madspin,arrange_output,SUSY_process
93 process_dir = new_process(SUSY_process('generate p p > go go'))
94 modify_param_card(process_dir=process_dir,params={'MASS':masses,'DECAY':decays})
95 param_card_old = process_dir+'/Cards/param_card.dat'
96 ktdurham = -1
97 import tarfile
98 if tarfile.is_tarfile(runArgs.inputGeneratorFile):
99 myTarball = tarfile.open(runArgs.inputGeneratorFile)
100 myEvents = None
101 for afile in myTarball.getnames():
102 if afile.endswith('.events'): myEvents = afile
103 if myEvents is None:
104 raise RuntimeError('No input events file found!')
105 else:
106 events_file = myTarball.extractfile( myEvents )
107 update_lhe_file(lhe_file_old=myEvents,param_card_old=param_card_old,masses=masses)
108 for aline in events_file:
109 # Note that because this was directly extracted, we have a binary file, not a text file!
110 if b'ktdurham' in aline and b'=' in aline:
111 ktdurham = float(aline.split(b'=')[0].strip())
112 break
113 myTarball.close()
114 else:
115 # Assume this is already an unzipped file -- happens when we run on multiple LHEs
116 update_lhe_file(lhe_file_old=runArgs.inputGeneratorFile,param_card_old=param_card_old,masses=masses)
117 with open(runArgs.inputGeneratorFile,'r') as events_file:
118 for aline in events_file:
119 if 'ktdurham' in aline and "=" in aline:
120 ktdurham = float(aline.split('=')[0].strip())
121 break
122
123 if madspin_card is not None:
124 # Do a stupid addition of madspin - requires a dummy process
125 add_madspin(madspin_card,process_dir=process_dir)
126 arrange_output(process_dir=process_dir,saveProcDir=keepOutput,runArgs=runArgs,fixEventWeightsForBridgeMode=fixEventWeightsForBridgeMode)
127
128# Check if we were running multi-core, and if so move back to single core for Pythia8
129check_reset_proc_number(opts)
130
131# Pythia8 setup for matching if necessary
132PYTHIA8_nJetMax=max([l.count('j') for l in process.split('\n')])
133njets_min=min([l.count('j') for l in process.split('\n') if 'generate ' in l or 'add process' in l])
134if PYTHIA8_nJetMax>0 and PYTHIA8_nJetMax!=njets_min and hasattr(genSeq,'Pythia8'):
135 # Matching was necessary, put things in the right places
136 PYTHIA8_TMS = ktdurham
137 PYTHIA8_Dparameter = 0.4
138 # If they didn't already define the variable, then go fishing
139 if 'PYTHIA8_Process' not in dir():
140 for acommand in genSeq.Pythia8.Commands:
141 if acommand.startswith('Merging:Process'):
142 PYTHIA8_Process = acommand.split('=')[1].strip()
143 break
144 else:
145 # If it _really_ wasn't defined by now, we're going for "guess"
146 PYTHIA8_Process = 'guess'
147 # The old command can stay, in the worst case - it just does the same thing twice
148
149 include('Pythia8_i/Pythia8_CKKWL_kTMerge.py')
150 # This is not included by the standard include, but is part of the SUSY standard
151 genSeq.Pythia8.Commands += ["Merging:mayRemoveDecayProducts = on"]
152
153# Configuration for EvgenJobTransforms
154#--------------------------------------------------------------
155evgenConfig.keywords += ["SUSY"]
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177