Logo ROOT   6.14/05
Reference Guide
RooFirstMoment.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 RooFirstMoment.cxx
19 \class RooFirstMoment
20 \ingroup Roofitcore
21 
22 RooFirstMoment represents the first, second, or third order derivative
23 of any RooAbsReal as calculated (numerically) by the MathCore Richardson
24 derivator class.
25 **/
26 
27 
28 #include "RooFit.h"
29 
30 #include "Riostream.h"
31 #include "Riostream.h"
32 #include <math.h>
33 
34 #include "RooFirstMoment.h"
35 #include "RooAbsReal.h"
36 #include "RooAbsPdf.h"
37 #include "RooErrorHandler.h"
38 #include "RooArgSet.h"
39 #include "RooMsgService.h"
40 #include "RooRealVar.h"
41 #include "RooFunctor.h"
42 #include "RooGlobalFunc.h"
43 #include "RooConstVar.h"
44 #include "RooRealIntegral.h"
45 #include "RooNumIntConfig.h"
46 #include "RooProduct.h"
47 #include <string>
48 using namespace std ;
49 
50 
52 ;
53 
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Default constructor
57 
59 {
60 }
61 
62 
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 
66 RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x) :
67  RooAbsMoment(name, title,func,x,1,kFALSE),
68  _xf("!xf","xf",this,kFALSE,kFALSE),
69  _ixf("!ixf","ixf",this),
70  _if("!if","if",this)
71 {
73 
74  string pname=Form("%s_product",name) ;
75 
76  RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
78 
79  if (func.isBinnedDistribution(x)) {
80  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
81  }
82 
85  intXF->setCacheNumeric(kTRUE) ;
86  intF->setCacheNumeric(kTRUE) ;
87 
88  _xf.setArg(*XF) ;
89  _ixf.setArg(*intXF) ;
90  _if.setArg(*intF) ;
91  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 
96 RooFirstMoment::RooFirstMoment(const char* name, const char* title, RooAbsReal& func, RooRealVar& x, const RooArgSet& nset, Bool_t intNSet) :
97  RooAbsMoment(name, title,func,x,1,kFALSE),
98  _xf("!xf","xf",this,kFALSE,kFALSE),
99  _ixf("!ixf","ixf",this),
100  _if("!if","if",this)
101 {
103 
104  _nset.add(nset) ;
105 
106  string pname=Form("%s_product",name) ;
107 
108  RooProduct* XF = new RooProduct(pname.c_str(),pname.c_str(),RooArgSet(x,func)) ;
110 
111  if (func.isBinnedDistribution(x)) {
112  XF->specialIntegratorConfig(kTRUE)->method1D().setLabel("RooBinIntegrator");
113  }
114 
115  if (intNSet && _nset.getSize()>0 && func.isBinnedDistribution(_nset)) {
116  XF->specialIntegratorConfig(kTRUE)->method2D().setLabel("RooBinIntegrator");
117  XF->specialIntegratorConfig(kTRUE)->methodND().setLabel("RooBinIntegrator");
118  }
119 
120  RooArgSet intSet(x) ;
121  if (intNSet) intSet.add(_nset,kTRUE) ;
122  RooRealIntegral* intXF = (RooRealIntegral*) XF->createIntegral(intSet,&_nset) ;
123  RooRealIntegral* intF = (RooRealIntegral*) func.createIntegral(intSet,&_nset) ;
124  intXF->setCacheNumeric(kTRUE) ;
125  intF->setCacheNumeric(kTRUE) ;
126 
127  _xf.setArg(*XF) ;
128  _ixf.setArg(*intXF) ;
129  _if.setArg(*intF) ;
130  addOwnedComponents(RooArgSet(*XF,*intXF,*intF)) ;
131 }
132 
133 
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 
138  RooAbsMoment(other, name),
139  _xf("xf",this,other._xf),
140  _ixf("ixf",this,other._ixf),
141  _if("if",this,other._if)
142 {
143 }
144 
145 
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Destructor
149 
151 {
152 }
153 
154 
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Calculate value
158 
160 {
161  Double_t ratio = _ixf / _if ;
162  //cout << "\nRooFirstMoment::eval(" << GetName() << ") val = " << ratio << endl ;
163  return ratio ;
164 }
165 
166 
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:86
RooCategory & methodND()
RooFirstMoment represents the first, second, or third order derivative of any RooAbsReal as calculate...
RooCategory & method2D()
bool Bool_t
Definition: RtypesCore.h:59
RooRealProxy _ixf
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of &#39;comps&#39;.
Definition: RooAbsArg.cxx:2273
STL namespace.
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Definition: RooAbsMoment.h:27
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
RooCategory & method1D()
Double_t x[n]
Definition: legend1.C:17
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects The class perfor...
friend class RooArgSet
Definition: RooAbsArg.h:471
RooRealProxy _xf
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
Int_t getSize() const
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:501
RooFirstMoment()
Default constructor.
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2333
virtual ~RooFirstMoment()
Destructor.
char * Form(const char *fmt,...)
virtual Bool_t setArg(RooAbsReal &newRef)
Change object held in proxy into newRef.
RooProduct a RooAbsReal implementation that represent the product of a given set of other RooAbsReal ...
Definition: RooProduct.h:32
const Bool_t kFALSE
Definition: RtypesCore.h:88
RooSetProxy _nset
Definition: RooAbsMoment.h:44
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:499
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Definition: RooAbsReal.h:277
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
RooRealProxy _if
Double_t evaluate() const
Calculate value.
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109
void setCacheNumeric(Bool_t flag)
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts &#39;var&#39; into set and registers &#39;var&#39; as server to owner with...