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 modify_param_card,check_reset_proc_number
3 from MadGraphControl.SUSY_Helpers import SUSY_Generation
4 from MadGraphControl.MadGraphUtilsHelpers import get_physics_short
5 
6 phys_short = get_physics_short()
7 
8 if '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
12 if evt_multiplier>0:
13  if runArgs.maxEvents>0:
14  nevts=runArgs.maxEvents*evt_multiplier
15  else:
16  nevts=evgenConfig.nEventsPerJob*evt_multiplier
17 else:
18  # Sensible default
19  nevts=evgenConfig.nEventsPerJob*2.
20 run_settings.update({'nevents':int(nevts)})
21 
22 # Only needed for something non-standard (not 1/4 heavy mass)
23 if ktdurham is not None:
24  run_settings.update({'ktdurham':ktdurham})
25 
26 if flavourScheme not in [4,5]:
27  raise RuntimeError('flavourScheme must be 4 or 5.')
28 
29 if 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
34 else:
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
57 if '_msup' in phys_short:
58  syst_mod='msup'
59 elif '_msdw' in phys_short:
60  syst_mod='msdw'
61 if 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
65 if 'mass' in [x.lower() for x in param_blocks]:
66  raise RuntimeError('Do not provide masses in param_blocks; use the masses variable instead')
67 param_blocks['MASS']=masses
68 # Add decays in if needed
69 if len(decays)>0: param_blocks['DECAY']=decays
70 argdict = {'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
86 if 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 
90 else:
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
130 
131 # Pythia8 setup for matching if necessary
132 PYTHIA8_nJetMax=max([l.count('j') for l in process.split('\n')])
133 njets_min=min([l.count('j') for l in process.split('\n') if 'generate ' in l or 'add process' in l])
134 if 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 #--------------------------------------------------------------
155 evgenConfig.keywords += ["SUSY"]
MadGraphUtils
python.JOsupport.check_reset_proc_number
def check_reset_proc_number(opts)
Definition: JOsupport.py:23
python.SUSY_Helpers.SUSY_process
str SUSY_process(str process='')
Definition: SUSY_Helpers.py:127
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
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:1702
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.MadGraphUtils.arrange_output
def arrange_output(process_dir=MADGRAPH_GRIDPACK_LOCATION, lhe_version=None, saveProcDir=False, runArgs=None, fixEventWeightsForBridgeMode=False)
Definition: MadGraphUtils.py:1178
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:1580
python.MadGraphUtils.new_process
def new_process(process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False)
Definition: MadGraphUtils.py:214
python.SUSY_Helpers.SUSY_Generation
float SUSY_Generation(RunArguments|None runArgs=None, str|None process=None, str|None plugin=None, str|None syst_mod=None, bool keepOutput=False, str|None param_card=None, bool writeGridpack=False, str|None madspin_card=None, dict run_settings={}, dict params={}, bool fixEventWeightsForBridgeMode=False, bool add_lifetimes_lhe=False, bool usePMGSettings=True)
Definition: SUSY_Helpers.py:162
python.Include.include
include
Definition: Include.py:318
beamspotman.dir
string dir
Definition: beamspotman.py:621
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
python.MadGraphUtils.add_madspin
def add_madspin(madspin_card=None, process_dir=MADGRAPH_GRIDPACK_LOCATION)
Definition: MadGraphUtils.py:1035
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.JOsupport.get_physics_short
def get_physics_short()
Definition: JOsupport.py:12
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65