TH1D* MakeHistoFromFile(TString filename) { ifstream inp; double x,x1,x2,y; inp.open(filename.Data()); int i = 0; while (inp >> x >> y) { if (i == 0) x1 = x; i++; } x2 = x; inp.close(); double bw = 1.; // Bin width int nb = i+1; // Number of bins auto h = new TH1D("h","AIST HPGe Detector Spectrum",nb,x1-bw/2.,x2+bw/2.); h->GetXaxis()->SetTitle("Energy (keV)"); h->GetYaxis()->SetTitle("Count"); inp.open(filename.Data()); i = 0; while (inp >> x >> y) { i++; h->SetBinContent(i,y); } inp.close(); return h; } void File1() { auto h = MakeHistoFromFile("File1.txt"); h->Draw(); }