// =====================================================================
/*!
//
//  \file Trootinit.h
//  \brief ROOTアプリケーションの初期化関数が定義されています.
//  \author Go IWAI <goiwai@users.sourceforge.jp>
//
//  $Id: Trootinit.h,v 1.10 2004/02/29 09:47:57 goiwai Exp $
//  $Name: CLDAQ-1-14-06 $
//  $Log: Trootinit.h,v $
//  Revision 1.10  2004/02/29 09:47:57  goiwai
//  #ifdef __CLDAQ_ROOT_USEを最も外側に配置した.
//
//  Revision 1.9  2004/02/27 17:04:10  goiwai
//  ROOTがらみの変更です
//
//  Revision 1.8  2004/01/29 04:52:29  goiwai
//  スタイルを指定できるようにしました.
//
//  Revision 1.7  2004/01/19 21:09:38  goiwai
//  プリプロセッサの接頭辞をCLDAQ__に変更しました.
//
//  Revision 1.6  2003/11/03 08:42:19  goiwai
//  Doxygen用のタグとコメントをうつ試みを開始しました.
//
//  Revision 1.5  2003/10/06 17:02:36  goiwai
//  *** empty log message ***
//
//  Revision 1.4  2003/07/30 16:17:11  goiwai
//  ファイルにコミットログをつけることにしました.
//
*/
// =====================================================================
#ifdef __CLDAQ_ROOT_USE
#ifndef CLDAQ__TROOTINIT_H
#define CLDAQ__TROOTINIT_H

#include <TROOT.h>
#include <TSystem.h>
#include <TApplication.h> 
#include <TStyle.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <TH1.h>
#include <TH2.h>
#include <TCanvas.h>
#include <TNtuple.h>
#include <TFile.h>
#include <TPad.h>
#include <TF1.h>
#include <TLegend.h>
#include <TPaveText.h>
#include <TRandom.h>
#include <TStopwatch.h>
#include <TGaxis.h>
#include <TLatex.h>
#include <TPaveStats.h>

#include "Tglobals.h"

static TApplication* rootinit( const Tstring& style = "", const Tstring& name = "CLDAQ ROOT APPLICATION", Tint* argc = 0, Tchar** argv = 0 );


//inline static TApplication* rootinit( const Tstring& style = "", const Tstring& name = "CLDAQ ROOT Application", Tint* argc = 0, Tchar** argv = 0 )
inline TApplication* rootinit( const Tstring& style, const Tstring& name, Tint* argc, Tchar** argv )
{
  TApplication* app = new TApplication( name.c_str(), argc, argv );
  gROOT -> Reset();

  if ( ! style.empty() && style == "Default" || style == "Plain" || style == "Pub" || style == "Video" || style == "Bold" ) {
    gROOT -> SetStyle( style.c_str() );
  } else {
    // ===================================================================
    const Float_t padmargint = 0.12;
    const Float_t padmarginb = 0.12;
    const Float_t padmarginr = 0.04;
    const Float_t padmarginl = 0.12;
    //const Color_t histfillcolor = 21;
    const Int_t optstat = 1111110;
    const Int_t optfit = 1111;
    const Int_t transparence = 10;
    //const Int_t titlecolor = transparence;
    const Float_t titlew = 1.0 - padmarginl - padmarginr;
    const Float_t titleh = padmargint / 2.0;
    const Float_t titlex = padmarginl;
    const Float_t titley = 1.0 - titleh + padmargint / 10.0;

    const Int_t statcolor = transparence;
    const Float_t statx = 1.0 - padmarginr;
    const Float_t statw = 0.32;
    const Float_t staty = 1.0 - padmargint;
    const Int_t framefillcolor = transparence;
    const Int_t canvascolor = transparence;
    //const Float_t datex = 0.88;
    //const Float_t datey = 0.91;
    //const Int_t maxdigits = 6;

    const Style_t markerstyle = 21;
    //const Color_t markercolor = 2;
    //const Size_t markersize = 1;
    //const Color_t funccolor = 4;
    //const Style_t funcstyle = 1;
    //const Width_t funcwidth = 5;
    // ===================================================================



    // Pad
    gStyle -> SetPadTickX( kTRUE );
    gStyle -> SetPadTickY( kTRUE );
    //gStyle -> SetPadGridX( kTRUE );
    //gStyle -> SetPadGridY( kTRUE );
    gStyle -> SetPadBorderSize( 0 );
    gStyle -> SetPadBorderMode( 0 );
    gStyle -> SetPadTopMargin( padmargint );
    gStyle -> SetPadBottomMargin( padmarginb );
    gStyle -> SetPadRightMargin( padmarginr );
    gStyle -> SetPadLeftMargin( padmarginl );


    // Status
    gStyle -> SetStatBorderSize( 1 );
    gStyle -> SetStatColor( statcolor );
    gStyle -> SetStatStyle( 0 );
    gStyle -> SetStatX( statx );
    gStyle -> SetStatW( statw );
    gStyle -> SetStatY( staty );


    // Frame
    //gStyle -> SetFrameFillColor( 21 );
    //gStyle -> SetFrameFillColor( 3 );
    //gStyle -> SetFrameFillStyle( 1001 );
    gStyle -> SetFrameBorderMode( 0 );
    gStyle -> SetFrameBorderSize( 0 );
    gStyle -> SetFrameFillColor( framefillcolor );
    gStyle -> SetFrameFillStyle( 0 );



    // Canvas
    gStyle -> SetCanvasBorderMode( 0 );
    gStyle -> SetCanvasBorderSize( 0 );
    gStyle -> SetCanvasColor( canvascolor );



    // Histogram
    //gStyle -> SetHistFillColor( transparence );

    // Marker
    gStyle -> SetMarkerStyle( markerstyle );
    //gStyle -> SetMarkerColor( markercolor );
    //gStyle -> SetMarkerSize( markersize );


    // Function
    //gStyle -> SetFuncColor( funccolor );
    //gStyle -> SetFuncStyle( funcstyle );
    //gStyle -> SetFuncWidth( funcwidth );





    // Option
    gStyle -> SetOptStat( optstat );
    gStyle -> SetOptFit( optfit );


    // title
    gStyle -> SetTitleBorderSize( 0 );
    gStyle -> SetTitleStyle( 0 );
    gStyle -> SetTitleX( titlex );
    gStyle -> SetTitleY( titley );
    gStyle -> SetTitleW( titlew );
    gStyle -> SetTitleH( titleh );



    //  TGaxis *axis;
    //  Int_t kCenterTitle = 1<<12;
    //TGaxis::SetMaxDigits( maxdigits );
    gStyle -> SetPaperSize( TStyle::kA4 );


    // Date
    //gStyle -> SetOptDate( 3 );
    //gStyle -> SetDateX( datex );
    //gStyle -> SetDateY( datey );

    // Palette
    gStyle -> SetPalette( 1 );
  }

  return app;
}

#endif
#endif
