TGrapherrors problem

Hi

This is my macro

[code]#include “Riostream.h”
//#include “iostream”
//#include “strings.h”
#include <TMath.h>
#include <TH2F.h>
#include <TH1F.h>
#include “iostream”
#include “stdio.h”
#include “stdlib.h”
#include “time.h”
#include “string”
#include “unistd.h”
#include “string.h”
#include “fstream”
#include “Riostream.h”

#include “TStyle.h”
#include “TFile.h”
#include “TTree.h”
#include “TH1F.h”
#include “TH2F.h”
#include “TH2.h”
#include “TF1.h”
#include “TMath.h”
#include “TLine.h”
#include “TPolyLine.h”
#include “TArc.h”
#include “TMatrixD.h”
#include “TMinuit.h”
#include “TMath.h”
#include “TChain.h”
#include
#include

void dat_straw() {

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

ifstream in;
//in.open(Form("/home/j/calib_good/ch2_1",dir.Data()));
in.open(Form("/home/j/output_1GeV_90deg/output_1GeV_90deg/straw",dir.Data()));
float x,y;
const int i=8;
float x[i],y[i];
//float dx[i],dy[i];
int nlines = 0;

TFile *f = new TFile(“asdfbc.root”,“RECREATE”);
TH2F *h1 = new TH2F(“h1”,“FLASH ADC Calibration”,400,0,19,7.9,11.5);
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[i] >> y[i];
if (!in.good()) break;
if (nlines < 5) printf(“x=%f, y=%f”,x[i],y[i]);

//for (i=0; i=6; i++)
//h1 ->gr(7,x,y,dx,dy);

//h1->Fill(x,y);

//h2->Fill(x,y);
ntuple->Fill(x[i],y[i]);
nlines++;
}

;
TCanvas *c1 = new TCanvas(“c12”,“show profile”,600,450);

float dx[i] = (0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1);
float dy[i]= (0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1);
TGraphErrors *gr = new TGraphErrors(i,x,y,dx,dy);
gr->SetTitle(“Resolution vs Number of straws”);
gr->GetXaxis()->SetTitle(“Number of straws”);
gr->GetYaxis()->SetTitle(“Resolution [%]”);
gr-draw(“ALP”);
// h1->SetTitle(“Resolution vs Number of straws”);
// h1->GetXaxis()->SetTitle(“Number of straws”);
// h1->GetYaxis()->SetTitle(“Resolution [%]”);
//h1->Draw();
//c1->cd(2);
//c1->cd(3);
//h2->Draw();

//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();
}[/code]

and when run… I get

root [0] .x dat_straw.C Error: Can't call TGraphErrors::TGraphErrors(i,x,y,dx,dy) in current scope /home/j/root/macros/dat_straw.C:81: Possible candidates are... (in TGraphErrors) /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(void); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(Int_t n); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(Int_t n,const Float_t* x,const Float_t* y,const Float_t* ex=0,const Float_t* ey=0); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(Int_t n,const Double_t* x,const Double_t* y,const Double_t* ex=0,const Double_t* ey=0); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TVectorF& vx,const TVectorF& vy,const TVectorF& vex,const TVectorF& vey); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TVectorD& vx,const TVectorD& vy,const TVectorD& vex,const TVectorD& vey); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TGraphErrors& gr); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TH1* h); /home/j/root/lib/libHist.so -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const char* filename,const char* format="%lg %lg %lg %lg",Option_t* option=""); (in TGraph) *** Interpreter error recovered *** x=11.000000, y=11.850000x=12.000000, y=10.420000x=13.000000, y=9.974000x=14.000000, y=9.426000x=15.000000, y=8.931000root

cant find the problem sadly
thanks for help

Jacek

Looking quickly at you macro I see already something weird:

float x,y;
const int i=8;
float x[i],y[i];

x and y are declared twice…

Also:

gr-draw("ALP");

How do you expect this to work ?

and…

float dx[i] = (0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1);
float dy[i]= (0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1);

… is wrong … it should be curly brackets…

After all the needed cleanups I end up with:

{
   const int i=8;
   int nlines = 0;
   TCanvas *c1 = new TCanvas("c12","show profile",600,450);

   float dx[i] = {0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1};
   float dy[i] = {0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1};
   float x[i]  = {1,2,3,4,5,6,7,8};
   float y[i]  = {1,2,3,4,5,6,7,8};
   TGraphErrors *gr = new TGraphErrors(i,x,y,dx,dy);
   gr->SetTitle("Resolution vs Number of straws");
   gr->GetXaxis()->SetTitle("Number of straws");
   gr->GetYaxis()->SetTitle("Resolution [%]");
   gr->Draw("ALP");
}

I initialized x and y to some values as I did not have the data file.

You should try to:
root [0] .L dat_straw.C++
and carefully inspect all errors and warnings reported by the compiler.

thank you for your help!
couet i used this way earlier, and it`s works yes, but i want my macro to read form an ASCII data file ( 2 rows of data) .

I understand that but:

  1. your file was full of mistakes.
  2. I did not have the ASCII file.

So:

  1. I fixed the mistakes
  2. I emulated the x and y data to show you it is working.

http://root.cern.ch/root/html/TGraphErrors.html#TGraphErrors:TGraphErrors%8
http://root.cern.ch/root/html/TGraph.html#TGraph:TGraph
http://root.cern.ch/root/html/TTree.html#TTree:ReadFile

thank you!

I executed .L dat_straw.C and did not get any errors.

execute:
.L dat_straw.C++