~maddevelopers/mg5amcnlo/WWW5_caching

« back to all changes in this revision

Viewing changes to users/mardelcourt/PROC_242195/PROC_242195/bin/internal/Gridpack/TheChopper-pl

  • Committer: John Doe
  • Date: 2013-03-25 20:27:02 UTC
  • Revision ID: john.doe@gmail.com-20130325202702-5sk3t1r8h33ca4p4
first clean version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#------------------------------------------------------------
 
3
# Simple script to chop out sub-processes  which have a small
 
4
# impact on the cross section, in the grid pack.
 
5
# This is meant to be run after the gridpack warming up run
 
6
# and before packing it up.
 
7
#
 
8
# The script should be run from the main directory of madevent
 
9
# and sits in the bin directory.
 
10
#
 
11
# This is still version 0, where no classes can be defined.
 
12
# However, the result is a script, chop_procs sitting in 
 
13
# SubProcesses, that can be edited by hand. 
 
14
#
 
15
# Author: Fabio Maltoni
 
16
# Date: 10/4/08
 
17
# Version: 0.1
 
18
#
 
19
# HISTORY
 
20
 
21
# 0.2 Fix bug in writing subproc.mg
 
22
#
 
23
# 0.1 Added the possibility to list SubProc IDs
 
24
#
 
25
# 0.0 Original
 
26
#
 
27
#------------------------------------------------------------
 
28
 
 
29
#------------------------------------------------------------
 
30
# Auxiliary Ordering function
 
31
#------------------------------------------------------------
 
32
 
 
33
    sub OrderInc {
 
34
     $all{$a} <=> $all{$b};
 
35
    };
 
36
 
 
37
#------------------------------------------------------------
 
38
# Input the chopping value. Example : 0.01 = 1%
 
39
#------------------------------------------------------------
 
40
 
 
41
    print "input chopping off value (e.g., 0.01=1% ):\n";
 
42
    $cutoff_lim=<STDIN>;
 
43
 
 
44
#------------------------------------------------------------
 
45
# Input the SubProcesses ids on which the script should run 
 
46
#------------------------------------------------------------
 
47
    
 
48
    print "Input SubProcesses ids to process (space separated):\n";
 
49
    @id_list=split('\s+',<STDIN>);
 
50
    
 
51
 
 
52
#------------------------------------------------------------
 
53
# Parse the form, look for known variables
 
54
#------------------------------------------------------------
 
55
 
 
56
   
 
57
    
 
58
    chdir("SubProcesses");
 
59
    open(SCRIPT,">chop_procs")  or die "Could not write chop_procs \n";
 
60
     
 
61
    foreach $id (@id_list) {
 
62
    
 
63
    print "\n\nNow processing SubProcesses with ID = $id\n";
 
64
    
 
65
    my @all_Pdirs = <P$id*>;
 
66
    my $xsec = 0;
 
67
    my $perc = 0;
 
68
    %all = ();
 
69
    %below = ();
 
70
    
 
71
    foreach $arg (@all_Pdirs) {
 
72
    chdir("$arg");
 
73
    open(RES,"<default_results.dat")  or die "Could not read default_results.dat\n";
 
74
    my $buff;
 
75
    my $number_read = read(RES,$buff,12);
 
76
    print "$arg has xsec $buff\n";
 
77
    $all{$arg} .= $buff;
 
78
    $xsec = $xsec + $buff;
 
79
    close(RES);
 
80
    chdir("..");
 
81
    };          
 
82
 
 
83
    print " total xsec for ID = $id : $xsec\n";
 
84
    $cutoff=$cutoff_lim*$xsec;
 
85
    print " cutoff for ID = $id : $cutoff \n";
 
86
 
 
87
 
 
88
#   now I have to order them and find those procs with fall
 
89
#   below xsec*cutoff.    
 
90
 
 
91
    $i=0;
 
92
    $integ[0]=0;
 
93
    print "Processes in order FOR ID = $id:\n";
 
94
    foreach $key (sort OrderInc (keys(%all))) {
 
95
    $integ[$i+1] = $integ[$i] + $all{$key};     
 
96
    if($integ[$i+1] < $cutoff) { 
 
97
        $below{$key} .= $all{$key};
 
98
        print "$integ[$i+1] : $all{$key} $key => below cutoff\n";}
 
99
    else {
 
100
        print "$integ[$i+1] : $all{$key} $key => above cutoff\n";}
 
101
    $i =$i + 1;
 
102
};
 
103
#
 
104
#  Now I move the corresponding procs out of the way
 
105
#
 
106
    print "The following SubProcess will be tagged to be removed:\n";
 
107
    foreach $key (keys(%below)){
 
108
        print "$key ";
 
109
        print SCRIPT "mv $key XXX$key \# $below{$key}\n";
 
110
#        system("mv $key XXX$key "); 
 
111
    };
 
112
#       print SCRIPT "ls -d P$id* >subproc.mg\n";
 
113
#        system("ls -d P* >subproc.mg");  
 
114
 }
 
115
 print SCRIPT "ls -d P* >subproc.mg";  
 
116
 close(SCRIPT);
 
117
 system("chmod +x chop_procs");
 
118