ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/scripts/mergeHists
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/scripts/mergeHists (file contents):
Revision 1.11 by ahart, Tue Dec 18 09:25:48 2012 UTC vs.
Revision 1.16 by ahart, Wed Jan 9 17:13:31 2013 UTC

# Line 17 | Line 17 | printHelp () if $opt{"help"} || !$opt{"p
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;
24   my %exitCodes;
25   my %signals;
26   my %crossSections;
27 + my %dirs;
28   my $integratedLuminosity = 10000;
29   $integratedLuminosity = $opt{"luminosity"} if $opt{"luminosity"};
30   my $cutFlow = "cutFlow";
# Line 85 | Line 87 | foreach my $file (@$files)
87        {
88          foreach my $arg (@ARGV)
89            {
90 <            if (substr ($file, 0, length ($arg)) eq $arg)
90 >            $dirs{$arg} = $dir;
91 >            if (substr ($file, 0, length ($arg)) eq $arg && countEvents ($file) >= 0)
92                {
93                  push (@{$rootFiles{$arg}}, $file);
94 <                push (@{$weights{$arg}}, 1.0);
94 >                push (@weights, $opt{"weight"}) if $opt{"weight"};
95 >                push (@weights, $opt{"xsection"} * $integratedLuminosity) if !$opt{"weight"} && $opt{"xsection"};
96 >                push (@weights, $crossSections{$dir} * $integratedLuminosity) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir};
97 >                push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir});
98 >                $weights{$arg} = $weights[-1];
99                }
100            }
101        }
# Line 100 | Line 107 | if (!%rootFiles)
107    }
108   my %nTotalEvents;
109   my $nTotalEvents = 0;
110 + my @mergedFiles;
111 + my @mergedWeights;
112   foreach my $arg (@ARGV)
113    {
114      my $rootFiles = join (" ", @{$rootFiles{$arg}});
115 <    my $weights = join (",", @{$weights{$arg}});
116 <    system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights");
117 <    my $count = countEvents ("$opt{'prefix'}.root", $cutFlow);
115 >    my $tmpName = $arg . "_" . "$opt{'prefix'}.root";
116 >    $tmpName =~ s/\//_/g;
117 >    system ("mergeTFileServiceHistograms -i $rootFiles -o $tmpName");
118 >    my $count = countEvents ($tmpName, $cutFlow);
119 >    system ("cutFlowLimits $tmpName");
120      $nTotalEvents{$arg} = $count;
121      $nTotalEvents += $count;
122 <    unlink ("$opt{'prefix'}.root");
123 <  }
124 < my @rootFiles;
125 < my @weights;
126 < %weights = ();
127 < foreach my $file (@$files)
122 >    $weights{$arg} /= $count if !$opt{"weight"} && $opt{"xsection"};
123 >    $weights{$arg} /= $count if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dirs{$arg}};
124 >    push (@mergedFiles, "$tmpName");
125 >    push (@mergedWeights, $weights{$arg});
126 >  }
127 > my $mergedFiles = join (" ", @mergedFiles);
128 > my $mergedWeights = join (",", @mergedWeights);
129 > system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}_Unweighted.root");
130 > system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}.root -w $mergedWeights");
131 > foreach my $mergedFile (@mergedFiles)
132    {
133 <    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 <      }
133 >    unlink ("$mergedFile");
134    }
146 my $rootFiles = join (" ", @rootFiles);
147 my $weights = join (",", @weights);
148 system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights");
135   print "Weights:\n";
136   foreach my $arg (keys %weights)
137    {
138 <    printf "  $arg: %.1f (%.1f pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity;
138 >    my $shortArg = $arg;
139 >    $shortArg =~ s/^.*\/([^\/]*)$/$1/;
140 >    printf "  $shortArg: %.5g (%.5g pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity;
141    }
142   my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow);
143   print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting;
# Line 245 | Line 233 | countEvents
233    my $cutFlow = shift;
234  
235    my $output = `getEventsFromCutFlow $file $cutFlow`;
236 <  if ($output =~ m/Did not find a histogram named/)
236 >  if ($output =~ m/Did not find a histogram named/ || $output =~ m/appears to be empty/ || $output =~ m/Failed to open/)
237      {
238        print $output;
239        return -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines