#!/usr/bin/perl 

use strict;
use warnings;

#my $pltDir="/cdf/www/offline/calibrations/plugcal/webval";
#my $htmDir="http://www-cdf.fnal.gov/offline/calibrations/plugcal/webval";
#my $pltDir="";
#my $htmlDir="";
my $htlDir="http://www-cdf.fnal.gov/offline/calibrations/plugcal/webval0";
my $log="junk.log";

system "rm -f $log";

print "<html><head><title>PEM/PHA Calibration Validation</title></head>\n";
print "<body>\n";
print "<h1 align=center>PEM/PHA Calibration Validation</center></h1>\n";
print "<br><center>Runs $ARGV[0] - $ARGV[1]</center><br>\n";
print "<br><br><center><h3>CC, CP Z-peak target: 90.6 GeV</h3></center><br><br>\n";
print "<hr><center><h3>PEM E/W quadrant Mass Plots</h3></center>\n";
makePlot("masc0", "Quadrant 0W");
makePlot("masc1", "Quadrant 1W");
makePlot("masc2", "Quadrant 2W");
makePlot("masc3", "Quadrant 3W");
makePlot("masc4", "Quadrant 4E");
makePlot("masc5", "Quadrant 5E");
makePlot("masc6", "Quadrant 6E");
makePlot("masc7", "Quadrant 7E");

print "<br><br>\n";
print "<hr><center><h3>Global CC and CP Mass Plots</h3></center>\n";
makePlot("mecem", "CC Z(ee)");
makePlot("emasc", "CP[East](ee)");
makePlot("wmasc", "CP[West](ee)");

print "<br><br>\n";
print "<hr><center><h3>Run Dependence CC and CP Plots</h3></center>\n";
print "<br><br><font color=green>Green: CC</font><br>
               <font color=red>Red: CP[East]</font><br>
	       <font color=blue>Blue: CP[West]</font><br><br>\n";
makePlot("runvar", "Run Dependence");

print "<br><br>\n";
print "<hr><center><h3>CP Detector Eta/Phi Plots</h3></center>\n";
makePlot("etavar", "Eta Dependence");
makePlot("phivar", "Phi Dependence");

print "<br><br>\n";
print "<hr><center><h3>CC and CP Mass Plots Overlayed</h3></center>\n";
makePlot("cccp", "CP over CC");
	       
print "</body></html>\n";


#sub makePlot {
#  print "<br><br>\n";
#  system "rm -f $pltDir/$_[0].gif";
#  print " $_[1]  Left/Right plots: Current/Last period <br>\n";
#  system "$pltDir/ps2gif.sh --dpi=75 $pltDir/$_[0].eps $pltDir/$_[0].gif > $log 2>&1";
#  print "<a href=$htmDir/$_[0].eps><img width=48% src=$htmDir/$_[0].gif /></a> &nbsp;
#         <a href=$htlDir/$_[0].eps><img width=48% src=$htlDir/$_[0].gif /></a>\n";
#  print "<br><br>\n";
#}

sub makePlot {
  print "<br><br>\n";
  #system "rm -f $pltDir/$_[0].gif";
  print " $_[1]  Left/Right plots: Current/Last period <br>\n";
  system "./ps2gif.sh --dpi=75 $_[0].eps $_[0].gif > $log 2>&1";
  print "<a href=$_[0].eps><img width=48% src=$_[0].gif /></a> &nbsp;
         <a href=$htlDir/$_[0].eps><img width=48% src=$htlDir/$_[0].gif /></a>\n";
  print "<br><br>\n";
}

exit;

