#!/bin/env perl

# Usage example:    classify_cross.pl 1000 00821
#                                      ^    ^
#                                      |    |  $i where script will search for cross-sec in $FA/whiz$i/whizard.log
#                                      | integer value for sqrt(s) in GeV
#
#  exit code =  0     if   1.E-3 fb < cross-section < 1.E+2 fb
#  exit code =  1     if   1.E+2 fb <= cross-section
#  exit code =  2     otherwise

use strict;
use IO::File;
use Env;

    my $isqrts = $ARGV[0];
    my $begin = $ARGV[1];

    my $i = $begin;
    my $istat = 2;
    my $sig = 0.;

    my $len = length($i);
    my $padlen = 5 - $len;
    my $pad = "0" x $padlen;
    my $jobnum = $pad . $i;

    my $logName = "$ENV{FA}/$isqrts/whiz$jobnum/whizard.log";
    my $logh = new IO::File("< $logName");

    foreach my $linelog (<$logh>)
       {
       #     sum            1.1816115E+03  7.67E-01    0.06         100.00
	   if ($linelog =~ /sum            (\d\.\d\d\d\d\d\d\d[E,e].\d\d)/)
	   {
	       $sig = $1;
# 	       print $sig, $/;
               if ($sig > 1.E-3 )
	       {
		   if($sig < 1.E+2)
		   {
		       $istat = 0;
		   }
		   else
		   {
		       $istat = 1;
		   }
		   last
	       }	       
	       else
	       {
		   $sig = 0.;
	       }
	   }
       }



print "sig = $sig   Exit status = $istat", $/;

exit($istat);


