Logo ROOT  
Reference Guide
RooFormula.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
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
17/**
18\file RooFormula.cxx
19\class RooFormula
20\ingroup Roofitcore
21
22RooFormula internally uses ROOT's TFormula to compute user-defined expressions
23of RooAbsArgs.
24
25The string expression can be any valid TFormula expression referring to the
26listed servers either by name or by their ordinal list position. These three are
27forms equivalent:
28```
29 RooFormula("formula", "x*y", RooArgList(x,y)) or
30 RooFormula("formula", "@0*@1", RooArgList(x,y))
31 RooFormula("formula", "x[0]*x[1]", RooArgList(x,y))
32```
33Note that `x[i]` is an expression reserved for TFormula. If a variable with
34the name `x` is given, the RooFormula interprets `x` as a variable name,
35but `x[i]` as an index in the list of variables.
36
37### Category expressions
38State information of RooAbsCategories can be accessed using the '::' operator,
39*i.e.*, `tagCat::Kaon` will resolve to the numerical value of
40the `Kaon` state of the RooAbsCategory object named `tagCat`.
41
42A formula to switch between lepton categories could look like this:
43```
44 RooFormula("formulaWithCat",
45 "x * (leptonMulti == leptonMulti::one) + y * (leptonMulti == leptonMulti::two)",
46 RooArgList(x, y, leptonMulti));
47```
48
49### Debugging a formula that won't compile
50When the formula is preprocessed, RooFit can print information in the debug stream.
51These can be retrieved by activating the RooFit::MsgLevel `RooFit::DEBUG`
52and the RooFit::MsgTopic `RooFit::InputArguments`.
53Check the tutorial rf506_msgservice.C for details.
54**/
55
56#include "RooFormula.h"
57
58#include "RooFit.h"
59#include "RooAbsReal.h"
60#include "RooAbsCategory.h"
61#include "RooArgList.h"
62#include "RooMsgService.h"
63#include "ROOT/RMakeUnique.hxx"
64#include "TObjString.h"
65#include "TClass.h"
66
67#include <sstream>
68#include <regex>
69
70using namespace std;
71
73
74namespace {
75
76////////////////////////////////////////////////////////////////////////////////
77/// Find all input arguments which are categories, and save this information in
78/// with the names of the variables that are being used to evaluate it.
79std::vector<bool> findCategoryServers(const RooAbsCollection& collection) {
80 std::vector<bool> output;
81 output.reserve(collection.size());
82
83 for (unsigned int i = 0; i < collection.size(); ++i) {
84 output.push_back(collection[i]->InheritsFrom(RooAbsCategory::Class()));
85 }
86
87 return output;
88}
89
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Default constructor
94/// coverity[UNINIT_CTOR]
95
97{
98}
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Construct a new formula.
103/// \param[in] name Name of the formula.
104/// \param[in] formula Formula to be evaluated. Parameters/observables are identified by name
105/// or ordinal position in `varList`.
106/// \param[in] varList List of variables to be passed to the formula.
107/// \param[in] checkVariables Check that the variables being passed in the `varList` are used in
108/// the formula expression.
109RooFormula::RooFormula(const char* name, const char* formula, const RooArgList& varList,
110 bool checkVariables) :
111 TNamed(name, formula), _tFormula{nullptr}
112{
113 _origList.add(varList);
114 _isCategory = findCategoryServers(_origList);
115
116 installFormulaOrThrow(formula);
117
118 RooArgList useList = usedVariables();
119 if (checkVariables && _origList.size() != useList.size()) {
120 coutI(InputArguments) << "The formula " << GetName() << " claims to use the variables " << _origList
121 << " but only " << useList << " seem to be in use."
122 << "\n inputs: " << formula << std::endl;
123 }
124}
125
126
127
128////////////////////////////////////////////////////////////////////////////////
129/// Copy constructor
130RooFormula::RooFormula(const RooFormula& other, const char* name) :
131 TNamed(name ? name : other.GetName(), other.GetTitle()), RooPrintable(other)
132{
133 _origList.add(other._origList);
134 _isCategory = findCategoryServers(_origList);
135
136 TFormula* newTF = nullptr;
137 if (other._tFormula) {
138 newTF = new TFormula(*other._tFormula);
139 newTF->SetName(GetName());
140 }
141
142 _tFormula.reset(newTF);
143}
144
145#ifndef _MSC_VER
146#if !defined(__GNUC__) || defined(__clang__) || (__GNUC__ > 4) || ( __GNUC__ == 4 && __GNUC_MINOR__ > 8)
147#define ROOFORMULA_HAVE_STD_REGEX
148////////////////////////////////////////////////////////////////////////////////
149/// Process given formula by replacing all ordinal and name references by
150/// `x[i]`, where `i` matches the position of the argument in `_origList`.
151/// Further, references to category states such as `leptonMulti:one` are replaced
152/// by the category index.
153std::string RooFormula::processFormula(std::string formula) const {
154
155 cxcoutD(InputArguments) << "Preprocessing formula step 1: find category tags (catName::catState) in "
156 << formula << endl;
157
158 // Step 1: Find all category tags and the corresponding index numbers
159 std::regex categoryReg("(\\w+)::(\\w+)");
160 std::map<std::string, int> categoryStates;
161 for (sregex_iterator matchIt = sregex_iterator(formula.begin(), formula.end(), categoryReg);
162 matchIt != sregex_iterator(); ++matchIt) {
163 assert(matchIt->size() == 3);
164 const std::string fullMatch = (*matchIt)[0];
165 const std::string catName = (*matchIt)[1];
166 const std::string catState = (*matchIt)[2];
167
168 const auto catVariable = dynamic_cast<const RooAbsCategory*>(_origList.find(catName.c_str()));
169 if (!catVariable) {
170 cxcoutD(InputArguments) << "Formula " << GetName() << " uses '::' to reference a category state as '" << fullMatch
171 << "' but a category '" << catName << "' cannot be found in the input variables." << endl;
172 continue;
173 }
174
175 if (!catVariable->hasLabel(catState)) {
176 coutE(InputArguments) << "Formula " << GetName() << " uses '::' to reference a category state as '" << fullMatch
177 << "' but the category '" << catName << "' does not seem to have the state '" << catState << "'." << endl;
178 throw std::invalid_argument(formula);
179 }
180 const int catNum = catVariable->lookupIndex(catState);
181
182 categoryStates[fullMatch] = catNum;
183 cxcoutD(InputArguments) << "\n\t" << fullMatch << "\tname=" << catName << "\tstate=" << catState << "=" << catNum;
184 }
185 cxcoutD(InputArguments) << "-- End of category tags --"<< endl;
186
187 // Step 2: Replace all category tags
188 for (const auto& catState : categoryStates) {
189 std::stringstream replacement;
190 replacement << catState.second;
191 formula = std::regex_replace(formula, std::regex(catState.first), replacement.str());
192 }
193
194 cxcoutD(InputArguments) << "Preprocessing formula step 2: replace category tags\n\t" << formula << endl;
195
196 // Step 3: Convert `@i`-style references to `x[i]`
197 std::regex ordinalRegex("@([0-9]+)");
198 formula = std::regex_replace(formula, ordinalRegex, "x[$1]");
199
200 cxcoutD(InputArguments) << "Preprocessing formula step 3: replace '@'-references\n\t" << formula << endl;
201
202 // Step 4: Replace all named references with "x[i]"-style
203 for (unsigned int i = 0; i < _origList.size(); ++i) {
204 const auto& var = _origList[i];
205 auto regex = std::string{"\\b"} + var.GetName();
206 regex = std::regex_replace(regex, std::regex("([\\[\\]\\{\\}])"), "\\$1"); // The name might contain [, ], {, or }.
207 regex += "\\b(?!\\[)"; // Veto '[' as next character. If the variable is called `x`, this might otherwise replace `x[0]`.
208 std::regex findParameterRegex(regex);
209
210 std::stringstream replacement;
211 replacement << "x[" << i << "]";
212 formula = std::regex_replace(formula, findParameterRegex, replacement.str());
213
214 cxcoutD(InputArguments) << "Preprocessing formula step 4: replace named references: "
215 << var.GetName() << " --> " << replacement.str()
216 << "\n\t" << formula << endl;
217 }
218
219 cxcoutD(InputArguments) << "Final formula:\n\t" << formula << endl;
220
221 return formula;
222}
223
224
225////////////////////////////////////////////////////////////////////////////////
226/// Analyse internal formula to find out which variables are actually in use.
228 RooArgList useList;
229 if (_tFormula == nullptr)
230 return useList;
231
232 const std::string formula(_tFormula->GetTitle());
233
234 std::set<unsigned int> matchedOrdinals;
235 std::regex newOrdinalRegex("\\bx\\[([0-9]+)\\]");
236 for (sregex_iterator matchIt = sregex_iterator(formula.begin(), formula.end(), newOrdinalRegex);
237 matchIt != sregex_iterator(); ++matchIt) {
238 assert(matchIt->size() == 2);
239 std::stringstream matchString((*matchIt)[1]);
240 unsigned int i;
241 matchString >> i;
242
243 matchedOrdinals.insert(i);
244 }
245
246 for (unsigned int i : matchedOrdinals) {
247 useList.add(_origList[i]);
248 }
249
250 return useList;
251}
252
253
254////////////////////////////////////////////////////////////////////////////////
255/// From the internal representation, construct a formula by replacing all index place holders
256/// with the names of the variables that are being used to evaluate it.
257std::string RooFormula::reconstructFormula(std::string internalRepr) const {
258 for (unsigned int i = 0; i < _origList.size(); ++i) {
259 const auto& var = _origList[i];
260 std::stringstream regexStr;
261 regexStr << "x\\[" << i << "\\]|@" << i;
262 std::regex regex(regexStr.str());
263
264 std::string replacement = std::string("[") + var.GetName() + "]";
265 internalRepr = std::regex_replace(internalRepr, regex, replacement);
266 }
267
268 return internalRepr;
269}
270#endif //GCC < 4.9 Check
271#endif //_MSC_VER
272
273
274
275
276////////////////////////////////////////////////////////////////////////////////
277/// Recompile formula with new expression. In case of error, the old formula is
278/// retained.
279Bool_t RooFormula::reCompile(const char* newFormula)
280{
281 try {
282 installFormulaOrThrow(newFormula);
283 } catch (std::runtime_error& e) {
284 coutE(InputArguments) << __func__ << ": new equation doesn't compile, formula unchanged."
285 << "\n" << e.what() << endl;
286 return true;
287 }
288
289 SetTitle(newFormula);
290 return false;
291}
292
294{
295 printMultiline(std::cout, 0);
296}
297
298
299////////////////////////////////////////////////////////////////////////////////
300/// Change used variables to those with the same name in given list.
301/// \param[in] newDeps New dependents to replace the old ones.
302/// \param[in] mustReplaceAll Will yield an error if one dependent does not have a replacement.
303/// \param[in] nameChange Passed down to RooAbsArg::findNewServer(const RooAbsCollection&, Bool_t) const.
304Bool_t RooFormula::changeDependents(const RooAbsCollection& newDeps, Bool_t mustReplaceAll, Bool_t nameChange)
305{
306 //Change current servers to new servers with the same name given in list
307 bool errorStat = false;
308
309 for (const auto arg : _origList) {
310 RooAbsReal* replace = (RooAbsReal*) arg->findNewServer(newDeps,nameChange) ;
311 if (replace) {
312 _origList.replace(*arg, *replace);
313
314 if (arg->getStringAttribute("origName")) {
315 replace->setStringAttribute("origName",arg->getStringAttribute("origName")) ;
316 } else {
317 replace->setStringAttribute("origName",arg->GetName()) ;
318 }
319
320 } else if (mustReplaceAll) {
321 coutE(LinkStateMgmt) << __func__ << ": cannot find replacement for " << arg->GetName() << endl;
322 errorStat = true;
323 }
324 }
325
326 _isCategory = findCategoryServers(_origList);
327
328 return errorStat;
329}
330
331
332
333////////////////////////////////////////////////////////////////////////////////
334/// Evaluate the internal TFormula.
335///
336/// First, all variables serving this instance are evaluated given the normalisation set,
337/// and then the formula is evaluated.
338/// \param[in] nset Normalisation set passed to evaluation of arguments serving values.
339/// \return The result of the evaluation.
341{
342 if (!_tFormula) {
343 coutF(Eval) << __func__ << " (" << GetName() << "): Formula didn't compile: " << GetTitle() << endl;
344 std::string what = "Formula ";
345 what += GetTitle();
346 what += " didn't compile.";
347 throw std::runtime_error(what);
348 }
349
350 std::vector<double> pars;
351 pars.reserve(_origList.size());
352 for (unsigned int i = 0; i < _origList.size(); ++i) {
353 if (_isCategory[i]) {
354 const auto& cat = static_cast<RooAbsCategory&>(_origList[i]);
355 pars.push_back(cat.getCurrentIndex());
356 } else {
357 const auto& real = static_cast<RooAbsReal&>(_origList[i]);
358 pars.push_back(real.getVal(nset));
359 }
360 }
361
362 return _tFormula->EvalPar(pars.data());
363}
364
365
366////////////////////////////////////////////////////////////////////////////////
367/// Printing interface
368
369void RooFormula::printMultiline(ostream& os, Int_t /*contents*/, Bool_t /*verbose*/, TString indent) const
370{
371 os << indent << "--- RooFormula ---" << endl;
372 os << indent << " Formula: '" << GetTitle() << "'" << endl;
373 os << indent << " Interpretation: '" << reconstructFormula(GetTitle()) << "'" << endl;
374 indent.Append(" ");
375 os << indent << "Servers: " << _origList << "\n";
376 os << indent << "In use : " << actualDependents() << endl;
377}
378
379
380////////////////////////////////////////////////////////////////////////////////
381/// Print value of formula
382
383void RooFormula::printValue(ostream& os) const
384{
385 os << const_cast<RooFormula*>(this)->eval(0) ;
386}
387
388
389////////////////////////////////////////////////////////////////////////////////
390/// Print name of formula
391
392void RooFormula::printName(ostream& os) const
393{
394 os << GetName() ;
395}
396
397
398////////////////////////////////////////////////////////////////////////////////
399/// Print title of formula
400
401void RooFormula::printTitle(ostream& os) const
402{
403 os << GetTitle() ;
404}
405
406
407////////////////////////////////////////////////////////////////////////////////
408/// Print class name of formula
409
410void RooFormula::printClassName(ostream& os) const
411{
412 os << IsA()->GetName() ;
413}
414
415
416////////////////////////////////////////////////////////////////////////////////
417/// Print arguments of formula, i.e. dependents that are actually used
418
419void RooFormula::printArgs(ostream& os) const
420{
421 os << "[ actualVars=";
422 for (const auto arg : usedVariables()) {
423 os << " " << arg->GetName();
424 }
425 os << " ]";
426}
427
428
429////////////////////////////////////////////////////////////////////////////////
430/// Check that the formula compiles, and also fulfills the assumptions.
431///
432void RooFormula::installFormulaOrThrow(const std::string& formula) {
433 const std::string processedFormula = processFormula(formula);
434
435 cxcoutD(InputArguments) << "RooFormula '" << GetName() << "' will be compiled as "
436 << "\n\t" << processedFormula
437 << "\n and used as"
438 << "\n\t" << reconstructFormula(processedFormula)
439 << "\n with the parameters " << _origList << endl;
440
441 auto theFormula = std::make_unique<TFormula>(GetName(), processedFormula.c_str(), false);
442
443 if (!theFormula || !theFormula->IsValid()) {
444 std::stringstream msg;
445 msg << "RooFormula '" << GetName() << "' did not compile or is invalid."
446 << "\nInput:\n\t" << formula
447 << "\nPassed over to TFormula:\n\t" << processedFormula << std::endl;
448 coutF(InputArguments) << msg.str();
449 throw std::runtime_error(msg.str());
450 }
451
452 if (theFormula && theFormula->GetNdim() != 1) {
453 // TFormula thinks that we have a multi-dimensional formula, e.g. with variables x,y,z,t.
454 // We have to check now that this is not the case, as RooFit only uses the syntax x[0], x[1], x[2], ...
455 bool haveProblem = false;
456 std::stringstream msg;
457 msg << "TFormula interprets the formula " << formula << " as " << theFormula->GetNdim() << "-dimensional with the variable(s) {";
458 for (int i=1; i < theFormula->GetNdim(); ++i) {
459 const TString varName = theFormula->GetVarName(i);
460 if (varName.BeginsWith("x[") && varName[varName.Length()-1] == ']')
461 continue;
462
463 haveProblem = true;
464 msg << theFormula->GetVarName(i) << ",";
465 }
466 if (haveProblem) {
467 msg << "}, which could not be supplied by RooFit."
468 << "\nThe formula must be modified, or those variables must be supplied in the list of variables." << std::endl;
469 coutF(InputArguments) << msg.str();
470 throw std::invalid_argument(msg.str());
471 }
472 }
473
474 _tFormula = std::move(theFormula);
475}
476
477
478#ifndef ROOFORMULA_HAVE_STD_REGEX
479/*
480 * g++ 4.8 doesn't support the std::regex. It has headers, but no implementations of the standard, leading to linker
481 * errors. As long as centos 7 needs to be supported, this forces us to have a legacy implementation.
482 */
483
484#include "TPRegexp.h"
485
486////////////////////////////////////////////////////////////////////////////////
487/// Process given formula by replacing all ordinal and name references by
488/// `x[i]`, where `i` matches the position of the argument in `_origList`.
489/// Further, references to category states such as `leptonMulti:one` are replaced
490/// by the category index.
491std::string RooFormula::processFormula(std::string formula) const {
492 TString formulaTString = formula.c_str();
493
494 cxcoutD(InputArguments) << "Preprocessing formula step 1: find category tags (catName::catState) in "
495 << formulaTString.Data() << endl;
496
497 // Step 1: Find all category tags and the corresponding index numbers
498 TPRegexp categoryReg("(\\w+)::(\\w+)");
499 std::map<std::string, int> categoryStates;
500 int offset = 0;
501 do {
502 std::unique_ptr<TObjArray> matches(categoryReg.MatchS(formulaTString, "", offset, 3));
503 if (matches->GetEntries() == 0)
504 break;
505
506 std::string fullMatch = static_cast<TObjString*>(matches->At(0))->GetString().Data();
507 std::string catName = static_cast<TObjString*>(matches->At(1))->GetString().Data();
508 std::string catState = static_cast<TObjString*>(matches->At(2))->GetString().Data();
509 offset = formulaTString.Index(categoryReg, offset) + fullMatch.size();
510
511 const auto catVariable = dynamic_cast<const RooAbsCategory*>(_origList.find(catName.c_str()));
512 if (!catVariable) {
513 cxcoutD(InputArguments) << "Formula " << GetName() << " uses '::' to reference a category state as '" << fullMatch
514 << "' but a category '" << catName << "' cannot be found in the input variables." << endl;
515 continue;
516 }
517
518 const RooCatType* catType = catVariable->lookupType(catState.c_str(), false);
519 if (!catType) {
520 coutE(InputArguments) << "Formula " << GetName() << " uses '::' to reference a category state as '" << fullMatch
521 << "' but the category '" << catName << "' does not seem to have the state '" << catState << "'." << endl;
522 throw std::invalid_argument(formula);
523 }
524 const int catNum = catType->getVal();
525
526 categoryStates[fullMatch] = catNum;
527 cxcoutD(InputArguments) << "\n\t" << fullMatch << "\tname=" << catName << "\tstate=" << catState << "=" << catNum;
528 } while (offset != -1);
529 cxcoutD(InputArguments) << "-- End of category tags --"<< endl;
530
531 // Step 2: Replace all category tags
532 for (const auto& catState : categoryStates) {
533 std::stringstream replacement;
534 replacement << catState.second;
535 formulaTString.ReplaceAll(catState.first.c_str(), replacement.str().c_str());
536 }
537
538 cxcoutD(InputArguments) << "Preprocessing formula step 2: replace category tags\n\t" << formulaTString.Data() << endl;
539
540 // Step 3: Convert `@i`-style references to `x[i]`
541 TPRegexp ordinalRegex("@([0-9]+)");
542 int nsub = 0;
543 do {
544 nsub = ordinalRegex.Substitute(formulaTString, "x[$1]");
545 } while (nsub > 0);
546
547 cxcoutD(InputArguments) << "Preprocessing formula step 3: replace '@'-references\n\t" << formulaTString.Data() << endl;
548
549 // Step 4: Replace all named references with "x[i]"-style
550 for (unsigned int i = 0; i < _origList.size(); ++i) {
551 const auto& var = _origList[i];
552 TString regex = "\\b";
553 regex += var.GetName();
554 regex += "\\b([^[]|$)"; //Negative lookahead. If the variable is called `x`, this might otherwise replace `x[0]`.
555 TPRegexp findParameterRegex(regex);
556
557 std::stringstream replacement;
558 replacement << "x[" << i << "]$1";
559 int nsub2 = 0;
560 do {
561 nsub2 = findParameterRegex.Substitute(formulaTString, replacement.str().c_str());
562 } while (nsub2 > 0);
563
564 cxcoutD(InputArguments) << "Preprocessing formula step 4: replace named references: "
565 << var.GetName() << " --> " << replacement.str()
566 << "\n\t" << formulaTString.Data() << endl;
567 }
568
569 cxcoutD(InputArguments) << "Final formula:\n\t" << formulaTString << endl;
570
571 return formulaTString.Data();
572}
573
574
575////////////////////////////////////////////////////////////////////////////////
576/// Analyse internal formula to find out which variables are actually in use.
578 RooArgList useList;
579 if (_tFormula == nullptr)
580 return useList;
581
582 const TString formulaTString = _tFormula->GetTitle();
583
584 std::set<unsigned int> matchedOrdinals;
585 TPRegexp newOrdinalRegex("\\bx\\[([0-9]+)\\]");
586 int offset = 0;
587 do {
588 std::unique_ptr<TObjArray> matches(newOrdinalRegex.MatchS(formulaTString, "", offset, 2));
589 if (matches->GetEntries() == 0)
590 break;
591
592 std::string fullMatch = static_cast<TObjString*>(matches->At(0))->GetString().Data();
593 std::string ordinal = static_cast<TObjString*>(matches->At(1))->GetString().Data();
594 offset = formulaTString.Index(newOrdinalRegex, offset) + fullMatch.size();
595
596 std::stringstream matchString(ordinal.c_str());
597 unsigned int i;
598 matchString >> i;
599
600 matchedOrdinals.insert(i);
601 } while (offset != -1);
602
603 for (unsigned int i : matchedOrdinals) {
604 useList.add(_origList[i]);
605 }
606
607 return useList;
608}
609
610
611////////////////////////////////////////////////////////////////////////////////
612/// From the internal representation, construct a formula by replacing all index place holders
613/// with the names of the variables that are being used to evaluate it.
614std::string RooFormula::reconstructFormula(std::string internalRepr) const {
615 TString internalReprT = internalRepr.c_str();
616
617 for (unsigned int i = 0; i < _origList.size(); ++i) {
618 const auto& var = _origList[i];
619 std::stringstream regexStr;
620 regexStr << "x\\[" << i << "\\]|@" << i;
621 TPRegexp regex(regexStr.str().c_str());
622
623 std::string replacement = std::string("[") + var.GetName() + "]";
624 regex.Substitute(internalReprT, replacement.c_str());
625 }
626
627 return internalReprT.Data();
628}
629#endif //GCC < 4.9 Check
int Int_t
Definition: CPyCppyy.h:43
void Class()
Definition: Class.C:29
#define e(i)
Definition: RSha256.hxx:103
#define coutI(a)
Definition: RooMsgService.h:30
#define cxcoutD(a)
Definition: RooMsgService.h:81
#define coutF(a)
Definition: RooMsgService.h:34
#define coutE(a)
Definition: RooMsgService.h:33
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
#define ClassImp(name)
Definition: Rtypes.h:361
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:109
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
Definition: RooAbsArg.cxx:289
RooAbsArg * findNewServer(const RooAbsCollection &newSet, Bool_t nameChange) const
Find the new server in the specified set that matches the old server.
Definition: RooAbsArg.cxx:1027
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return kTRUE for success.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Storage_t::size_type size() const
const char * GetName() const
Returns name of object.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Int_t getVal() const
RooFormula internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition: RooFormula.h:28
Bool_t reCompile(const char *newFormula)
Recompile formula with new expression.
Definition: RooFormula.cxx:279
virtual void printName(std::ostream &os) const
Print name of formula.
Definition: RooFormula.cxx:392
virtual void printTitle(std::ostream &os) const
Print title of formula.
Definition: RooFormula.cxx:401
virtual void printClassName(std::ostream &os) const
Print class name of formula.
Definition: RooFormula.cxx:410
RooArgSet actualDependents() const
Return list of arguments which are used in the formula.
Definition: RooFormula.h:38
RooArgList usedVariables() const
Analyse internal formula to find out which variables are actually in use.
Definition: RooFormula.cxx:227
virtual void printValue(std::ostream &os) const
Print value of formula.
Definition: RooFormula.cxx:383
RooFormula()
Default constructor coverity[UNINIT_CTOR].
Definition: RooFormula.cxx:96
Double_t eval(const RooArgSet *nset=0) const
Evalute all parameters/observables, and then evaluate formula.
Definition: RooFormula.cxx:340
void installFormulaOrThrow(const std::string &formulaa)
Check that the formula compiles, and also fulfills the assumptions.
Definition: RooFormula.cxx:432
void dump() const
DEBUG: Dump state information.
Definition: RooFormula.cxx:293
std::vector< bool > _isCategory
Original list of dependents.
Definition: RooFormula.h:86
std::string processFormula(std::string origFormula) const
Process given formula by replacing all ordinal and name references by x[i], where i matches the posit...
Definition: RooFormula.cxx:153
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Printing interface.
Definition: RooFormula.cxx:369
virtual void printArgs(std::ostream &os) const
Print arguments of formula, i.e. dependents that are actually used.
Definition: RooFormula.cxx:419
std::string reconstructFormula(std::string internalRepr) const
From the internal representation, construct a formula by replacing all index place holders with the n...
Definition: RooFormula.cxx:257
RooArgList _origList
Definition: RooFormula.h:85
Bool_t changeDependents(const RooAbsCollection &newDeps, Bool_t mustReplaceAll, Bool_t nameChange)
Change used variables to those with the same name in given list.
Definition: RooFormula.cxx:304
std::unique_ptr< TFormula > _tFormula
Whether an element of the _origList is a category.
Definition: RooFormula.h:87
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
The Formula class.
Definition: TFormula.h:84
void SetName(const char *name)
Set the name of the TNamed.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Collectable string class.
Definition: TObjString.h:28
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:610
const char * Data() const
Definition: TString.h:364
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:634
@ InputArguments
Definition: RooGlobalFunc.h:68
@ LinkStateMgmt
Definition: RooGlobalFunc.h:67
static const char * what
Definition: stlLoader.cc:6
static void output(int code)
Definition: gifencode.c:226