Common Analysis Code

The capability for using common analysis modules has been added to the
FlatNtuple.  The tag as of November 7, 2003 is

        flatnt_59716_anal_Nov072003

What we want to do is offer a standard set of analysis tools that people can
use in order to let people move quickly and avoid mistakes, and to let the
Chicago group do analyses uniformly.

To this end, We have two sets of analysis packages:

Package One -- The first runs code inside of root and sets
               up a Class structure that mimics the standard ntuple.

Package Two -- The second compiles code to run outside of 
               root and does not use classes (if you don't want to).

Both are available using the above tag.


One Analysis Package

The basic idea is to make a new analysis release, add a current version of the FlatNtuple, and run your analysis code. The structure is similar to what Pasha has done for the Stntuple (but the implementation is much less complex). Starting from a unix directory named "home", the instructions are: home> newrel -t 4.11.2 ucnt_anal home> cd ucnt_anal home/ucnt_anal> cvs co -r [current tag listed above in bold face] FlatNtuple home/ucnt_anal> cd include home/ucnt_anal> ln -s FlatNtuple UCNtuple home/ucnt_anal> ln -s ../FlatNtuple/FlatNtuple . Now you are ready to run the analysis code. home/ucnt_anal> root -l root [0] .L FlatNtuple/anal/driver.C root [1] driver("/cdf/data10a/Datasets/non_express/electron/UCntuples/4.11.2_inclusive") root [2] _h_std_cem_elec_et->Draw() root [3] _h_muon_pt_cor->Draw() FlatNtuple now contains a dir called anal. Inside anal/, there are these files: driver.C analysis.cc analysis.hh goodrun_100303_nosi.C goodrun_100303_si.C StandardSelectionAlg.cc StandardSelectionAlg.hh driver.C To be run using the CINT interpreter as shown above. This file then compiles analysis.cc and StandardSelectionAlg.cc. As an argument, it takes the directory containing files *.root that should contain a "ucntuple" TTree and adds them to a TChain. Then it makes an analysis object. The number of events one wishes to run over can be given as a second argument. analysis.cc Class that loops over the events in the TChain and implements the analysis code. It relies on the functions in StandardSelectionAlg to check whether electrons, muons, etc. are "good". Skips events not part of a good run list (currently defined for the latest data in goodrun_100303_nosi.C) Also makes histograms. This exists basically as a skeleton now and should be tailored by each user to suit his/her analysis needs. StandardSelectionAlg.cc Class that implements standard functions that everyone can use. Currently implemented are GoodTrackQ, StandardCentralElectronQ, and MuonCurvCorrection. This is just a start and I hope we can quickly add a StandardCMUMuonQ, StandardPlugElectronQ, StandardJetQ, etc. Please email
Stephen Levy with any comments / suggestions / complaints.

Another Analysis Package

Up to date Jet Corrections So, I've created my own standard analysis tools that are a bit more functional and useful (I think). This is the foundation for my analysis code and (I think) is pretty easy to use. The basic idea of the code is that you write a program which runs as a stand alone executable and which runs over ntuples and does stuff, and then fills ntuples and/or histograms and writes them to a root file, and/or plots histograms and writes the output to a postscript file. So if you like playing with histograms, you can then go into root and plot the appropriate histograms yourself. I generally find this an easier and more stable operation than running code inside root. It's also faster. More importantly, the reason I've designed things this way is that it lets you use root for what it's good at -- plotting histograms, fitting histograms, applying simple cuts to simple ntuples -- and avoiding the major problems of root -- mainly it's C interpretor and environment. One issue that might arise is that you need a KAI compiler to compile this code as it stands. If your machine does not have one, then perhaps try another that does (type "ls ~cdfsoft/products/kai_key/v34/NULL/" to see which machines have them). Unfortunately, this does not worth with gcc due to root issues. If there's a desperate demand for gcc, I'll see if I can fix this (I certainly don't see a fundamental limitation). I've included a basic program Zee.C which is described below. But to run, you follow similar steps to what Steve does above -- create a "release" directory, and inside of that create your analysis directory, and copy the contents of FlatNtuple/anal/mcw/ to your analysis directory: home> newrel -t 4.11.2 ucnt_ana home> cd ucnt_ana home/ucnt_ana> cvs co -r [current tag listed above in bold face] FlatNtuple home/ucnt_ana> cd include home/ucnt_ana/include> ln -s FlatNtuple UCNtuple home/ucnt_ana/include> ln -s ../FlatNtuple/FlatNtuple . home/ucnt_ana/include> cd .. home/ucnt_ana> mkdir my_ana home/ucnt_ana> cd my_ana home/ucnt_ana/my_ana> cp -r ../FlatNtuple/anal/mcw/* . home/ucnt_ana/my_ana> ln -s ../FlatNtuple/declarestructs.C . To make and run the program Zee.C over the 4.11.2 tight lepton dataset, you type: home/ucnt_ana/my_ana> make Zee home/ucnt_ana/my_ana> Zee /cdf/data10a/Datasets/non_express/electron/UCntuples/4.11.2_lepton/*.root /cdf/data10a/Datasets/non_express/muon/UCntuples/4.11.2_lepton/*.root (This just shows that you can give it a list of files with wildcards and such. Running over all these events will take a bit of time.) Two files are created. The first is a postscript file called zee.ps which contains two plots -- one of the invariant mass and the other of the MET. The other is a root file called zee.root which just has these two histograms in it if you don't want to mess with postscript files. You can change both of these names in Zee.C. The main files are: objects.C and objects.h This file contains the definitions of various objects (electrons, muons, jets, photons, MET) and basic types of events (W's, Z's, lepton+photon). The file objects.h is well documented and should explain how to use these things. This and the Makefile are my real additions to this code. But a few basic selling points about the routines: * They let you choose between Data and Monte Carlo -- For good or bad Data and Monte Carlo are not treated exactly the same, specifically in Jet Corrections. This code lets you pass a bool (true if you're running over data) to select between the two. * They let you decide whether to use likelihood or standard cuts (or the OR of both). * The isGoodObject routines will let you turn off cuts with a bitmask if you don't want to use them. You can also pass these bitmasks to the isWenu and isZee (e.g.) functions. This lets you choose what your definition of a loose electron or what MET is. The objects.h file lists these bitmasks, so you don't have to look at the code if you don't want to. * The isGoodObject routines also let you print out information about each object -- basically whether it passed each cut. This is useful in debugging and in displaying basic information about events. * Generally useful routines like calculating invariant and transverse masses and four vectors from E, eta, and phi or pt, eta and phi are also included. Makefile This is the makefile to create executables. To use, you simply create a .C file with a main() function (an example is given in Zee.C). Let's say you call the file my_program.C. Then to create an executable, you simply type "make my_program" and it will create an executable called my_program from the my_program.C file, and link it against all the necessary root and object files. You should never have to touch the Makefile if you don't want to. JetEnergyCorrections.C and JetCorrections/ This is the jet energy corrections code. I think a new version of this came out just before I released this code, so this is probably not the most up to date stuff. goodrun.hh and goodrun.list This utility picks up a goodrun list (in this case goodrun.list) and then lets you ask if a run is good. You can either set the appropriate list inside goodrun.hh, or just copy your favorite list to goodrun.list. Note this list should be ascending order and only contain run numbers (so, no luminosity). *Likelihood* and UsefulRoutines.* These are for running Bruce K.'s Likelihoods for electrons, photons, and muons. Zee.C This is a basic example of how to use the objects.C functions. It loops through an ntuple (or set of ntuples) and asks if an event is a Z->ee event. If it is, it fills two histograms -- one with the invariant mass and one with the MET of the event. When it's done, a postscript file is written printing these two histograms as well as a root file containing these two histograms so you can fit them, etc (though you can also do these things inside the executable). A (much) more complicated example which does essentially the same thing, but on a larger scale for Wenu, Zee, Wmunu, Zmumu can be found in ~cwolfe/topana/devel/wandz.C. The plotting function is wandz_hist.C in the same directory. strip_evt.C This simple program strips Zee events from a set of input ntuples and outputs the resulting ntuple to a file. To compile it, type: home/ucnt_ana/my_ana> make strip_evt To run: home/ucnt_ana/my_ana> strip_evt -o outfile.root -i /cdf/data10a/Datasets/non_express/electron/UCntuples/4.11.2_lepton/*.root where outfile.root is the output file you want to create. The main() function contains example code of how to specify command line parameters to an executable like this, which I find useful.

How to get up to date Jet Corrections

If you've set up the second analysis package above, it's relatively simple to get up to date jet corrections. Here are the steps: 1. Check out the newest JetUser package: home/ucnt_ana> cvs co -r jetCorr00 JetUser home/ucnt_ana> cd include home/ucnt_ana/include> ln -s ../JetUser/JetUser/ . home/ucnt_ana/include> cd .. 2. You need to edit two files to remove a dependence on the HepLorentz class which we don't need (and it breaks compilation): home/ucnt_ana> emacs JetUser/JetUser/JetEnergyCorrections.hh & Comment out the lines near the beginning which say: #ifndef __CINT__ #include "CLHEP/Vector/LorentzVector.h" #else class HepLorentzVector; #endif Also, comment out the line float doEnergyCorrections(HepLorentzVector &fourVector,float& emf,const float eta); Save this, and exit. 3. Now we need to edit the source code: home/ucnt_ana> emacs JetUser/JetEnergyCorrections.cc & Add the following lines with the other include directives: #include <math.h> #include <algorithm> And comment out the function: float JetEnergyCorrections::doEnergyCorrections(HepLorentzVector &fourVector,float& emf,const float eta){ float ptin = fourVector.perp(); return doEnergyCorrections(ptin, emf, eta); } now save and exit. 4. Now we need to copy the source code to the analysis directory: home/ucnt_ana> cd my_ana home/ucnt_ana/my_ana> cp ../JetUser/src/JetEnergyCorrections.cc JetEnergyCorrections.C (we rename the file from .cc to .C just becuase that's how the Makefile expects it) 5. If you have the directory my_ana/JetCorrections/ remove it: home/ucnt_ana/my_ana> rm -r JetCorrections That's it! The Makefile should compile everything correctly and objects.C should have no problems using it. Enjoy! Email me (
cwolfe@hep.uchicago.edu) with questions or comments.

collin wolfe
Last modified: Fri Jun 11 15:14:58 CDT 2004