~maddevelopers/mg5amcnlo/color_ordering

« back to all changes in this revision

Viewing changes to madgraph/fks/fks_common.py

  • Committer: olivier-mattelaer
  • Date: 2021-02-21 11:03:42 UTC
  • mfrom: (50.85.73 madgraph5)
  • Revision ID: olivier-mattelaer-20210221110342-wn2nvdefctey5e0k
merge up to 2.8.0 --not python3 compatible

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
"""Definitions of the objects needed both for MadFKS from real 
17
17
and MadFKS from born"""
18
18
 
 
19
from __future__ import absolute_import
 
20
from __future__ import print_function
19
21
import madgraph.core.base_objects as MG
20
22
import madgraph.core.helas_objects as helas_objects
21
23
import madgraph.core.diagram_generation as diagram_generation
22
24
import madgraph.core.color_amp as color_amp
23
25
import madgraph.core.color_algebra as color_algebra
 
26
import madgraph.various.misc as misc
24
27
from operator import itemgetter
25
28
import copy
26
29
import logging
27
30
import array
28
31
import fractions
 
32
import six
 
33
from six.moves import range
29
34
    
30
35
    
31
36
    
191
196
 
192
197
    # and compare them
193
198
    if len(born_tags) != len(real_tags):
194
 
        print '\n'.join([str(r) for r in real_tags]) + '\n'
 
199
        print('\n'.join([str(r) for r in real_tags]) + '\n')
195
200
        raise FKSProcessError('Cannot map born/real configurations between \
196
201
                %s and %s (i,j=%d,%d): not same number of configurations: %d %d' % \
197
202
                (born_amp.get('process').nice_string().replace('Process:',''), 
209
214
            real_tags.remove(btag)
210
215
            good_diags.pop(ir)
211
216
        except ValueError:
212
 
            print real_tags, i, j, ij
213
 
            print '\n'.join( d['diagram'].nice_string() for d in good_diags)
 
217
            print(real_tags, i, j, ij)
 
218
            print('\n'.join( d['diagram'].nice_string() for d in good_diags))
214
219
            raise FKSProcessError('Linking %s to %s: could not link born diagram %s' % \
215
220
                 (born_amp.get('process').nice_string().replace('Process:',''), 
216
221
                  real_amp.get('process').nice_string().replace('Process:',''),
228
233
    orders = {}
229
234
    for diag in amp.get('diagrams'):
230
235
        for order, value in diag.get('orders').items():
231
 
            if value != 0 or order in amp['process']['orders'].keys():
 
236
            if value != 0 or order in list(amp['process']['orders'].keys()):
232
237
                try:
233
238
                    orders[order] = max(orders[order], value)
234
239
                except KeyError:
329
334
    elif pert == 'QED':
330
335
        color = 'charge'
331
336
    else:
332
 
        raise FKSProcessError, "Only QCD or QED is allowed not  %s" % pert
 
337
        raise FKSProcessError("Only QCD or QED is allowed not  %s" % pert)
333
338
    # the deepcopy statement is crucial
334
339
    leglist = FKSLegList(copy.deepcopy(leglist_orig))         
335
340
    #find the position of the first final state leg
349
354
                                             if abs(l[color]) == col and not l['massless']])
350
355
    #no need to keep info on particles with color > i
351
356
    if pert == 'QCD':
352
 
        for col in copy.copy(col_maxindex.keys()):
 
357
        for col in copy.copy(list(col_maxindex.keys())):
353
358
            if abs(col) > abs(split[1][color]):
354
359
                del col_maxindex[col]
355
360
###        for col in copy.copy(mass_col_maxindex.keys()):
366
371
        except KeyError:
367
372
            pass
368
373
    #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])
 
374
    leglist.insert(max(list(col_maxindex.values()) + list(mass_col_maxindex.values()) + [firstfinal - 1] ) + 1, split[1])
370
375
###    leglist.insert(max(col_maxindex.values() + [firstfinal - 1] ) + 1, split[1])
371
376
#    for sleg in split:            
372
377
#        leglist.insert(i, sleg)
486
491
                    if pp['mass'].lower() == 'zero':
487
492
                        soft_parts.append(pp.get_pdg_code())
488
493
 
489
 
    return {'interactions': sorted(qcd_inter), 
 
494
    return {'interactions': sorted(qcd_inter, key=misc.cmp_to_key(misc.dict_cmp)),
490
495
            'pert_particles': sorted(set(pert_parts)),
491
496
            'soft_particles': sorted(set(soft_parts))}    
492
497
 
555
560
        color = 'charge'
556
561
        zero = 0.
557
562
    else:
558
 
        raise FKSProcessError,"Only QCD or QED is allowed not %s" % pert
 
563
        raise FKSProcessError("Only QCD or QED is allowed not %s" % pert)
559
564
    color_links = []
560
565
    for leg1 in leglist:
561
566
        for leg2 in leglist:
637
642
            string.coeff = string.coeff * fractions.Fraction(leg['charge']*3.)*\
638
643
            fractions.Fraction(1,3)            
639
644
    else:
640
 
        raise FKSProcessError,"Only QCD or QED is allowed not %s"% pert
 
645
        raise FKSProcessError("Only QCD or QED is allowed not %s"% pert)
641
646
    
642
647
    dict['replacements'] = replacements
643
648
    dict['string'] = string  
735
740
            color = 'charge'
736
741
            zero = 0.
737
742
        else:
738
 
            raise FKSProcessError,"Only QCD and QED is allowed not %s"% pert
 
743
            raise FKSProcessError("Only QCD and QED is allowed not %s"% pert)
739
744
        colors = sorted(set([abs(l[color]) for l in final_legs]))
740
745
        # first put massless particles, without any rearrangment
741
746
        if zero in colors:
825
830
 
826
831
        if name == 'fks':
827
832
            if not isinstance(value, str):
828
 
                raise self.PhysicsObjectError, \
829
 
                        "%s is not a valid string for leg fks flag" \
830
 
                                                        % str(value)
 
833
                raise self.PhysicsObjectError("%s is not a valid string for leg fks flag" \
 
834
                                                        % str(value))
831
835
        if name in ['color', 'spin']:
832
836
            if not isinstance(value, int):
833
 
                raise self.PhysicsObjectError, \
834
 
                        "%s is not a valid leg %s flag" % \
835
 
                                                 str(value),name
 
837
                six.reraise(self.PhysicsObjectError, "%s is not a valid leg %s flag" % \
 
838
                                                 str(value), name)
836
839
                                                 
837
840
        if name in ['massless','self_antipart','is_part']:
838
841
            if not isinstance(value, bool):
839
 
                raise self.PhysicsObjectError, \
840
 
                        "%s is not a valid boolean for leg flag %s" % \
841
 
                                                                    str(value),name
842
 
        if name is 'charge':
 
842
                six.reraise(self.PhysicsObjectError, "%s is not a valid boolean for leg flag %s" % \
 
843
                                                                    str(value), name)
 
844
        if name == 'charge':
843
845
            if not isinstance(value, float):
844
 
                raise self.PhysicsObjectError, \
845
 
                    "%s is not a valid float for leg flag charge" \
846
 
                    % str(value)                                                           
 
846
                raise self.PhysicsObjectError("%s is not a valid float for leg flag charge" \
 
847
                    % str(value))                                                           
847
848
        return super(FKSLeg,self).filter(name, value)
848
849
    
849
850