ROOT logo
//////////////////////////////////////////////////////////////////////////
//
// 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #508
// 
//   RooArgSet and RooArgList tools and tricks
//
//
//
// 07/2008 - Wouter Verkerke 
// 
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "RooArgSet.h"
#include "RooArgList.h"
#include "RooCategory.h"
using namespace RooFit ;


void rf508_listsetmanip()
{

  // C r e a t e   d u m m y   o b j e c t s 
  // ---------------------------------------

  // Create some variables
  RooRealVar a("a","a",1,-10,10) ;
  RooRealVar b("b","b",2,-10,10) ;
  RooRealVar c("c","c",3,-10,10) ;
  RooRealVar d("d","d",4,-10,10) ;
  RooRealVar x("x","x",0,-10,10) ;
  c.setError(0.5) ;
  a.setConstant() ;
  b.setConstant() ;

  // Create a category
  RooCategory e("e","e") ;
  e.defineType("sig") ;
  e.defineType("bkg") ;

  // Create a pdf
  RooGaussian g("g","g",x,a,b) ;



  // 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 
  // -------------------------------------------------------

  // A RooArgSet is a set of RooAbsArg objects. Each object in the set must have
  // a unique name 

  // Set constructors exists with up to 9 initial arguments
  RooArgSet s(a,b) ;

  // At any time objects can be added with add()
  s.add(e) ;

  // Add up to 9 additional arguments in one call
  s.add(RooArgSet(c,d)) ;

  // Sets can contain any type of RooAbsArg, also pdf and functions
  s.add(g) ;

  // Remove element d
  s.remove(d) ;



  // 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
  // -------------------------------------------------------
  
  // You can look up objects by name
  RooAbsArg* aptr = s.find("a") ;

  // Construct a subset by name
  RooArgSet* subset1 = (RooArgSet*) s.selectByName("a,b,c") ;

  // Construct asubset by attribute
  RooArgSet* subset2 = (RooArgSet*) s.selectByAttrib("Constant",kTRUE) ;

  // Construct the subset of overlapping contents with another set
  RooArgSet s1(a,b,c) ;
  RooArgSet s2(c,d,e) ;
  RooArgSet* subset3 = (RooArgSet*) s1.selectCommon(s2) ;



  // O w n i n g   R o o A r g S e t s 
  // ---------------------------------  

  // Create a RooArgSet that owns its components
  // A set either owns all of its components or none,
  // so once addOwned() is used, add() can no longer be
  // used and will result in an error message

  RooRealVar* ac = (RooRealVar*) a.clone("a") ;
  RooRealVar* bc = (RooRealVar*) b.clone("b") ;
  RooRealVar* cc = (RooRealVar*) c.clone("c") ;

  RooArgSet s3 ;
  s3.addOwned(RooArgSet(*ac,*bc,*cc)) ;

  // Another possibility is to add an owned clone
  // of an object instead of the original
  s3.addClone(RooArgSet(d,e,g)) ;

  // A clone of a owning set is non-owning and its
  // contents is owned by the originating owning set
  RooArgSet* sclone = (RooArgSet*) s3.Clone("sclone") ;

  // To make a clone of a set and its contents use
  // the snapshot method
  RooArgSet* sclone2 = (RooArgSet*) s3.snapshot() ;

  // If a set contains function objects, only the head node
  // is cloned in a snapshot. To make a snapshot of all
  // servers of a function object do as follows. The result
  // of a RooArgSet snapshot with deepCloning option is a set
  // of cloned objects, and all their clone (recursive) server
  // dependencies, that together form a self-consistent
  // set that is free of external dependencies

  RooArgSet* sclone3 = (RooArgSet*) s3.snapshot(kTRUE) ;



  // S e t   p r i n t i n g 
  // ------------------------

  // Inline printing only show list of names of contained objects
  cout << "sclone = " << (*sclone) << endl ;

  // Plain print shows the same, prefixed by name of the set
  sclone->Print() ;

  // Standard printing shows one line for each item with the items name, class name and value
  sclone->Print("s") ;

  // Verbose printing adds each items arguments, address and 'extras' as defined by the object
  sclone->Print("v") ;



  // U s i n g   R o o A r g L i s t s 
  // ---------------------------------

  // List constructors exists with up to 9 initial arguments
  RooArgList l(a,b,c,d) ;

  // Lists have an explicit order and allow multiple arguments with the same name
  l.add(RooArgList(a,b,c,d)) ;

  // Access by index is provided
  RooAbsArg* arg4 = l.at(4) ;


}
 rf508_listsetmanip.C:1
 rf508_listsetmanip.C:2
 rf508_listsetmanip.C:3
 rf508_listsetmanip.C:4
 rf508_listsetmanip.C:5
 rf508_listsetmanip.C:6
 rf508_listsetmanip.C:7
 rf508_listsetmanip.C:8
 rf508_listsetmanip.C:9
 rf508_listsetmanip.C:10
 rf508_listsetmanip.C:11
 rf508_listsetmanip.C:12
 rf508_listsetmanip.C:13
 rf508_listsetmanip.C:14
 rf508_listsetmanip.C:15
 rf508_listsetmanip.C:16
 rf508_listsetmanip.C:17
 rf508_listsetmanip.C:18
 rf508_listsetmanip.C:19
 rf508_listsetmanip.C:20
 rf508_listsetmanip.C:21
 rf508_listsetmanip.C:22
 rf508_listsetmanip.C:23
 rf508_listsetmanip.C:24
 rf508_listsetmanip.C:25
 rf508_listsetmanip.C:26
 rf508_listsetmanip.C:27
 rf508_listsetmanip.C:28
 rf508_listsetmanip.C:29
 rf508_listsetmanip.C:30
 rf508_listsetmanip.C:31
 rf508_listsetmanip.C:32
 rf508_listsetmanip.C:33
 rf508_listsetmanip.C:34
 rf508_listsetmanip.C:35
 rf508_listsetmanip.C:36
 rf508_listsetmanip.C:37
 rf508_listsetmanip.C:38
 rf508_listsetmanip.C:39
 rf508_listsetmanip.C:40
 rf508_listsetmanip.C:41
 rf508_listsetmanip.C:42
 rf508_listsetmanip.C:43
 rf508_listsetmanip.C:44
 rf508_listsetmanip.C:45
 rf508_listsetmanip.C:46
 rf508_listsetmanip.C:47
 rf508_listsetmanip.C:48
 rf508_listsetmanip.C:49
 rf508_listsetmanip.C:50
 rf508_listsetmanip.C:51
 rf508_listsetmanip.C:52
 rf508_listsetmanip.C:53
 rf508_listsetmanip.C:54
 rf508_listsetmanip.C:55
 rf508_listsetmanip.C:56
 rf508_listsetmanip.C:57
 rf508_listsetmanip.C:58
 rf508_listsetmanip.C:59
 rf508_listsetmanip.C:60
 rf508_listsetmanip.C:61
 rf508_listsetmanip.C:62
 rf508_listsetmanip.C:63
 rf508_listsetmanip.C:64
 rf508_listsetmanip.C:65
 rf508_listsetmanip.C:66
 rf508_listsetmanip.C:67
 rf508_listsetmanip.C:68
 rf508_listsetmanip.C:69
 rf508_listsetmanip.C:70
 rf508_listsetmanip.C:71
 rf508_listsetmanip.C:72
 rf508_listsetmanip.C:73
 rf508_listsetmanip.C:74
 rf508_listsetmanip.C:75
 rf508_listsetmanip.C:76
 rf508_listsetmanip.C:77
 rf508_listsetmanip.C:78
 rf508_listsetmanip.C:79
 rf508_listsetmanip.C:80
 rf508_listsetmanip.C:81
 rf508_listsetmanip.C:82
 rf508_listsetmanip.C:83
 rf508_listsetmanip.C:84
 rf508_listsetmanip.C:85
 rf508_listsetmanip.C:86
 rf508_listsetmanip.C:87
 rf508_listsetmanip.C:88
 rf508_listsetmanip.C:89
 rf508_listsetmanip.C:90
 rf508_listsetmanip.C:91
 rf508_listsetmanip.C:92
 rf508_listsetmanip.C:93
 rf508_listsetmanip.C:94
 rf508_listsetmanip.C:95
 rf508_listsetmanip.C:96
 rf508_listsetmanip.C:97
 rf508_listsetmanip.C:98
 rf508_listsetmanip.C:99
 rf508_listsetmanip.C:100
 rf508_listsetmanip.C:101
 rf508_listsetmanip.C:102
 rf508_listsetmanip.C:103
 rf508_listsetmanip.C:104
 rf508_listsetmanip.C:105
 rf508_listsetmanip.C:106
 rf508_listsetmanip.C:107
 rf508_listsetmanip.C:108
 rf508_listsetmanip.C:109
 rf508_listsetmanip.C:110
 rf508_listsetmanip.C:111
 rf508_listsetmanip.C:112
 rf508_listsetmanip.C:113
 rf508_listsetmanip.C:114
 rf508_listsetmanip.C:115
 rf508_listsetmanip.C:116
 rf508_listsetmanip.C:117
 rf508_listsetmanip.C:118
 rf508_listsetmanip.C:119
 rf508_listsetmanip.C:120
 rf508_listsetmanip.C:121
 rf508_listsetmanip.C:122
 rf508_listsetmanip.C:123
 rf508_listsetmanip.C:124
 rf508_listsetmanip.C:125
 rf508_listsetmanip.C:126
 rf508_listsetmanip.C:127
 rf508_listsetmanip.C:128
 rf508_listsetmanip.C:129
 rf508_listsetmanip.C:130
 rf508_listsetmanip.C:131
 rf508_listsetmanip.C:132
 rf508_listsetmanip.C:133
 rf508_listsetmanip.C:134
 rf508_listsetmanip.C:135
 rf508_listsetmanip.C:136
 rf508_listsetmanip.C:137
 rf508_listsetmanip.C:138
 rf508_listsetmanip.C:139
 rf508_listsetmanip.C:140
 rf508_listsetmanip.C:141
 rf508_listsetmanip.C:142
 rf508_listsetmanip.C:143
 rf508_listsetmanip.C:144
 rf508_listsetmanip.C:145
 rf508_listsetmanip.C:146
 rf508_listsetmanip.C:147
 rf508_listsetmanip.C:148
 rf508_listsetmanip.C:149
 rf508_listsetmanip.C:150
 rf508_listsetmanip.C:151
 rf508_listsetmanip.C:152
 rf508_listsetmanip.C:153
 rf508_listsetmanip.C:154
 rf508_listsetmanip.C:155
 rf508_listsetmanip.C:156
 rf508_listsetmanip.C:157
 rf508_listsetmanip.C:158
 rf508_listsetmanip.C:159
 rf508_listsetmanip.C:160
 rf508_listsetmanip.C:161
 rf508_listsetmanip.C:162
 rf508_listsetmanip.C:163
 rf508_listsetmanip.C:164
 rf508_listsetmanip.C:165
 rf508_listsetmanip.C:166
 rf508_listsetmanip.C:167