Logo ROOT  
Reference Guide
RooFormulaVar.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooFormulaVar.h,v 1.29 2007/08/09 19:55:47 wouter Exp $
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16#ifndef ROO_FORMULA_VAR
17#define ROO_FORMULA_VAR
18
19#include "RooAbsReal.h"
20#include "RooFormula.h"
21#include "RooArgList.h"
22#include "RooListProxy.h"
23#include "RooTrace.h"
24
25#include <memory>
26#include <list>
27
28class RooArgSet ;
29
30class RooFormulaVar : public RooAbsReal {
31public:
32 // Constructors, assignment etc
34 RooFormulaVar(const char *name, const char *title, const char* formula, const RooArgList& dependents, bool checkVariables = true);
35 RooFormulaVar(const char *name, const char *title, const RooArgList& dependents, bool checkVariables = true);
36 RooFormulaVar(const RooFormulaVar& other, const char* name=nullptr);
37 TObject* clone(const char* newname) const override { return new RooFormulaVar(*this,newname); }
38
39 inline bool ok() const { return getFormula().ok() ; }
40 const char* expression() const { return _formExpr.Data(); }
41 const RooArgList& dependents() const { return _actualVars; }
42
43 /// Return pointer to parameter with given name.
44 inline RooAbsArg* getParameter(const char* name) const {
45 return _actualVars.find(name) ;
46 }
47 /// Return pointer to parameter at given index.
49 return _actualVars.at(index) ;
50 }
51
52 // I/O streaming interface (machine readable)
53 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
54 void writeToStream(std::ostream& os, bool compact) const override ;
55
56 // Printing interface (human readable)
57 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent= "") const override ;
58 void printMetaArgs(std::ostream& os) const override ;
59
60 // Debugging
61 /// Dump the formula to stdout.
62 void dumpFormula() { getFormula().dump() ; }
63 /// Get reference to the internal formula object.
64 const RooFormula& formula() const {
65 return getFormula();
66 }
67
68 double defaultErrorLevel() const override ;
69
70 std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
71 std::list<double>* plotSamplingHint(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
72
73 // Function evaluation
74 double evaluate() const override ;
75 RooSpan<double> evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const override;
76 inline void computeBatch(cudaStream_t* stream, double* output, size_t nEvents, RooFit::Detail::DataMap const& dataMap) const override
77 {
78 formula().computeBatch(stream, output, nEvents, dataMap);
79 }
80
81
82 protected:
83 // Post-processing of server redirection
84 bool redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override ;
85
86 bool isValidReal(double /*value*/, bool /*printError*/) const override {return true;}
87
88 private:
89 RooFormula& getFormula() const;
90
91 RooListProxy _actualVars ; ///< Actual parameters used by formula engine
92 std::unique_ptr<RooFormula> _formula{nullptr}; ///<! Formula engine
93 mutable RooArgSet* _nset{nullptr}; ///<! Normalization set to be passed along to contents
94 TString _formExpr ; ///< Formula expression string
95
96 ClassDefOverride(RooFormulaVar,1) // Real-valued function of other RooAbsArgs calculated by a TFormula expression
97};
98
99#endif
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:71
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooAbsArg * getParameter(Int_t index) const
Return pointer to parameter at given index.
Definition: RooFormulaVar.h:48
RooAbsArg * getParameter(const char *name) const
Return pointer to parameter with given name.
Definition: RooFormulaVar.h:44
RooListProxy _actualVars
Actual parameters used by formula engine.
Definition: RooFormulaVar.h:91
const char * expression() const
Definition: RooFormulaVar.h:40
RooFormula & getFormula() const
Return reference to internal RooFormula object.
const RooFormula & formula() const
Get reference to the internal formula object.
Definition: RooFormulaVar.h:64
void dumpFormula()
Dump the formula to stdout.
Definition: RooFormulaVar.h:62
void computeBatch(cudaStream_t *stream, double *output, size_t nEvents, RooFit::Detail::DataMap const &dataMap) const override
Base function for computing multiple values of a RooAbsReal.
Definition: RooFormulaVar.h:76
double defaultErrorLevel() const override
Return the default error level for MINUIT error analysis If the formula contains one or more RooNLLVa...
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Propagate server change information to embedded RooFormula object.
bool ok() const
Definition: RooFormulaVar.h:39
const RooArgList & dependents() const
Definition: RooFormulaVar.h:41
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
RooSpan< double > evaluateSpan(RooBatchCompute::RunContext &evalData, const RooArgSet *normSet) const override
Evaluate the formula for all entries of our servers found in inputData.
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
TString _formExpr
Formula expression string.
Definition: RooFormulaVar.h:94
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
double evaluate() const override
Calculate current value of object from internal formula.
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
void printMetaArgs(std::ostream &os) const override
Add formula expression as meta argument in printing interface.
TObject * clone(const char *newname) const override
Definition: RooFormulaVar.h:37
std::unique_ptr< RooFormula > _formula
! Formula engine
Definition: RooFormulaVar.h:92
RooArgSet * _nset
! Normalization set to be passed along to contents
Definition: RooFormulaVar.h:93
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
bool isValidReal(double, bool) const override
Interface function to check if given value is a valid value for this object. Returns true unless over...
Definition: RooFormulaVar.h:86
RooFormula internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition: RooFormula.h:33
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const
Definition: RooFormula.cxx:500
bool ok() const
Definition: RooFormula.h:58
void dump() const
DEBUG: Dump state information.
Definition: RooFormula.cxx:384
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
Mother of all ROOT objects.
Definition: TObject.h:41
Basic string class.
Definition: TString.h:136
const char * Data() const
Definition: TString.h:369
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:32
static void output()