next up previous contents index
Next: Writing, viewing ... Up: Module HiStats Previous: Profile Histograms   Contents   Index


Data tables (tuples)

NTuple are memory resident tables of 32 bits floating values (float). They are arranged in columns. Each line is often called an event. These objects are frequently used to analyze data. Graphicals tools (spiapp) can plot a column against an other one with respect to various selection cuts.
Here is an example of creation and filling :

#include "ntuple.h"
#include "srandgen.h"
// ...
char* nament[4] = {"i","x","y","ey"};
r_4 xnt[4];
NTuple NT(4,nament);
for(i=0;i<5000;i++) {
  xnt[0] = i+1;
  xnt[1] = 5.*drandpm1();       // a random value between -5 and +5
  xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
  xnt[3] = sqrt(xnt[2]);
  xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
  NT.Fill(xnt);
}

XNTuple are sophisticated NTuple : they accept various types of column values (double,float,int,string,...) and can handle very large data sets, through swap space on disk. In the sample code below we show how to create a XNTuple object with four columns (double, double, int, string). Several entries (lines) are then appended to the table, which is saved to a PPF file.


#include "xntuple.h"
// ...
char * names[4] = {"X", "X2", "XInt","XStr"};
// XNTuple (Table) creation with 4 columns, of integer, 
// double(2) and string type
XNTuple  xnt(2,0,1,1, names);
// Filling the NTuple
r_8 xd[2];
int_4 xi[2];
char xss[2][32];
char * xs[2] = {xss[0], xss[1]} ;
for(int i=0; i<50; i++) {
   xi[0] = i;  xd[0] = i+0.5;  xd[1] = xd[0]*xd[0];
   sprintf(xs[0],"X=%g", xd[0]);
   xnt.Fill(xd, NULL, xi, xs);
}
// Printing table info
cout << xnt ;
// Saving object into a PPF file
POutPersist po("xnt.ppf");
po << xnt ;



Reza Ansari
2001-03-07