TGrapherrors problem


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”

void dat_straw() {

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

ifstream in;
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);

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

TProfile *prof = h1->ProfileX();
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);



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 [%]”);
// h1->SetTitle(“Resolution vs Number of straws”);
// h1->GetXaxis()->SetTitle(“Number of straws”);
// h1->GetYaxis()->SetTitle(“Resolution [%]”);

// TProfile *prof = h1->ProfileX();
//TF1 *fit = h2->GetFunction(“pol1”);
//double chi2 = fit->GetChisquare();
//double p0 = fit->GetParameter(0);
//double p1 = fit->GetParameter(1);



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/ -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(void); /home/j/root/lib/ -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(Int_t n); /home/j/root/lib/ -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/ -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/ -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TVectorF& vx,const TVectorF& vy,const TVectorF& vex,const TVectorF& vey); /home/j/root/lib/ -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TVectorD& vx,const TVectorD& vy,const TVectorD& vex,const TVectorD& vey); /home/j/root/lib/ -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TGraphErrors& gr); /home/j/root/lib/ -1:-1 0 public: TGraphErrors TGraphErrors::TGraphErrors(const TH1* h); /home/j/root/lib/ -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


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…



How do you expect this to work ?


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 [%]");

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.


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

thank you!

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

.L dat_straw.C++