rf505_asciicfg.C

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #505
00004 // 
00005 // Reading and writing ASCII configuration files
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 "RooPolynomial.h"
00021 #include "RooAddPdf.h"
00022 #include "TCanvas.h"
00023 #include "TAxis.h"
00024 #include "RooPlot.h"
00025 using namespace RooFit ;
00026 
00027 
00028 void rf505_asciicfg()
00029 {
00030   // C r e a t e  p d f 
00031   // ------------------
00032   
00033   // Construct gauss(x,m,s)
00034   RooRealVar x("x","x",-10,10) ;
00035   RooRealVar m("m","m",0,-10,10) ;
00036   RooRealVar s("s","s",1,-10,10) ;
00037   RooGaussian gauss("g","g",x,m,s) ;
00038 
00039   // Construct poly(x,p0)
00040   RooRealVar p0("p0","p0",0.01,0.,1.) ;
00041   RooPolynomial poly("p","p",x,p0) ;             
00042 
00043   // Construct model = f*gauss(x) + (1-f)*poly(x)
00044   RooRealVar f("f","f",0.5,0.,1.) ;
00045   RooAddPdf model("model","model",RooArgSet(gauss,poly),f) ;
00046 
00047 
00048 
00049   // F i t   m o d e l   t o   t o y   d a t a
00050   // -----------------------------------------
00051 
00052   RooDataSet* d = model.generate(x,1000) ;
00053   model.fitTo(*d) ;
00054 
00055 
00056   // W r i t e   p a r a m e t e r s   t o   a s c i i   f i l e 
00057   // -----------------------------------------------------------
00058 
00059   // Obtain set of parameters
00060   RooArgSet* params = model.getParameters(x) ;
00061 
00062   // Write parameters to file
00063   params->writeToFile("rf505_asciicfg_example.txt") ;
00064 
00065 
00066 
00067   // R e a d    p a r a m e t e r s   f r o m    a s c i i   f i l e 
00068   // ----------------------------------------------------------------
00069   
00070   // Read parameters from file
00071   params->readFromFile("rf505_asciicfg_example.txt") ;
00072   params->Print("v") ;
00073 
00074   // Read parameters from section 'Section2' of file
00075   params->readFromFile("rf505_asciicfg.txt",0,"Section2") ;
00076   params->Print("v") ;
00077 
00078   // Read parameters from section 'Section3' of file. Mark all
00079   // variables that were processed with the "READ" attribute
00080   params->readFromFile("rf505_asciicfg.txt","READ","Section3") ;
00081 
00082   // Print the list of parameters that were not read from Section3
00083   cout << "The following parameters of the were _not_ read from Section3: " 
00084        << (*params->selectByAttrib("READ",kFALSE)) << endl ;
00085 
00086 
00087   // Read parameters from section 'Section4' of file, which contains
00088   // 'include file' statement of rf505_asciicfg_example.txt
00089   // so that we effective read the same
00090   params->readFromFile("rf505_asciicfg.txt",0,"Section4") ;
00091   params->Print("v") ;
00092 
00093 
00094 
00095 }

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