11 |
|
|
12 |
|
my %opt; |
13 |
|
Getopt::Long::Configure ("bundling"); |
14 |
< |
GetOptions (\%opt, "luminosity|l=s", "prefix|p=s", "weight|w=s", "help|h"); |
14 |
> |
GetOptions (\%opt, "cutflow|c=s", "luminosity|l=s", "prefix|p=s", "weight|w=s", "xsection|x=s", "help|h"); |
15 |
|
|
16 |
|
printHelp () if $opt{"help"} || !$opt{"prefix"}; |
17 |
|
my $files = processArgs (\@ARGV); |
24 |
|
my %crossSections; |
25 |
|
my $integratedLuminosity = 10000; |
26 |
|
$integratedLuminosity = $opt{"luminosity"} if $opt{"luminosity"}; |
27 |
+ |
my $cutFlow = "cutFlow"; |
28 |
+ |
$cutFlow = $opt{"cutflow"} if $opt{"cutflow"}; |
29 |
|
foreach my $file (@$files) |
30 |
|
{ |
31 |
|
next if $file eq "."; |
59 |
|
$crossSections{$dir} = $crossSection; |
60 |
|
} |
61 |
|
} |
60 |
– |
my $nTotalEvents = 0; |
62 |
|
foreach my $file (@$files) |
63 |
|
{ |
64 |
|
next if $file eq "."; |
75 |
|
next if $badJob; |
76 |
|
if ($file =~ m/^.*\.root$/) |
77 |
|
{ |
78 |
< |
my $nEvents = countEvents ($file); |
79 |
< |
$nTotalEvents = -1 if $nTotalEvents < 0 || $nEvents < 0; |
79 |
< |
$nTotalEvents += $nEvents if !($nTotalEvents < 0 || $nEvents < 0); |
78 |
> |
push (@rootFiles, $file); |
79 |
> |
push (@weights, 1.0); |
80 |
|
} |
81 |
|
} |
82 |
+ |
if (!@rootFiles) |
83 |
+ |
{ |
84 |
+ |
print "Found no ROOT files to merge!\n"; |
85 |
+ |
exit; |
86 |
+ |
} |
87 |
+ |
my $rootFiles = join (" ", @rootFiles); |
88 |
+ |
my $weights = join (",", @weights); |
89 |
+ |
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
90 |
+ |
my $nTotalEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
91 |
+ |
unlink ("$opt{'prefix'}.root"); |
92 |
+ |
@weights = (); |
93 |
|
foreach my $file (@$files) |
94 |
|
{ |
95 |
|
next if $file eq "."; |
106 |
|
next if $badJob; |
107 |
|
if ($file =~ m/^.*\.root$/) |
108 |
|
{ |
98 |
– |
push (@rootFiles, $file); |
109 |
|
push (@weights, $opt{"weight"}) if $opt{"weight"}; |
110 |
< |
push (@weights, ($crossSections{$dir} * $integratedLuminosity) / $nTotalEvents) if !$opt{"weight"} && defined $crossSections{$dir}; |
111 |
< |
push (@weights, 1.0) if !$opt{"weight"} && !(defined $crossSections{$dir}); |
110 |
> |
push (@weights, ($opt{"xsection"} * $integratedLuminosity) / $nTotalEvents) if !$opt{"weight"} && $opt{"xsection"}; |
111 |
> |
push (@weights, ($crossSections{$dir} * $integratedLuminosity) / $nTotalEvents) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir}; |
112 |
> |
push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir}); |
113 |
|
} |
114 |
|
} |
104 |
– |
if (!@rootFiles) |
105 |
– |
{ |
106 |
– |
print "Found no ROOT files to merge!\n"; |
107 |
– |
exit; |
108 |
– |
} |
109 |
– |
my $rootFiles = join (" ", @rootFiles); |
115 |
|
my $weights = join (",", @weights); |
116 |
|
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
117 |
< |
system ("cutFlowTable $opt{'prefix'}.root cutFlow >& $opt{'prefix'}.tex"); |
118 |
< |
my $goodEvents = countEvents ("$opt{'prefix'}.root"); |
117 |
> |
system ("cutFlowTable $opt{'prefix'}.root $cutFlow >& $opt{'prefix'}.tex"); |
118 |
> |
my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow); |
119 |
|
print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting; |
120 |
|
print "$nBadJobs jobs failed to run.\n" if $counting; |
121 |
|
|
161 |
|
my $exeName = $0; |
162 |
|
$exeName =~ s/^.*\/([^\/]*)$/$1/; |
163 |
|
|
164 |
< |
print "Usage: $exeName -p PREFIX [OPTION]... DIRECTORIES_AND_FILES\n"; |
164 |
> |
print "Usage: $exeName [OPTION]... -p PREFIX DIRECTORIES_AND_FILES\n"; |
165 |
|
print "Merges ROOT files containing histograms and produces a cutflow table in the\n"; |
166 |
< |
print "form of a LaTeX document from the histogram named \"cutFlow\". If there are\n"; |
167 |
< |
print "Condor logs in the specified directories, checks for nonzero return values. If\n"; |
168 |
< |
print "the directories where created by \"osusub\", uses the cross section from the\n"; |
164 |
< |
print "database to weight all histograms.\n"; |
166 |
> |
print "form of a LaTeX document. If there are Condor logs in the specified\n"; |
167 |
> |
print "directories, checks for nonzero return values. If the directories where created\n"; |
168 |
> |
print "by \"osusub\", uses the cross section from the database to weight all histograms.\n"; |
169 |
|
print "\n"; |
170 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
171 |
+ |
printf "%-29s%s\n", " -c, --cutflow HISTOGRAM", "name of histogram to use for the cutflow (default:"; |
172 |
+ |
printf "%-29s%s\n", " ", "cutFlow)"; |
173 |
|
printf "%-29s%s\n", " -h, --help", "print this help message"; |
174 |
|
printf "%-29s%s\n", " -l, --luminosity", "integrated luminosity to which the histograms are"; |
175 |
|
printf "%-29s%s\n", " ", "weighted (default: 10000/pb)"; |
177 |
|
printf "%-29s%s\n", " -w, --weight WEIGHT", "scale the output by WEIGHT, overriding the"; |
178 |
|
printf "%-29s%s\n", " ", "automatic weighting using the cross section from"; |
179 |
|
printf "%-29s%s\n", " ", "the database"; |
180 |
+ |
printf "%-29s%s\n", " -x, --xsection XSECTION", "use XSECTION to weight the histograms instead of"; |
181 |
+ |
printf "%-29s%s\n", " ", "the value in the database"; |
182 |
|
|
183 |
|
exit; |
184 |
|
} |
206 |
|
countEvents |
207 |
|
{ |
208 |
|
my $file = shift; |
209 |
+ |
my $cutFlow = shift; |
210 |
|
|
211 |
< |
my $output = `getEventsFromCutFlow $file cutFlow`; |
211 |
> |
my $output = `getEventsFromCutFlow $file $cutFlow`; |
212 |
|
if ($output =~ m/Did not find a histogram named/) |
213 |
|
{ |
214 |
|
print $output; |