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.17 by ahart, Tue Jan 29 00:23:24 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 $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";
# Line 50 | Line 54 | foreach my $file (@$files)
54              $exitCodes{$dir}{$jobNumber} = $fileContents;
55              $counting = 1;
56            }
57 <        if ($fileContents =~ m/signal/)
57 >        elsif ($fileContents =~ m/signal/)
58            {
59              $fileContents =~ s/.*\(signal ([^)]*)\).*/$1/g;
60              $nBadJobs++;
# Line 58 | Line 62 | foreach my $file (@$files)
62              $signals{$dir}{$jobNumber} = $fileContents;
63              $counting = 1;
64            }
65 +        else
66 +          {
67 +            $nIncompleteJobs++;
68 +            $partial{$dir}{$jobNumber} = 1;
69 +          }
70        }
71      if ($file =~ m/^.*\/crossSectionInPicobarn\.txt$/)
72        {
# Line 78 | Line 87 | foreach my $file (@$files)
87        {
88          my $jobNumber = $file;
89          $jobNumber =~ s/^.*_([^_]*)\.root$/$1/;
90 <        $badJob = defined $signals{$dir} && defined $signals{$dir}{$jobNumber};
90 >        $badJob = (defined $signals{$dir} && defined $signals{$dir}{$jobNumber}) || (defined $partial{$dir} && defined $partial{$dir}{$jobNumber});
91        }
92      next if $badJob;
93      if ($file =~ m/^.*\.root$/)
94        {
95          foreach my $arg (@ARGV)
96            {
97 <            if (substr ($file, 0, length ($arg)) eq $arg)
97 >            $dirs{$arg} = $dir;
98 >            if (substr ($file, 0, length ($arg)) eq $arg && countEvents ($file) >= 0)
99                {
100                  push (@{$rootFiles{$arg}}, $file);
101 <                push (@{$weights{$arg}}, 1.0);
101 >                push (@weights, $opt{"weight"}) if $opt{"weight"};
102 >                push (@weights, $opt{"xsection"} * $integratedLuminosity) if !$opt{"weight"} && $opt{"xsection"};
103 >                push (@weights, $crossSections{$dir} * $integratedLuminosity) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir};
104 >                push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir});
105 >                $weights{$arg} = $weights[-1];
106                }
107            }
108        }
# Line 100 | Line 114 | if (!%rootFiles)
114    }
115   my %nTotalEvents;
116   my $nTotalEvents = 0;
117 + my @mergedFiles;
118 + my @mergedWeights;
119   foreach my $arg (@ARGV)
120    {
121      my $rootFiles = join (" ", @{$rootFiles{$arg}});
122 <    my $weights = join (",", @{$weights{$arg}});
123 <    system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights");
124 <    my $count = countEvents ("$opt{'prefix'}.root", $cutFlow);
122 >    my $tmpName = $arg . "_" . "$opt{'prefix'}.root";
123 >    $tmpName =~ s/\//_/g;
124 >    system ("mergeTFileServiceHistograms -i $rootFiles -o $tmpName");
125 >    my $count = countEvents ($tmpName, $cutFlow);
126 >    system ("cutFlowLimits $tmpName");
127      $nTotalEvents{$arg} = $count;
128      $nTotalEvents += $count;
129 <    unlink ("$opt{'prefix'}.root");
130 <  }
131 < my @rootFiles;
132 < my @weights;
133 < %weights = ();
134 < foreach my $file (@$files)
129 >    $weights{$arg} /= $count if !$opt{"weight"} && $opt{"xsection"};
130 >    $weights{$arg} /= $count if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dirs{$arg}};
131 >    push (@mergedFiles, "$tmpName");
132 >    push (@mergedWeights, $weights{$arg});
133 >  }
134 > my $mergedFiles = join (" ", @mergedFiles);
135 > my $mergedWeights = join (",", @mergedWeights);
136 > system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}_Unweighted.root");
137 > system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}.root -w $mergedWeights");
138 > foreach my $mergedFile (@mergedFiles)
139    {
140 <    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 <      }
140 >    unlink ("$mergedFile");
141    }
146 my $rootFiles = join (" ", @rootFiles);
147 my $weights = join (",", @weights);
148 system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights");
142   print "Weights:\n";
143   foreach my $arg (keys %weights)
144    {
145 <    printf "  $arg: %.1f (%.1f pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity;
145 >    my $shortArg = $arg;
146 >    $shortArg =~ s/^.*\/([^\/]*)$/$1/;
147 >    printf "  $shortArg: %.5g (%.5g pb)\n", $weights{$arg}, $weights{$arg} / $integratedLuminosity;
148    }
149   my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow);
150   print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting;
151   print "$nBadJobs jobs failed to run.\n" if $counting;
152 + print "$nIncompleteJobs jobs have not finished.\n" if $counting;
153  
154   sub
155   processArgs
# Line 245 | Line 241 | countEvents
241    my $cutFlow = shift;
242  
243    my $output = `getEventsFromCutFlow $file $cutFlow`;
244 <  if ($output =~ m/Did not find a histogram named/)
244 >  if ($output =~ m/Did not find a histogram named/ || $output =~ m/appears to be empty/ || $output =~ m/Failed to open/)
245      {
246        print $output;
247        return -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines