def __init__(self, model, output_path, wanted_lorentz=[], wanted_couplings=[], replace_dict={}): """ initialization of the objects """ self.model = model self.model_name = export_cpp.ProcessExporterCPP.get_model_name( model['name']) self.aloha_model = create_aloha.AbstractALOHAModel(self.model_name) self.dir_path = output_path self.default_replace_dict = dict(replace_dict) # List of needed ALOHA routines self.wanted_lorentz = wanted_lorentz self.wanted_couplings = wanted_couplings # For dependent couplings, only want to update the ones # actually used in each process. For other couplings and # parameters, just need a list of all. self.coups_dep = {} # name -> base_objects.ModelVariable self.coups_indep = [] # base_objects.ModelVariable self.params_dep = [] # base_objects.ModelVariable self.params_indep = [] # base_objects.ModelVariable self.p_to_cpp = None # Prepare parameters and couplings for writeout in C++ self.prepare_parameters() self.prepare_couplings(wanted_couplings)
def make_UFO_pkl(): """ """ file_cond = lambda p: os.path.exists( os.path.join(MG5DIR, 'models', p, 'particles.py')) #1. find UFO model: ufo_model = [ os.path.join(MG5DIR, 'models', p) for p in os.listdir(os.path.join(MG5DIR, 'models')) if file_cond(p) ] # model.pkl for model_path in ufo_model: start = time.time() print 'make model.pkl for %s :' % os.path.basename(model_path), #remove old pkl try: os.remove(os.path.join(model_path, 'model.pkl')) except: pass import_ufo.import_full_model(model_path) print '%2fs' % (time.time() - start) return # aloha routine for model_path in ufo_model: start = time.time() print 'make ALOHA for %s' % os.path.basename(model_path) #remove old pkl try: os.remove(os.path.join(model_path, 'aloha.pkl')) except: pass try: os.system('rm -rf %s &> /dev/null' % os.path.join(model_path, 'Fortran')) except: pass ufo_path, ufo_name = os.path.split(model_path) sys.path.insert(0, ufo_path) output_dir = os.path.join(model_path, 'Fortran') create_aloha.AbstractALOHAModel(ufo_name, write_dir=output_dir, format='Fortran') print 'done in %2fs' % (time.time() - start)
def test_run_python_matrix_element(self): """Test a complete running of a Python matrix element without writing any files""" # Import the SM sm_path = import_ufo.find_ufo_path('sm') model = import_ufo.import_model(sm_path) myleglist = base_objects.LegList() myleglist.append( base_objects.Leg({ 'id': -11, 'state': False, 'number': 1 })) myleglist.append( base_objects.Leg({ 'id': 11, 'state': False, 'number': 2 })) myleglist.append( base_objects.Leg({ 'id': 22, 'state': True, 'number': 3 })) myleglist.append( base_objects.Leg({ 'id': 22, 'state': True, 'number': 4 })) myleglist.append( base_objects.Leg({ 'id': 22, 'state': True, 'number': 5 })) myproc = base_objects.Process({'legs': myleglist, 'model': model}) myamplitude = diagram_generation.Amplitude({'process': myproc}) mymatrixelement = helas_objects.HelasMatrixElement(myamplitude) # Create only the needed aloha routines wanted_lorentz = mymatrixelement.get_used_lorentz() aloha_model = create_aloha.AbstractALOHAModel(model.get('name')) aloha_model.compute_subset(wanted_lorentz) # Write out the routines in Python aloha_routines = [] for routine in aloha_model.values(): aloha_routines.append(routine.write(output_dir = None, language = 'Python').\ replace('import wavefunctions', 'import aloha.template_files.wavefunctions as wavefunctions')) # Define the routines to be available globally for routine in aloha_routines: exec(routine, globals()) # Write the matrix element(s) in Python mypythonmodel = helas_call_writers.PythonUFOHelasCallWriter(\ model) exporter = export_python.ProcessExporterPython(\ mymatrixelement, mypythonmodel) matrix_methods = exporter.get_python_matrix_methods() # Calculate parameters and couplings full_model = model_reader.ModelReader(model) full_model.set_parameters_and_couplings() # Define a momentum p = [[ 0.5000000e+03, 0.0000000e+00, 0.0000000e+00, 0.5000000e+03, 0.0000000e+00 ], [ 0.5000000e+03, 0.0000000e+00, 0.0000000e+00, -0.5000000e+03, 0.0000000e+00 ], [ 0.4585788e+03, 0.1694532e+03, 0.3796537e+03, -0.1935025e+03, 0.6607249e-05 ], [ 0.3640666e+03, -0.1832987e+02, -0.3477043e+03, 0.1063496e+03, 0.7979012e-05 ], [ 0.1773546e+03, -0.1511234e+03, -0.3194936e+02, 0.8715287e+02, 0.1348699e-05 ]] # Evaluate the matrix element for the given momenta answer = 1.39189717257175028e-007 for process in matrix_methods.keys(): # Define Python matrix element for process exec(matrix_methods[process]) # Calculate the matrix element for the momentum p value = eval("Matrix_0_epem_aaa().smatrix(p, full_model)") self.assertTrue(abs(value-answer)/answer < 1e-6, "Value is: %.9e should be %.9e" % \ (abs(value), answer))