#include #include #include #include #include "TFile.h" #include "Riostream.h" #include #include #include "TF1.h" #include "TH1D.h" #include "TH2D.h" #include "TFile.h" #include "TGraph2D.h" #include "TCanvas.h" #include "TLegend.h" #include "TProfile.h" #include "TStyle.h" #include "TColor.h" #include "TLatex.h" #include "TAttFill.h" #include "TGraphErrors.h" #include "TGraph.h" #include "TAttMarker.h" using std::cout; using std::endl; using std::getline; void gaus() { TCanvas *c21 = new TCanvas(); TH1F *g = new TH1F("g", "example histogram",20,1450,3450); ifstream inp; double x,y; inp.open("datos.txt"); while(!inp.eof()) // To get you all the lines. { inp >> x >> y; if (!inp.good()) { //input failure, leave the loop break; } g->Fill(x,y); g->SetBinContent(x,y); g->SetBinError(x,0); } double parc[6]; TF1 *g1 = new TF1("g1","gaus",1500,3400); TF1 *g2 = new TF1("g2","gaus",1700,2600); g->Fit(g1,"R"); g->Fit(g2,"R+"); g1->GetParameters(&parc[0]); g2->GetParameters(&parc[3]); /* TF1 *f = new TF1 ("f","gaus(0)+gaus(3)",1500,3400); f->SetParameters(parc); g->Fit(f,"R"); f->SetLineColor(2); */ gStyle->SetOptStat(); gStyle->SetOptFit(111); g->SetTitle ("# de tracks para 8 enero"); g->GetXaxis()->SetTitle("adc cut"); g->GetYaxis()->SetTitle("# eventos"); g->SetFillColor(38); g->Draw(""); //g->SetBinContent(x,y); //g->SetBinError(1500,0); TImage *img21 = TImage::Create(); img21->FromPad(c21); img21->WriteImage("grafica.png"); delete g; delete c21; delete img21; }