#!/usr/bin/python
# -*- coding: iso-8859-15 -*-

import os,sys
# import getopt
##maybe it's supposed to be sys.argv[:] ... maybe
tmpargv = sys.argv
sys.argv = [ '-n' ]
from ROOT import *
sys.argv = tmpargv

# import psyco
# psyco.full()

# from time import sleep
# from optparse import OptionParser

# from ROOT_Tools import RootHandler
# from CommandLineMod import CommandLine



if __name__ == "__main__":

	gStyle.SetTitleBorderSize	( 0			)   # duh
	# gStyle.SetTitleBorderSize	( 1			)
	gStyle.SetPadBorderMode		( 0			)
	gStyle.SetOptStat			( 111111	)	# Good standard stats display.
	gStyle.SetOptFit			( 1111		)	# Display fit info if available.
	gStyle.SetStatX				( 0.55		)	# Statistic box X
	gStyle.SetStatY				( 0.95		)	# Statistic box Y
	gStyle.SetStatW				( 0.4		)	# Statistic box width
	gStyle.SetStatH				( 0.3		)	# Statistic box height
	# gStyle.SetMarkerStyle		( 24		)	# Open circle.
	gStyle.SetOptTitle			( 1			)	# Display histogram titles.
	gStyle.SetCanvasColor		( 10		)	# Background color (white)
	gStyle.SetPadColor			( 10		)	# Background color (white)
	gStyle.SetFillColor			( 10		)	# Background color (white)
	gStyle.SetHistFillColor		( 10		)	# Background color (white)
	gStyle.SetFrameFillColor	( 10		)	# Background color (white)
	gStyle.SetStatColor			( 10		)	# Background color (white)
	gStyle.SetTextFont			( 132			)

	gStyle.SetPadLeftMargin		(0.12)
	gStyle.SetPadBottomMargin	(0.17)
	gStyle.SetPadTopMargin	(0.05)
	gStyle.SetPadRightMargin		(0.04)

	gStyle.SetTitleFillColor	( 10		)	# Background color (white)
	gStyle.SetTitleFontSize		( 0.08		)	# Title Font Size
	gStyle.SetTitleX			( 0.10		)	# Title box width
	gStyle.SetTitleW			( 0.50		)	# Title box width
	gStyle.SetTitleH			( 0.09		)	# Title box width

	gStyle.SetStatBorderSize	( 1			)
	gStyle.SetLegendBorderSize	( 1			)
	gStyle.SetPalette			( 1			)	# Nicer colour scale for 2D histograms.
	gStyle.SetPaperSize			( 20., 24.	)
	gStyle.SetHistLineWidth		( 1			)
	
	gStyle.SetLabelFont(132)
	gStyle.SetLabelFont(132,"X")
	gStyle.SetLabelFont(132,"Y")
	gStyle.SetLabelFont(132,"Z")
	gStyle.SetLabelFont(132,"T")
	gStyle.SetTitleFont(132)
	gStyle.SetTitleFont(132,"X")
	gStyle.SetTitleFont(132,"Y")
	gStyle.SetTitleFont(132,"Z")
	gStyle.SetTitleFont(132,"T")
	gStyle.SetLabelSize(0.07)
	gStyle.SetLabelSize(0.07,"X")
	gStyle.SetLabelSize(0.07,"Y")
	gStyle.SetLabelSize(0.07,"Z")
	gStyle.SetLabelSize(0.07,"T")
	gStyle.SetTitleSize(0.07   )
	gStyle.SetTitleSize(0.07,"X")
	gStyle.SetTitleSize(0.07,"Y")
	gStyle.SetTitleSize(0.07,"Z")
	gStyle.SetTitleSize(0.07,"T")
	gStyle.SetTextFont(132)
	gStyle.SetStatFont(132)

	gROOT.SetBatch()
	gROOT.ForceStyle()

	# No Stats !
	# gStyle.SetOptStat			( 0	)	# Good standard stats display.
	gStyle.SetOptStat			( 1110	)	# Good standard stats display.
	gStyle.SetOptFit			( 0	)	# Display fit info if available.

	gStyle.SetTitleW			( 0.70		)	# Title box width

	gStyle.SetPaperSize(6,15)
	gStyle.SetCanvasDefH(700)                 # Default = 700
	gStyle.SetCanvasDefW(700)                 # Default = 700

	# We can have many files in input
	FileList	= 'DCA12_Translation/run8260_R.dat'

	HistName 	= 'PrecisionTranslation'
	OutputFile	= '../DCA_Precision_Trans.eps'

	Canv = TCanvas()
	# Leg = TLegend(0.7, 0.7,0.9,0.9)

	MinX = -34.999
	MaxX = 20

	# Title	= 'TDC time versus TDC width, wire 12;Width [ns];Hit time [ns]'
	Title	= ';#Delta_{translation} [#mu m];Number of planes'


	Histo	= TH1D( HistName, Title, 15, MinX, MaxX);

	
	F = open(FileList, 'r')
	 
	for line in F:
		T = float(line)					# cm
		M = T * 10000					# microns
		Histo.Fill( M )

	Histo.SetTitleOffset( 1.2, 'X')
	Histo.SetTitleOffset( 0.8, 'Y')
	Histo.GetXaxis().SetNdivisions(5)
	Histo.GetYaxis().SetNdivisions(10)

	Histo.Draw()


# 	for i,f in enumerate(FileList):
# 		Fname = f.split(':')[0]
# 
# 		F.append( TFile(Fname) )
# 		H	= F[i].Get(HistName)
# 
# 		if ( i == 0):
# 			H.Draw()
# 			H.SetTitle(Title)
# 			H.SetAxisRange(MinY,MaxY,'Y')
# 			H.SetLineWidth(1)
# 			H.SetTitleOffset( 1.2, 'Y')
# 			H.Fit('pol1', "Q","", 20.0, 150.0)
# 			H.GetFunction('pol1').SetLineWidth(1)
# 		else:
# 			if ( i > 3 ):
# 				H.SetLineColor(i+2)
# 				H.SetMarkerColor(i+2)
# 			else:
# 				H.SetLineColor(i+1)
# 				H.SetMarkerColor(i+1)
# 			H.SetLineWidth(1)
# 			H.Draw('same')
# 		Leg.AddEntry(H, LegName[i], 'lp')
# 
# 	Leg.Draw()

	# For Postscript
	# Canv.Print(OutputFile,"Landscape")
	# For eps
	Canv.Print(OutputFile)