Babar logo
HEPIC E,S & H Databases PDG HEP preprints
Organization Detector Computing Physics Documentation
Personnel Glossary Sitemap Search Hypernews
Workbook Home Introduction Account Setup QuickTour Packages Modules Unwrap page!
Event Information Tcl Commands Editing Compile and Link Run the Job Debugging
Check this page with the
W3C Validator
(More checks...)
Parameters Tcl Files Find Data Batch Analysis ROOT Tutorial

Analysis in PAW II

Further use of PAW for BaBar physics analyses.


This workbook chapter follows on from the first Workbook section about analysis in PAW. In this section you will learn additional techniques regarding macros, use a fortran program to analyse ntuples produced with BtaTupleMake, and produce publication-ready plots in PAW.


Set up a directory to store your PAW macros

It is convenient to set up a directory to store general-purpose PAW macros. This can be done by adding a line to the .pawlogon.kumac file in your home directory. If you don't have such a file, create one with the single line:
macro/default '.,~/pawmacros' -auto

This means that PAW will look for macros first in the current directory (.), then in the directory ~/pawmacros.

While you're editing .pawlogon.kumac , you should probably also add the line:

filecase keep

This command forces PAW to retain information about capitalisation in all files it reads in and write out. Otherwise PAW tends to assume that all filenames are given in lower-case characters - unlike unix.

You can also add the other command lines that are discussed in the pawlogon section of PAW I.

Define several macros in a single file

So far all the macros we have used have been contained in a file with the same name as the macro, and there has only been one macro per file. You can actually have more than one macro defined in a given file. To do this, you start each macro in the file with:
macro myfirstmacro

where myfirstmacro doesn't have to have the same name as the file. You then place the macro code below this line in the usual way, and you define the end of the macro with


Any code after this will be ignored until another macro is defined with, say,

macro mysecondmacro

You should put a return at the end of your final macro in your file also.

The macros are then executed from within a PAW session with

exec mymacrocollection#mysecondmacro

Where mymacrocollection is the name of the file (i.e. mymacrocollection.kumac), and mysecondmacro is the name of one of the macros defined in that file. We shall see several examples of this in the sections below.

Analyze a ntuple with a Fortran program

Produce a paw ntuple using BtaTupleMaker

Although macros are extremely useful, and you will certainly use them, the heart of a real publication-quality analysis in paw will be fortran programs.  This section assumes that you are using BtaTupleMaker to produce the ntuples, as outlined in the cm2-ntuples section of the workbook.

To produce an hbook (paw) ntuple, follow the instructions in the workbook, but in your tcl snippet, set BetaMiniTuple "hbook" and change the file name to be xxx.hbook instead of xxx.root.  Here is the snippet to generate a paw file from 1000 events of SP-989-Run1-3.tcl:

#..See Analysis.tcl for description of FwkCfgVars.
sourceFoundFile tcl/SP-989-Run1-3.tcl
set MCTruth "true"
set FilterOnTag "false"
set BetaMiniTuple "hbook"
set histFileName ntuples/SP-989-Run1-3.hbook
set NEvents 1000
sourceFoundFile Analysis.tcl

Submit this to the batch system with the command

bsub -q kanga -o log/SP-989-Run1-3.log ../bin/$BFARCH/BtaTupleApp snippets/run_SP-989-Run1-3.tcl

Once the job completes successfully, you can move it to your "successful" directory, or to your laptop, or where ever you intend to do your analysis.  Here is a gzipped version in case you need it. Be sure to gunzip it before trying to use it.

Ntuple Structure

Take a look at the resulting ntuple (now located in the "successful" directory). To start paw, type:
and then "enter" to accept the default workstation type. Now, to look at your ntuple, do:
PAW > hist/file 1 successful/SP-989-Run1-3.hbook 
PAW > nt/list

===> Directory :
2 (N) myNtuple
1 (N) Analysis Ntuple

This gives you a list of ntuples in your hbook file. The one you are interested in is myNtuple. To see a list of its contents, type:
PAW > nt/print 2
Here is the printout of the ntuple structure: ntuple-structure.txt

You will want to navigate between the different blocks and different candidates.

BLund tells you what type of B this candidate is

Bd1Lund is the particle type of the first daughter; that is to say, the type assumed by the composition code when it created the B, which may or may not be the same as the true particle type.

How do you know what the numbers mean? One way to find out is to look in the file:

The lund ID numbers of the different particles are given in the fifth column. For example, a J/psi has ID number 443.

Bd1Idx is the index of that daughter in the relevant block (Jpsi in this case). Note that the indices all use C++ numbering, so that Bd1Idx = 0 refers to the first entry in the Jpsi block. If you are actually going to use paw, you will need to add 1 to all the indices. You will probably get this wrong numerous times.

You can similarly navigate from the Jpsi block to the mu block (or e block, once you add Jpsi --> e e decays), and from the mu block to the TRK block.

When using electrons with bremsstrahlung recovery (in which radiated photons are added back into the reconstructed electron), the navigation is a bit tricky. The brem-recovered electron is a composite, consisting of an electron plus one, two, or three photons. So it does not point to the TRK block (the index is -1); you need to navigate to the daughter electron, which does point to the TRK block. This is the only case where a daughter of a particle is the same type of particle.

A fortran program to produce a histogram

Here's a fortran program called smallcode.f, which you can copy to your workdir. When doing analyses in paw, I use nt/loop.
PAW > hist/file 1 successful/SP-989-Run1-3.hbook
PAW > nt/loop 2 smallcode.f(0)
PAW > h/pl 100
PAW > pps

