{
//
// To see the output of this macro, click begin_html <a href="gif/hsum.gif" >here</a> end_html
//    Simple example illustrating how to use the C++ interpreter	
//    to fill histograms in a loop and show the graphics results
//

  gROOT->Reset();

 // c1 = new TCanvas("c1","The HSUM example",200,10,600,400);


  TCanvas c1("name","XML vs CSV", 200, 10, 600, 600);
  TPaveLabel l1(0.3, 0.91, 0.7, 0.99, "Global Title");
  l1.Draw();
  c1.Divide(1,2);
 
 	c1.SetGrid();
	c1.cd(1);
	gPad->SetGrid();
	/*
	c1.Divide(1,2);
	gBenchmark->Start("hsum");
	#include <fstream.h>
	float num[10010], xmldata[10010];
	ifstream data("ex1xml.csv");
	int index = 0;
	TH1S h1("ex1xml", "EX1 Read XML data", 150, 0, 5 );
	h1.GetXaxis()->SetLabelFont(112);
	while ( !data.eof() ) {
		data >> num[index] >> xmldata[index];
		h1.Fill(xmldata[index]);
		index++;
	}
	data.close();
	h1.GetXaxis().SetTitle("time[ms]");
	h1.GetYaxis().SetTitle("number of Events");
	h1.SetFillColor(4);
	h1.SetFillStyle(3002);
	h1.Draw();
	Float_t minval, maxval;
	h1.Fit("gaus","","",2.07,2.3);
	
	gStyle->SetOptFit();

	c1->Modified();
	c1->Update();
*/
	 
  gStyle->SetOptStat(1001111);
  gStyle->SetOptFit(111);
  gStyle->SetCanvasBorderMode(0);
  gStyle->SetCanvasColor(0);
  gStyle->SetStatColor(0);
  gStyle->SetFrameBorderSize(0);
  gStyle->SetFrameBorderMode(0);
  
  	#include <fstream.h>
	ntuple = new TNtuple("name", "title", "no:dat");
	ifstream data("ex1xml.csv");
	float no,dat;
	while( data >> no >> dat ) {
		ntuple->Fill(no, dat );
	}
	data.close();
	//ntuple->Print();
	TCut positiveCut = "dat>=0&&dat<=220";
	//TH1F* hnew = new TH1F("hnew", "EX1 Read XML data", 150, 0, 5);//MAC mini サーバ
	TH1F* hnew = new TH1F("hnew", "EX1 Read XML data", 220, 6.5, 8.5);
	hnew->GetXaxis()->SetTitle("time[ms]");
	hnew.GetYaxis().SetTitle("number of Events");
	//hnew.SetFillStyle(3002);
	hnew->SetLineColor(1);//ヒストグラムの線の色
	ntuple->Draw("dat>>hnew",positiveCut);
	hnew->Draw();
  	hnew->SetFillColor(42);//ヒストグラムを塗りつぶす色
	hnew->SetMarkerColor(9);
	TF1 f1("f1", "gaus");
	f1.SetLineColor(2);
	//hnew.Fit("f1","","", 2.07,2.3); //MAC mini サーバ
	hnew.Fit("f1","","", 7.6,7.7);	  //Junk3 Server
	gStyle->SetOptFit();
	
	c1.cd(2);
	gPad->SetGrid();
	ntuple = new TNtuple("name", "title", "no:dat");
	ifstream data("ex1csv.csv");
	float no,dat;
	while( data >> no >> dat ) {
		ntuple->Fill(no, dat );
	}
	data.close();
	//ntuple->Print();
	TCut positiveCut = "dat>=0&&dat<=220";
	//TH1F* hnew = new TH1F("hnew", "EX1 Read CSV data", 150, 0, 5);
	TH1F* hnew = new TH1F("hnew", "EX1 Read CSV data", 101, 1, 1.1);
	hnew->GetXaxis()->SetTitle("time[ms]");
	hnew.GetYaxis().SetTitle("number of Events");
	//hnew.SetFillStyle(3002);
	hnew->SetLineColor(1);//ヒストグラムの線の色
	ntuple->Draw("dat>>hnew",positiveCut);
	hnew->Draw();
  	hnew->SetFillColor(42);//ヒストグラムを塗りつぶす色
	hnew->SetMarkerColor(9);
	
	//hnew.Fit("gaus", "", "", 0.91, 1.04 );
	//hnew.Fit("f1", "", "", 0.91, 1.04 );
	//hnew.Fit("f1", "", "", 1.1, 1.12 );
	hnew.Fit("f1", "", "", 1.013, 1.025 );
	
	gStyle->SetOptFit();
	c1.Print("csvvwxml.eps");
	
// Create some histograms.
/*  total  = new TH1F("total","This is the total distribution",100,-4,4);
  main   = new TH1F("main","Main contributor",100,-4,4);
  s1     = new TH1F("s1","This is the first signal",100,-4,4);
  s2     = new TH1F("s2","This is the second signal",100,-4,4);
  total->Sumw2();   // this makes sure that the sum of squares of weights will be stored
  total->SetMarkerStyle(21);
  total->SetMarkerSize(0.7);
  main->SetFillColor(16);
  s1->SetFillColor(42);
  s2->SetFillColor(46);
  TSlider *slider = 0;

// Fill histograms randomly
  gRandom->SetSeed();
  const Int_t kUPDATE = 500;
  Float_t xs1, xs2, xmain;
  for ( Int_t i=0; i<10000; i++) {
     xmain = gRandom->Gaus(-1,1.5);
     xs1   = gRandom->Gaus(-0.5,0.5);
     xs2   = gRandom->Landau(1,0.15);
     main->Fill(xmain);
     s1->Fill(xs1,0.3);
     s2->Fill(xs2,0.2);
     total->Fill(xmain);
     total->Fill(xs1,0.3);
     total->Fill(xs2,0.2);
     if (i && (i%kUPDATE) == 0) {
        if (i == kUPDATE) {
           total->Draw("e1p");
           main->Draw("same");
           s1->Draw("same");
           s2->Draw("same");
           c1->Update();
           slider = new TSlider("slider","test",4.2,0,4.6,total->GetMaximum(),38);
           slider->SetFillColor(46);
        }
        if (slider) slider->SetRange(0,Float_t(i)/10000.);
        c1->Modified();
        c1->Update();
     }
  }
  slider->SetRange(0,1);
  total->Draw("sameaxis"); // to redraw axis hidden by the fill area
  c1->Modified();
  gBenchmark->Show("hsum");
  */
}
