17 |
|
my $files = processArgs (\@ARGV); |
18 |
|
my %rootFiles; |
19 |
|
my %weights; |
20 |
+ |
my @weights; |
21 |
|
my $nGoodJobs = 0; |
22 |
|
my $nBadJobs = 0; |
23 |
|
my $counting = 0; |
89 |
|
if (substr ($file, 0, length ($arg)) eq $arg) |
90 |
|
{ |
91 |
|
push (@{$rootFiles{$arg}}, $file); |
92 |
< |
push (@{$weights{$arg}}, 1.0); |
92 |
> |
push (@weights, $opt{"weight"}) if $opt{"weight"}; |
93 |
> |
push (@weights, $opt{"xsection"} * $integratedLuminosity) if !$opt{"weight"} && $opt{"xsection"}; |
94 |
> |
push (@weights, $crossSections{$dir} * $integratedLuminosity) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir}; |
95 |
> |
push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir}); |
96 |
> |
$weights{$arg} = $weights[-1]; |
97 |
|
} |
98 |
|
} |
99 |
|
} |
105 |
|
} |
106 |
|
my %nTotalEvents; |
107 |
|
my $nTotalEvents = 0; |
108 |
+ |
my @mergedFiles; |
109 |
+ |
my @mergedWeights; |
110 |
|
foreach my $arg (@ARGV) |
111 |
|
{ |
112 |
|
my $rootFiles = join (" ", @{$rootFiles{$arg}}); |
113 |
< |
my $weights = join (",", @{$weights{$arg}}); |
114 |
< |
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
115 |
< |
my $count = countEvents ("$opt{'prefix'}.root", $cutFlow); |
113 |
> |
my $tmpName = $arg . "_" . "$opt{'prefix'}.root"; |
114 |
> |
$tmpName =~ s/\//_/g; |
115 |
> |
system ("mergeTFileServiceHistograms -i $rootFiles -o $tmpName"); |
116 |
> |
my $count = countEvents ($tmpName, $cutFlow); |
117 |
> |
system ("cutFlowLimits $tmpName"); |
118 |
|
$nTotalEvents{$arg} = $count; |
119 |
|
$nTotalEvents += $count; |
120 |
< |
unlink ("$opt{'prefix'}.root"); |
120 |
> |
push (@mergedFiles, "$tmpName"); |
121 |
> |
push (@mergedWeights, $weights{$arg} / $count); |
122 |
|
} |
123 |
< |
my @rootFiles; |
124 |
< |
my @weights; |
125 |
< |
%weights = (); |
126 |
< |
foreach my $file (@$files) |
123 |
> |
my $mergedFiles = join (" ", @mergedFiles); |
124 |
> |
my $mergedWeights = join (",", @mergedWeights); |
125 |
> |
system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}.root -w $mergedWeights"); |
126 |
> |
foreach my $mergedFile (@mergedFiles) |
127 |
|
{ |
128 |
< |
next if $file eq "."; |
119 |
< |
next if $file eq ".."; |
120 |
< |
my $dir = $file; |
121 |
< |
$dir =~ s/^(.*)\/[^\/]*$/$1/; |
122 |
< |
my $badJob = 0; |
123 |
< |
if ($file =~ m/^.*_[^_]*\.root$/) |
124 |
< |
{ |
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 |
< |
} |
128 |
> |
unlink ("$mergedFile"); |
129 |
|
} |
146 |
– |
my $rootFiles = join (" ", @rootFiles); |
147 |
– |
my $weights = join (",", @weights); |
148 |
– |
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
130 |
|
print "Weights:\n"; |
131 |
|
foreach my $arg (keys %weights) |
132 |
|
{ |
133 |
< |
printf " $arg: %.1f (%.1f pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity; |
133 |
> |
my $shortArg = $arg; |
134 |
> |
$shortArg =~ s/^.*\/([^\/]*)$/$1/; |
135 |
> |
printf " $shortArg: %.5g (%.5g pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity; |
136 |
|
} |
137 |
|
my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
138 |
|
print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting; |