#include #include #include #include "TString.h" #include "TSystem.h" #include "TInterpreter.h" #include "TFile.h" #include "TH1.h" #include "TNtuple.h" #include "TCanvas.h" #include "TStyle.h" void basic() { // Read data from an ascii file and create a root file with an histogram and an ntuple. // see a variant of this macro in basic2.C //Author: Rene Brun // read file $ROOTSYS/tutorials/tree/basic.dat // this file has 3 columns of float data TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName()); dir.ReplaceAll("basic.C",""); dir.ReplaceAll("/./","/"); ifstream in; in.open(Form("%sFirstStripSignal.dat",dir.Data())); Float_t x,y; Int_t nlines = 0; TFile *f = new TFile("FirstStripSignal.root","RECREATE"); TH1F *h1 = new TH1F("h1", "x distribution", 1024, 0.5, 1024.5); TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y"); while (1) { in >> x >> y; if (!in.good()) break; if (nlines < 5) printf("x=%8f, y=%8f\n", x, y); h1->Fill(x,y); ntuple->Fill(x,y); nlines++; } printf(" found %d points\n",nlines); in.close(); f->Write(); // http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptStat gStyle->SetOptStat(1111); // http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptFit gStyle->SetOptFit(1111); TCanvas *c = new TCanvas("c", "c"); h1->Draw(); h1->Fit("gaus", "W", "", 200, 400); //TPaveStats *st = ((TPaveStats*)(h1->GetListOfFunctions()->FindObject("stats"))); // c->SetLogy(0); c->SaveAs("c.pdf"); }