Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooRecursiveFraction.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 RooRecursiveFraction.cxx
19 \class RooRecursiveFraction
20 \ingroup Roofitcore
21 
22 Class RooRecursiveFraction is a RooAbsReal implementation that
23 calculates the plain fraction of sum of RooAddPdf components
24 from a set of recursive fractions: for a given set of input fractions
25 a_i it returns a_0 * Prod_i (1 - a_i).
26 **/
27 
28 
29 #include "RooFit.h"
30 
31 #include "Riostream.h"
32 #include "Riostream.h"
33 #include <math.h>
34 
35 #include "RooRecursiveFraction.h"
36 #include "RooAbsReal.h"
37 #include "RooAbsPdf.h"
38 #include "RooErrorHandler.h"
39 #include "RooArgSet.h"
40 #include "RooNLLVar.h"
41 #include "RooChi2Var.h"
42 #include "RooMsgService.h"
43 
44 using namespace std;
45 
46 ClassImp(RooRecursiveFraction);
47 ;
48 
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Default constructor
52 
53 RooRecursiveFraction::RooRecursiveFraction()
54 {
55  _listIter = _list.createIterator() ;
56 }
57 
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Constructor of plain RooAddPdf fraction from list of recursive fractions
62 
63 RooRecursiveFraction::RooRecursiveFraction(const char* name, const char* title, const RooArgList& fracList) :
64  RooAbsReal(name, title),
65  _list("list","First set of components",this)
66 {
67  _listIter = _list.createIterator() ;
68 
69  for (Int_t ifrac=fracList.getSize()-1 ; ifrac>=0 ; ifrac--) {
70  RooAbsArg* comp = fracList.at(ifrac) ;
71  if (!dynamic_cast<RooAbsReal*>(comp)) {
72  coutE(InputArguments) << "RooRecursiveFraction::ctor(" << GetName() << ") ERROR: component " << comp->GetName()
73  << " is not of type RooAbsReal" << endl ;
74  RooErrorHandler::softAbort() ;
75  }
76  _list.add(*comp) ;
77  }
78 }
79 
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Copy constructor
84 
85 RooRecursiveFraction::RooRecursiveFraction(const RooRecursiveFraction& other, const char* name) :
86  RooAbsReal(other, name),
87  _list("list",this,other._list)
88 {
89  _listIter = _list.createIterator() ;
90 }
91 
92 
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Destructor
96 
97 RooRecursiveFraction::~RooRecursiveFraction()
98 {
99  if (_listIter) delete _listIter ;
100 }
101 
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Calculate and return value of 1 - prod_i (1 - f_i )
106 
107 Double_t RooRecursiveFraction::evaluate() const
108 {
109  RooAbsReal* comp ;
110  const RooArgSet* nset = _list.nset() ;
111 
112  _listIter->Reset() ;
113  comp=(RooAbsReal*)_listIter->Next() ;
114  Double_t prod = comp->getVal(nset) ;
115 
116  while((comp=(RooAbsReal*)_listIter->Next())) {
117  prod *= (1-comp->getVal(nset)) ;
118  }
119 
120  return prod ;
121 }
122