rarAdd.cc

Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Project: BaBar detector at the SLAC PEP-II B-factory
00003 * Package: RooRarFit
00004  *    File: $Id: rarAdd.cc,v 1.11 2011/06/16 13:18:49 fwilson Exp $
00005  * Authors: Lei Zhang
00006  * History:
00007  * 
00008  * Copyright (C) 2005-2012, University of California, Riverside
00009  *****************************************************************************/
00010 
00011 // -- CLASS DESCRIPTION [RooRarFit] --
00012 // This class provides AddPdf/AddModel class for RooRarFit
00014 //
00015 // BEGIN_HTML
00016 // This class provides AddPdf/AddModel class for RooRarFit
00017 // END_HTML
00018 //
00019 
00020 #include "RooRarFit/rarVersion.hh"
00021 
00022 #include "Riostream.h"
00023 
00024 #include "RooFitCore/RooArgList.hh"
00025 #include "RooFitCore/RooDataSet.hh"
00026 #include "RooFitCore/RooProdPdf.hh"
00027 #include "RooFitCore/RooRealVar.hh"
00028 #include "RooFitCore/RooStringVar.hh"
00029 #include "RooFitCore/RooGlobalFunc.hh"
00030 using namespace RooFit;
00031 
00032 #include "RooFitCore/RooAddPdf.hh"
00033 #include "RooFitCore/RooAddModel.hh"
00034 
00035 #include "RooRarFit/rarAdd.hh"
00036 
00037 ClassImp(rarAdd)
00038   ;
00039 
00043 rarAdd::rarAdd()
00044   : rarCompBase(),
00045     _nCoeff(0)
00046 {
00047   init();
00048 }
00049 
00067 rarAdd::rarAdd(const char *configFile, const char *configSec,
00068                const char *configStr,
00069                rarDatasets *theDatasets, RooDataSet *theData,
00070                const char *name, const char *title,
00071                Bool_t useBasePdfFit, Bool_t buildAddPdf)
00072   : rarCompBase(configFile, configSec, configStr,
00073                 theDatasets, theData, name, title, useBasePdfFit),
00074     _nCoeff(0), _buildAddPdf(buildAddPdf)
00075 {
00076   init();
00077 }
00078 
00079 rarAdd::~rarAdd()
00080 {
00081 }
00082 
00091 void rarAdd::init()
00092 {
00093   // create coeffs
00094   createAbsVars("Coeffs", 0, &_coeffs);
00095   _nCoeff=_coeffs.getSize();
00096   if (_nCoeff>_nComp) {
00097     cout<<"You should define at most "<<_nComp
00098         <<" coeffs in config \"Coeffs\" in section \""
00099         <<getVarSec()<<"\""<<endl;
00100     exit(-1);
00101   }
00102   if (_nCoeff<_nComp-1) {
00103     cout<<"You should define at least "<<_nComp-1
00104         <<" coeffs in config \"Coeffs\" in section \""
00105         <<getVarSec()<<"\""<<endl;
00106     exit(-1);
00107   }
00108   // make sure AddModel is non-extended
00109   if (("AddModel"==_pdfType) && (_nCoeff==_nComp)) {
00110     cout<<"You should define "<<_nComp-1
00111         <<" coeffs in config \"Coeffs\" in section \""
00112         <<getVarSec()<<"\""<<endl;
00113     exit(-1);
00114   }
00115   _params.Print("v");
00116   
00117   if (_buildAddPdf) {
00118     // build pdf function
00119     if ("AddModel"==_pdfType) {
00120       _thePdf=new RooAddModel(Form("the_%s", GetName()),
00121                               _pdfType+" "+GetTitle(), _subPdfs, _coeffs);
00122     } else {
00123       _thePdf=new RooAddPdf(Form("the_%s", GetName()), _pdfType+" "+GetTitle(),
00124                             _subPdfs, _coeffs);
00125     }
00126   }
00127   // by default do comp plot
00128   setControlBit("CompsOnPlot", "compsOnPlot");
00129   
00130   cout<<"done init of rarAdd for "<<GetName()<<endl<<endl;
00131 }
00132 
00140 RooPlot *rarAdd::doPdfPlot(TList &plotList, TString pdfList)
00141 {
00142   return rarBasePdf::doPdfPlot(plotList, pdfList);
00143 }
00144 
00152 RooAbsPdf *rarAdd::getPdfWOvar(RooArgList ignoredObs)
00153 {
00154   RooAbsPdf *thePdf=_thePdf;
00155   // check if thePdf depends on theVar
00156   if (!(thePdf->dependsOn(ignoredObs))) return thePdf;
00157   // create individual Pdf
00158   TString theName=Form("the_%s_%s", ignoredObs[0].GetName(), GetName());
00159   TString theTitle=Form("%s w/o %s", GetTitle(), ignoredObs[0].GetName());
00160   RooArgList myPdfList=getPdfsWOvar(ignoredObs);
00161   if ("AddModel"==_pdfType) {
00162     thePdf=new RooAddModel(theName, theTitle, myPdfList, _coeffs);
00163   } else {
00164     thePdf=new RooAddPdf(theName, theTitle, myPdfList, _coeffs);
00165   }
00166   //thePdf->Print("v");
00167   //thePdf->Print();
00168   if (!(thePdf->dependsOn(ignoredObs))) return thePdf;
00169   delete thePdf;
00170   // create a dummy for it
00171   thePdf=new RooGenericPdf(theName, theTitle, "1",
00172                            *_thePdf->getParameters(_fullObs));
00173   //thePdf->Print("v");
00174   //thePdf->Print();
00175   return thePdf;
00176 }
00177 
00182 RooAbsPdf *rarAdd::getProtGen()
00183 {
00184   if (_theProtGen) return _theProtGen;
00185   // call super class' getProtGen
00186   rarCompBase::getProtGen();
00187   _theProtGen=_myDummyPdf;
00188   if (!getControlBit("dummySubGenPdfs")) {
00189     if ("AddModel"==_pdfType) {
00190       _theProtGen=new RooAddModel
00191         (Form("genAdd_%s", GetName()), Form("GenAdd for %s", GetName()),
00192          _subProtGenPdfs, _coeffs);
00193     } else {
00194       _theProtGen=new RooAddPdf
00195         (Form("genAdd_%s", GetName()), Form("GenAdd for %s", GetName()),
00196          _subProtGenPdfs, _coeffs);
00197     }
00198   }
00199   if (_protGenPdfs.getSize()>0) {
00200     RooArgList pdfList(_protGenPdfs);
00201     pdfList.add(*_theProtGen);
00202     _theProtGen = new RooProdPdf
00203       (Form("protGen_%s",GetName()),Form("Prot Gen for %s",GetName()),pdfList);
00204   }
00205   
00206   return _theProtGen;
00207 }

Generated on 30 Oct 2013 for RooRarFit by  doxygen 1.4.7