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; |
55 |
– |
$counting = 1; |
56 |
|
} |
57 |
|
elsif ($fileContents =~ m/signal/) |
58 |
|
{ |
60 |
|
$nBadJobs++; |
61 |
|
print "WARNING: Skipping job $jobNumber. (signal $fileContents)\n"; |
62 |
|
$signals{$dir}{$jobNumber} = $fileContents; |
63 |
– |
$counting = 1; |
63 |
|
} |
64 |
|
else |
65 |
|
{ |
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}) || (defined $partial{$dir} && defined $partial{$dir}{$jobNumber}); |
91 |
|
} |
94 |
|
{ |
95 |
|
foreach my $arg (@ARGV) |
96 |
|
{ |
97 |
< |
$dirs{$arg} = $dir; |
98 |
< |
if (substr ($file, 0, length ($arg)) eq $arg && countEvents ($file) >= 0) |
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); |
142 |
|
my $mergedWeights = join (",", @mergedWeights); |
136 |
– |
system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}_Unweighted.root"); |
143 |
|
system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}.root -w $mergedWeights"); |
144 |
|
foreach my $mergedFile (@mergedFiles) |
145 |
|
{ |
146 |
|
unlink ("$mergedFile"); |
147 |
|
} |
148 |
< |
print "Weights:\n"; |
148 |
> |
print "=============================================\n"; |
149 |
> |
my $output = sprintf "Cross-section 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 pb\n", $output, ($crossSections{$dirs{$arg}}); |
156 |
> |
$printOutput = 1 if $weights{$arg} != 1; |
157 |
> |
} |
158 |
> |
print $output if $printOutput; |
159 |
> |
|
160 |
> |
my $output = sprintf "Effective luminosities of samples:\n"; |
161 |
> |
my $printOutput = 0; |
162 |
|
foreach my $arg (keys %weights) |
163 |
|
{ |
164 |
|
my $shortArg = $arg; |
165 |
|
$shortArg =~ s/^.*\/([^\/]*)$/$1/; |
166 |
< |
printf " $shortArg: %.5g (%.5g pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity; |
166 |
> |
$output = sprintf "%s $shortArg: %.5g/fb\n", $output, ($integratedLuminosity / (1000.0 * $weights{$arg})) if $weights{$arg} != 1; |
167 |
> |
$printOutput = 1 if $weights{$arg} != 1; |
168 |
|
} |
169 |
+ |
print $output if $printOutput; |
170 |
+ |
|
171 |
+ |
$output = sprintf "Weights for target luminosity of %g/fb:\n", ($integratedLuminosity / 1000.0); |
172 |
+ |
$printOutput = 0; |
173 |
+ |
foreach my $arg (keys %weights) |
174 |
+ |
{ |
175 |
+ |
my $shortArg = $arg; |
176 |
+ |
$shortArg =~ s/^.*\/([^\/]*)$/$1/; |
177 |
+ |
$output = sprintf "%s $shortArg: %.5g\n", $output, $weights{$arg} if $weights{$arg} != 1; |
178 |
+ |
$printOutput = 1 if $weights{$arg} != 1; |
179 |
+ |
} |
180 |
+ |
print $output if $printOutput; |
181 |
+ |
|
182 |
|
my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
183 |
|
print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting; |
184 |
|
print "$nBadJobs jobs failed to run.\n" if $counting; |
185 |
|
print "$nIncompleteJobs jobs have not finished.\n" if $counting; |
186 |
+ |
print "=============================================\n"; |
187 |
|
|
188 |
|
sub |
189 |
|
processArgs |
237 |
|
printf "%-29s%s\n", " -c, --cutflow HISTOGRAM", "name of histogram to use for the cutflow (default:"; |
238 |
|
printf "%-29s%s\n", " ", "cutFlow)"; |
239 |
|
printf "%-29s%s\n", " -h, --help", "print this help message"; |
240 |
< |
printf "%-29s%s\n", " -l, --luminosity", "integrated luminosity to which the histograms are"; |
207 |
< |
printf "%-29s%s\n", " ", "weighted (default: 10000/pb)"; |
240 |
> |
printf "%-29s%s\n", " -l, --luminosity", "integrated luminosity to which the histograms are weighted"; |
241 |
|
printf "%-29s%s\n", " -p, --prefix PREFIX", "output is named PREFIX.root"; |
242 |
|
printf "%-29s%s\n", " -w, --weight WEIGHT", "scale the output by WEIGHT, overriding the"; |
243 |
|
printf "%-29s%s\n", " ", "automatic weighting using the cross section from"; |