~maddevelopers/mg5amcnlo/2.7.4_array

« back to all changes in this revision

Viewing changes to MadSpin/interface_madspin.py

  • Committer: olivier-mattelaer
  • Date: 2019-10-16 11:38:38 UTC
  • mfrom: (282.1.28 2.6.7)
  • Revision ID: olivier-mattelaer-20191016113838-6u4j5u3hn06rq2wc
pass to 2.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1408
1408
                    if name not in self.list_branches or len(self.list_branches[name]) == 0:
1409
1409
                        continue
1410
1410
                    raise self.InvalidCmd("The onshell mode of MadSpin does not support event files where events do not *all* share the same set of final state particles to be decayed.")
 
1411
 
1411
1412
        self.branching_ratio = br
1412
1413
        self.efficiency = 1
1413
1414
        self.cross, self.error = self.banner.get_cross(witherror=True)
1425
1426
        #4. determine the maxwgt
1426
1427
        maxwgt = self.get_maxwgt_for_onshell(orig_lhe, evt_decayfile)
1427
1428
        
1428
 
        
1429
1429
        #5. generate the decay 
1430
1430
        orig_lhe.seek(0)
1431
1431
        output_lhe = lhe_parser.EventFile(orig_lhe.name.replace('.lhe', '_decayed.lhe'), 'w')
1539
1539
        # event_decay is a dict pdg -> list of event file (contain the decay)
1540
1540
        
1541
1541
        
 
1542
        if self.options['ms_dir'] and os.path.exists(pjoin(self.options['ms_dir'], 'max_wgt')):
 
1543
            return float(open(pjoin(self.options['ms_dir'], 'max_wgt'),'r').read())
 
1544
        
1542
1545
        nevents = self.options['Nevents_for_max_weigth']
1543
1546
        if nevents == 0 :
1544
1547
            nevents = 75
1548
1551
        logger.info("*****************************")
1549
1552
        logger.info("Probing the first %s events with %s phase space points" % (nevents, self.options['max_weight_ps_point']))
1550
1553
 
1551
 
 
1552
1554
        self.efficiency = 1. / self.options['max_weight_ps_point']
1553
1555
        start = time.time()
1554
1556
        for i in range(nevents):
1561
1563
                base_event = base_event[0]
1562
1564
            for j in range(self.options['max_weight_ps_point']):
1563
1565
                decays = self.get_decay_from_file(base_event, evt_decayfile, nevents-i)   
1564
 
                #carefull base_event is modified by the following function                  
 
1566
                #carefull base_event is modified by the following function 
1565
1567
                _, wgt = self.get_onshell_evt_and_wgt(base_event, decays)
1566
1568
                maxwgt = max(wgt, maxwgt)
1567
1569
            all_maxwgt.append(maxwgt)
1581
1583
                
1582
1584
            if all_maxwgt[1] > base_max_weight:
1583
1585
                base_max_weight = 1.05 * all_maxwgt[1]
 
1586
        if self.options['ms_dir']:
 
1587
            open(pjoin(self.options['ms_dir'], 'max_wgt'),'w').write(str(base_max_weight))
1584
1588
        return base_max_weight
1585
1589
            
1586
1590
            
1602
1606
            raise
1603
1607
        import copy
1604
1608
        
1605
 
        
1606
1609
        if hasattr(production, 'me_wgt'):
1607
1610
            production_me = production.me_wgt
1608
1611
        else:
1609
1612
            production_me = self.calculate_matrix_element(production)
1610
1613
            production.me_wgt = production_me
1611
 
            
1612
1614
        decay_me = 1.0
1613
1615
        for pdg in decays:
1614
1616
            for dec in decays[pdg]:
1636
1638
            final = tuple(-i for i in final)
1637
1639
            tag = (init, final)
1638
1640
            orig_order = self.all_me[tag]['order']
1639
 
            
1640
1641
        pdir = self.all_me[tag]['pdir']
1641
1642
        if pdir in self.all_f2py:
1642
1643
            p = event.get_momenta(orig_order)
1651
1652
            
1652
1653
            mymod = __import__("%s.matrix2py" % (pdir))
1653
1654
            reload(mymod)
1654
 
            mymod = getattr(mymod, 'matrix2py')  
 
1655
            mymod = getattr(mymod, 'matrix2py')
1655
1656
            with misc.chdir(pjoin(self.path_me, 'madspin_me', 'SubProcesses', pdir)):
1656
1657
                with misc.stdchannel_redirected(sys.stdout, os.devnull):
1657
 
                    mymod.initialisemodel(pjoin(self.path_me, 'Cards','param_card.dat'))
1658
 
            self.all_f2py[pdir] = mymod.get_value  
 
1658
                    if not os.path.exists(pjoin(self.path_me, 'Cards','param_card.dat')) and \
 
1659
                            os.path.exists(pjoin(self.path_me,'param_card.dat')):
 
1660
                        mymod.initialisemodel(pjoin(self.path_me,'param_card.dat'))
 
1661
                    else:
 
1662
                        mymod.initialisemodel(pjoin(self.path_me, 'Cards','param_card.dat'))
 
1663
            self.all_f2py[pdir] = mymod.get_value 
1659
1664
            return self.calculate_matrix_element(event)
1660
1665
        
1661
1666