ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id$
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// BEGIN_HTML
// RooGenericPdf is a concrete implementation of a probability density function,
// which takes a RooArgList of servers and a C++ expression string defining how
// its value should be calculated from the given list of servers.
// A fully numerical integration is automatically performed to normalize the given
// expression. RooGenericPdf uses a RooFormula object to perform the expression evaluation
//
// The string expression can be any valid TFormula expression referring to the
// listed servers either by name or by their ordinal list position:
//
//   RooGenericPdf("gen","x*y",RooArgList(x,y))  or
//   RooGenericPdf("gen","@0*@1",RooArgList(x,y)) 
//
// The latter form, while slightly less readable, is more versatile because it
// doesn't hardcode any of the variable names it expects
// END_HTML
//

#include "RooFit.h"
#include "Riostream.h"

#include "RooGenericPdf.h"
#include "RooGenericPdf.h"
#include "RooStreamParser.h"
#include "RooMsgService.h"
#include "RooArgList.h"



using namespace std;

ClassImp(RooGenericPdf)



//_____________________________________________________________________________
RooGenericPdf::RooGenericPdf(const char *name, const char *title, const RooArgList& dependents) : 
  RooAbsPdf(name,title), 
  _actualVars("actualVars","Variables used by PDF expression",this),
  _formula(0),
  _formExpr(title)
{  
  // Constructor with formula expression and list of input variables
  _actualVars.add(dependents) ; 

  if (_actualVars.getSize()==0) _value = traceEval(0) ;
}



//_____________________________________________________________________________
RooGenericPdf::RooGenericPdf(const char *name, const char *title, 
			     const char* inFormula, const RooArgList& dependents) : 
  RooAbsPdf(name,title), 
  _actualVars("actualVars","Variables used by PDF expression",this),
  _formula(0),
  _formExpr(inFormula)
{  
  // Constructor with a name, title, formula expression and a list of variables

  _actualVars.add(dependents) ; 

  if (_actualVars.getSize()==0) _value = traceEval(0) ;
}



//_____________________________________________________________________________
RooGenericPdf::RooGenericPdf(const RooGenericPdf& other, const char* name) : 
  RooAbsPdf(other, name), 
  _actualVars("actualVars",this,other._actualVars),
  _formula(0),
  _formExpr(other._formExpr)
{
  // Copy constructor
}



//_____________________________________________________________________________
RooGenericPdf::~RooGenericPdf() 
{
  // Destructor
  if (_formula) delete _formula ;
}



//_____________________________________________________________________________
RooFormula& RooGenericPdf::formula() const
{
  if (!_formula) {
    _formula = new RooFormula(GetName(),_formExpr.Data(),_actualVars) ;
  } 
  return *_formula ;
}



//_____________________________________________________________________________
Double_t RooGenericPdf::evaluate() const
{
  // Calculate current value of this object
  
  return formula().eval(_normSet) ;
}



//_____________________________________________________________________________
Bool_t RooGenericPdf::setFormula(const char* inFormula) 
{
  // Change formula expression to given expression

  if (formula().reCompile(inFormula)) return kTRUE ;

  _formExpr = inFormula ;
  setValueDirty() ;
  return kFALSE ;
}



//_____________________________________________________________________________
Bool_t RooGenericPdf::isValidReal(Double_t /*value*/, Bool_t /*printError*/) const 
{
  // Check if given value is valid
  return kTRUE ;
}



//_____________________________________________________________________________
Bool_t RooGenericPdf::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t /*isRecursive*/)
{
  // Propagate server changes to embedded formula object

  if (_formula) {
     return _formula->changeDependents(newServerList,mustReplaceAll,nameChange) ;
  } else {
    return kTRUE ;
  }
}



//_____________________________________________________________________________
void RooGenericPdf::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
{
  // Print info about this object to the specified stream. 

  RooAbsPdf::printMultiline(os,content,verbose,indent);
  if (verbose) {
    os << " --- RooGenericPdf --- " << endl ;
    indent.Append("  ");
    os << indent ;
    formula().printMultiline(os,content,verbose,indent);
  }
}



//_____________________________________________________________________________
void RooGenericPdf::printMetaArgs(ostream& os) const 
{
  // Add formula expression as meta argument in printing interface
  os << "formula=\"" << _formExpr << "\" " ;
}



//_____________________________________________________________________________
Bool_t RooGenericPdf::readFromStream(istream& is, Bool_t compact, Bool_t /*verbose*/)
{
  // Read object contents from given stream

  if (compact) {
    coutE(InputArguments) << "RooGenericPdf::readFromStream(" << GetName() << "): can't read in compact mode" << endl ;
    return kTRUE ;
  } else {
    RooStreamParser parser(is) ;
    return setFormula(parser.readLine()) ;
  }
}


