Reading from ASCII file and PAW interoperability

Hello,
2 things really. I have a bunch of old PAW routines that take care of about half of the work i need to do. Is there anyway that i can make use of this routines and go on to analyze their output (various histograms) in ROOT?

  I have some of the output in an ascii file with the data arranged in columns like so:

1.50000 0.00333 0.00000 0.00000 0.00000 0.00000 0.000E+00 0.000E+00 4.50000 0.00333 0.00000 0.00000 0.00000 0.00000 0.000E+00 0.000E+00 7.50000 0.00333 0.00000 0.00000 0.00000 0.00000 0.000E+00 0.000E+00 10.50000 0.00333 0.00000 0.00000 0.00000 0.00000 0.000E+00 0.000E+00

I took the cernstaff ($ROOTSYS/tutorials/cernstaff.C) example and edited it for my purposes:

[code]{
//Purpose: extract data from ascii tables and save in ROOT tree
gROOT->Reset();

//Struct carrying the corrections and their attriputes for each particle's bin
struct corr_t{

	Double_t phi;
	Double_t phistep;
	Double_t ratio;
	Double_t ratiosig;
	Double_t sigsig;
	Double_t N;
	Double_t Nsig;
	Double_t miss;

	};

corr_t corr;

//open the ASCII file
FILE *fp = fopen("/w/work3602b/goettj/g11/physics/tables/p1_0903.vec","r");

char line[99];

//create a new ROOT file
TFile *f = new TFile("corrdat.root","RECREATE");

//create a TTree
TTree *corrections = new TTree("corr","results from PAW calculations");

//create one branch with all information from the structure
corrections->Branch("corr", &corr.phi,"phi/F:phi:phistep:ratio:ratiosig:sigsig:N:Nsig:miss");

//fill the tree with the values from the ASCII file
//while(fgets(line, sizeof(line), fp) !=NULL){
	sscanf(&line[0],"%g%g%g%g%g%g%g",&corr.phi,&corr.phistep,&corr.ratio,&corr.ratiosig,&corr.sigsig,&corr.N,&corr.Nsig,&corr.miss);

	printf("%g %g %g %g %g %g %g\n", corr.phi , corr.phistep , corr.ratio , corr.ratiosig , corr.sigsig , corr.N , corr.Nsig , corr.miss);

	cout << endl << endl;

	corrections->Fill();

	}

//check that the tree was created properly
corrections->Print();
//close the input file
fclose(fp);
f->Write();

}[/code]

Everything seems to work fine, except for the fact that instead of saving the values as in the file:

instead it saves:

2.08862e-278 2.18187e+243 9.28602e+242 2.17354e+243 1.71434e+161 1.66881e-307 3. 68978e-313

Am i missing something?

Thanks,
Johnny

Dear Johnny,

[quote]I have a bunch of old PAW routines that take care of about half of the work i need to do. Is there anyway that i can make use of this routines and go on to analyze their output (various histograms) in ROOT?
[/quote]
You cannot run PAW macros into ROOT. You can find example guidelines to translate your PAW code to ROOT scripts at:
www-subatech.in2p3.fr/~photons/paw2root.shtml
Alternatively, you can save the PAW histograms into a file and then convert the file into ROOT format with ‘h2root’.

[quote]struct corr_t{

  Double_t phi;
  Double_t phistep;
  Double_t ratio;
  Double_t ratiosig;
  Double_t sigsig;
  Double_t N;
  Double_t Nsig;
  Double_t miss;

  }; 

  ...

sscanf(&line[0],"%g%g%g%g%g%g%g",
&corr.phi,&corr.phistep,&corr.ratio,&corr.ratiosig,&corr.sigsig,&corr.N,&corr.Nsig,&corr.miss);

Am i missing something?
[/quote]

‘sscanf’ requires pointers to ‘float’; see man page. (Btw, you are missing one ‘%g’).

Gerri Ganis

I’m not quite sure what you mean, but i looked at the man page and changed all the variabled in the struct to Float_t types and the %g’s to %f’s, but the same problem persists.
I also tried changing

sscanf(&line[0],"%f %f %f %f %f %f %f %f",&corr.phi,&corr.phistep,&corr.ratio,&corr.ratiosig,&c orr.sig,&corr.sigsig,&corr.N,&corr.Nsig);

to

sscanf(&line,"%f %f %f %f %f %f %f %f",&corr.phi,&corr.phistep,&corr.ratio,&corr.ratiosig,&c orr.sig,&corr.sigsig,&corr.N,&corr.Nsig);

all that seemed to do was give me all zeroes for each entry with the last containing an enormous (20 digit) integer.

Is there a simper method for just reading in vectors from a text file?
All PAW needed was “vect/read”?

Thanks again,
Johnny

Hi,

[quote=“goettj”]Is there a simper method for just reading in vectors from a text file?[/quote]You could use e.g. TTree::ReadFile, see http://root.cern.ch/root/html/TTree#TTree:ReadFile. You’d have to store the data in a TTree with simple data branches instead of your own class, though. Or use the c++ ifstream class.
Axel.

Hi Johnny,

Yes, that’s what I meant. Just to make sure, attached are: i) the modified version of your macro; ii) a small macro reading the file produced; iii) the outputs I get when I run them. This seems to work fine for me.

Cheers, Gerri
exa1.tar (10 KB)