Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooRealConstant.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 RooRealConstant.cxx
19\class RooRealConstant
20\ingroup Roofitcore
21
22Provides static functions to create and keep track
23of RooRealVar constants. Instead of creating such constants by
24hand (e.g. RooRealVar one("one","one",1)), simply use
25~~~{.cpp}
26 RooRealConstant::value(1.0)
27~~~
28whenever a reference to RooRealVar with constant value 1.0 is needed.
29RooRealConstant keeps an internal database of previously created
30RooRealVar objects and will recycle them as appropriate.
31**/
32
33#include <cmath>
34#include <sstream>
35#include "RooRealConstant.h"
36#include "RooConstVar.h"
37#include "RooArgList.h"
38
39using namespace std;
40
42
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Return a constant value object with given value.
47/// Return previously created object if available,
48/// otherwise create a new one on the fly.
49
51{
52 // Lookup existing constant
53 for (auto varArg : constDB()) {
54 auto var = static_cast<RooConstVar*>(varArg);
55 if ((var->getVal()==value) && (!var->getAttribute("REMOVAL_DUMMY"))) return *var ;
56 }
57
58 // Create new constant
59 std::ostringstream s ;
60 s << value ;
61
62 auto var = std::make_unique<RooConstVar>(s.str().c_str(),s.str().c_str(),value);
63 var->setAttribute("RooRealConstant_Factory_Object",true) ;
64 RooConstVar &varRef = *var;
65 constDB().addOwned(std::move(var));
66
67 return varRef;
68}
69
70
71////////////////////////////////////////////////////////////////////////////////
72/// Create a dummy node used in node-removal operations
73
75{
76 auto var = std::make_unique<RooConstVar>("REMOVAL_DUMMY","REMOVAL_DUMMY",1) ;
77 var->setAttribute("RooRealConstant_Factory_Object",true) ;
78 var->setAttribute("REMOVAL_DUMMY") ;
79 RooConstVar &varRef = *var;
80 constDB().addOwned(std::move(var));
81
82 return varRef;
83}
84
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// One-time initialization of constants database
89
91{
92 static RooArgList constDB("RooRealVar Constants Database");
93 return constDB;
94}
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
Represents a constant real-valued object.
Definition RooConstVar.h:23
Provides static functions to create and keep track of RooRealVar constants.
static RooConstVar & value(double value)
Return a constant value object with given value.
static RooArgList & constDB()
One-time initialization of constants database.
static RooConstVar & removalDummy()
Create a dummy node used in node-removal operations.