//_____________________________________________________________________________
void RooGenericPdf::writeToStream(ostream& os, Bool_t compact) const
{
  // Write object contents to given stream

  if (compact) {
    os << getVal() << endl ;
  } else {
    os << GetTitle() ;
  }
}



 RooGenericPdf.cxx:1
 RooGenericPdf.cxx:2
 RooGenericPdf.cxx:3
 RooGenericPdf.cxx:4
 RooGenericPdf.cxx:5
 RooGenericPdf.cxx:6
 RooGenericPdf.cxx:7
 RooGenericPdf.cxx:8
 RooGenericPdf.cxx:9
 RooGenericPdf.cxx:10
 RooGenericPdf.cxx:11
 RooGenericPdf.cxx:12
 RooGenericPdf.cxx:13
 RooGenericPdf.cxx:14
 RooGenericPdf.cxx:15
 RooGenericPdf.cxx:16
 RooGenericPdf.cxx:17
 RooGenericPdf.cxx:18
 RooGenericPdf.cxx:19
 RooGenericPdf.cxx:20
 RooGenericPdf.cxx:21
 RooGenericPdf.cxx:22
 RooGenericPdf.cxx:23
 RooGenericPdf.cxx:24
 RooGenericPdf.cxx:25
 RooGenericPdf.cxx:26
 RooGenericPdf.cxx:27
 RooGenericPdf.cxx:28
 RooGenericPdf.cxx:29
 RooGenericPdf.cxx:30
 RooGenericPdf.cxx:31
 RooGenericPdf.cxx:32
 RooGenericPdf.cxx:33
 RooGenericPdf.cxx:34
 RooGenericPdf.cxx:35
 RooGenericPdf.cxx:36
 RooGenericPdf.cxx:37
 RooGenericPdf.cxx:38
 RooGenericPdf.cxx:39
 RooGenericPdf.cxx:40
 RooGenericPdf.cxx:41
 RooGenericPdf.cxx:42
 RooGenericPdf.cxx:43
 RooGenericPdf.cxx:44
 RooGenericPdf.cxx:45
 RooGenericPdf.cxx:46
 RooGenericPdf.cxx:47
 RooGenericPdf.cxx:48
 RooGenericPdf.cxx:49
 RooGenericPdf.cxx:50
 RooGenericPdf.cxx:51
 RooGenericPdf.cxx:52
 RooGenericPdf.cxx:53
 RooGenericPdf.cxx:54
 RooGenericPdf.cxx:55
 RooGenericPdf.cxx:56
 RooGenericPdf.cxx:57
 RooGenericPdf.cxx:58
 RooGenericPdf.cxx:59
 RooGenericPdf.cxx:60
 RooGenericPdf.cxx:61
 RooGenericPdf.cxx:62
 RooGenericPdf.cxx:63
 RooGenericPdf.cxx:64
 RooGenericPdf.cxx:65
 RooGenericPdf.cxx:66
 RooGenericPdf.cxx:67
 RooGenericPdf.cxx:68
 RooGenericPdf.cxx:69
 RooGenericPdf.cxx:70
 RooGenericPdf.cxx:71
 RooGenericPdf.cxx:72
 RooGenericPdf.cxx:73
 RooGenericPdf.cxx:74
 RooGenericPdf.cxx:75
 RooGenericPdf.cxx:76
 RooGenericPdf.cxx:77
 RooGenericPdf.cxx:78
 RooGenericPdf.cxx:79
 RooGenericPdf.cxx:80
 RooGenericPdf.cxx:81
 RooGenericPdf.cxx:82
 RooGenericPdf.cxx:83
 RooGenericPdf.cxx:84
 RooGenericPdf.cxx:85
 RooGenericPdf.cxx:86
 RooGenericPdf.cxx:87
 RooGenericPdf.cxx:88
 RooGenericPdf.cxx:89
 RooGenericPdf.cxx:90
 RooGenericPdf.cxx:91
 RooGenericPdf.cxx:92
 RooGenericPdf.cxx:93
 RooGenericPdf.cxx:94
 RooGenericPdf.cxx:95
 RooGenericPdf.cxx:96
 RooGenericPdf.cxx:97
 RooGenericPdf.cxx:98
 RooGenericPdf.cxx:99
 RooGenericPdf.cxx:100
 RooGenericPdf.cxx:101
 RooGenericPdf.cxx:102
 RooGenericPdf.cxx:103
 RooGenericPdf.cxx:104
 RooGenericPdf.cxx:105
 RooGenericPdf.cxx:106
 RooGenericPdf.cxx:107
 RooGenericPdf.cxx:108
 RooGenericPdf.cxx:109
 RooGenericPdf.cxx:110
 RooGenericPdf.cxx:111
 RooGenericPdf.cxx:112
 RooGenericPdf.cxx:113
 RooGenericPdf.cxx:114
 RooGenericPdf.cxx:115
 RooGenericPdf.cxx:116
 RooGenericPdf.cxx:117
 RooGenericPdf.cxx:118
 RooGenericPdf.cxx:119
 RooGenericPdf.cxx:120
 RooGenericPdf.cxx:121
 RooGenericPdf.cxx:122
 RooGenericPdf.cxx:123
 RooGenericPdf.cxx:124
 RooGenericPdf.cxx:125
 RooGenericPdf.cxx:126
 RooGenericPdf.cxx:127
 RooGenericPdf.cxx:128
 RooGenericPdf.cxx:129
 RooGenericPdf.cxx:130
 RooGenericPdf.cxx:131
 RooGenericPdf.cxx:132
 RooGenericPdf.cxx:133
 RooGenericPdf.cxx:134
 RooGenericPdf.cxx:135
 RooGenericPdf.cxx:136
 RooGenericPdf.cxx:137
 RooGenericPdf.cxx:138
 RooGenericPdf.cxx:139
 RooGenericPdf.cxx:140
 RooGenericPdf.cxx:141
 RooGenericPdf.cxx:142
 RooGenericPdf.cxx:143
 RooGenericPdf.cxx:144
 RooGenericPdf.cxx:145
 RooGenericPdf.cxx:146
 RooGenericPdf.cxx:147
 RooGenericPdf.cxx:148
 RooGenericPdf.cxx:149
 RooGenericPdf.cxx:150
 RooGenericPdf.cxx:151
 RooGenericPdf.cxx:152
 RooGenericPdf.cxx:153
 RooGenericPdf.cxx:154
 RooGenericPdf.cxx:155
 RooGenericPdf.cxx:156
 RooGenericPdf.cxx:157
 RooGenericPdf.cxx:158
 RooGenericPdf.cxx:159
 RooGenericPdf.cxx:160
 RooGenericPdf.cxx:161
 RooGenericPdf.cxx:162
 RooGenericPdf.cxx:163
 RooGenericPdf.cxx:164
 RooGenericPdf.cxx:165
 RooGenericPdf.cxx:166
 RooGenericPdf.cxx:167
 RooGenericPdf.cxx:168
 RooGenericPdf.cxx:169
 RooGenericPdf.cxx:170
 RooGenericPdf.cxx:171
 RooGenericPdf.cxx:172
 RooGenericPdf.cxx:173
 RooGenericPdf.cxx:174
 RooGenericPdf.cxx:175
 RooGenericPdf.cxx:176
 RooGenericPdf.cxx:177
 RooGenericPdf.cxx:178
 RooGenericPdf.cxx:179
 RooGenericPdf.cxx:180
 RooGenericPdf.cxx:181
 RooGenericPdf.cxx:182
 RooGenericPdf.cxx:183
 RooGenericPdf.cxx:184
 RooGenericPdf.cxx:185
 RooGenericPdf.cxx:186
 RooGenericPdf.cxx:187
 RooGenericPdf.cxx:188
 RooGenericPdf.cxx:189
 RooGenericPdf.cxx:190
 RooGenericPdf.cxx:191
 RooGenericPdf.cxx:192
 RooGenericPdf.cxx:193
 RooGenericPdf.cxx:194
 RooGenericPdf.cxx:195
 RooGenericPdf.cxx:196
 RooGenericPdf.cxx:197
 RooGenericPdf.cxx:198
 RooGenericPdf.cxx:199
 RooGenericPdf.cxx:200
 RooGenericPdf.cxx:201
 RooGenericPdf.cxx:202
 RooGenericPdf.cxx:203
 RooGenericPdf.cxx:204
 RooGenericPdf.cxx:205
 RooGenericPdf.cxx:206
 RooGenericPdf.cxx:207
 RooGenericPdf.cxx:208
 RooGenericPdf.cxx:209
 RooGenericPdf.cxx:210
 RooGenericPdf.cxx:211
 RooGenericPdf.cxx:212
 RooGenericPdf.cxx:213
 RooGenericPdf.cxx:214
 RooGenericPdf.cxx:215
 RooGenericPdf.cxx:216
 RooGenericPdf.cxx:217
 RooGenericPdf.cxx:218