// read and create root file #include #include"Riostream.h" #include"TSpectrum.h" #include"TFile.h" #include"TH1.h" #include"TNtuple.h" #include"TStyle.h" //#include"Macros/Background.C" using namespace std; void lamtron() { TFile *f1 = new TFile("/home/bigboss/Data/file_root/trysmooth/Mauda1x2_AF11222_mat1.pdf","recreate"); TFile *f2 = new TFile("/home/bigboss/Data/file_root/trysmooth/Mauda1x2_AF11222_mat1_truphong.pdf","recreate"); //TFile *f3 = new TFile("/home/bigboss/Data/file_root/trysmooth/lam tron pho.root","recreate"); //cout << "txt1" << endl; const int n = 2000000; const int nlines = 2048; // create the histogram gStyle->SetOptStat("imr"); TH1F *h1 = new TH1F("tru phong","energy vs count",2048,0., 2048.);// xem lai h1->GetYaxis()->SetTitle("Count"); h1->GetYaxis()->CenterTitle(1); h1->GetXaxis()->SetTitle("Chanel"); h1->GetXaxis()->CenterTitle(1); TH1F *h2 = new TH1F("phong","background",2048,0., 2048.); h2->GetYaxis()->SetTitle("Count"); h2->GetYaxis()->CenterTitle(1); h2->GetXaxis()->SetTitle("Chanel"); h2->GetXaxis()->CenterTitle(1); //TH1F *h3 = new TH1F(*h1); //h1->Add(h2,-1.); // make the variable for the read txt Float_t line1,line; Double_t y1[n],y[n]; Double_t Chanel[nlines]; ifstream input1,input; // read txt file ifstream input1; input1.open(Form("/home/bigboss/Data/TN_3416/mautheobeday/Mau AF11225_5x20x20.TKA")); //cout << "Test"<< c1 << endl; int i=0; if (input1.is_open()) { for (i=0; i>line1; i=i++; if (i<2) y1[i]=0; else //cout <SetBinContent(i,y1[i]); h1->GetBinWidth(1); h1->Fill(n); }} input1.close(); //h1->Draw() f1->Write(); f1->Close(); f1->cd(); cout<<"-----Background spectrum------"<>line; j=j++; if (j<2) y[j]=0; else y[j]=line; cout<SetBinContent(j,y[j]); h2->GetBinWidth(1); h2->Fill(n); }} input.close(); h1->Add(-h2,1.); //TH1F *h3 = h1->Add(h2,-1); f2->Write(); f2->Close(); f2->cd(); //---------------------------------------------------------------------------------------------------------------------------- /* TH1F *h3 = (TH1F*)h1->Clone(); h3->SetLineColor(kRed); TSpectrum *s = new TSpectrum(); TH1F *bg = s->Background(h3,5,"same"); //s->Background(50); //TH1F *bg = new TH1F("estimate","nen",2048,0., 2048.); //bg = s->Background(50); bg->SetLineColor(kBlue); //THStack *hs = new THStack(); //THStack hs("hs","lamtron"); hs->Add(h3); hs->Add(bg); hs->Draw(); f3->Write(); f3->Close(); f3->cd(); */ }