This will give you a nice plot of the reconstructed Jpsi mass and write it to the file  pps is a macro I have defined in my .pawlogon.kumac file. The Paw-I tutorial gives another method of doing the same thing.

On some systems, you can say nt/loop 2 smallcode.f77(0) to compile the code before it is run.

A couple of things to note in this program. The "Include ?" is a piece of paw magic that makes the entire ntuple structure accessible to your code. I like to pass a histogram ID offset (id0) to the code, so I can run it with id0 = 0 with signal MC, id0  = 1000 for BB MC, 2000 for real data, and so forth.  I always use Implicit None; it takes a tiny bit longer to type the code, but will save you lots of time in the end.  For this structure to work (i.e., where you are running the same piece of code on  both data and MC) you need to make sure the the MC truth block is created in your data ntuples. Of course, it will not contain any useful information. But if you don't, your code will complain about undefined variables when you run on data.

Note on MC truth Matching

The MC block contains the full MC truth for the event at the four-vector level, and is very useful for categorizing different types of backgrounds, for example.

The names such as JpsiMCIdx connect the reconstructed candidate to the MC truth block. However, the MC matching is a bit dicey for any state that can radiate. (And we use Photos not just for leptons, but also for hadrons in our MC). For example, if you plot JpsiMCIdx, you will see that it is -1 in many cases (i.e., no MC truth match was found). But if you plot the lund ID of the MC-truth matched partners of the muon daughters of the Jpsi, you see that they are actually muons:

nt/plot 2.mclund(muMcidx(1)+1)
nt/plot 2.mclund(muMcidx(2)+1)

(Why muons? Because the plots show that all entries fall in the bins [-12,-13] and [13, 14] - that is, they have ID numbers of +/-13. And looking in workdir/PARENT/PDT/pdt.table, you see that 13 = mu- and -13 = mu+.)

The problem is that in the MC truth, the Jpsi actually decayed to mu+ mu- gamma, while the reconstructed Jpsi contains only the muons. In principal, this gamma could be 1 MeV, and of no real consequence. The lesson is that you cannot blindly use the MC truth match for composites. Actually, it is probably better to avoid MC truth matching entirely if you can. (In this case, if I did need to match, I would say the Jpsi is matched if the two muons daughter match the MC-truth daughters of the Jpsi)

Producing publication-ready plots in PAW

This section contains instructions for making attractive-looking plots, with the BABAR logo, rather for publications and presentations. There is one basic example and two complicated ones. The complicated examples are intended primarily as a reference so that the reader can see what else can be done.

Useful presentation macros

You will need two general-purpose macros

Put both of these in your ~/pawmacros directory.

Simple example

For each plot you will want to have a single macro that generates the plot of interet. Here is one that makes a mass distribution of Psi2s->mu+mu-: psi2smm-mass.kumac.

You will need the hbook file inclusive-fits-p52.hbook

There is not much to the kumac code. In this case, I find the defaults put the left title a little too close to the axis number labels, so I moved it a bit. Also, there is a bit of code to convert the ps file to an eps file with no preview. PAW believes it can directly produce an eps file, but I find that the bounding box is wrong.

Create the plot

[~/Work/text/temp]: paw
* *
* W E L C O M E to P A W *
* *
* Version 2.13/08 19 September 2002 *
* *
Workstation type (?=HELP) <CR>=1 :
Version 1.28/07 of HIGZ started
*** Using default PAWLOGON file "/Users/hearty/.pawlogon.kumac"

In private pawlogon.kumac.
PAW > exec pub-plot psi2smm-mass 1. 0.7
now calling psi2smm-mass.kumac
Postscript Output File =

The first argument passed to pub-plot is the name of the macro that draws the specific plot. The other two arguments give the size of the plot in x and y, where 1. = 15cm. This aspect ratio is nice for PRL and PRD single-column figures.

Note that what you see on screen psi2smm-mass-screen.tiff is not the same as the final plot psi2smm-mass.eps which has the full formatting with superscripts and Greek characters.

Note that if you want to include the BaBar logo in this plot, and in the two examples below, you will need to include a line in the kumac before the lines which create the images (the exec makeps... command to call the babar macro from within your plot macro.

Adding "BaBar" to your plot

To add the "BaBar" logo to the top-right corner of your plot, you can use one of the macros defined in pub-plot.kumac. After producing a plot in PAW, for example by running the simple example below, you issue the command
exec pub-plot#babar 
If you wish to change the position where the BaBar word appears and the size of the word, you can pass three arguments when you execute the babar macro. The defaults are 1. (scale), 68. (x-position) and 85. (y-position).

There's also a similar macro defined in pub-plot.kumac for adding the word "PRELIMINARY" below "BABAR". It is run using the same syntax as pub-plot#babar:

exec pub-plot#preliminary .5 58. 79.
where in this example, the defaults parameters are passed to the macro.

More complicated example

Here is a more complicated example from PRL 90 231801, projdata3.kumac.

In this case, we create an ntuple from an ascii list in the file, then fill a 2D histogram from this ntuple. In this way, we get the exact (mes, DeltaE) locations, instead of the PAW default, which plots a random location within the histogram bin. We then create projections of mes and DeltaE and plot those as well. This is done for two different final states, giving six plots in one figure.

To generate the plot, use the command:

exec pub-plot projdata3 1. 1.
The square aspect ratio (15cm by 15cm) is more appripriate in this case. The resulting plot is here: projdata3.eps

Another example

Here is another example from the same paper pstarjpl.kumac.

In this case we read three p* plots from an hbook file, then plot them beside each other. Run it using

exec pub-plot pstarjpl 1. 1.

You will need the hbook file pstarjpl.hbook.

General Related documents:

Back to Workbook Front Page

Send comments to Workbook Team.