// read and create root file //#include #include"Riostream.h" #include"TFile.h" #include"TH1.h" #include"TNtuple.h" #include"TStyle.h" #include"TSpectrum.h" #include"TVirtualFitter.h" using namespace std; void phongdien042016() { TFile *f1 = new TFile("/home/mydanguyen/Documents/khongbia_7200_03042016.root","recreate"); //cout << "txt1" << endl; const int n = 2000000; const int nlines = 2048; // create the histogram TH1F *h1 = new TH1F("h1","energy vs count",2048,0., 2048.);// xem lai TH1F *b = new TH1F("bg","",2048,0.,2048.); h1->GetYaxis()->SetTitle("Count"); h1->GetYaxis()->CenterTitle(1); h1->GetXaxis()->SetTitle("Chanel"); h1->GetXaxis()->CenterTitle(1); gStyle->SetOptStat("imr"); // make the variable for the read txt Float_t line; Double_t y[n]; Double_t Chanel[nlines]; ifstream input; //TSpectrum *s= new TSpectrum(); //s->Background(h1,2048,6,kBackIncreasingWindow,kBackOrder2,kFALSE,kBackSmoothing3,kFLASE); // read txt file ifstream input; input.open(Form("/home/mydanguyen/Documents/Khongbia_7200s_03042016.TKA")); //cout << "Test"<< c1 << endl; int i=0; if (input.is_open()) { for (i=0; i>line; i=i++; if (i<2) y[i]=0; else //cout <SetBinContent(i,y[i]); h1->GetBinWidth(1); //h1->Fill(n); b->SetBinContent(i,y[i]); b->SetLineColor(kRed); }} input.close(); f1->Write(); f1->Close(); f1->cd(); }