~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to madgraph/madevent/sum_html.py

  • Committer: olivier-mattelaer
  • Date: 2020-08-21 09:16:56 UTC
  • mfrom: (284.2.24 python3)
  • Revision ID: olivier-mattelaer-20200821091656-iizux2mj94tkssuo
pass to 2.8.0 (and move to python3 branch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
################################################################################
15
15
from __future__ import division
 
16
from __future__ import absolute_import
16
17
import os
17
18
import math
18
19
import logging
19
20
import re
20
21
import xml.dom.minidom as minidom
 
22
from six.moves import range
21
23
 
22
24
logger = logging.getLogger('madevent.stdout') # -> stdout
23
25
 
79
81
            new_stats = [new_stats, ]
80
82
        elif isinstance(new_stats,list):
81
83
            if any(not isinstance(_,RunStatistics) for _ in new_stats):
82
 
                raise MadGraph5Error, "The 'new_stats' argument of the function "+\
 
84
                raise MadGraph5Error("The 'new_stats' argument of the function "+\
83
85
                        "'updtate_statistics' must be a (possibly list of) "+\
84
 
                                                       "RunStatistics instance."
 
86
                                                       "RunStatistics instance.")
85
87
 
86
88
        keys = set([])
87
89
        for stat in [self,]+new_stats:
280
282
        elif isinstance(filepath, file):
281
283
            finput = filepath
282
284
        else:
283
 
            raise Exception, "filepath should be a path or a file descriptor"
 
285
            raise Exception("filepath should be a path or a file descriptor")
284
286
        
285
287
        i=0
286
288
        found_xsec_line = False
311
313
                        if 'end code not correct' in line:
312
314
                            error_code = data[4]
313
315
                            log = pjoin(os.path.dirname(filepath), 'log.txt')
314
 
                            raise Exception, "Reported error: End code %s \n Full associated log: \n%s"\
315
 
                                  % (error_code, open(log).read())
 
316
                            raise Exception("Reported error: End code %s \n Full associated log: \n%s"\
 
317
                                  % (error_code, open(log).read()))
316
318
                        else:
317
319
                            log = pjoin(os.path.dirname(filepath), 'log.txt')
318
 
                            raise Exception, "Wrong formatting in results.dat: %s \n Full associated log: \n%s"\
319
 
                                %  (line, open(log).read())                        
 
320
                            raise Exception("Wrong formatting in results.dat: %s \n Full associated log: \n%s"\
 
321
                                %  (line, open(log).read()))                        
320
322
                if len(data) > 10:
321
323
                    self.maxwgt = data[10]
322
324
                if len(data) >12:
364
366
        if statistics_node:
365
367
            try:
366
368
                self.run_statistics.load_statistics(statistics_node[0])
367
 
            except ValueError, IndexError:
 
369
            except ValueError as IndexError:
368
370
                logger.warning('Fail to read run statistics from results.dat')
369
371
 
370
372
    def set_mfactor(self, value):
502
504
        """Compute iterations to have a chi-square on the stability of the 
503
505
        integral"""
504
506
 
505
 
        nb_iter = min([len(a.ysec_iter) for a in self], 0)
 
507
        #iter = [len(a.ysec_iter) for a in self]
 
508
        #if iter:
 
509
        #    nb_iter = min(iter)
 
510
        #else:
 
511
        #    nb_iter = 0 
 
512
        #nb_iter = misc.mmin([len(a.ysec_iter) for a in self], 0)
 
513
        #misc.sprint(nb_iter)
506
514
        # syncronize all iterations to a single one
507
515
        for oneresult in self:
508
 
            oneresult.change_iterations_number(nb_iter)
 
516
            oneresult.change_iterations_number(0)
509
517
            
510
518
        # compute value error for each iteration
511
 
        for i in range(nb_iter):
512
 
            value = [one.ysec_iter[i] for one in self]
513
 
            error = [one.yerr_iter[i]**2 for one in self]
514
 
            
515
 
            # store the value for the iteration
516
 
            self.ysec_iter.append(sum(value))
517
 
            self.yerr_iter.append(math.sqrt(sum(error)))
 
519
        #for i in range(nb_iter):
 
520
        #    value = [one.ysec_iter[i] for one in self]
 
521
        #    error = [one.yerr_iter[i]**2 for one in self]
 
522
        #    
 
523
        #   # store the value for the iteration
 
524
        #    raise Exception
 
525
        #    self.ysec_iter.append(sum(value))
 
526
        #    self.yerr_iter.append(math.sqrt(sum(error)))
518
527
    
519
528
       
520
529
    template_file = \
712
721
        P_comb = Combine_results(Pdir)
713
722
        
714
723
        if jobs:
715
 
            for job in filter(lambda j: j['p_dir'] in Pdir, jobs):
 
724
            for job in [j for j in jobs if j['p_dir'] in Pdir]:
716
725
                    P_comb.add_results(os.path.basename(job['dirname']),\
717
726
                                       pjoin(job['dirname'],'results.dat'))
718
727
        elif folder_names:
731
740
                            dir = folder.replace('*', '_G' + name)
732
741
                        P_comb.add_results(dir, pjoin(Pdir,dir,'results.dat'), mfactor)
733
742
                if jobs:
734
 
                    for job in filter(lambda j: j['p_dir'] == Pdir, jobs):
 
743
                    for job in [j for j in jobs if j['p_dir'] == Pdir]:
735
744
                        P_comb.add_results(os.path.basename(job['dirname']),\
736
745
                                       pjoin(job['dirname'],'results.dat'))
737
746
            except IOError:
745
754
                    else:
746
755
                        path = pjoin(G,'results.dat')
747
756
                    P_comb.add_results(os.path.basename(G), path, mfactors[G])
748
 
                
 
757
 
749
758
        P_comb.compute_values()
750
759
        all.append(P_comb)
751
760
    all.compute_values()