20 |
|
my @weights; |
21 |
|
my $nGoodJobs = 0; |
22 |
|
my $nBadJobs = 0; |
23 |
+ |
my $nIncompleteJobs = 0; |
24 |
|
my $counting = 0; |
25 |
|
my %exitCodes; |
26 |
|
my %signals; |
27 |
+ |
my %partial; |
28 |
|
my %crossSections; |
29 |
|
my %dirs; |
30 |
|
my $integratedLuminosity = 10000; |
46 |
|
close (FILE); |
47 |
|
my $fileContents = join ("", @fileContents); |
48 |
|
$fileContents =~ s/\n/ /g; |
49 |
+ |
$counting = 1; |
50 |
|
if ($fileContents =~ m/return value/) |
51 |
|
{ |
52 |
|
$fileContents =~ s/.*\(return value ([^)]*)\).*/$1/g; |
53 |
|
$nGoodJobs++; |
54 |
|
print "WARNING: Nonzero exit code for job $jobNumber. (return value $fileContents)\n" if $fileContents != 0; |
55 |
|
$exitCodes{$dir}{$jobNumber} = $fileContents; |
53 |
– |
$counting = 1; |
56 |
|
} |
57 |
< |
if ($fileContents =~ m/signal/) |
57 |
> |
elsif ($fileContents =~ m/signal/) |
58 |
|
{ |
59 |
|
$fileContents =~ s/.*\(signal ([^)]*)\).*/$1/g; |
60 |
|
$nBadJobs++; |
61 |
|
print "WARNING: Skipping job $jobNumber. (signal $fileContents)\n"; |
62 |
|
$signals{$dir}{$jobNumber} = $fileContents; |
63 |
< |
$counting = 1; |
63 |
> |
} |
64 |
> |
else |
65 |
> |
{ |
66 |
> |
$nIncompleteJobs++; |
67 |
> |
$partial{$dir}{$jobNumber} = 1; |
68 |
|
} |
69 |
|
} |
70 |
|
if ($file =~ m/^.*\/crossSectionInPicobarn\.txt$/) |
82 |
|
my $dir = $file; |
83 |
|
$dir =~ s/^(.*)\/[^\/]*$/$1/; |
84 |
|
my $badJob = 0; |
85 |
+ |
my $jobNumber; |
86 |
|
if ($file =~ m/^.*_[^_]*\.root$/) |
87 |
|
{ |
88 |
< |
my $jobNumber = $file; |
88 |
> |
$jobNumber = $file; |
89 |
|
$jobNumber =~ s/^.*_([^_]*)\.root$/$1/; |
90 |
< |
$badJob = defined $signals{$dir} && defined $signals{$dir}{$jobNumber}; |
90 |
> |
$badJob = (defined $signals{$dir} && defined $signals{$dir}{$jobNumber}) || (defined $partial{$dir} && defined $partial{$dir}{$jobNumber}); |
91 |
|
} |
92 |
|
next if $badJob; |
93 |
|
if ($file =~ m/^.*\.root$/) |
94 |
|
{ |
95 |
|
foreach my $arg (@ARGV) |
96 |
|
{ |
90 |
– |
$dirs{$arg} = $dir; |
97 |
|
if (substr ($file, 0, length ($arg)) eq $arg) |
98 |
|
{ |
99 |
+ |
$dirs{$arg} = $dir; |
100 |
+ |
if (countEvents ($file, $cutFlow) < 0) |
101 |
+ |
{ |
102 |
+ |
$nGoodJobs--; |
103 |
+ |
$nBadJobs++; |
104 |
+ |
print "WARNING: Skipping job $jobNumber. (bad ROOT file)\n"; |
105 |
+ |
last; |
106 |
+ |
} |
107 |
|
push (@{$rootFiles{$arg}}, $file); |
108 |
|
push (@weights, $opt{"weight"}) if $opt{"weight"}; |
109 |
|
push (@weights, $opt{"xsection"} * $integratedLuminosity) if !$opt{"weight"} && $opt{"xsection"}; |
135 |
|
$nTotalEvents += $count; |
136 |
|
$weights{$arg} /= $count if !$opt{"weight"} && $opt{"xsection"}; |
137 |
|
$weights{$arg} /= $count if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dirs{$arg}}; |
138 |
< |
push (@mergedFiles, "$tmpName"); |
138 |
> |
push (@mergedFiles, $tmpName); |
139 |
|
push (@mergedWeights, $weights{$arg}); |
140 |
|
} |
141 |
|
my $mergedFiles = join (" ", @mergedFiles); |
145 |
|
{ |
146 |
|
unlink ("$mergedFile"); |
147 |
|
} |
148 |
< |
print "Weights:\n"; |
148 |
> |
print "=============================================\n"; |
149 |
> |
my $output = sprintf "Effective luminosities of samples:\n"; |
150 |
> |
my $printOutput = 0; |
151 |
> |
foreach my $arg (keys %weights) |
152 |
> |
{ |
153 |
> |
my $shortArg = $arg; |
154 |
> |
$shortArg =~ s/^.*\/([^\/]*)$/$1/; |
155 |
> |
$output = sprintf "%s $shortArg: %.5g/fb\n", $output, ($integratedLuminosity / (1000.0 * $weights{$arg})) if $weights{$arg} != 1; |
156 |
> |
$printOutput = 1 if $weights{$arg} != 1; |
157 |
> |
} |
158 |
> |
print $output if $printOutput; |
159 |
> |
$output = sprintf "Weights for target luminosity of %g/fb:\n", ($integratedLuminosity / 1000.0); |
160 |
> |
$printOutput = 0; |
161 |
|
foreach my $arg (keys %weights) |
162 |
|
{ |
163 |
|
my $shortArg = $arg; |
164 |
|
$shortArg =~ s/^.*\/([^\/]*)$/$1/; |
165 |
< |
printf " $shortArg: %.5g (%.5g pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity; |
165 |
> |
$output = sprintf "%s $shortArg: %.5g\n", $output, $weights{$arg} if $weights{$arg} != 1; |
166 |
> |
$printOutput = 1 if $weights{$arg} != 1; |
167 |
|
} |
168 |
+ |
print $output if $printOutput; |
169 |
|
my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
170 |
|
print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting; |
171 |
|
print "$nBadJobs jobs failed to run.\n" if $counting; |
172 |
+ |
print "$nIncompleteJobs jobs have not finished.\n" if $counting; |
173 |
+ |
print "=============================================\n"; |
174 |
|
|
175 |
|
sub |
176 |
|
processArgs |
262 |
|
my $cutFlow = shift; |
263 |
|
|
264 |
|
my $output = `getEventsFromCutFlow $file $cutFlow`; |
265 |
< |
if ($output =~ m/Did not find a histogram named/) |
265 |
> |
if ($output =~ m/Did not find a histogram named/ || $output =~ m/appears to be empty/ || $output =~ m/Failed to open/) |
266 |
|
{ |
267 |
|
print $output; |
268 |
|
return -1; |