Loading ASCII and f(x) fit

Hello

I have a little problem with this macro, when i rune it I get:
" Warning in TCanvas::Constructor: Deleting canvas with same name: c1
Warning in : Fit data is empty
"
I can see my data in Canvas window, sadly there is no fit.
My data file looks like this:

100 255.727
200 581.545
300 946.455
400 1335.64
500 1723.09
604 2030.55
704 2234.82

I cant find where Im making a mistake.

greetings

Jacek

#include "Riostream.h"
void dat() {

TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());

ifstream in;
in.open(Form("/home/j/calib_good/ch2_1",dir.Data()));

Float_t x,y;
Int_t nlines = 0;
TFile *f = new TFile(“Calib.root”,“RECREATE”);
TH2F *h1 = new TH2F(“h1”,“x distribution”,200,0,800,0,3000);
h1->SetBit(TH2::kCanRebin);

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=%f, y=%f”,x,y);
h1->Fill(x,y);
ntuple->Fill(x,y);
nlines++;
}
//printf(" found %d points\n",nlines);

TCanvas *c1 = new TCanvas(“c1”,“show profile”,600,900);
c1->Divide(1,2);
c1->cd(1);
h1->Draw();
c1->cd(2);

TProfile *prof = h1->ProfileX();
prof->Fit(“pol1”);

in.close();

f->Write();
}

// …
in.open(Form("/home/j/calib_good/ch2_1/%s",dir.Data()))
// …
TH2F *h1 = new TH2F(“h1”,“x distribution”, 200, 0.0, 800.0, 200, 0.0, 3000.0);

#include "Riostream.h"
void dat() {

TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());

ifstream in;
in.open(Form("/home/j/calib_good/ch2_1",dir.Data()));

float x,y;
int nlines = 0;

TFile *f = new TFile(“Calib.root”,“RECREATE”);
TH2F *h1 = new TH2F(“h1”,“FLASH ADC Calibration”,200,0,800,0,3000);
TH2F h2 = new TH2F(“h2”,“x distribution”,200,0,800,0,3000);
h1->SetBit(TH2::kCanRebin);
h2->SetBit(TH2::kCanRebin);
/

TCanvas *c1 = new TCanvas(“c1”,“show profile”,600,900);
c1->Divide(1,2);
c1->cd(1);
h1->Draw();
c1->cd(2);

TProfile *prof = h1->ProfileX();
prof->Fit(“pol1”);
*/
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=%f, y=%f”,x,y);
h1->Fill(x,y);
h2->Fill(x,y);
ntuple->Fill(x,y);
nlines++;
}
//printf(" found %d points\n",nlines);
//if (h2->IsInside(x,y)) h2->Fill(x,y);

TCanvas *c1 = new TCanvas(“c12”,“show profile”,600,900);
c1->Divide(1,2);
c1->cd(1);
h1->Draw();
c1->cd(2);
//c1->cd(3);
//h2->Draw();
gStyle->SetHistFillColor(kRed);
h1->UseCurrentStyle();
// TProfile *prof = h1->ProfileX();
h2->Fit(“pol1”);
//h2->GetParameters();
TF1 *fit = h2->GetFunction(“pol1”);
//fit->draw();
double chi2 = fit->GetChisquare();
double p0 = fit->GetParameter(0);
double p1 = fit->GetParameter(1);

in.close();

f->Write();
}

solved this way.

cheers thanks for info.

Jacek

I believe you incorrectly use ‘new TH2F’, see: http://root.cern.ch/root/html/TH2F.html
And in the line ‘in.open(Form("/home/j/calib_good/ch2_1",dir.Data()));’, the contents of ‘dir.Data()’ is not used at all.

Thanks, you`r right it did not do anything. As for the TH2F I cant see my error. Could you point out what is exactly wrong ?

greetings

Jacek

See my first post in this thread.

Sorry my mistake. The data points look way better now thank you.