Using ROOT with Kanga Data

Document Sample
Using ROOT with Kanga Data Powered By Docstoc
					Using ROOT with Kanga Data




Eric Charles
       Kanga makes data more accessible

           • The idea behind Kanga is to treat all of our data
             as n-tuples
              – The ideal would be to remove the need to make
                massive n-tuple productions in various AWGs
           • Kanga uses and copies existing ROOT
             functionality for plotting/ browsing data
              – If you are familiar with ROOT using Kanga should be
                easy




4/7/2010                                       2        Eric Charles
    To get started, load Kanga into ROOT

           • Kanga shared libraries are built as part of the
             BaBar release
                 • addpkg Kanga; gmake Kanga.root;
                 • cd workdir; bbrroot;
                 • root[0] gSystem->Load(“libKanga_root.so”);
           • This is the same process as loading RooFitCore
             / RooFitModels
              – It allows ROOT to interpret the C++ classes that
                make up Kanga.




4/7/2010                                             3          Eric Charles
   All you need have to inspect data is the
              collection name
           • Use KanEventSource class to read collections.
             – KanEventSource does all the bookkeeping for you.
                • root[1] KanEventSource* input = KanEventSource::mini(“in”);
                    – Specifies type of input, which components are active
                • root[2] input->Add(“myCollection”);
                    – Locates and opens all the components for 1 collection
                • root[3] input->Add(“otherColl”);
                    – Appends second collection to input
             – KanEventSource is equivalent to TTree/ TChain
                   – All the same commands are defined
           • These are the same collection names as used
             in KanEventInput module
4/7/2010                                            4          Eric Charles
     Making plots is just like regular ROOT

           • All you need to do is call the “Draw” function
              – You can draw many types of quantities
                 • root[4] in->Draw(“SimpleValue”);
                     – A value or values which was stored as a number
                 • root[5] in->Draw(“Object.function()”);
                     – A function of a stored object
                 • root[6] in->Draw(“Object.ref()->function()”);
                     – A function of an object reference by another object
                 • root[7] in->Draw(“Objects.function()”);
                     – A function from a vector of stored objects
                 • root[8] in->Draw(“Objects.ref()->function()”);
                 • root[9] in->Draw(“Objects.ref()->ref()->p4().Theta()”);
                     – You can follow multiple references/ functions

4/7/2010                                              5           Eric Charles
      Collection components are N-Tuples

           • Collections are built of components which are
             stored as TTrees.
             –   hdr => Locations of other components
             –   usr => User data
             –   tag => Tag bits
             –   cnd => Beta Candidate genealogy
             –   aod => “Micro” Pid, Trk, Emc, Ifr
             –   esd => “Mini” Svt, Drc, remainder lists
             –   tru => Monte Carlo truth
           • Each event is stored as a entry in the several
             trees.

4/7/2010                                          6        Eric Charles
            It is easy to print collection data

           • Most objects have built-in print functions.
              – Often there are actually several:
                 • root[10] input->Print();
                     – Does the same as TChain::Print(), give a list of branches
                 • root[11] input->printCollections();
                     – Prints the collection names in the chain.
                 • root[12] input->listComponents();
                     – Prints the list of components in the collection.
                 • root[13] input->getComponent(KanCompMap::aod)->Print();
                     – Prints the branch structure of tree for “aod” data (micro)




4/7/2010                                               7          Eric Charles
It is easy to determine component content

           • Use the specialized print function:
                 • input->getComponent(KanCompMap::aod)->print();
                                                                                       Tree Name

                 ***************************************************
                 KanEventTree @ 4. aod -+- Babar ROOT Tree
                 ----------------------------------------------------------------------------
                 aod__Eid                                               R@ 4:1 W +XXX+
                            KanEvtIDK
                 ----------------------------------------------------------------------------
                 Trk_Tracks                                 R@ 4:2 W +XXX+
                            KanClonesVector_I<TrkRecoTrkI>[KalMiniTrkK]
           Branch Name


                         Type of Object on Branch
                                                                                 Branch ID

4/7/2010                                                         8              Eric Charles
                     Interface Classes

           • Many versions of the same class inherit from
             the same interface and live on the same branch
                • XxxObjK, XxxObjK_001, XxxObjK_002… are all just
                  different ways of storing an XxxObj. They all live on the
                  branch “Xxx_Data”.
                • They all inherit from XxxObjI, which is the “Interface” class.
             – The class XxxObjI defines the functions they must all
               be able to perform.
                • input->Draw(“XxxData.function()”); gives the same result for
                  all the data.




