#!/usr/bin/perl

## usage: give the YEAR as an input parameter
## processes 20 files from each year; produce hbooks:
##   --all hits

my $year  = $ARGV[0];
my $begin = $ARGV[1];
my $end   = $ARGV[2];

if (($begin eq "")||($end eq "")) { die "Usage: munt.pl 2002 beginday endday\n"; }

my $dir;
my @listoffiles;

$dir = "/data/csong/";
$outdir = "/data/csong/";
@listoffiles = ($begin..$end);

my $sieg_dir = "/home/csong/siegmund/recoos";
#my $munt = "micromunt";
my $munt = "minimunt";
my @segs;
my $outfile;
my $cmd;

## Flags for checking the ADC gate
#my $blocks = "-XU";
my $blocks = "-XUP";
my $flags = "-v -n";
## this way is better: modules USED by fit #2 (the linefit)
$flags .= " -yU=2";


my $head = "s2ab_"."$year"."_L1";
foreach $file (@listoffiles) {
    $outfile = "$head.$file.comp.cal.f2k.hbook";
    $cmd = "gunzip -c $dir/$head.$file.comp.cal.f2k.gz ".
        "| $sieg_dir/$munt $blocks $flags -f -O $outdir/$outfile";
    print "$cmd\n";
    `$cmd`;
}
