17 |
|
my $files = processArgs (\@ARGV); |
18 |
|
my %rootFiles; |
19 |
|
my %weights; |
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; |
31 |
|
$integratedLuminosity = $opt{"luminosity"} if $opt{"luminosity"}; |
32 |
|
my $cutFlow = "cutFlow"; |
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; |
51 |
– |
$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$/) |
86 |
|
{ |
87 |
|
my $jobNumber = $file; |
88 |
|
$jobNumber =~ s/^.*_([^_]*)\.root$/$1/; |
89 |
< |
$badJob = defined $signals{$dir} && defined $signals{$dir}{$jobNumber}; |
89 |
> |
$badJob = (defined $signals{$dir} && defined $signals{$dir}{$jobNumber}) || (defined $partial{$dir} && defined $partial{$dir}{$jobNumber}); |
90 |
|
} |
91 |
|
next if $badJob; |
92 |
|
if ($file =~ m/^.*\.root$/) |
95 |
|
{ |
96 |
|
if (substr ($file, 0, length ($arg)) eq $arg) |
97 |
|
{ |
98 |
+ |
$dirs{$arg} = $dir; |
99 |
|
push (@{$rootFiles{$arg}}, $file); |
100 |
< |
push (@{$weights{$arg}}, 1.0); |
100 |
> |
push (@weights, $opt{"weight"}) if $opt{"weight"}; |
101 |
> |
push (@weights, $opt{"xsection"} * $integratedLuminosity) if !$opt{"weight"} && $opt{"xsection"}; |
102 |
> |
push (@weights, $crossSections{$dir} * $integratedLuminosity) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir}; |
103 |
> |
push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir}); |
104 |
> |
$weights{$arg} = $weights[-1]; |
105 |
|
} |
106 |
|
} |
107 |
|
} |
113 |
|
} |
114 |
|
my %nTotalEvents; |
115 |
|
my $nTotalEvents = 0; |
116 |
+ |
my @mergedFiles; |
117 |
+ |
my @mergedWeights; |
118 |
|
foreach my $arg (@ARGV) |
119 |
|
{ |
120 |
|
my $rootFiles = join (" ", @{$rootFiles{$arg}}); |
121 |
< |
my $weights = join (",", @{$weights{$arg}}); |
122 |
< |
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
123 |
< |
my $count = countEvents ("$opt{'prefix'}.root", $cutFlow); |
121 |
> |
my $tmpName = $arg . "_" . "$opt{'prefix'}.root"; |
122 |
> |
$tmpName =~ s/\//_/g; |
123 |
> |
system ("mergeTFileServiceHistograms -i $rootFiles -o $tmpName"); |
124 |
> |
my $count = countEvents ($tmpName, $cutFlow); |
125 |
> |
system ("cutFlowLimits $tmpName"); |
126 |
|
$nTotalEvents{$arg} = $count; |
127 |
|
$nTotalEvents += $count; |
128 |
< |
unlink ("$opt{'prefix'}.root"); |
129 |
< |
} |
130 |
< |
my @rootFiles; |
131 |
< |
my @weights; |
132 |
< |
%weights = (); |
133 |
< |
foreach my $file (@$files) |
128 |
> |
$weights{$arg} /= $count if !$opt{"weight"} && $opt{"xsection"}; |
129 |
> |
$weights{$arg} /= $count if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dirs{$arg}}; |
130 |
> |
push (@mergedFiles, $tmpName); |
131 |
> |
push (@mergedWeights, $weights{$arg}); |
132 |
> |
} |
133 |
> |
my $mergedFiles = join (" ", @mergedFiles); |
134 |
> |
my $mergedWeights = join (",", @mergedWeights); |
135 |
> |
system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}.root -w $mergedWeights"); |
136 |
> |
foreach my $mergedFile (@mergedFiles) |
137 |
> |
{ |
138 |
> |
unlink ("$mergedFile"); |
139 |
> |
} |
140 |
> |
print "=============================================\n"; |
141 |
> |
my $output = sprintf "Effective luminosities of samples:\n"; |
142 |
> |
my $printOutput = 1; |
143 |
> |
foreach my $arg (keys %weights) |
144 |
|
{ |
145 |
< |
next if $file eq "."; |
146 |
< |
next if $file eq ".."; |
147 |
< |
my $dir = $file; |
148 |
< |
$dir =~ s/^(.*)\/[^\/]*$/$1/; |
149 |
< |
my $badJob = 0; |
150 |
< |
if ($file =~ m/^.*_[^_]*\.root$/) |
151 |
< |
{ |
125 |
< |
my $jobNumber = $file; |
126 |
< |
$jobNumber =~ s/^.*_([^_]*)\.root$/$1/; |
127 |
< |
$badJob = defined $signals{$dir} && defined $signals{$dir}{$jobNumber}; |
128 |
< |
} |
129 |
< |
next if $badJob; |
130 |
< |
if ($file =~ m/^.*\.root$/) |
131 |
< |
{ |
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"; |
145 |
> |
my $shortArg = $arg; |
146 |
> |
$shortArg =~ s/^.*\/([^\/]*)$/$1/; |
147 |
> |
$output = sprintf "%s $shortArg: %.5g/fb\n", $output, ($integratedLuminosity / (1000.0 * $weights{$arg})); |
148 |
> |
} |
149 |
> |
print $output if $printOutput; |
150 |
> |
$output = sprintf "Weights for target luminosity of %g/fb:\n", ($integratedLuminosity / 1000.0); |
151 |
> |
$printOutput = 0; |
152 |
|
foreach my $arg (keys %weights) |
153 |
|
{ |
154 |
< |
printf " $arg: %.1f (%.1f pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity; |
154 |
> |
my $shortArg = $arg; |
155 |
> |
$shortArg =~ s/^.*\/([^\/]*)$/$1/; |
156 |
> |
$output = sprintf "%s $shortArg: %.5g\n", $output, $weights{$arg}; |
157 |
> |
$printOutput = 1 if $weights{$arg} != 1; |
158 |
|
} |
159 |
+ |
print $output if $printOutput; |
160 |
|
my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
161 |
|
print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting; |
162 |
|
print "$nBadJobs jobs failed to run.\n" if $counting; |
163 |
+ |
print "$nIncompleteJobs jobs have not finished.\n" if $counting; |
164 |
+ |
print "=============================================\n"; |
165 |
|
|
166 |
|
sub |
167 |
|
processArgs |
253 |
|
my $cutFlow = shift; |
254 |
|
|
255 |
|
my $output = `getEventsFromCutFlow $file $cutFlow`; |
256 |
< |
if ($output =~ m/Did not find a histogram named/) |
256 |
> |
if ($output =~ m/Did not find a histogram named/ || $output =~ m/appears to be empty/ || $output =~ m/Failed to open/) |
257 |
|
{ |
258 |
|
print $output; |
259 |
|
return -1; |