4/7/2010                                               9           Eric Charles
       Each branch has one type of object

           • For example, the branch “aod__Eid” is a
             KanEvtIDK object
             – This is just a simple event id
                • It stores timestamp, run number, etc.
           • The branch “Trk_Tracks” is a vector of object of
             type KalMiniTrkK
             – The associated branch “Trk_Tracks__n” is the size of
               the vector
                • The indvidual tracks store references to their hits, fit
                  parameters, etc.




4/7/2010                                               10           Eric Charles
              You can get access to list of
                    BtaCandidates
                 • Warning: this code is still uncommitted.
           • The interface provides a std::list of BtaCandIdI*.
                 • bta->fillList(lst,”listName”);
                 • for(itr=lst.begin();itr!=lst.end();++itr); { do stuff; }
           • Can be used in macros
              – root[] .L printTracks.C
              – root[] printTracks(*input);




4/7/2010                                                    11            Eric Charles
      It is easy to get more info about data
                     structures
           • Use tab completion to list the functions defined
             for that class.
             – Most of what you see are built-in ROOT functions
           • Use the “Print()” and “Dump()” functions to see
             the object structure and status.
           • Use the documentation:
             – http://www.slac.stanford.edu/BFROOT/www/Physics/CM2/Kanga




4/7/2010                                                 12           Eric Charles
  To write macros you first define the data
            you will need to read
           • The structure is similar to what you get from
             TTree::MakeClass().
           • Declare the data you want to read
                  • input>setBranchToRead(KanCompMap::aod,”Pid_DrcPids”);
              – This setups up a branch for reading
                  • KanBranch* br = input>getBranch(KanCompMap::aod,”…”);
              – “br” now points to the place that ROOT will put the data when it
                reads it for each event
                  • DataType* myData = (DataType*)(br);
              – you must cast the pointer to the correct type to be able to use it.
                      – In this case, the branch stores an object of type
                        KanClonesVector_I<DrcPidInfoI>*




4/7/2010                                                   13               Eric Charles
Once you have defined the data, you loop
             over events
           • You use the same functions as in your regular
             ROOT macros
             – UInt_t nEvt = input->nEvt();
                • Get the number of events in the chain
             – input->Load(iEvent);                   Inside Event Loop
                • Load a particular event
             – Read the data for each event
                • myData->read(*input->registry());
             – Do something useful
                • aHistogram->Fill(myData->value());




4/7/2010                                              14         Eric Charles
  It is easy to use Kanga with RooFitCore

           • You can fill histograms and RooDataSets from
             Kanga
             – TH1F mesHist(“mes”,”mes”,100,5.2,5.3);
             – input->Project(“mes”,”BSemiExcl_mES”);
           • Then fit using RooFitCore as usual
             – gSystem->Load(“libRooFitBabar_root.so”)
             – FitBMass(mesHist);




4/7/2010                                    15           Eric Charles
                 Kanga dos and don’ts:
                    Pointer Skims
           • To use “borrowed” components in pointer skims
             you must explicitly load the component for the
             current event.
                • input->LoadTree(iEvent);
                • input->setupInputLocation(KanCompMap::aod);
                    – This line is a recent addition
           • Since you can’t call explicitly load the borrowed
             trees inside a TTree::Draw() loop, you must use
             macros with borrowed components.



4/7/2010                                         16         Eric Charles
                 Kanga dos and don’ts:
                 Refitting and Conditions
           • Most of the fitting/ calibrating functions are part
             of the transient object.
              – Kanga is intended to allow you to browse the data,
                not to fit/ do combinatorics.
                 • Think about what you want to store.
           • Conditions access is not availible yet.
              – I claim that it is not difficult, but no one is working on
                it.
                 • This affects the BField and the Emc Calibrations.




4/7/2010                                             17          Eric Charles
 What you have seen is just the beginning

           • There are 40 types of data objects stored in the
             micro
             – They all need to have:                      Get Involved
                • access functions for useful variables
                • informative print functions
                • comments added so the auto-doc is more useful
           • User data and storing composite candidates are
             still new tools
             – Think carefully about what you can add to User data
               and what composite lists you want to store



4/7/2010                                          18         Eric Charles
             More information is available

           • Kanga documentation online
             – http://www.slac.stanford.edu/BFROOT/www/Physics/CM2/Kanga
                 •   ROOT style class reference
                 •   List of classes used in the data
                 •   Brief Tutorial
                 •   Example macros
                       – And growing…
           • Hypernews discussion group
             – Kanga Based Analysis Tools




4/7/2010                                                 19           Eric Charles

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:4/8/2010
language:English
pages:19