rf508_listsetmanip.C

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #508
00004 // 
00005 //   RooArgSet and RooArgList tools and tricks
00006 //
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 // 
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooGaussian.h"
00019 #include "RooConstVar.h"
00020 #include "TCanvas.h"
00021 #include "TAxis.h"
00022 #include "RooPlot.h"
00023 #include "RooArgSet.h"
00024 #include "RooArgList.h"
00025 #include "RooCategory.h"
00026 using namespace RooFit ;
00027 
00028 
00029 void rf508_listsetmanip()
00030 {
00031 
00032   // C r e a t e   d u m m y   o b j e c t s 
00033   // ---------------------------------------
00034 
00035   // Create some variables
00036   RooRealVar a("a","a",1,-10,10) ;
00037   RooRealVar b("b","b",2,-10,10) ;
00038   RooRealVar c("c","c",3,-10,10) ;
00039   RooRealVar d("d","d",4,-10,10) ;
00040   RooRealVar x("x","x",0,-10,10) ;
00041   c.setError(0.5) ;
00042   a.setConstant() ;
00043   b.setConstant() ;
00044 
00045   // Create a category
00046   RooCategory e("e","e") ;
00047   e.defineType("sig") ;
00048   e.defineType("bkg") ;
00049 
00050   // Create a pdf
00051   RooGaussian g("g","g",x,a,b) ;
00052 
00053 
00054 
00055   // C r e a t i n g ,   f i l l i n g   R o o A r g S e t s 
00056   // -------------------------------------------------------
00057 
00058   // A RooArgSet is a set of RooAbsArg objects. Each object in the set must have
00059   // a unique name 
00060 
00061   // Set constructors exists with up to 9 initial arguments
00062   RooArgSet s(a,b) ;
00063 
00064   // At any time objects can be added with add()
00065   s.add(e) ;
00066 
00067   // Add up to 9 additional arguments in one call
00068   s.add(RooArgSet(c,d)) ;
00069 
00070   // Sets can contain any type of RooAbsArg, also pdf and functions
00071   s.add(g) ;
00072 
00073   // Remove element d
00074   s.remove(d) ;
00075 
00076 
00077 
00078   // A c c e s s i n g   R o o A r g S e t   c o n t e n t s
00079   // -------------------------------------------------------
00080   
00081   // You can look up objects by name
00082   RooAbsArg* aptr = s.find("a") ;
00083 
00084   // Construct a subset by name
00085   RooArgSet* subset1 = (RooArgSet*) s.selectByName("a,b,c") ;
00086 
00087   // Construct asubset by attribute
00088   RooArgSet* subset2 = (RooArgSet*) s.selectByAttrib("Constant",kTRUE) ;
00089 
00090   // Construct the subset of overlapping contents with another set
00091   RooArgSet s1(a,b,c) ;
00092   RooArgSet s2(c,d,e) ;
00093   RooArgSet* subset3 = (RooArgSet*) s1.selectCommon(s2) ;
00094 
00095 
00096 
00097   // O w n i n g   R o o A r g S e t s 
00098   // ---------------------------------  
00099 
00100   // Create a RooArgSet that owns its components
00101   // A set either owns all of its components or none,
00102   // so once addOwned() is used, add() can no longer be
00103   // used and will result in an error message
00104 
00105   RooRealVar* ac = (RooRealVar*) a.clone("a") ;
00106   RooRealVar* bc = (RooRealVar*) b.clone("b") ;
00107   RooRealVar* cc = (RooRealVar*) c.clone("c") ;
00108 
00109   RooArgSet s3 ;
00110   s3.addOwned(RooArgSet(*ac,*bc,*cc)) ;
00111 
00112   // Another possibility is to add an owned clone
00113   // of an object instead of the original
00114   s3.addClone(RooArgSet(d,e,g)) ;
00115 
00116   // A clone of a owning set is non-owning and its
00117   // contents is owned by the originating owning set
00118   RooArgSet* sclone = (RooArgSet*) s3.Clone("sclone") ;
00119 
00120   // To make a clone of a set and its contents use
00121   // the snapshot method
00122   RooArgSet* sclone2 = (RooArgSet*) s3.snapshot() ;
00123 
00124   // If a set contains function objects, only the head node
00125   // is cloned in a snapshot. To make a snapshot of all
00126   // servers of a function object do as follows. The result
00127   // of a RooArgSet snapshot with deepCloning option is a set
00128   // of cloned objects, and all their clone (recursive) server
00129   // dependencies, that together form a self-consistent
00130   // set that is free of external dependencies
00131 
00132   RooArgSet* sclone3 = (RooArgSet*) s3.snapshot(kTRUE) ;
00133 
00134 
00135 
00136   // S e t   p r i n t i n g 
00137   // ------------------------
00138 
00139   // Inline printing only show list of names of contained objects
00140   cout << "sclone = " << (*sclone) << endl ;
00141 
00142   // Plain print shows the same, prefixed by name of the set
00143   sclone->Print() ;
00144 
00145   // Standard printing shows one line for each item with the items name, class name and value
00146   sclone->Print("s") ;
00147 
00148   // Verbose printing adds each items arguments, address and 'extras' as defined by the object
00149   sclone->Print("v") ;
00150 
00151 
00152 
00153   // U s i n g   R o o A r g L i s t s 
00154   // ---------------------------------
00155 
00156   // List constructors exists with up to 9 initial arguments
00157   RooArgList l(a,b,c,d) ;
00158 
00159   // Lists have an explicit order and allow multiple arguments with the same name
00160   l.add(RooArgList(a,b,c,d)) ;
00161 
00162   // Access by index is provided
00163   RooAbsArg* arg4 = l.at(4) ;
00164 
00165 
00166 }

Generated on Tue Jul 5 15:45:08 2011 for ROOT_528-00b_version by  doxygen 1.5.1