Working with Ntuples


    In a given analysis you may have hundreds of variables on a Data Summary Tape.
Normally not all are needed for each analysis so you have to read the DST over and over again
depending on which variables you want to look at. This takes time, reading tapes is not a fast
process, so here's where the Ntuples come to the rescue.

    You can read all variables and the corresponding event data into a huge matrix structure. If
you use a row-wise Ntuple and pick out 100 variables in 1 million "events" then you'll get a
matrix with 1 million rows and 100 columns, where each column represent a variable and each
row an "event". This is the normal way of representing Ntuples, but one can also define
column-wise Ntuples where the each column is an "event" and the rows are variables. But
no matter what representation you use, for a given column and a given row you'll get the
value of one specific variable in one specific "event".

    With the Ntuple structure you can refine cuts and make selections without having to read the
DST over again, and PAW handles Ntuples very well.
 
 

Creating Ntuples

    There are several ways of creating Ntuples. I will concentrate on the one used by Patchy, in
the .car file. You need to define a character array EVTVAR which can store the names of the
variables you want to keep, and an integer NVAR which must be equal to the number of
variables (the size of EVTVAR). Then you fill the variables and book the Ntuple using
HBOOKN:

    CALL HBOOKN(ID, 'TITLE', NVAR, PATH , NW, EVTVAR)

ID = Ntuple Identifier
TITLE = A name for the Ntuple
NVAR = Number of variables you want pr "event" (NVAR < 513)
PATH = Location for the Ntuple. If PATH = ' ' a bank of NW words is created, further banks of
the same size is located in a linear chain if additional space is required at filling time. But if
PATH='//LOC' then the Ntuple will be written to disk where LOC is the top directory name of an
existing file opened with HROPEN or HRFILE.
NW = Number of Words for primary allocation of Ntuple (buffer)
EVTVAR = Character array of length NVAR providing short names (up to 8 characters) for each
variable.
 
 

Accessing Ntuples in PAW

    Because Ntuples are hbook-objects they can be stored into histogram files opened in PAW
with the command HI/FILE, but you need to tell PAW the size of each record RSIZE (which you
set in the .car file) and give it a LUN-number (between 1 and 100). The name
MY_NTUPLE.HBO is also given in the .car file, so to open the Ntuple for a PAW-session this
should do the trick:

    PAW> HI/FILE LUN MY_NTUPLE.HBO RSIZE
 
 

PAW tools for Ntuples

    When the Ntuple is read into PAW it can be accessed by it's ID. If you want to plot the PX
variable of the Ntuple with ID=344 you simply type

    PAW> NT/PLOT 344.PX

And if you want to make a fancy one dimensional plot you can type:

    PAW> 1D NR 'My title!' BINS MAX_BIN. MIN_BIN.

    PAW> NT/PLOT 344.PX IDH=NR

    PAW> HI/PLOT NR

Where NR is an identifier for the new plot with BINS number of bins ranging from MAX_BIN to
MIN_BIN, where the period-marks must be included. From now on you can always retrive that
plot by the HI/PLOT NR call, unless you decide to make another plot with the same NR.