15 |
|
|
16 |
|
printHelp () if $opt{"help"} || !$opt{"prefix"}; |
17 |
|
my $files = processArgs (\@ARGV); |
18 |
< |
my @rootFiles; |
19 |
< |
my @weights; |
18 |
> |
my %rootFiles; |
19 |
> |
my %weights; |
20 |
|
my $nGoodJobs = 0; |
21 |
|
my $nBadJobs = 0; |
22 |
|
my $counting = 0; |
45 |
|
if ($fileContents =~ m/return value/) |
46 |
|
{ |
47 |
|
$fileContents =~ s/.*\(return value ([^)]*)\).*/$1/g; |
48 |
< |
if ($fileContents != 0) |
49 |
< |
{ |
50 |
< |
$nGoodJobs++; |
51 |
< |
print "WARNING: Nonzero exit code for job $jobNumber. (return value $fileContents)\n"; |
52 |
< |
} |
48 |
> |
$nGoodJobs++; |
49 |
> |
print "WARNING: Nonzero exit code for job $jobNumber. (return value $fileContents)\n" if $fileContents != 0; |
50 |
|
$exitCodes{$dir}{$jobNumber} = $fileContents; |
51 |
|
$counting = 1; |
52 |
|
} |
78 |
|
{ |
79 |
|
my $jobNumber = $file; |
80 |
|
$jobNumber =~ s/^.*_([^_]*)\.root$/$1/; |
84 |
– |
#$badJob = defined $exitCodes{$dir} && defined $exitCodes{$dir}{$jobNumber} && $exitCodes{$dir}{$jobNumber}; |
81 |
|
$badJob = defined $signals{$dir} && defined $signals{$dir}{$jobNumber}; |
82 |
|
} |
83 |
|
next if $badJob; |
84 |
|
if ($file =~ m/^.*\.root$/) |
85 |
|
{ |
86 |
< |
push (@rootFiles, $file); |
87 |
< |
push (@weights, 1.0); |
86 |
> |
foreach my $arg (@ARGV) |
87 |
> |
{ |
88 |
> |
if (substr ($file, 0, length ($arg)) eq $arg) |
89 |
> |
{ |
90 |
> |
push (@{$rootFiles{$arg}}, $file); |
91 |
> |
push (@{$weights{$arg}}, 1.0); |
92 |
> |
} |
93 |
> |
} |
94 |
|
} |
95 |
|
} |
96 |
< |
if (!@rootFiles) |
96 |
> |
if (!%rootFiles) |
97 |
|
{ |
98 |
|
print "Found no ROOT files to merge!\n"; |
99 |
|
exit; |
100 |
|
} |
101 |
< |
my $rootFiles = join (" ", @rootFiles); |
102 |
< |
my $weights = join (",", @weights); |
103 |
< |
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
104 |
< |
my $nTotalEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
105 |
< |
unlink ("$opt{'prefix'}.root"); |
106 |
< |
@weights = (); |
101 |
> |
my %nTotalEvents; |
102 |
> |
my $nTotalEvents = 0; |
103 |
> |
foreach my $arg (@ARGV) |
104 |
> |
{ |
105 |
> |
my $rootFiles = join (" ", @{$rootFiles{$arg}}); |
106 |
> |
my $weights = join (",", @{$weights{$arg}}); |
107 |
> |
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
108 |
> |
my $count = countEvents ("$opt{'prefix'}.root", $cutFlow); |
109 |
> |
$nTotalEvents{$arg} = $count; |
110 |
> |
$nTotalEvents += $count; |
111 |
> |
unlink ("$opt{'prefix'}.root"); |
112 |
> |
} |
113 |
> |
my @rootFiles; |
114 |
> |
my @weights; |
115 |
> |
%weights = (); |
116 |
|
foreach my $file (@$files) |
117 |
|
{ |
118 |
|
next if $file eq "."; |
124 |
|
{ |
125 |
|
my $jobNumber = $file; |
126 |
|
$jobNumber =~ s/^.*_([^_]*)\.root$/$1/; |
116 |
– |
#$badJob = defined $exitCodes{$dir} && defined $exitCodes{$dir}{$jobNumber} && $exitCodes{$dir}{$jobNumber}; |
127 |
|
$badJob = defined $signals{$dir} && defined $signals{$dir}{$jobNumber}; |
128 |
|
} |
129 |
|
next if $badJob; |
130 |
|
if ($file =~ m/^.*\.root$/) |
131 |
|
{ |
132 |
< |
push (@weights, $opt{"weight"}) if $opt{"weight"}; |
133 |
< |
push (@weights, ($opt{"xsection"} * $integratedLuminosity) / $nTotalEvents) if !$opt{"weight"} && $opt{"xsection"}; |
134 |
< |
push (@weights, ($crossSections{$dir} * $integratedLuminosity) / $nTotalEvents) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir}; |
135 |
< |
push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir}); |
132 |
> |
foreach my $arg (@ARGV) |
133 |
> |
{ |
134 |
> |
if (substr ($file, 0, length ($arg)) eq $arg) |
135 |
> |
{ |
136 |
> |
push (@rootFiles, $file); |
137 |
> |
push (@weights, $opt{"weight"}) if $opt{"weight"}; |
138 |
> |
push (@weights, ($opt{"xsection"} * $integratedLuminosity) / $nTotalEvents{$arg}) if !$opt{"weight"} && $opt{"xsection"}; |
139 |
> |
push (@weights, ($crossSections{$dir} * $integratedLuminosity) / $nTotalEvents{$arg}) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir}; |
140 |
> |
push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir}); |
141 |
> |
$weights{$arg} = $weights[-1]; |
142 |
> |
} |
143 |
> |
} |
144 |
|
} |
145 |
|
} |
146 |
+ |
my $rootFiles = join (" ", @rootFiles); |
147 |
|
my $weights = join (",", @weights); |
148 |
|
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
149 |
+ |
print "Weights:\n"; |
150 |
+ |
foreach my $arg (keys %weights) |
151 |
+ |
{ |
152 |
+ |
printf " $arg: %.1f (%.1f pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity; |
153 |
+ |
} |
154 |
|
my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
155 |
|
print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting; |
156 |
|
print "$nBadJobs jobs failed to run.\n" if $counting; |