Package madgraph :: Package fks :: Module fks_common
[hide private]
[frames] | no frames]

Source Code for Module madgraph.fks.fks_common

  1  ################################################################################ 
  2  # 
  3  # Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors 
  4  # 
  5  # This file is a part of the MadGraph5_aMC@NLO project, an application which  
  6  # automatically generates Feynman diagrams and matrix elements for arbitrary 
  7  # high-energy processes in the Standard Model and beyond. 
  8  # 
  9  # It is subject to the MadGraph5_aMC@NLO license which should accompany this  
 10  # distribution. 
 11  # 
 12  # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 
 13  # 
 14  ################################################################################ 
 15   
 16  """Definitions of the objects needed both for MadFKS from real  
 17  and MadFKS from born""" 
 18   
 19  import madgraph.core.base_objects as MG 
 20  import madgraph.core.helas_objects as helas_objects 
 21  import madgraph.core.diagram_generation as diagram_generation 
 22  import madgraph.core.color_amp as color_amp 
 23  import madgraph.core.color_algebra as color_algebra 
 24  from operator import itemgetter 
 25  import copy 
 26  import logging 
 27  import array 
 28  import fractions 
29 30 31 32 -class FKSProcessError(Exception):
33 """Exception for MadFKS""" 34 pass
35
36 37 -class FKSDiagramTag(diagram_generation.DiagramTag): #test written
38 """Modified diagram tags to be used to link born and real configurations. 39 """ 40 41 @staticmethod 48 220
221 222 223 -def find_orders(amp): #test_written
224 """Takes an amplitude as input, and returns a dictionary with the 225 orders of the couplings. 226 """ 227 assert isinstance(amp, diagram_generation.Amplitude) 228 orders = {} 229 for diag in amp.get('diagrams'): 230 for order, value in diag.get('orders').items(): 231 if value != 0 or order in amp['process']['orders'].keys(): 232 try: 233 orders[order] = max(orders[order], value) 234 except KeyError: 235 orders[order] = value 236 return orders 237
238 239 -def find_splittings(leg, model, dict, pert='QCD'): #test written
240 """Finds the possible splittings corresponding to leg 241 """ 242 if dict == {}: 243 dict = find_pert_particles_interactions(model, pert) 244 splittings = [] 245 #check that the leg is a qcd leg 246 247 if leg.get('id') in dict['pert_particles']: 248 part = model.get('particle_dict')[leg.get('id')] 249 antipart = model.get('particle_dict')[part.get_anti_pdg_code()] 250 for ii in dict['interactions']: 251 #check which interactions contain leg and at least one soft particles: 252 parts = copy.deepcopy(ii['particles']) 253 nsoft = 0 254 if part in parts: 255 #pops the ANTI-particle of part from the interaction 256 parts.pop(parts.index(antipart)) 257 for p in parts: 258 if p.get_pdg_code() in dict['soft_particles']: 259 nsoft += 1 260 if nsoft >= 1: 261 splittings.extend(split_leg(leg, parts, model)) 262 return splittings 263
264 265 -def split_leg(leg, parts, model): #test written
266 """Splits the leg into parts, and returns the two new legs. 267 """ 268 #for an outgoing leg take the antiparticles 269 split = [] 270 #for a final state particle one can have only a splitting 271 if leg['state'] : 272 split.append([]) 273 for part in parts: 274 split[-1].append(to_fks_leg({'state': True, \ 275 'id': part.get_pdg_code()},model)) 276 ij_final(split[-1]) 277 #while for an initial state particle one can have two splittings 278 # if the two partons are different 279 else: 280 if parts[0] != parts[1]: 281 for part in parts: 282 cparts = copy.deepcopy(parts) 283 split.append([\ 284 to_fks_leg({'state': False, 285 'id': cparts.pop(cparts.index(part)).get_pdg_code(), 286 'fks': 'j'}, model), 287 to_fks_leg({'state': True, 288 'id': cparts[0].get_anti_pdg_code(), 289 'fks': 'i'}, model)\ 290 ]) 291 else: 292 split.append([\ 293 to_fks_leg({'state': False, 294 'id': parts[0].get_pdg_code(), 295 'fks': 'j'}, model), 296 to_fks_leg({'state': True, 297 'id': parts[1].get_anti_pdg_code(), 298 'fks': 'i'}, model)]) 299 return split 300
301 302 -def ij_final(pair):
303 """given a pair of legs in the final state, assigns the i/j fks id 304 NOTE: the j partons is always put before the i one 305 """ 306 #if a massless bosonic particle is in the pair, it is i 307 #else by convention the anti-particle is labeled i 308 #the order of the splitting is [ j, i] 309 if len(pair) == 2: 310 for i in range(len(pair)): 311 set = 0 312 if (pair[i]['massless'] and pair[i]['self_antipart']) or \ 313 (not pair[i]['is_part'] and pair[1-i]['is_part'] and\ 314 (pair[i]['spin']+pair[1-i]['spin'])%2==0) and not set: 315 pair[i]['fks'] = 'i' 316 pair[1-i]['fks'] = 'j' 317 #check that first j then i 318 if i < 1 - i: 319 pair.reverse() 320 set = 1
321
322 -def insert_legs(leglist_orig, leg, split,pert='QCD'):
323 """Returns a new leglist with leg splitted into split. 324 The convention is to remove leg ij, replace it with leg j, and put 325 i at the end of the group of legs with the same color(charge) representation 326 """ 327 if pert =='QCD': 328 color = 'color' 329 elif pert == 'QED': 330 color = 'charge' 331 else: 332 raise FKSProcessError, "Only QCD or QED is allowed not %s" % pert 333 # the deepcopy statement is crucial 334 leglist = FKSLegList(copy.deepcopy(leglist_orig)) 335 #find the position of the first final state leg 336 for i in range(len(leglist)): 337 if leglist[-i - 1].get('state'): 338 firstfinal = len(leglist) - i - 1 339 # replace leg with leg_j (split[0]) 340 leglist[leglist.index(leg)] = split[0] 341 # and find where to insert i (split[1]) 342 col_maxindex = {} 343 mass_col_maxindex = {} 344 for col in set([l[color] for l in leglist[firstfinal:] if l['massless']]): 345 col_maxindex[col] = max([0] + [leglist.index(l) for l in leglist[firstfinal:]\ 346 if l[color] == col and l['massless']]) 347 for col in set([abs(l[color]) for l in leglist[firstfinal:] if not l['massless']]): 348 mass_col_maxindex[col] = max([0] + [leglist.index(l) for l in leglist[firstfinal:]\ 349 if abs(l[color]) == col and not l['massless']]) 350 #no need to keep info on particles with color > i 351 if pert == 'QCD': 352 for col in copy.copy(col_maxindex.keys()): 353 if abs(col) > abs(split[1][color]): 354 del col_maxindex[col] 355 ### for col in copy.copy(mass_col_maxindex.keys()): 356 ### if abs(col) > abs(split[1][color]): 357 ### del mass_col_maxindex[col] 358 #also remove antiquarks if i is a quark or a fermion 359 if split[1]['is_part'] and not split[1]['self_antipart']: 360 # In old MADFKS5, the line below was used instead. It is however equivalent in principle. 361 # We can remove this comment and the line below altogether after validation and complete 362 # merge of the EW branch in aMC@NLO trunk. 363 #if split[1][color] > 0: 364 try: 365 del col_maxindex[-split[1][color]] 366 except KeyError: 367 pass 368 #so now the maximum of the max_col entries should be the position to insert leg i 369 leglist.insert(max(col_maxindex.values() + mass_col_maxindex.values() + [firstfinal - 1] ) + 1, split[1]) 370 ### leglist.insert(max(col_maxindex.values() + [firstfinal - 1] ) + 1, split[1]) 371 # for sleg in split: 372 # leglist.insert(i, sleg) 373 # #keep track of the number for initial state legs 374 # #if not sleg.get('state') and not leg.get('state'): 375 # leglist[i]['number'] = leg['number'] 376 # i += 1 377 # if i < firstfinal: 378 # i = firstfinal 379 # 380 # leglist.sort() 381 for i, leg in enumerate(leglist): 382 leg['number'] = i + 1 383 return leglist
384
385 386 -def combine_ij( i, j, model, dict, pert='QCD'): #test written
387 """checks whether FKSlegs i and j can be combined together in the given model 388 and with given perturbation order and if so combines them into ij. 389 If dict is empty it is initialized with find_pert_particles_interactions 390 """ 391 if dict == {}: 392 dict = find_pert_particles_interactions(model, pert) 393 ij = [] 394 num = copy.copy(min(i.get('number'), j.get('number'))) 395 396 # we do not want j being a massless vector unless also i is or j is initial 397 not_double_counting = (j.get('spin') == 3 and j.get('massless') and 398 i.get('spin') == 3 and i.get('massless')) or \ 399 j.get('spin') != 3 or not j.get('massless') or \ 400 not j.get('state') 401 402 #if i and j are a final state particle and antiparticle pair, 403 # then we want i to be antipart and j to be 404 if j.get('state') and j.get('id') == - i.get('id'): 405 not_double_counting = not_double_counting and j.get('id') >0 406 407 if i.get('id') in dict['soft_particles'] and \ 408 j.get('id') in dict['pert_particles'] and \ 409 i.get('state') and not_double_counting: 410 for int in dict['interactions']: 411 parts= copy.copy(int['particles']) 412 #remove i 413 try: 414 parts.remove(model.get('particle_dict')[i.get('id')]) 415 except ValueError: 416 continue 417 418 #remove j if final state, anti j if initial state 419 if j.get('state'): 420 j_id = j.get('id') 421 else: 422 j_id = model.get('particle_dict')[j.get('id')].get_anti_pdg_code() 423 try: 424 parts.remove(model.get('particle_dict')[j_id]) 425 except ValueError: 426 continue 427 428 #ij is what remains if j is initial, the anti of if j is final 429 if j.get('state'): 430 ij.append(MG.Leg({ 431 'id': parts[0].get_anti_pdg_code(), 432 'state': True, 433 'number': num})) 434 else: 435 ij.append(MG.Leg({ 436 'id': parts[0].get_pdg_code(), 437 'state': False, 438 'number': num})) 439 return to_fks_legs(ij, model) 440
441 442 -def find_pert_particles_interactions(model, pert_order = 'QCD'): #test written
443 """given a model and pert_order, returns a dictionary with as entries: 444 --interactions : the interactions of order pert_order 445 --pert_particles : pdgs of particles taking part to interactions 446 --soft_particles : pdgs of massless particles in pert_particles 447 """ 448 #ghost_list = [82, -82] # make sure ghost_list is non-empty 449 ghost_list = [] 450 ghost_list += [ p.get_pdg_code() for p in model.get('particles') if p.get('ghost')] 451 qcd_inter = MG.InteractionList() 452 pert_parts = [] 453 soft_parts = [] 454 for i, ii in model.get('interaction_dict').items(): 455 # i want interections of pert_order: 1 (from LO to NLO), 456 # without any other orders 457 if ii.get('orders') == {pert_order:1} and len(ii['particles']) == 3 : 458 masslist = [p.get('mass').lower() for p in ii['particles']] 459 # check that there is at least a massless particle, and that the 460 # remaining ones have the same mass 461 # (otherwise the real emission final state will not be degenerate 462 # with the born one 463 try: 464 masslist.remove('zero') 465 except ValueError: 466 continue 467 if len(set(masslist)) == 1 and not \ 468 any( [ p.get_pdg_code() in ghost_list for p in ii['particles']]) : 469 qcd_inter.append(ii) 470 for pp in ii['particles']: 471 pert_parts.append(pp.get_pdg_code()) 472 if pp['mass'].lower() == 'zero': 473 soft_parts.append(pp.get_pdg_code()) 474 475 return {'interactions': sorted(qcd_inter), 476 'pert_particles': sorted(set(pert_parts)), 477 'soft_particles': sorted(set(soft_parts))} 478 481 """insert the color links in col_obj: returns a list of dictionaries 482 (one for each link) with the following entries: 483 --link: the numbers of the linked legs 484 --link_basis: the linked color basis 485 --link_matrix: the color matrix created from the original basis and the linked one 486 """ 487 assert isinstance(col_basis, color_amp.ColorBasis) 488 assert isinstance(col_obj, list) 489 result =[] 490 for link in links: 491 this = {} 492 #define the link 493 l =[] 494 for leg in link['legs']: 495 l.append(leg.get('number')) 496 this['link'] = l 497 498 #replace the indices in col_obj of the linked legs according to 499 # link['replacements'] 500 # and extend-> product the color strings 501 502 this_col_obj = [] 503 for old_dict in col_obj: 504 new_dict = dict(old_dict) 505 for k, string in new_dict.items(): 506 new_dict[k] = string.create_copy() 507 for col in new_dict[k]: 508 for ind in col: 509 for pair in link['replacements']: 510 if ind == pair[0]: 511 col[col.index(ind)] = pair[1] 512 new_dict[k].product(link['string']) 513 this_col_obj.append(new_dict) 514 basis_link = color_amp.ColorBasis() 515 for ind, new_dict in enumerate(this_col_obj): 516 basis_link.update_color_basis(new_dict, ind) 517 518 this['link_basis'] = basis_link 519 this['link_matrix'] = color_amp.ColorMatrix(col_basis,basis_link) 520 result.append(this) 521 basis_orig = color_amp.ColorBasis() 522 for ind, new_dict in enumerate(col_obj): 523 basis_orig.update_color_basis(new_dict, ind) 524 525 for link in result: 526 link['orig_basis'] = basis_orig 527 return result 528 532 """Finds all the possible color(charge) links between any 533 two legs of the born. 534 If symm is true, only half of the color links are generated, those 535 for which leg1['number'] <= leg2['number'] 536 """ 537 if pert == 'QCD': 538 color = 'color' 539 zero = 1 540 elif pert == 'QED': 541 color = 'charge' 542 zero = 0. 543 else: 544 raise FKSProcessError,"Only QCD or QED is allowed not %s" % pert 545 color_links = [] 546 for leg1 in leglist: 547 for leg2 in leglist: 548 #legs must be colored(charged) and different, unless massive 549 if (leg1.get(color) != zero and leg2.get(color) != zero) \ 550 and (leg1 != leg2 or not leg1.get('massless')): 551 if not symm or leg1['number'] <= leg2['number']: 552 col_dict = legs_to_color_link_string(leg1,leg2,pert = pert) 553 color_links.append({ 554 'legs': [leg1, leg2], 555 'string': col_dict['string'], 556 'replacements': col_dict['replacements']}) 557 558 return color_links 559 562 """given two FKSlegs, returns a dictionary containing: 563 --string: the color link between the two particles, to be appended to 564 the old color string 565 extra minus or 1/2 factor are included as it was done in MadDipole 566 --replacements: a pair of lists containing the replacements of the color 567 indices in the old string to match the link 568 """ 569 #the second-to-last index of the t is the triplet, 570 # the last is the anti-triplet 571 572 legs = FKSLegList([leg1, leg2]) 573 dict = {} 574 min_index = -3000 575 iglu = min_index*2 576 string = color_algebra.ColorString() 577 replacements = [] 578 if pert == 'QCD': 579 if leg1 != leg2: 580 for leg in legs: 581 min_index -= 1 582 num = leg.get('number') 583 replacements.append([num, min_index]) 584 icol = 1 585 if not leg.get('state'): 586 icol = - 1 587 if leg.get('color') * icol == 3: 588 string.product(color_algebra.ColorString([ 589 color_algebra.T(iglu, num, min_index)])) 590 string.coeff = string.coeff * (-1) 591 elif leg.get('color') * icol == - 3: 592 string.product(color_algebra.ColorString([ 593 color_algebra.T(iglu, min_index, num)])) 594 elif leg.get('color') == 8: 595 string.product(color_algebra.ColorString(init_list = [ 596 color_algebra.f(min_index,iglu,num)], 597 is_imaginary =True)) 598 599 else: 600 icol = 1 601 if not leg1.get('state'): 602 icol = - 1 603 num = leg1.get('number') 604 replacements.append([num, min_index -1]) 605 if leg1.get('color') * icol == 3: 606 string = color_algebra.ColorString( 607 [color_algebra.T(iglu, iglu, num, min_index -1)]) 608 elif leg1.get('color') * icol == - 3: 609 string = color_algebra.ColorString( 610 [color_algebra.T(iglu, iglu, min_index-1, num)]) 611 elif leg1.get('color') == 8: 612 string = color_algebra.ColorString(init_list = [ 613 color_algebra.f(min_index-1,iglu,min_index)], 614 is_imaginary =True) 615 string.product(color_algebra.ColorString(init_list = [ 616 color_algebra.f(min_index,iglu,num)], 617 is_imaginary =True)) 618 string.coeff = string.coeff * fractions.Fraction(1, 2) 619 620 elif pert == 'QED': 621 for leg in legs: 622 # make it a fraction 623 string.coeff = string.coeff * fractions.Fraction(leg['charge']*3.)*\ 624 fractions.Fraction(1,3) 625 else: 626 raise FKSProcessError,"Only QCD or QED is allowed not %s"% pert 627 628 dict['replacements'] = replacements 629 dict['string'] = string 630 return dict 631
632 633 -def sort_proc(process,pert = 'QCD'):
634 """Given a process, this function returns the same process 635 but with sorted FKSLegs. 636 """ 637 leglist = to_fks_legs(process.get('legs'), process.get('model')) 638 leglist.sort(pert = pert) 639 for n, leg in enumerate(leglist): 640 leg['number'] = n + 1 641 process['legs'] = leglist 642 # add this line to pass ./test_managers.py -p A test_check_ppzjj 643 process['legs_with_decays']=MG.LegList() 644 645 return process
646
647 648 -def to_leg(fksleg):
649 """Given a FKSLeg, returns the original Leg. 650 """ 651 leg = MG.Leg( \ 652 {'id': fksleg.get('id'), 653 'number': fksleg.get('number'), 654 'state': fksleg.get('state'), 655 'from_group': fksleg.get('from_group'), 656 }) 657 return leg
658
659 660 -def to_legs(fkslegs):
661 """Given a FKSLegList, returns the corresponding LegList. 662 """ 663 leglist = MG.LegList() 664 for leg in fkslegs: 665 leglist.append(to_leg(leg)) 666 return leglist
667
668 669 -def to_fks_leg(leg, model): #test written
670 """Given a leg or a dict with Leg entries, 671 adds color, spin and massless entries, according to model""" 672 fksleg = FKSLeg(leg) 673 part = model.get('particle_dict')[leg['id']] 674 fksleg['color'] = part.get_color() 675 fksleg['charge'] = part.get_charge() 676 fksleg['massless'] = part['mass'].lower() == 'zero' 677 fksleg['spin'] = part.get('spin') 678 fksleg['is_part'] = part.get('is_part') 679 fksleg['self_antipart'] = part.get('self_antipart') 680 return fksleg 681
682 683 -def to_fks_legs(leglist, model): #test written
684 """given leglist, sets color and massless entries according to the model 685 variable. 686 return a FKSLeglist""" 687 fkslegs = FKSLegList() 688 for leg in leglist: 689 fkslegs.append(to_fks_leg(leg, model)) 690 return fkslegs 691
692 693 -class FKSLegList(MG.LegList):
694 """list of FKSLegs""" 695
696 - def is_valid_element(self, obj):
697 """Test if object obj is a valid FKSLeg for the list.""" 698 return isinstance(obj, FKSLeg)
699
700 - def sort(self,pert='QCD'):
701 """Sorting routine, sorting chosen to be optimal for madfks""" 702 sorted_leglist = FKSLegList() 703 #find initial state legs 704 initial_legs = FKSLegList([l for l in copy.copy(self) if not l['state']]) 705 #find final state legs 706 final_legs = FKSLegList([l for l in copy.copy(self) if l['state']]) 707 if len(initial_legs) == 1: 708 sorted_leglist.extend(initial_legs) 709 elif len(initial_legs) == 2: 710 if initial_legs[0]['number'] > initial_legs[1]['number']: 711 initial_legs.reverse() 712 sorted_leglist.extend(initial_legs) 713 else: 714 raise FKSProcessError('Too many initial legs') 715 #find color representations 716 if pert == 'QCD': 717 color = 'color' 718 zero = 1 719 elif pert == 'QED': 720 color = 'charge' 721 zero = 0. 722 else: 723 raise FKSProcessError,"Only QCD and QED is allowed not %s"% pert 724 colors = sorted(set([abs(l[color]) for l in final_legs])) 725 # first put massless particles, without any rearrangment 726 if zero in colors: 727 sorted_leglist.extend(sorted(\ 728 [l for l in final_legs if l[color] == zero], key = itemgetter('number'))) 729 colors.remove(zero) 730 731 #now go for colored legs, put first all massive legs, then all massless legs 732 massless_dict = {} 733 massive_dict = {} 734 for col in colors: 735 col_legs = FKSLegList([l for l in final_legs if abs(l[color]) == col]) 736 #find massive and massless legs in this color repr 737 massive_dict[col] = [l for l in col_legs if not l['massless']] 738 massless_dict[col] = [l for l in col_legs if l['massless']] 739 740 for i_m, dict in enumerate([massive_dict, massless_dict]): 741 for col in colors: 742 # sorting may be different for massive and massless particles 743 # for color singlets, do not change order 744 if col == zero: 745 keys = [itemgetter('number'), itemgetter('number')] 746 reversing = False 747 else: 748 keys = [itemgetter('id'), itemgetter('id')] 749 reversing = True 750 751 init_pdg_legs = [] 752 list = dict[col] 753 if len(initial_legs) == 2: 754 #put first legs which have the same abs(pdg) of the initial ones 755 for i in range(len(set([ abs(l['id']) for l in initial_legs]))): 756 pdg = abs(initial_legs[i]['id']) 757 init_pdg_legs = [l for l in list if abs(l['id']) == pdg] 758 if init_pdg_legs: 759 # sort in order to put first quarks then antiparticles, 760 # and to put fks partons as n j i 761 init_pdg_legs.sort(key = keys[i_m], reverse=reversing) 762 sorted_leglist.extend(FKSLegList(init_pdg_legs)) 763 764 init_pdgs = [ abs(l['id']) for l in initial_legs] 765 other_legs = [l for l in list if not abs(l['id']) in init_pdgs] 766 other_legs.sort(key = keys[i_m], reverse=reversing) 767 sorted_leglist.extend(FKSLegList(other_legs)) 768 else: 769 list.sort(key = keys[i_m], reverse=reversing) 770 sorted_leglist.extend(FKSLegList(list)) 771 772 for i, l in enumerate(sorted_leglist): 773 self[i] = l
774
775 776 777 -class FKSLeg(MG.Leg):
778 """a class for FKS legs: it inherits from the ususal leg class, with two 779 extra keys in the dictionary: 780 -'fks', whose value can be 'i', 'j' or 'n' (for "normal" particles) 781 -'color', which gives the color of the leg 782 -'charge', which gives the charge of the leg 783 -'massless', boolean, true if leg is massless 784 -'spin' which gives the spin of leg 785 -'is_part', boolean, true if leg is an particle 786 -'self_antipart', boolean, true if leg is an self-conjugated particle 787 """ 788
789 - def default_setup(self):
790 """Default values for all properties""" 791 super(FKSLeg, self).default_setup() 792 793 self['fks'] = 'n' 794 self['color'] = 0 795 self['charge'] = 0. 796 self['massless'] = True 797 self['spin'] = 0 798 self['is_part'] = True 799 self['self_antipart'] = False
800
801 - def get_sorted_keys(self):
802 """Return particle property names as a nicely sorted list.""" 803 keys = super(FKSLeg, self).get_sorted_keys() 804 keys += ['fks', 'color','charge', 'massless', 'spin','is_part','self_antipart'] 805 return keys
806 807
808 - def filter(self, name, value):
809 """Filter for valid leg property values.""" 810 811 if name == 'fks': 812 if not isinstance(value, str): 813 raise self.PhysicsObjectError, \ 814 "%s is not a valid string for leg fks flag" \ 815 % str(value) 816 if name in ['color', 'spin']: 817 if not isinstance(value, int): 818 raise self.PhysicsObjectError, \ 819 "%s is not a valid leg %s flag" % \ 820 str(value),name 821 822 if name in ['massless','self_antipart','is_part']: 823 if not isinstance(value, bool): 824 raise self.PhysicsObjectError, \ 825 "%s is not a valid boolean for leg flag %s" % \ 826 str(value),name 827 if name is 'charge': 828 if not isinstance(value, float): 829 raise self.PhysicsObjectError, \ 830 "%s is not a valid float for leg flag charge" \ 831 % str(value) 832 return super(FKSLeg,self).filter(name, value)
833