ATLAS Offline Software
SUSY_SimplifiedModel_PostInclude.py
Go to the documentation of this file.
1 # This comes after all Simplified Model setup files
2 from MadGraphControl.MadGraphUtils import SUSY_Generation,modify_param_card,check_reset_proc_number
3 from MadGraphControl.MadGraphUtilsHelpers import get_physics_short
4 
5 phys_short = get_physics_short()
6 
7 if 'rpv' in phys_short.lower() and not 'import ' in process:
8  raise RuntimeError('Please import a model when using an RPV decay; these are not handled by the standard MSSM model in MadGraph')
9 
10 # Set maximum number of events if the event multiplier has been modified
11 if evt_multiplier>0:
12  if runArgs.maxEvents>0:
13  nevts=runArgs.maxEvents*evt_multiplier
14  else:
15  nevts=evgenConfig.nEventsPerJob*evt_multiplier
16 else:
17  # Sensible default
18  nevts=evgenConfig.nEventsPerJob*2.
19 run_settings.update({'nevents':int(nevts)})
20 
21 # Only needed for something non-standard (not 1/4 heavy mass)
22 if ktdurham is not None:
23  run_settings.update({'ktdurham':ktdurham})
24 
25 if flavourScheme not in [4,5]:
26  raise RuntimeError('flavourScheme must be 4 or 5.')
27 
28 if flavourScheme == 4:
29  run_settings.update({
30  'pdgs_for_merging_cut': '1, 2, 3, 4, 21' # Terrible default in MG
31  })
32  _nQuarksMerge = 5 if finalStateB else 4
33 else:
34  run_settings.update({
35  'pdgs_for_merging_cut': '1, 2, 3, 4, 5, 21',
36  'asrwgtflavor': 5,
37  'maxjetflavor': 5
38  })
39  _nQuarksMerge = 5
40  if define_pj_5FS:
41  # Add the 5FS p and j definition to the beginning of the process string
42  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
43  # Check that if p and j get redefined that it is consistent with 5FS otherwise raise error
44  for l in process.split('\n'):
45  l_nocomment = l.split('#')[0]
46  if ("define p" in l_nocomment or "define j" in l_nocomment) and l_nocomment.count("=") == 1:
47  l_equals = (l_nocomment.split("=")[-1]).split(" ")
48  if not set(['g', 'u', 'c', 'd', 's', 'b', 'u~', 'c~', 'd~', 's~', 'b~']) <= set(l_equals):
49  raise RuntimeError('Invalid definition found for p or j in process string while using 5FS')
50  if force_nobmass_5FS:
51  if masses.get('5',0.0) != 0.0:
52  raise RuntimeError('Non-zero mass found for b while using 5FS')
53  masses['5'] = 0.0
54 
55 # systematic variation
56 if 'scup' in phys_short:
57  syst_mod=dict_index_syst[0]
58 elif 'scdw' in phys_short:
59  syst_mod=dict_index_syst[1]
60 elif 'alup' in phys_short:
61  syst_mod=dict_index_syst[2]
62 elif 'aldw' in phys_short:
63  syst_mod=dict_index_syst[3]
64 elif 'qcup' in phys_short:
65  syst_mod=dict_index_syst[6]
66 elif 'qcdw' in phys_short:
67  syst_mod=dict_index_syst[7]
68 
69 # Pass arguments as a dictionary: the "decays" argument is not accepted in older versions of MadGraphControl
70 if 'mass' in [x.lower() for x in param_blocks]:
71  raise RuntimeError('Do not provide masses in param_blocks; use the masses variable instead')
72 param_blocks['MASS']=masses
73 # Add decays in if needed
74 if len(decays)>0: param_blocks['DECAY']=decays
75 argdict = {'runArgs' : runArgs,
76  'process' : process,
77  'params' : param_blocks,
78  'fixEventWeightsForBridgeMode': fixEventWeightsForBridgeMode,
79  'madspin_card' : madspin_card,
80  'keepOutput' : keepOutput, # Should only ever be true for testing!
81  'run_settings' : run_settings, # All goes into the run card
82  'writeGridpack' : writeGridpack,
83  'syst_mod' : syst_mod,
84  'param_card' : param_card, # Only set if you *can't* modify the default param card to get your settings
85  'add_lifetimes_lhe' : add_lifetimes_lhe,
86  'usePMGSettings' : usePMGSettings,
87  'plugin' : plugin,
88  }
89 
90 # First the standard case: No input LHE file
91 if not hasattr(runArgs,'inputGeneratorFile') or runArgs.inputGeneratorFile is None:
92  # Note that for gridpack generation, the job will exit after this command
93  ktdurham = SUSY_Generation(**argdict)
94 
95 else:
96  # These manipulations require a dummy SUSY process
97  from MadGraphControl.MadGraphUtils import new_process,update_lhe_file,add_madspin,arrange_output,SUSY_process
98  process_dir = new_process(SUSY_process('generate p p > go go'))
99  modify_param_card(process_dir=process_dir,params={'MASS':masses,'DECAY':decays})
100  param_card_old = process_dir+'/Cards/param_card.dat'
101  ktdurham = -1
102  import tarfile
103  if tarfile.is_tarfile(runArgs.inputGeneratorFile):
104  myTarball = tarfile.open(runArgs.inputGeneratorFile)
105  myEvents = None
106  for afile in myTarball.getnames():
107  if afile.endswith('.events'): myEvents = afile
108  if myEvents is None:
109  raise RuntimeError('No input events file found!')
110  else:
111  events_file = myTarball.extractfile( myEvents )
112  update_lhe_file(lhe_file_old=myEvents,param_card_old=param_card_old,masses=masses)
113  for aline in events_file:
114  # Note that because this was directly extracted, we have a binary file, not a text file!
115  if b'ktdurham' in aline and b'=' in aline:
116  ktdurham = float(aline.split(b'=')[0].strip())
117  break
118  myTarball.close()
119  else:
120  # Assume this is already an unzipped file -- happens when we run on multiple LHEs
121  update_lhe_file(lhe_file_old=runArgs.inputGeneratorFile,param_card_old=param_card_old,masses=masses)
122  with open(runArgs.inputGeneratorFile,'r') as events_file:
123  for aline in events_file:
124  if 'ktdurham' in aline and "=" in aline:
125  ktdurham = float(aline.split('=')[0].strip())
126  break
127 
128  if madspin_card is not None:
129  # Do a stupid addition of madspin - requires a dummy process
130  add_madspin(madspin_card,process_dir=process_dir)
131  arrange_output(process_dir=process_dir,saveProcDir=keepOutput,runArgs=runArgs,fixEventWeightsForBridgeMode=fixEventWeightsForBridgeMode)
132 
133 # Check if we were running multi-core, and if so move back to single core for Pythia8
135 
136 # Pythia8 setup for matching if necessary
137 njets=max([l.count('j') for l in process.split('\n')])
138 njets_min=min([l.count('j') for l in process.split('\n') if 'generate ' in l or 'add process' in l])
139 if njets>0 and njets!=njets_min and hasattr(genSeq,'Pythia8'):
140  genSeq.Pythia8.Commands += ["Merging:mayRemoveDecayProducts = on",
141  "Merging:nJetMax = "+str(njets),
142  "Merging:doKTMerging = on",
143  "Merging:TMS = "+str(ktdurham),
144  "Merging:ktType = 1",
145  "Merging:Dparameter = 0.4",
146  "Merging:nQuarksMerge = {0:d}".format(_nQuarksMerge)]
147 
148 # Configuration for EvgenJobTransforms
149 #--------------------------------------------------------------
150 evgenConfig.keywords += ["SUSY"]
python.MadGraphUtils.check_reset_proc_number
def check_reset_proc_number(opts)
Definition: MadGraphUtils.py:2577
max
#define max(a, b)
Definition: cfImp.cxx:41
MadGraphUtils
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.MadGraphUtils.modify_param_card
def modify_param_card(param_card_input=None, param_card_backup=None, process_dir=MADGRAPH_GRIDPACK_LOCATION, params={}, output_location=None)
Definition: MadGraphUtils.py:2019
python.MadGraphUtils.arrange_output
def arrange_output(process_dir=MADGRAPH_GRIDPACK_LOCATION, lhe_version=None, saveProcDir=False, runArgs=None, fixEventWeightsForBridgeMode=False)
Definition: MadGraphUtils.py:1247
python.MadGraphUtils.update_lhe_file
def update_lhe_file(lhe_file_old, param_card_old=None, lhe_file_new=None, masses={}, delete_old_lhe=True)
Definition: MadGraphUtils.py:1831
python.MadGraphUtils.new_process
def new_process(process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False)
Definition: MadGraphUtils.py:216
python.MadGraphUtils.SUSY_Generation
def SUSY_Generation(runArgs=None, process=None, plugin=None, syst_mod=None, keepOutput=False, param_card=None, writeGridpack=False, madspin_card=None, run_settings={}, params={}, fixEventWeightsForBridgeMode=False, add_lifetimes_lhe=False, usePMGSettings=True)
Definition: MadGraphUtils.py:1776
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
min
#define min(a, b)
Definition: cfImp.cxx:40
python.MadGraphUtils.add_madspin
def add_madspin(madspin_card=None, process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:1102
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
python.MadGraphUtils.SUSY_process
def SUSY_process(process='')
Definition: MadGraphUtils.py:1746
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.MadGraphUtilsHelpers.get_physics_short
def get_physics_short()
Definition: MadGraphUtilsHelpers.py:107