rarMLPdf Class Reference

Simple mlFit model builder. More...

#include <rarMLPdf.hh>

Inheritance diagram for rarMLPdf:

rarAdd rarCompBase rarBasePdf rarConfig List of all members.

Public Member Functions

 rarMLPdf ()
 Trivial ctor.
 rarMLPdf (const char *configFile, const char *configSec, const char *configStr, rarDatasets *theDatasets, RooDataSet *theData, const char *name, const char *title)
 Default ctor.
virtual ~rarMLPdf ()
virtual RooArgList getSCoeffList ()
 return sCoeff List
virtual RooArgSet getSpecialSet (TString setName="specialSet")
 Return the special ArgSet for splitting.
virtual TString getSpecialStr ()
 Return the special config string for splitting.
virtual RooAbsPdf * getProtGen ()
 Return prototype var generator for toy study.
virtual RooPlot * doPdfPlot (TList &plotList, TString pdfList="")
 Do pdfPlot for given PDFs.

Protected Member Functions

void init ()
 Initial function called by ctor.

Protected Attributes

RooArgList _sCoeffs
 Coeff before splitting.
RooArgSet _specialSet
 Special ArgSet for splitting.
RooArgSet _cat1Set
 ArgSet for the 1st type of each cat.
RooArgSet _asymSet
 ArgSet for two-state cat.
TString _specialStr
 Special config string for splitting.

Private Member Functions

 rarMLPdf (const rarMLPdf &)
 ClassDef (rarMLPdf, 0)

Detailed Description

Simple mlFit model builder.

Build a simple mlFit model which is basically an extended AddPdf. This simple model can be used to build SimPdf for the final mlFit model, or if no SimPdf is used at all, the first such simple model can be used as the final model (you can build many such simple model in rarMLFitter anyway).

Config Directives:
/// configStr = MLPdf ["<Optional Title>"]
/// Comps = <name1> <name2>  ... <nameN>
/// Coeffs = <coeff1> <coeff2> ... <coeffN>
/// <coeff1> = AbsReal Def
/// ...
/// <coeffN> = AbsReal Def
Comps defines names of all its components. Each component has its own config section, namely, comp <name1> is configured in config section named "<name1> Config". Coeffs defines names of all its coefficients. All the coeffs can be defined as RooRealVar or RooFormulaVar. The number of coeffs should match that of components since it is an extended AddPdf.

Definition at line 43 of file rarMLPdf.hh.


Constructor & Destructor Documentation

rarMLPdf::rarMLPdf (  ) 

Trivial ctor.

Usually the objects should be created using other ctors.

Definition at line 45 of file rarMLPdf.cc.

References init().

00046   : rarAdd(),
00047     _specialStr("")
00048 {
00049   init();
00050 }

rarMLPdf::rarMLPdf ( const char *  configFile,
const char *  configSec,
const char *  configStr,
rarDatasets theDatasets,
RooDataSet *  theData,
const char *  name,
const char *  title 
)

Default ctor.

Parameters:
configFile The config file
configSec The config section
configStr The config string
theDatasets Available datasets
theData Default dataset for this PDF
name The name
title The title
The default ctor first initializes data members, and then calls init.

Definition at line 64 of file rarMLPdf.cc.

References init().

00068   : rarAdd(configFile, configSec, configStr,
00069               theDatasets, theData, name, title, kFALSE, kFALSE),
00070     _specialStr("")
00071 {
00072   init();
00073 }

rarMLPdf::~rarMLPdf (  )  [virtual]

Definition at line 75 of file rarMLPdf.cc.

00076 {
00077 }

rarMLPdf::rarMLPdf ( const rarMLPdf  )  [private]


Member Function Documentation

rarMLPdf::ClassDef ( rarMLPdf  ,
 
) [private]

RooPlot * rarMLPdf::doPdfPlot ( TList &  plotList,
TString  pdfList = "" 
) [virtual]

Do pdfPlot for given PDFs.

Parameters:
plotList List of plots
pdfList List of PDFs to be plotted
Returns:
The last RooPlot created
The function of rarCompBase should be used to get pdfPlot instead of that of rarAdd, its direct super-class, because it is more useful to get individual plots of its components rather than the total plot of its own.

Reimplemented from rarAdd.

Definition at line 428 of file rarMLPdf.cc.

References rarCompBase::doPdfPlot().

00429 {
00430   return rarCompBase::doPdfPlot(plotList, pdfList);
00431 }

RooAbsPdf * rarMLPdf::getProtGen (  )  [virtual]

Return prototype var generator for toy study.

Returns:
The generator
It constrcuts prototype var generator for toy study

Reimplemented from rarAdd.

Definition at line 386 of file rarMLPdf.cc.

References rarBasePdf::_coeffs, rarCompBase::_nComp, rarBasePdf::_protGenPdfs, rarBasePdf::_subPdfs, rarCompBase::_subProtGenPdfs, rarBasePdf::_theProtGen, and rarCompBase::getProtGen().

00387 {
00388   if (_theProtGen) return _theProtGen;
00389   // call super class' getProtGen
00390   rarCompBase::getProtGen();
00391   // construct prototype var generator from components
00392   RooArgList compList;
00393   for (Int_t i=0; i<_nComp; i++) {
00394     if (_protGenPdfs.getSize()>0) {
00395       RooArgList pdfList(_protGenPdfs);
00396       pdfList.add(_subProtGenPdfs[i]);
00397       TString compName=
00398         Form("prodProtGen_%s_%s",GetName(),_subPdfs[i].GetName());
00399       TString compTitle=
00400         Form("Prod Prot Gen %s %s",GetName(),_subPdfs[i].GetName());
00401       RooAbsPdf *thePdf=new RooProdPdf (compName, compTitle, pdfList);
00402       compList.add(*thePdf);
00403     } else compList.add(_subProtGenPdfs[i]);
00404   }
00405   _theProtGen=new RooAddPdf
00406     (Form("gen_%s", GetName()), Form("Gen Add for %s", GetName()),
00407      compList, _coeffs);
00408   
00409   cout<<"getProtGen: Expected number of events "
00410       <<_theProtGen->expectedEvents(0)<<endl;
00411   
00412   cout<<"protGen created for "<<GetName()<<endl;
00413   _theProtGen->Print();
00414   //_theProtGen->Print("v");
00415   return _theProtGen;
00416 }

virtual RooArgList rarMLPdf::getSCoeffList (  )  [inline, virtual]

return sCoeff List

Definition at line 53 of file rarMLPdf.hh.

References _sCoeffs.

00053 {return _sCoeffs;}

RooArgSet rarMLPdf::getSpecialSet ( TString  setName = "specialSet"  )  [virtual]

Return the special ArgSet for splitting.

Parameters:
setName The name of the ArgSet
Returns:
The special ArgSet for splitting
It returns the named special ArgSet for splitting

Definition at line 375 of file rarMLPdf.cc.

References _asymSet, _cat1Set, and _specialSet.

00376 {
00377   if ("cat1Set"==setName) return _cat1Set;
00378   if ("asymSet"==setName) return _asymSet;
00379   return _specialSet; // default
00380 }

virtual TString rarMLPdf::getSpecialStr (  )  [inline, virtual]

Return the special config string for splitting.

Returns:
The special config string for splitting

Definition at line 58 of file rarMLPdf.hh.

References _specialStr.

00058 {return _specialStr;}

void rarMLPdf::init (  )  [protected, virtual]

Initial function called by ctor.

init is called by the ctor. The coeff info is read in with rarAdd::init(), then it re-define the coeffs using the splitting info of the final ML model, and finally it builds the RooAddPdf.

Essentially, the splitting can be done manually by fitting on to separate sub-datasets for individual categories. So for each category, the yields, nSig, nBkg, etc. need to be split, which means for n number of category types, there should be n sub-yields. To get the final yield, just sum up all these values. It is then convenient to have the total yield, and n-1 sub-yield fractions as free parameters:

/// subY1=Ntot*(1-frac2...-fracn),
/// subY2=Ntot*frac2,
/// ...
/// subYn=Ntot*fracn.
That is the basic idea for _coeffs splitting of the extended AddPdf. For each category, you will need similar splitting setttings. Depending on the auto splitting method used, the unity constraint can be imposed by RooFit or RooRarFit itself.

Reimplemented from rarAdd.

Definition at line 104 of file rarMLPdf.cc.

References _asymSet, _cat1Set, rarBasePdf::_coeffs, rarBasePdf::_compCat, rarConfig::_fullObs, rarAdd::_nCoeff, rarCompBase::_nComp, rarBasePdf::_pdfType, _sCoeffs, _specialSet, _specialStr, rarBasePdf::_subPdfs, rarBasePdf::_theData, rarBasePdf::_thePdf, rarConfig::addToConfStr(), rarConfig::createAbsVar(), rarConfig::createAbsVars(), rarBasePdf::getControlBit(), rarDatasets::getData(), rarBasePdf::getDatasets(), rarBasePdf::getFitter(), rarConfig::getMasterSec(), rarMLFitter::getPhysCat(), rarMLFitter::getSplitCat(), rarMLFitter::getSplitCats(), rarBasePdf::getVarSec(), rarStrParser::Index(), rarStrParser::nArgs(), rarConfig::readConfStr(), rarConfig::readConfStrCnA(), rarBasePdf::saveFracName(), and rarBasePdf::setVarSec().

Referenced by rarMLPdf().

00105 {
00106   // make sure it is extended
00107   if (_nCoeff!=_nComp) {
00108     cout<<"Pdf model should be extended pdf"<<endl;
00109     exit(-1);
00110   }
00111   // add compCat type, the last type for embedded events
00112   for (Int_t i=0; i<=_nComp; i++) _compCat.defineType(Form("%02d",i));
00113   // save the original coeff List anyway
00114   _sCoeffs.add(_coeffs);
00115   // to deal with simu fit and splitting of coeffs
00116   TString masterSec=getMasterSec();
00117   Bool_t simFit=getControlBit("SimFit")&&
00118     ("simple"!=readConfStr("simultaneousFit", "yes",masterSec));
00119   // for split specials
00120   if (simFit) {
00121     createAbsVars("splitSpecials", &_specialSet);
00122     // run master sec's
00123     TString myVarSec=getVarSec();
00124     setVarSec(masterSec);
00125     createAbsVars("splitSpecials", &_specialSet);
00126     setVarSec(myVarSec);
00127   }
00128   TString yieldSplitMethod=readConfStr("yieldSplitMethod", "auto", masterSec);
00129   if (simFit && ("manual"!=yieldSplitMethod)) {
00130     // use master sec config
00131     TString myVarSec=getVarSec();
00132     setVarSec(masterSec);
00133     // get coeff list, coeff param set, param list
00134     RooArgSet coeffParamSet("Coeff Parameter Set");
00135     for (Int_t i=0; i<_nCoeff; i++) {
00136       coeffParamSet.add(*(_coeffs[i].getParameters(*_fullObs)));
00137     }
00138     RooArgList coeffParamList(coeffParamSet);
00139     // let's make sure coeffs are not split in the mlFitter
00140     // coz we are going to split them here
00141     TString pdfSplitStr=readConfStr(Form("the_%s", GetName()), "", masterSec);
00142     if ("semi"==yieldSplitMethod) {
00143       for (Int_t i=0; i<_coeffs.getSize(); i++) {
00144         if (pdfSplitStr.Contains(_coeffs[i].GetName())) {
00145           cout<<"Please do not include "<<_coeffs[i].GetName()
00146               <<" or its dependents in your simPdfBuilder configs"<<endl
00147               <<"in section \""<<masterSec<<"\":"<<endl
00148               <<pdfSplitStr<<endl
00149               <<"We will split it for you."<<endl;
00150           exit(-1);
00151         }
00152       }
00153       for (Int_t i=0; i<coeffParamList.getSize(); i++) {
00154         if (pdfSplitStr.Contains(coeffParamList[i].GetName())) {
00155           cout<<"Please do not include "<<coeffParamList[i].GetName()
00156               <<" or its dependents in your simPdfBuilder configs"<<endl
00157               <<"in section \""<<masterSec<<"\":"<<endl
00158               <<pdfSplitStr<<endl
00159               <<"We will split it for you."<<endl;
00160           exit(-1);
00161         }
00162       }
00163     }
00164     // get splitting cats
00165     TString physCat=getFitter()->getPhysCat();
00166     TString splitCats=getFitter()->getSplitCats();
00167     // build split coeffs
00168     _coeffs.removeAll();
00169     for (Int_t i=0; i<_nCoeff; i++) {
00170       // formula for the final coeff
00171       TString coeffArgsStr=_sCoeffs[i].GetName();
00172       TString formulaStr="@0";
00173       // get frac split rules
00174       TString fracRuleStr=readConfStr("fracRule", splitCats, masterSec);
00175       fracRuleStr=readConfStr("fracRule_"+coeffArgsStr,fracRuleStr, masterSec);
00176       rarStrParser catsStrParser=fracRuleStr;
00177       Int_t nSCat=catsStrParser.nArgs();
00178       // create multiple cat coeffs
00179       RooArgSet splitCatSet(getFitter()->getSplitCatSet());
00180       for (Int_t j=0; j<nSCat; j++) {
00181         TString catName=catsStrParser[j];
00182         RooAbsCategory *theCat=getFitter()->getSplitCat(splitCatSet, catName);
00183         if (!theCat) {
00184           cout<<"Can not find cat "<<catName<<endl
00185               <<"Please make sure the cat you are using exists"<<endl;
00186           exit(-1);
00187         }
00188         // rename the catName
00189         catName=theCat->GetName();
00190         // cat ceoff name
00191         TString catCoeffName=Form("Frac_%s_%s",
00192                                   _sCoeffs[i].GetName(), catName.Data());
00193         TString catCoeffStr=readConfStr(catCoeffName, "notSet", masterSec);
00194         if ("notSet"==catCoeffStr)
00195           catCoeffStr=Form("%s %s RooRealVar \"cat coeff\" C 1. 0. 1.",
00196                            catCoeffName.Data(), catCoeffName.Data());
00197         else
00198           catCoeffStr=catCoeffName+" "+catCoeffStr;
00199         RooRealVar *catCoeff=(RooRealVar*)createAbsVar(catCoeffStr);
00200         catCoeffName=catCoeff->GetName();
00201         // save the var name
00202         saveFracName(catCoeffName);
00203         // addToConfStr("Ignored", catCoeff->GetName(), myVarSec);
00204         coeffArgsStr+=Form(" %s ", catCoeff->GetName());
00205         formulaStr+=Form("*@%d",j+1);
00206         // let's make sure catCoeff is created as RooRealVar
00207         if ("RooRealVar"!=TString(catCoeff->ClassName())) {
00208           cout<<catCoeffName<<" is created in config file as "
00209               <<catCoeff->ClassName()<<","<<endl
00210               <<"but it should be RooRealVar"<<endl;
00211           exit(-1);
00212         }
00213         // now, we create split catCoeffs for this catCoeff
00214         // first we find out how many types for this cat
00215         TString catTypesStr="";
00216         TIterator* catTypeIter = theCat->typeIterator();
00217         RooCatType *theType(0);
00218         while(theType=(RooCatType*)catTypeIter->Next()) {
00219           catTypesStr+=Form(" %s ", theType->GetName());
00220         }
00221         delete catTypeIter;
00222         //cout<<catTypesStr<<endl;
00223         rarStrParser catTypesStrParser=catTypesStr;
00224         if (catTypesStrParser.nArgs()<1) continue; // nothing in the cat
00225         TString cat1FormulaStr="1.";
00226         TString cat1ArgSet="";
00227         Roo1DTable* theTable(0);
00228         if (_theData) theTable = _theData->table(*theCat);
00229         // check if we have fracSrc config
00230         Bool_t useFracSrc=kFALSE;
00231         TString fracSrcStr=
00232           readConfStrCnA(Form("fracSrc_%s_%s", _sCoeffs[i].GetName(),
00233                               catName.Data()),"notSet");
00234         if ("notSet"==fracSrcStr)
00235           fracSrcStr=
00236             readConfStrCnA(Form("fracSrc_%s",_sCoeffs[i].GetName()), "notSet");
00237         if ("notSet"==fracSrcStr)
00238           fracSrcStr=readConfStrCnA("fracSrc", "notSet");
00239         if ("notSet"!=fracSrcStr) {
00240           RooDataSet *theData=getDatasets()->getData(fracSrcStr);
00241           if (theData) {
00242             theTable = theData->table(*theCat);
00243             useFracSrc=kTRUE;
00244             cout<<" Using table from "<<theData->GetName()
00245                 <<" for "<<_sCoeffs[i].GetName()<<" "<<catName<<endl;
00246             theTable->Print();
00247           }
00248         }
00249         // now we need to find out which type to be the non-free
00250         Int_t nonIdx=0;
00251         // first for auto mode
00252         if ("auto"==yieldSplitMethod) {
00253           Bool_t notFound=(catTypesStrParser.nArgs()>1); // if #types>1
00254           for (Int_t k=0; k<catTypesStrParser.nArgs(); k++) {
00255             TString myNonFreeName=catCoeffName+"["+catTypesStrParser[k]+"]";
00256             Int_t strIdx=pdfSplitStr.Index(myNonFreeName);
00257             if (strIdx<0) continue;
00258             // check cat seq
00259             TString subpdfSplitStr=pdfSplitStr(0,strIdx);
00260             Int_t colonIdx=subpdfSplitStr.Last(':');
00261             if (colonIdx<=0) break;
00262             rarStrParser pdfSplitStrParser=TString(subpdfSplitStr(0,colonIdx));
00263             //cout<<pdfSplitStr<<endl<<myNonFreeName<<endl<<strIdx<<endl;
00264             // get cats
00265             TString splitCatName=
00266               pdfSplitStrParser[pdfSplitStrParser.nArgs()-1];
00267             splitCatName.ReplaceAll(",", "_");
00268             //cout<<splitCatName<<endl;
00269             if (splitCatName==catName) {
00270               nonIdx=k;
00271               notFound=kFALSE;
00272             }
00273             break;
00274           }
00275           if (notFound) {
00276             cout<<" Can not find splitting specif. for"<<endl
00277                 <<" "<<catCoeffName<<" wrt types:"<<endl
00278                 <<" "<<catTypesStr<<endl
00279                 <<" in the_"<<GetName()<<endl<<pdfSplitStr<<endl
00280                 <<" from section ["<<getVarSec()<<"]"<<endl;
00281             exit(-1);
00282           }
00283         } else { // semi mode
00284           TString nonFreeStr=readConfStr("nonFreeCatTypes", "", getVarSec());
00285           for (Int_t k=0; k<catTypesStrParser.nArgs(); k++) {
00286             if (nonFreeStr.
00287                 Contains(catCoeffName+"["+catTypesStrParser[k]+"]")) {
00288               nonIdx=k;
00289               break;
00290             }
00291           }
00292         }
00293         for (Int_t k=0; k<catTypesStrParser.nArgs(); k++) {
00294           // make sure the name is a cat type
00295           const RooCatType *theType=theCat->lookupType(catTypesStrParser[k]);
00296           if (!theType) {
00297             cout <<"The cat type "<<catTypesStrParser[k]
00298                  <<" does not exist in cat "<<theCat->GetName()<<endl;
00299             exit(-1);
00300           }
00301           if (k==nonIdx) continue;
00302           TString catCoeffTypeName=catCoeffName+"_"+catTypesStrParser[k]+"";
00303           Double_t typeFrac=1./catTypesStrParser.nArgs();
00304           if (theTable) typeFrac=theTable->getFrac(catTypesStrParser[k]);
00305           RooAbsReal *catCoeffType=(RooAbsReal*)
00306             createAbsVar(Form("%s %s RooRealVar \"cat type coeff\" C %f 0 1",
00307                               catCoeffTypeName.Data(), catCoeffTypeName.Data(),
00308                               typeFrac));
00309           // save the var name
00310           saveFracName(catCoeffTypeName);
00311           if (useFracSrc)
00312             addToConfStr("Ignored", catCoeffType->GetName(), myVarSec);
00313           _specialSet.add(*catCoeffType);
00314           if (2==catTypesStrParser.nArgs()) _asymSet.add(*catCoeffType);
00315           Int_t fvIdx = k<nonIdx ? k : k-1;
00316           cat1FormulaStr+=Form("-@%d", fvIdx);
00317           cat1ArgSet+=Form(" %s ", catCoeffType->GetName());
00318         }
00319         // for nonfree cat type
00320         TString catCoeffTypeName=catCoeffName+"_"+catTypesStrParser[nonIdx]+"";
00321         // old way, ie RoorarFit way, RooRealVar
00322         RooAbsReal *catCoeffType=(RooAbsReal*)
00323           createAbsVar(Form("%s %s RooFormulaVar %s %s",
00324                             catCoeffTypeName.Data(), catCoeffTypeName.Data(),
00325                             cat1FormulaStr.Data(), cat1ArgSet.Data()));
00326         // make sure it is RooFormulaVar
00327         if ("RooFormulaVar"!=TString(catCoeffType->ClassName())) {
00328           cout<<catCoeffTypeName<<" is created in config file as "
00329               <<catCoeffType->ClassName()<<","<<endl
00330               <<"but it should be RooFormulaVar"<<endl;
00331           exit(-1);
00332         }
00333         _specialSet.add(*catCoeffType);
00334         if (catTypesStrParser.nArgs()>1) _cat1Set.add(*catCoeffType);
00335         if ("semi"==yieldSplitMethod) {
00336           _specialStr+=Form(" %s : %s ", catName.Data(), catCoeffName.Data());
00337         }
00338       }
00339       // do we still have any left over?
00340       if (splitCatSet.getSize()>0) {
00341         cout<<" No splitting rules for "<<_sCoeffs[i].GetName()<<" wrt:"<<endl;
00342         splitCatSet.Print();
00343         cout<<" Please check config fracRule or fracRule_"
00344             <<_sCoeffs[i].GetName()<<" in section \""<<masterSec<<"\":"<<endl;
00345         exit(-1);
00346       }
00347       TString coeffName=Form("theSim_%s", _sCoeffs[i].GetName());
00348       //cout<<coeffName<<endl
00349       //<<formulaStr<<endl
00350       //<<coeffArgsStr<<endl;
00351       RooAbsReal *coeff=(RooAbsReal*)
00352         createAbsVar(Form("%s %s RooFormulaVar %s %s",
00353                           coeffName.Data(), coeffName.Data(),
00354                           formulaStr.Data(), coeffArgsStr.Data()));
00355       //coeff->Print("v");
00356       _coeffs.add(*coeff);
00357     }
00358     //_specialSet.Print("v");
00359     // restore myVarSec
00360     setVarSec(myVarSec);
00361   }
00362   // build pdf function
00363   _thePdf=new RooAddPdf(Form("the_%s", GetName()), _pdfType+" "+GetTitle(),
00364                         _subPdfs, _coeffs);
00365   //_thePdf->Print("v");
00366   cout<<"done init of rarMLPdf for "<<GetName()<<endl<<endl;
00367 }


Member Data Documentation

RooArgSet rarMLPdf::_asymSet [protected]

ArgSet for two-state cat.

Definition at line 69 of file rarMLPdf.hh.

Referenced by getSpecialSet(), and init().

RooArgSet rarMLPdf::_cat1Set [protected]

ArgSet for the 1st type of each cat.

Definition at line 68 of file rarMLPdf.hh.

Referenced by getSpecialSet(), and init().

RooArgList rarMLPdf::_sCoeffs [protected]

Coeff before splitting.

Definition at line 66 of file rarMLPdf.hh.

Referenced by getSCoeffList(), and init().

RooArgSet rarMLPdf::_specialSet [protected]

Special ArgSet for splitting.

Definition at line 67 of file rarMLPdf.hh.

Referenced by getSpecialSet(), and init().

TString rarMLPdf::_specialStr [protected]

Special config string for splitting.

Definition at line 70 of file rarMLPdf.hh.

Referenced by getSpecialStr(), and init().


The documentation for this class was generated from the following files:
Generated on 30 Oct 2013 for RooRarFit by  doxygen 1.4.7