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.18 by ahart, Thu Jan 31 17:32:03 2013 UTC vs.
Revision 1.24 by ahart, Fri Apr 12 05:18:05 2013 UTC

# Line 46 | Line 46 | foreach my $file (@$files)
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            {
# Line 60 | Line 60 | foreach my $file (@$files)
60              $nBadJobs++;
61              print "WARNING: Skipping job $jobNumber. (signal $fileContents)\n";
62              $signals{$dir}{$jobNumber} = $fileContents;
63            $counting = 1;
63            }
64          else
65            {
# Line 83 | Line 82 | foreach my $file (@$files)
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        }
# Line 94 | Line 94 | foreach my $file (@$files)
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"};
108 >                if ($opt{"weight"})
109 >                  {
110 >                    push (@weights, $opt{"weight"}) if !($opt{"weight"} =~ m/,/);
111 >                    push (@weights, 1.0) if $opt{"weight"} =~ m/,/;
112 >                  }
113                  push (@weights, $opt{"xsection"} * $integratedLuminosity) if !$opt{"weight"} && $opt{"xsection"};
114                  push (@weights, $crossSections{$dir} * $integratedLuminosity) if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dir};
115                  push (@weights, 1.0) if !$opt{"weight"} && !$opt{"xsection"} && !(defined $crossSections{$dir});
# Line 128 | Line 139 | foreach my $arg (@ARGV)
139      $nTotalEvents += $count;
140      $weights{$arg} /= $count if !$opt{"weight"} && $opt{"xsection"};
141      $weights{$arg} /= $count if !$opt{"weight"} && !$opt{"xsection"} && defined $crossSections{$dirs{$arg}};
142 <    push (@mergedFiles, "$tmpName");
142 >    push (@mergedFiles, $tmpName);
143      push (@mergedWeights, $weights{$arg});
144    }
145   my $mergedFiles = join (" ", @mergedFiles);
146   my $mergedWeights = join (",", @mergedWeights);
147 < system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}_Unweighted.root");
147 > $mergedWeights = $opt{"weight"} if $opt{"weight"} && $opt{"weight"} =~ m/,/;
148   system ("mergeTFileServiceHistograms -i $mergedFiles -o $opt{'prefix'}.root -w $mergedWeights");
149   foreach my $mergedFile (@mergedFiles)
150    {
151      unlink ("$mergedFile");
152    }
153 < my $output = sprintf "Weights:\n";
153 > print "=============================================\n";
154 > my $output = sprintf "Cross-section of samples:\n";
155 > my $printOutput = 0;
156 > foreach my $arg (keys %weights)
157 > {
158 >    my $shortArg = $arg;
159 >    $shortArg =~ s/^.*\/([^\/]*)$/$1/;
160 >    $output = sprintf "%s  $shortArg: %.5g pb\n", $output, ($crossSections{$dirs{$arg}});
161 >    $printOutput = 1 if $weights{$arg} != 1;
162 > }
163 > print $output if $printOutput;
164 >
165 > my $output = sprintf "Effective luminosities of samples:\n";
166   my $printOutput = 0;
167   foreach my $arg (keys %weights)
168    {
169      my $shortArg = $arg;
170      $shortArg =~ s/^.*\/([^\/]*)$/$1/;
171 <    $output = sprintf "%s  $shortArg: %.5g (%.5g pb)\n", $output, $weights{$arg}, $weights{$arg} / $integratedLuminosity;
171 >    $output = sprintf "%s  $shortArg: %.5g/fb\n", $output, ($integratedLuminosity / (1000.0 * $weights{$arg})) if $weights{$arg} != 1;
172      $printOutput = 1 if $weights{$arg} != 1;
173    }
174   print $output if $printOutput;
175 +
176 + $output = sprintf "Weights for target luminosity of %g/fb:\n", ($integratedLuminosity / 1000.0);
177 + $printOutput = 0;
178 + foreach my $arg (keys %weights)
179 +  {
180 +    my $shortArg = $arg;
181 +    $shortArg =~ s/^.*\/([^\/]*)$/$1/;
182 +    $output = sprintf "%s  $shortArg: %.5g\n", $output, $weights{$arg} if $weights{$arg} != 1;
183 +    $printOutput = 1 if $weights{$arg} != 1;
184 +  }
185 + print $output if $printOutput;
186 +
187   my $goodEvents = countEvents ("$opt{'prefix'}.root", $cutFlow);
188   print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting;
189   print "$nBadJobs jobs failed to run.\n" if $counting;
190   print "$nIncompleteJobs jobs have not finished.\n" if $counting;
191 + print "=============================================\n";
192  
193   sub
194   processArgs
# Line 211 | Line 247 | printHelp
247    printf "%-29s%s\n", "  -p, --prefix PREFIX", "output is  named PREFIX.root";
248    printf "%-29s%s\n", "  -w, --weight WEIGHT", "scale the output by WEIGHT, overriding the";
249    printf "%-29s%s\n", "                     ", "automatic weighting using the cross section from";
250 <  printf "%-29s%s\n", "                     ", "the database";
250 >  printf "%-29s%s\n", "                     ", "the database; WEIGHT may be a single number or a";
251 >  printf "%-29s%s\n", "                     ", "comma-separated list, one for each input file";
252    printf "%-29s%s\n", "  -x, --xsection XSECTION", "use XSECTION to weight the histograms instead of";
253    printf "%-29s%s\n", "                     ", "the value in the database";
254  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines