RooGenericPdf.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooGenericPdf.cxx 28259 2009-04-16 16:21:16Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // RooGenericPdf is a concrete implementation of a probability density function,
00021 // which takes a RooArgList of servers and a C++ expression string defining how
00022 // its value should be calculated from the given list of servers.
00023 // A fully numerical integration is automatically performed to normalize the given
00024 // expression. RooGenericPdf uses a RooFormula object to perform the expression evaluation
00025 //
00026 // The string expression can be any valid TFormula expression referring to the
00027 // listed servers either by name or by their ordinal list position:
00028 //
00029 //   RooGenericPdf("gen","x*y",RooArgList(x,y))  or
00030 //   RooGenericPdf("gen","@0*@1",RooArgList(x,y)) 
00031 //
00032 // The latter form, while slightly less readable, is more versatile because it
00033 // doesn't hardcode any of the variable names it expects
00034 // END_HTML
00035 //
00036 
00037 #include "RooFit.h"
00038 #include "Riostream.h"
00039 
00040 #include "RooGenericPdf.h"
00041 #include "RooGenericPdf.h"
00042 #include "RooStreamParser.h"
00043 #include "RooMsgService.h"
00044 #include "RooArgList.h"
00045 
00046 
00047 
00048 ClassImp(RooGenericPdf)
00049 
00050 
00051 
00052 //_____________________________________________________________________________
00053 RooGenericPdf::RooGenericPdf(const char *name, const char *title, const RooArgList& dependents) : 
00054   RooAbsPdf(name,title), 
00055   _actualVars("actualVars","Variables used by PDF expression",this),
00056   _formula(0),
00057   _formExpr(title)
00058 {  
00059   // Constructor with formula expression and list of input variables
00060   _actualVars.add(dependents) ; 
00061 
00062   if (_actualVars.getSize()==0) _value = traceEval(0) ;
00063 }
00064 
00065 
00066 
00067 //_____________________________________________________________________________
00068 RooGenericPdf::RooGenericPdf(const char *name, const char *title, 
00069                              const char* inFormula, const RooArgList& dependents) : 
00070   RooAbsPdf(name,title), 
00071   _actualVars("actualVars","Variables used by PDF expression",this),
00072   _formula(0),
00073   _formExpr(inFormula)
00074 {  
00075   // Constructor with a name, title, formula expression and a list of variables
00076 
00077   _actualVars.add(dependents) ; 
00078 
00079   if (_actualVars.getSize()==0) _value = traceEval(0) ;
00080 }
00081 
00082 
00083 
00084 //_____________________________________________________________________________
00085 RooGenericPdf::RooGenericPdf(const RooGenericPdf& other, const char* name) : 
00086   RooAbsPdf(other, name), 
00087   _actualVars("actualVars",this,other._actualVars),
00088   _formula(0),
00089   _formExpr(other._formExpr)
00090 {
00091   // Copy constructor
00092 }
00093 
00094 
00095 
00096 //_____________________________________________________________________________
00097 RooGenericPdf::~RooGenericPdf() 
00098 {
00099   // Destructor
00100   if (_formula) delete _formula ;
00101 }
00102 
00103 
00104 
00105 //_____________________________________________________________________________
00106 RooFormula& RooGenericPdf::formula() const
00107 {
00108   if (!_formula) {
00109     _formula = new RooFormula(GetName(),_formExpr.Data(),_actualVars) ;
00110   } 
00111   return *_formula ;
00112 }
00113 
00114 
00115 
00116 //_____________________________________________________________________________
00117 Double_t RooGenericPdf::evaluate() const
00118 {
00119   // Calculate current value of this object
00120   
00121   return formula().eval(_normSet) ;
00122 }
00123 
00124 
00125 
00126 //_____________________________________________________________________________
00127 Bool_t RooGenericPdf::setFormula(const char* inFormula) 
00128 {
00129   // Change formula expression to given expression
00130 
00131   if (formula().reCompile(inFormula)) return kTRUE ;
00132 
00133   _formExpr = inFormula ;
00134   setValueDirty() ;
00135   return kFALSE ;
00136 }
00137 
00138 
00139 
00140 //_____________________________________________________________________________
00141 Bool_t RooGenericPdf::isValidReal(Double_t /*value*/, Bool_t /*printError*/) const 
00142 {
00143   // Check if given value is valid
00144   return kTRUE ;
00145 }
00146 
00147 
00148 
00149 //_____________________________________________________________________________
00150 Bool_t RooGenericPdf::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t /*isRecursive*/)
00151 {
00152   // Propagate server changes to embedded formula object
00153 
00154   if (_formula) {
00155      return _formula->changeDependents(newServerList,mustReplaceAll,nameChange) ;
00156   } else {
00157     return kTRUE ;
00158   }
00159 }
00160 
00161 
00162 
00163 //_____________________________________________________________________________
00164 void RooGenericPdf::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
00165 {
00166   // Print info about this object to the specified stream. 
00167 
00168   RooAbsPdf::printMultiline(os,content,verbose,indent);
00169   if (verbose) {
00170     os << " --- RooGenericPdf --- " << endl ;
00171     indent.Append("  ");
00172     os << indent ;
00173     formula().printMultiline(os,content,verbose,indent);
00174   }
00175 }
00176 
00177 
00178 
00179 //_____________________________________________________________________________
00180 void RooGenericPdf::printMetaArgs(ostream& os) const 
00181 {
00182   // Add formula expression as meta argument in printing interface
00183   os << "formula=\"" << _formExpr << "\" " ;
00184 }
00185 
00186 
00187 
00188 //_____________________________________________________________________________
00189 Bool_t RooGenericPdf::readFromStream(istream& is, Bool_t compact, Bool_t /*verbose*/)
00190 {
00191   // Read object contents from given stream
00192 
00193   if (compact) {
00194     coutE(InputArguments) << "RooGenericPdf::readFromStream(" << GetName() << "): can't read in compact mode" << endl ;
00195     return kTRUE ;
00196   } else {
00197     RooStreamParser parser(is) ;
00198     return setFormula(parser.readLine()) ;
00199   }
00200 }
00201 
00202 
00203 //_____________________________________________________________________________
00204 void RooGenericPdf::writeToStream(ostream& os, Bool_t compact) const
00205 {
00206   // Write object contents to given stream
00207 
00208   if (compact) {
00209     os << getVal() << endl ;
00210   } else {
00211     os << GetTitle() ;
00212   }
00213 }
00214 
00215 
00216 

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