/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id$
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// Class RooRealSumPdf implements a PDF constructed from a sum of
// functions:
//
//                 Sum(i=1,n-1) coef_i * func_i(x) + [ 1 - (Sum(i=1,n-1) coef_i ] * func_n(x)
//   pdf(x) =    ------------------------------------------------------------------------------
//             Sum(i=1,n-1) coef_i * Int(func_i)dx + [ 1 - (Sum(i=1,n-1) coef_i ] * Int(func_n)dx
//
//
// where coef_i and func_i are RooAbsReal objects, and x is the collection of dependents. 
// In the present version coef_i may not depend on x, but this limitation may be removed in the future
//

#include "RooFit.h"
#include "Riostream.h"

#include "TIterator.h"
#include "TList.h"
#include "RooRealSumPdf.h"
#include "RooRealProxy.h"
#include "RooPlot.h"
#include "RooRealVar.h"
#include "RooAddGenContext.h"
#include "RooRealConstant.h"
#include "RooRealIntegral.h"
#include "RooMsgService.h"
#include "RooNameReg.h"
#include <memory>
#include <algorithm>

#include "TError.h"

using namespace std;

ClassImp(RooRealSumPdf)
;

Bool_t RooRealSumPdf::_doFloorGlobal = kFALSE ; 

//_____________________________________________________________________________
RooRealSumPdf::RooRealSumPdf() 
{
  // Default constructor
  // coverity[UNINIT_CTOR]
  _funcIter  = _funcList.createIterator() ;
  _coefIter  = _coefList.createIterator() ;
  _extended = kFALSE ;
  _doFloor = kFALSE ;
}



//_____________________________________________________________________________
RooRealSumPdf::RooRealSumPdf(const char *name, const char *title) :
  RooAbsPdf(name,title), 
  _normIntMgr(this,10),
  _haveLastCoef(kFALSE),
  _funcList("!funcList","List of functions",this),
  _coefList("!coefList","List of coefficients",this),
  _extended(kFALSE),
  _doFloor(kFALSE)
{
  // Constructor with name and title
  _funcIter   = _funcList.createIterator() ;
  _coefIter  = _coefList.createIterator() ;
}



//_____________________________________________________________________________
RooRealSumPdf::RooRealSumPdf(const char *name, const char *title,
		     RooAbsReal& func1, RooAbsReal& func2, RooAbsReal& coef1) : 
  RooAbsPdf(name,title),
  _normIntMgr(this,10),
  _haveLastCoef(kFALSE),
  _funcList("!funcList","List of functions",this),
  _coefList("!coefList","List of coefficients",this),
  _extended(kFALSE),
  _doFloor(kFALSE)
{
  // Construct p.d.f consisting of coef1*func1 + (1-coef1)*func2
  // The input coefficients and functions are allowed to be negative
  // but the resulting sum is not, which is enforced at runtime

  // Special constructor with two functions and one coefficient
  _funcIter  = _funcList.createIterator() ;
  _coefIter = _coefList.createIterator() ;

  _funcList.add(func1) ;  
  _funcList.add(func2) ;
  _coefList.add(coef1) ;

}


//_____________________________________________________________________________
RooRealSumPdf::RooRealSumPdf(const char *name, const char *title, const RooArgList& inFuncList, const RooArgList& inCoefList, Bool_t extended) :
  RooAbsPdf(name,title),
  _normIntMgr(this,10),
  _haveLastCoef(kFALSE),
  _funcList("!funcList","List of functions",this),
  _coefList("!coefList","List of coefficients",this),
  _extended(extended),
  _doFloor(kFALSE)
{ 
  // Constructor p.d.f implementing sum_i [ coef_i * func_i ], if N_coef==N_func
  // or sum_i [ coef_i * func_i ] + (1 - sum_i [ coef_i ] )* func_N if Ncoef==N_func-1
  // 
  // All coefficients and functions are allowed to be negative
  // but the sum is not, which is enforced at runtime.

  if (!(inFuncList.getSize()==inCoefList.getSize()+1 || inFuncList.getSize()==inCoefList.getSize())) {
    coutE(InputArguments) << "RooRealSumPdf::RooRealSumPdf(" << GetName() 
			  << ") number of pdfs and coefficients inconsistent, must have Nfunc=Ncoef or Nfunc=Ncoef+1" << endl ;
    assert(0) ;
  }

  _funcIter  = _funcList.createIterator() ;
  _coefIter = _coefList.createIterator() ;
 
  // Constructor with N functions and N or N-1 coefs
  TIterator* funcIter = inFuncList.createIterator() ;
  TIterator* coefIter = inCoefList.createIterator() ;
  RooAbsArg* func ;
  RooAbsArg* coef ;

  while((coef = (RooAbsArg*)coefIter->Next())) {
    func = (RooAbsArg*) funcIter->Next() ;

    if (!dynamic_cast<RooAbsReal*>(coef)) {
      coutW(InputArguments) << "RooRealSumPdf::RooRealSumPdf(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal, ignored" << endl ;
      continue ;
    }
    if (!dynamic_cast<RooAbsReal*>(func)) {
      coutW(InputArguments) << "RooRealSumPdf::RooRealSumPdf(" << GetName() << ") func " << func->GetName() << " is not of type RooAbsReal, ignored" << endl ;
      continue ;
    }
    _funcList.add(*func) ;
    _coefList.add(*coef) ;    
  }

  func = (RooAbsReal*) funcIter->Next() ;
  if (func) {
    if (!dynamic_cast<RooAbsReal*>(func)) {
      coutE(InputArguments) << "RooRealSumPdf::RooRealSumPdf(" << GetName() << ") last func " << coef->GetName() << " is not of type RooAbsReal, fatal error" << endl ;
      assert(0) ;
    }
    _funcList.add(*func) ;  
  } else {
    _haveLastCoef = kTRUE ;
  }
  
  delete funcIter ;
  delete coefIter  ;
}




//_____________________________________________________________________________
RooRealSumPdf::RooRealSumPdf(const RooRealSumPdf& other, const char* name) :
  RooAbsPdf(other,name),
  _normIntMgr(other._normIntMgr,this),
  _haveLastCoef(other._haveLastCoef),
  _funcList("!funcList",this,other._funcList),
  _coefList("!coefList",this,other._coefList),
  _extended(other._extended),
  _doFloor(other._doFloor)
{
  // Copy constructor

  _funcIter  = _funcList.createIterator() ;
  _coefIter = _coefList.createIterator() ;
}



//_____________________________________________________________________________
RooRealSumPdf::~RooRealSumPdf()
{
  // Destructor
  delete _funcIter ;
  delete _coefIter ;
}





//_____________________________________________________________________________
RooAbsPdf::ExtendMode RooRealSumPdf::extendMode() const 
{
  return (_extended && (_funcList.getSize()==_coefList.getSize())) ? CanBeExtended : CanNotBeExtended ;
}




//_____________________________________________________________________________
Double_t RooRealSumPdf::evaluate() const 
{
  // Calculate the current value

  Double_t value(0) ;

  // Do running sum of coef/func pairs, calculate lastCoef.
  RooFIter funcIter = _funcList.fwdIterator() ;
  RooFIter coefIter = _coefList.fwdIterator() ;
  RooAbsReal* coef ;
  RooAbsReal* func ;
      
  // N funcs, N-1 coefficients 
  Double_t lastCoef(1) ;
  while((coef=(RooAbsReal*)coefIter.next())) {
    func = (RooAbsReal*)funcIter.next() ;
    Double_t coefVal = coef->getVal() ;
    if (coefVal) {
      cxcoutD(Eval) << "RooRealSumPdf::eval(" << GetName() << ") coefVal = " << coefVal << " funcVal = " << func->IsA()->GetName() << "::" << func->GetName() << " = " << func->getVal() << endl ;
      if (func->isSelectedComp()) {
	value += func->getVal()*coefVal ;
      }
      lastCoef -= coef->getVal() ;
    }
  }
  
  if (!_haveLastCoef) {
    // Add last func with correct coefficient
    func = (RooAbsReal*) funcIter.next() ;
    if (func->isSelectedComp()) {
      value += func->getVal()*lastCoef ;
    }

    cxcoutD(Eval) << "RooRealSumPdf::eval(" << GetName() << ") lastCoef = " << lastCoef << " funcVal = " << func->getVal() << endl ;
    
    // Warn about coefficient degeneration
    if (lastCoef<0 || lastCoef>1) {
      coutW(Eval) << "RooRealSumPdf::evaluate(" << GetName() 
		  << " WARNING: sum of FUNC coefficients not in range [0-1], value=" 
		  << 1-lastCoef << endl ;
    } 
  }

  // Introduce floor if so requested
  if (value<0 && (_doFloor || _doFloorGlobal)) {
    value = 0 ;
  }
  
  return value ;
}




//_____________________________________________________________________________
Bool_t RooRealSumPdf::checkObservables(const RooArgSet* nset) const 
{
  // Check if FUNC is valid for given normalization set.
  // Coeffient and FUNC must be non-overlapping, but func-coefficient 
  // pairs may overlap each other
  //
  // In the present implementation, coefficients may not be observables or derive
  // from observables

  Bool_t ret(kFALSE) ;

  _funcIter->Reset() ;
  _coefIter->Reset() ;
  RooAbsReal* coef ;
  RooAbsReal* func ;
  while((coef=(RooAbsReal*)_coefIter->Next())) {
    func = (RooAbsReal*)_funcIter->Next() ;
    if (func->observableOverlaps(nset,*coef)) {
      coutE(InputArguments) << "RooRealSumPdf::checkObservables(" << GetName() << "): ERROR: coefficient " << coef->GetName() 
			    << " and FUNC " << func->GetName() << " have one or more observables in common" << endl ;
      ret = kTRUE ;
    }
    if (coef->dependsOn(*nset)) {
      coutE(InputArguments) << "RooRealPdf::checkObservables(" << GetName() << "): ERROR coefficient " << coef->GetName() 
			    << " depends on one or more of the following observables" ; nset->Print("1") ;
      ret = kTRUE ;
    }
  }
  
  return ret ;
}




//_____________________________________________________________________________
Int_t RooRealSumPdf::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, 
					     const RooArgSet* normSet2, const char* rangeName) const 
{
  //cout << "RooRealSumPdf::getAnalyticalIntegralWN:"<<GetName()<<"("<<allVars<<",analVars,"<<(normSet2?*normSet2:RooArgSet())<<","<<(rangeName?rangeName:"<none>") << endl;
  // Advertise that all integrals can be handled internally.

  // Handle trivial no-integration scenario
  if (allVars.getSize()==0) return 0 ;
  if (_forceNumInt) return 0 ;

  // Select subset of allVars that are actual dependents
  analVars.add(allVars) ;
  RooArgSet* normSet = normSet2 ? getObservables(normSet2) : 0 ;


  // Check if this configuration was created before
  Int_t sterileIdx(-1) ;
  CacheElem* cache = (CacheElem*) _normIntMgr.getObj(normSet,&analVars,&sterileIdx,RooNameReg::ptr(rangeName)) ;
  if (cache) {
    //cout << "RooRealSumPdf("<<this<<")::getAnalyticalIntegralWN:"<<GetName()<<"("<<allVars<<","<<analVars<<","<<(normSet2?*normSet2:RooArgSet())<<","<<(rangeName?rangeName:"<none>") << " -> " << _normIntMgr.lastIndex()+1 << " (cached)" << endl;
    return _normIntMgr.lastIndex()+1 ;
  }
  
  // Create new cache element
  cache = new CacheElem ;

  // Make list of function projection and normalization integrals 
  _funcIter->Reset() ;
  RooAbsReal *func ;
  while((func=(RooAbsReal*)_funcIter->Next())) {
    RooAbsReal* funcInt = func->createIntegral(analVars,rangeName) ;
    cache->_funcIntList.addOwned(*funcInt) ;
    if (normSet && normSet->getSize()>0) {
      RooAbsReal* funcNorm = func->createIntegral(*normSet) ;
      cache->_funcNormList.addOwned(*funcNorm) ;
    }
  }

  // Store cache element
  Int_t code = _normIntMgr.setObj(normSet,&analVars,(RooAbsCacheElement*)cache,RooNameReg::ptr(rangeName)) ;

  if (normSet) {
    delete normSet ;
  }

  //cout << "RooRealSumPdf("<<this<<")::getAnalyticalIntegralWN:"<<GetName()<<"("<<allVars<<","<<analVars<<","<<(normSet2?*normSet2:RooArgSet())<<","<<(rangeName?rangeName:"<none>") << " -> " << code+1 << endl;
  return code+1 ; 
}




//_____________________________________________________________________________
Double_t RooRealSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normSet2, const char* rangeName) const 
{
  //cout << "RooRealSumPdf::analyticalIntegralWN:"<<GetName()<<"("<<code<<","<<(normSet2?*normSet2:RooArgSet())<<","<<(rangeName?rangeName:"<none>") << endl;
  // Implement analytical integrations by deferring integration of component
  // functions to integrators of components

  // Handle trivial passthrough scenario
  if (code==0) return getVal(normSet2) ;


  // WVE needs adaptation for rangeName feature
  CacheElem* cache = (CacheElem*) _normIntMgr.getObjByIndex(code-1) ;
  if (cache==0) { // revive the (sterilized) cache
     //cout << "RooRealSumPdf("<<this<<")::analyticalIntegralWN:"<<GetName()<<"("<<code<<","<<(normSet2?*normSet2:RooArgSet())<<","<<(rangeName?rangeName:"<none>") << ": reviving cache "<< endl;
     std::auto_ptr<RooArgSet> vars( getParameters(RooArgSet()) );
     std::auto_ptr<RooArgSet> iset(  _normIntMgr.nameSet2ByIndex(code-1)->select(*vars) );
     std::auto_ptr<RooArgSet> nset(  _normIntMgr.nameSet1ByIndex(code-1)->select(*vars) );
     RooArgSet dummy;
     Int_t code2 = getAnalyticalIntegralWN(*iset,dummy,nset.get(),rangeName);
     R__ASSERT(code==code2); // must have revived the right (sterilized) slot...
     cache = (CacheElem*) _normIntMgr.getObjByIndex(code-1) ;
     R__ASSERT(cache!=0);
  }

  RooFIter funcIntIter = cache->_funcIntList.fwdIterator() ;
  RooFIter coefIter = _coefList.fwdIterator() ;
  RooFIter funcIter = _funcList.fwdIterator() ;
  RooAbsReal *coef(0), *funcInt(0), *func(0) ;
  Double_t value(0) ;

  // N funcs, N-1 coefficients 
  Double_t lastCoef(1) ;
  while((coef=(RooAbsReal*)coefIter.next())) {
    funcInt = (RooAbsReal*)funcIntIter.next() ;
    func    = (RooAbsReal*)funcIter.next() ;
    Double_t coefVal = coef->getVal(normSet2) ;
    if (coefVal) {
      assert(func);
      if (normSet2 ==0 || func->isSelectedComp()) {
	assert(funcInt);
	value += funcInt->getVal()*coefVal ;
      }
      lastCoef -= coef->getVal(normSet2) ;
    }
  }
  
  if (!_haveLastCoef) {
    // Add last func with correct coefficient
    funcInt = (RooAbsReal*) funcIntIter.next() ;
    if (normSet2 ==0 || func->isSelectedComp()) {
      assert(funcInt);
      value += funcInt->getVal()*lastCoef ;
    }
    
    // Warn about coefficient degeneration
    if (lastCoef<0 || lastCoef>1) {
      coutW(Eval) << "RooRealSumPdf::evaluate(" << GetName() 
		  << " WARNING: sum of FUNC coefficients not in range [0-1], value=" 
		  << 1-lastCoef << endl ;
    } 
  }
  
  Double_t normVal(1) ;
  if (normSet2 && normSet2->getSize()>0) {
    normVal = 0 ;

    // N funcs, N-1 coefficients 
    RooAbsReal* funcNorm ;
    RooFIter funcNormIter = cache->_funcNormList.fwdIterator() ;
    RooFIter coefIter2 = _coefList.fwdIterator() ;
    while((coef=(RooAbsReal*)coefIter2.next())) {
      funcNorm = (RooAbsReal*)funcNormIter.next() ;
      Double_t coefVal = coef->getVal(normSet2) ;
      if (coefVal) {
	assert(funcNorm);
	normVal += funcNorm->getVal()*coefVal ;
      }
    }
    
    // Add last func with correct coefficient
    if (!_haveLastCoef) {
      funcNorm = (RooAbsReal*) funcNormIter.next() ;
      assert(funcNorm);
      normVal += funcNorm->getVal()*lastCoef ;
    }      
  }

  return value / normVal;
}


//_____________________________________________________________________________
Double_t RooRealSumPdf::expectedEvents(const RooArgSet* nset) const
{

  Double_t n = getNorm(nset) ;  
  if (n<0) {
    logEvalError("Expected number of events is negative") ;
  }
  return n ;
}


//_____________________________________________________________________________
std::list<Double_t>* RooRealSumPdf::binBoundaries(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const
{
  list<Double_t>* sumBinB = 0 ;
  Bool_t needClean(kFALSE) ;
  
  RooFIter iter = _funcList.fwdIterator() ;
  RooAbsReal* func ;
  // Loop over components pdf
  while((func=(RooAbsReal*)iter.next())) {

    list<Double_t>* funcBinB = func->binBoundaries(obs,xlo,xhi) ;
    
    // Process hint
    if (funcBinB) {
      if (!sumBinB) {
	// If this is the first hint, then just save it
	sumBinB = funcBinB ;
      } else {
	
	list<Double_t>* newSumBinB = new list<Double_t>(sumBinB->size()+funcBinB->size()) ;

	// Merge hints into temporary array
	merge(funcBinB->begin(),funcBinB->end(),sumBinB->begin(),sumBinB->end(),newSumBinB->begin()) ;
	
	// Copy merged array without duplicates to new sumBinBArrau
	delete sumBinB ;
	delete funcBinB ;
	sumBinB = newSumBinB ;
	needClean = kTRUE ;	
      }
    }
  }

  // Remove consecutive duplicates
  if (needClean) {
    list<Double_t>::iterator new_end = unique(sumBinB->begin(),sumBinB->end()) ;
    sumBinB->erase(new_end,sumBinB->end()) ;
  }

  return sumBinB ;
}



//_____________________________________________________________________________B
Bool_t RooRealSumPdf::isBinnedDistribution(const RooArgSet& obs) const 
{
  // If all components that depend on obs are binned that so is the product
  
  RooFIter iter = _funcList.fwdIterator() ;
  RooAbsReal* func ;
  while((func=(RooAbsReal*)iter.next())) {
    if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
      return kFALSE ;
    }
  }
  
  return kTRUE  ;  
}





//_____________________________________________________________________________
std::list<Double_t>* RooRealSumPdf::plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const
{
  list<Double_t>* sumHint = 0 ;
  Bool_t needClean(kFALSE) ;
  
  RooFIter iter = _funcList.fwdIterator() ;
  RooAbsReal* func ;
  // Loop over components pdf
  while((func=(RooAbsReal*)iter.next())) {

    list<Double_t>* funcHint = func->plotSamplingHint(obs,xlo,xhi) ;
    
    // Process hint
    if (funcHint) {
      if (!sumHint) {

	// If this is the first hint, then just save it
	sumHint = funcHint ;

      } else {
	
	list<Double_t>* newSumHint = new list<Double_t>(sumHint->size()+funcHint->size()) ;
	
	// Merge hints into temporary array
	merge(funcHint->begin(),funcHint->end(),sumHint->begin(),sumHint->end(),newSumHint->begin()) ;

	// Copy merged array without duplicates to new sumHintArrau
	delete sumHint ;
	sumHint = newSumHint ;
	needClean = kTRUE ;	
      }
    }
  }

  // Remove consecutive duplicates
  if (needClean) {
    list<Double_t>::iterator new_end = unique(sumHint->begin(),sumHint->end()) ;
    sumHint->erase(new_end,sumHint->end()) ;
  }

  return sumHint ;
}




//_____________________________________________________________________________
void RooRealSumPdf::setCacheAndTrackHints(RooArgSet& trackNodes) 
{
  // Label OK'ed components of a RooRealSumPdf with cache-and-track
  RooFIter siter = funcList().fwdIterator() ;
  RooAbsArg* sarg ;
  while ((sarg=siter.next())) {
    if (sarg->canNodeBeCached()==Always) {
      trackNodes.add(*sarg) ;
      //cout << "tracking node RealSumPdf component " << sarg->IsA()->GetName() << "::" << sarg->GetName() << endl ;
    }
  }
}



//_____________________________________________________________________________
void RooRealSumPdf::printMetaArgs(ostream& os) const 
{
  // Customized printing of arguments of a RooRealSumPdf to more intuitively reflect the contents of the
  // product operator construction

  _funcIter->Reset() ;
  _coefIter->Reset() ;

  Bool_t first(kTRUE) ;
    
  RooAbsArg* coef, *func ;
  if (_coefList.getSize()!=0) { 
    while((coef=(RooAbsArg*)_coefIter->Next())) {
      if (!first) {
	os << " + " ;
      } else {
	first = kFALSE ;
      }
      func=(RooAbsArg*)_funcIter->Next() ;
      os << coef->GetName() << " * " << func->GetName() ;
    }
    func = (RooAbsArg*) _funcIter->Next() ;
    if (func) {
      os << " + [%] * " << func->GetName() ;
    }
  } else {
    
    while((func=(RooAbsArg*)_funcIter->Next())) {
      if (!first) {
	os << " + " ;
      } else {
	first = kFALSE ;
      }
      os << func->GetName() ; 
    }  
  }

  os << " " ;    
}
 RooRealSumPdf.cxx:1
 RooRealSumPdf.cxx:2
 RooRealSumPdf.cxx:3
 RooRealSumPdf.cxx:4
 RooRealSumPdf.cxx:5
 RooRealSumPdf.cxx:6
 RooRealSumPdf.cxx:7
 RooRealSumPdf.cxx:8
 RooRealSumPdf.cxx:9
 RooRealSumPdf.cxx:10
 RooRealSumPdf.cxx:11
 RooRealSumPdf.cxx:12
 RooRealSumPdf.cxx:13
 RooRealSumPdf.cxx:14
 RooRealSumPdf.cxx:15
 RooRealSumPdf.cxx:16
 RooRealSumPdf.cxx:17
 RooRealSumPdf.cxx:18
 RooRealSumPdf.cxx:19
 RooRealSumPdf.cxx:20
 RooRealSumPdf.cxx:21
 RooRealSumPdf.cxx:22
 RooRealSumPdf.cxx:23
 RooRealSumPdf.cxx:24
 RooRealSumPdf.cxx:25
 RooRealSumPdf.cxx:26
 RooRealSumPdf.cxx:27
 RooRealSumPdf.cxx:28
 RooRealSumPdf.cxx:29
 RooRealSumPdf.cxx:30
 RooRealSumPdf.cxx:31
 RooRealSumPdf.cxx:32
 RooRealSumPdf.cxx:33
 RooRealSumPdf.cxx:34
 RooRealSumPdf.cxx:35
 RooRealSumPdf.cxx:36
 RooRealSumPdf.cxx:37
 RooRealSumPdf.cxx:38
 RooRealSumPdf.cxx:39
 RooRealSumPdf.cxx:40
 RooRealSumPdf.cxx:41
 RooRealSumPdf.cxx:42
 RooRealSumPdf.cxx:43
 RooRealSumPdf.cxx:44
 RooRealSumPdf.cxx:45
 RooRealSumPdf.cxx:46
 RooRealSumPdf.cxx:47
 RooRealSumPdf.cxx:48
 RooRealSumPdf.cxx:49
 RooRealSumPdf.cxx:50
 RooRealSumPdf.cxx:51
 RooRealSumPdf.cxx:52
 RooRealSumPdf.cxx:53
 RooRealSumPdf.cxx:54
 RooRealSumPdf.cxx:55
 RooRealSumPdf.cxx:56
 RooRealSumPdf.cxx:57
 RooRealSumPdf.cxx:58
 RooRealSumPdf.cxx:59
 RooRealSumPdf.cxx:60
 RooRealSumPdf.cxx:61
 RooRealSumPdf.cxx:62
 RooRealSumPdf.cxx:63
 RooRealSumPdf.cxx:64
 RooRealSumPdf.cxx:65
 RooRealSumPdf.cxx:66
 RooRealSumPdf.cxx:67
 RooRealSumPdf.cxx:68
 RooRealSumPdf.cxx:69
 RooRealSumPdf.cxx:70
 RooRealSumPdf.cxx:71
 RooRealSumPdf.cxx:72
 RooRealSumPdf.cxx:73
 RooRealSumPdf.cxx:74
 RooRealSumPdf.cxx:75
 RooRealSumPdf.cxx:76
 RooRealSumPdf.cxx:77
 RooRealSumPdf.cxx:78
 RooRealSumPdf.cxx:79
 RooRealSumPdf.cxx:80
 RooRealSumPdf.cxx:81
 RooRealSumPdf.cxx:82
 RooRealSumPdf.cxx:83
 RooRealSumPdf.cxx:84
 RooRealSumPdf.cxx:85
 RooRealSumPdf.cxx:86
 RooRealSumPdf.cxx:87
 RooRealSumPdf.cxx:88
 RooRealSumPdf.cxx:89
 RooRealSumPdf.cxx:90
 RooRealSumPdf.cxx:91
 RooRealSumPdf.cxx:92
 RooRealSumPdf.cxx:93
 RooRealSumPdf.cxx:94
 RooRealSumPdf.cxx:95
 RooRealSumPdf.cxx:96
 RooRealSumPdf.cxx:97
 RooRealSumPdf.cxx:98
 RooRealSumPdf.cxx:99
 RooRealSumPdf.cxx:100
 RooRealSumPdf.cxx:101
 RooRealSumPdf.cxx:102
 RooRealSumPdf.cxx:103
 RooRealSumPdf.cxx:104
 RooRealSumPdf.cxx:105
 RooRealSumPdf.cxx:106
 RooRealSumPdf.cxx:107
 RooRealSumPdf.cxx:108
 RooRealSumPdf.cxx:109
 RooRealSumPdf.cxx:110
 RooRealSumPdf.cxx:111
 RooRealSumPdf.cxx:112
 RooRealSumPdf.cxx:113
 RooRealSumPdf.cxx:114
 RooRealSumPdf.cxx:115
 RooRealSumPdf.cxx:116
 RooRealSumPdf.cxx:117
 RooRealSumPdf.cxx:118
 RooRealSumPdf.cxx:119
 RooRealSumPdf.cxx:120
 RooRealSumPdf.cxx:121
 RooRealSumPdf.cxx:122
 RooRealSumPdf.cxx:123
 RooRealSumPdf.cxx:124
 RooRealSumPdf.cxx:125
 RooRealSumPdf.cxx:126
 RooRealSumPdf.cxx:127
 RooRealSumPdf.cxx:128
 RooRealSumPdf.cxx:129
 RooRealSumPdf.cxx:130
 RooRealSumPdf.cxx:131
 RooRealSumPdf.cxx:132
 RooRealSumPdf.cxx:133
 RooRealSumPdf.cxx:134
 RooRealSumPdf.cxx:135
 RooRealSumPdf.cxx:136
 RooRealSumPdf.cxx:137
 RooRealSumPdf.cxx:138
 RooRealSumPdf.cxx:139
 RooRealSumPdf.cxx:140
 RooRealSumPdf.cxx:141
 RooRealSumPdf.cxx:142
 RooRealSumPdf.cxx:143
 RooRealSumPdf.cxx:144
 RooRealSumPdf.cxx:145
 RooRealSumPdf.cxx:146
 RooRealSumPdf.cxx:147
 RooRealSumPdf.cxx:148
 RooRealSumPdf.cxx:149
 RooRealSumPdf.cxx:150
 RooRealSumPdf.cxx:151
 RooRealSumPdf.cxx:152
 RooRealSumPdf.cxx:153
 RooRealSumPdf.cxx:154
 RooRealSumPdf.cxx:155
 RooRealSumPdf.cxx:156
 RooRealSumPdf.cxx:157
 RooRealSumPdf.cxx:158
 RooRealSumPdf.cxx:159
 RooRealSumPdf.cxx:160
 RooRealSumPdf.cxx:161
 RooRealSumPdf.cxx:162
 RooRealSumPdf.cxx:163
 RooRealSumPdf.cxx:164
 RooRealSumPdf.cxx:165
 RooRealSumPdf.cxx:166
 RooRealSumPdf.cxx:167
 RooRealSumPdf.cxx:168
 RooRealSumPdf.cxx:169
 RooRealSumPdf.cxx:170
 RooRealSumPdf.cxx:171
 RooRealSumPdf.cxx:172
 RooRealSumPdf.cxx:173
 RooRealSumPdf.cxx:174
 RooRealSumPdf.cxx:175
 RooRealSumPdf.cxx:176
 RooRealSumPdf.cxx:177
 RooRealSumPdf.cxx:178
 RooRealSumPdf.cxx:179
 RooRealSumPdf.cxx:180
 RooRealSumPdf.cxx:181
 RooRealSumPdf.cxx:182
 RooRealSumPdf.cxx:183
 RooRealSumPdf.cxx:184
 RooRealSumPdf.cxx:185
 RooRealSumPdf.cxx:186
 RooRealSumPdf.cxx:187
 RooRealSumPdf.cxx:188
 RooRealSumPdf.cxx:189
 RooRealSumPdf.cxx:190
 RooRealSumPdf.cxx:191
 RooRealSumPdf.cxx:192
 RooRealSumPdf.cxx:193
 RooRealSumPdf.cxx:194
 RooRealSumPdf.cxx:195
 RooRealSumPdf.cxx:196
 RooRealSumPdf.cxx:197
 RooRealSumPdf.cxx:198
 RooRealSumPdf.cxx:199
 RooRealSumPdf.cxx:200
 RooRealSumPdf.cxx:201
 RooRealSumPdf.cxx:202
 RooRealSumPdf.cxx:203
 RooRealSumPdf.cxx:204
 RooRealSumPdf.cxx:205
 RooRealSumPdf.cxx:206
 RooRealSumPdf.cxx:207
 RooRealSumPdf.cxx:208
 RooRealSumPdf.cxx:209
 RooRealSumPdf.cxx:210
 RooRealSumPdf.cxx:211
 RooRealSumPdf.cxx:212
 RooRealSumPdf.cxx:213
 RooRealSumPdf.cxx:214
 RooRealSumPdf.cxx:215
 RooRealSumPdf.cxx:216
 RooRealSumPdf.cxx:217
 RooRealSumPdf.cxx:218
 RooRealSumPdf.cxx:219
 RooRealSumPdf.cxx:220
 RooRealSumPdf.cxx:221
 RooRealSumPdf.cxx:222
 RooRealSumPdf.cxx:223
 RooRealSumPdf.cxx:224
 RooRealSumPdf.cxx:225
 RooRealSumPdf.cxx:226
 RooRealSumPdf.cxx:227
 RooRealSumPdf.cxx:228
 RooRealSumPdf.cxx:229
 RooRealSumPdf.cxx:230
 RooRealSumPdf.cxx:231
 RooRealSumPdf.cxx:232
 RooRealSumPdf.cxx:233
 RooRealSumPdf.cxx:234
 RooRealSumPdf.cxx:235
 RooRealSumPdf.cxx:236
 RooRealSumPdf.cxx:237
 RooRealSumPdf.cxx:238
 RooRealSumPdf.cxx:239
 RooRealSumPdf.cxx:240
 RooRealSumPdf.cxx:241
 RooRealSumPdf.cxx:242
 RooRealSumPdf.cxx:243
 RooRealSumPdf.cxx:244
 RooRealSumPdf.cxx:245
 RooRealSumPdf.cxx:246
 RooRealSumPdf.cxx:247
 RooRealSumPdf.cxx:248
 RooRealSumPdf.cxx:249
 RooRealSumPdf.cxx:250
 RooRealSumPdf.cxx:251
 RooRealSumPdf.cxx:252
 RooRealSumPdf.cxx:253
 RooRealSumPdf.cxx:254
 RooRealSumPdf.cxx:255
 RooRealSumPdf.cxx:256
 RooRealSumPdf.cxx:257
 RooRealSumPdf.cxx:258
 RooRealSumPdf.cxx:259
 RooRealSumPdf.cxx:260
 RooRealSumPdf.cxx:261
 RooRealSumPdf.cxx:262
 RooRealSumPdf.cxx:263
 RooRealSumPdf.cxx:264
 RooRealSumPdf.cxx:265
 RooRealSumPdf.cxx:266
 RooRealSumPdf.cxx:267
 RooRealSumPdf.cxx:268
 RooRealSumPdf.cxx:269
 RooRealSumPdf.cxx:270
 RooRealSumPdf.cxx:271
 RooRealSumPdf.cxx:272
 RooRealSumPdf.cxx:273
 RooRealSumPdf.cxx:274
 RooRealSumPdf.cxx:275
 RooRealSumPdf.cxx:276
 RooRealSumPdf.cxx:277
 RooRealSumPdf.cxx:278
 RooRealSumPdf.cxx:279
 RooRealSumPdf.cxx:280
 RooRealSumPdf.cxx:281
 RooRealSumPdf.cxx:282
 RooRealSumPdf.cxx:283
 RooRealSumPdf.cxx:284
 RooRealSumPdf.cxx:285
 RooRealSumPdf.cxx:286
 RooRealSumPdf.cxx:287
 RooRealSumPdf.cxx:288
 RooRealSumPdf.cxx:289
 RooRealSumPdf.cxx:290
 RooRealSumPdf.cxx:291
 RooRealSumPdf.cxx:292
 RooRealSumPdf.cxx:293
 RooRealSumPdf.cxx:294
 RooRealSumPdf.cxx:295
 RooRealSumPdf.cxx:296
 RooRealSumPdf.cxx:297
 RooRealSumPdf.cxx:298
 RooRealSumPdf.cxx:299
 RooRealSumPdf.cxx:300
 RooRealSumPdf.cxx:301
 RooRealSumPdf.cxx:302
 RooRealSumPdf.cxx:303
 RooRealSumPdf.cxx:304
 RooRealSumPdf.cxx:305
 RooRealSumPdf.cxx:306
 RooRealSumPdf.cxx:307
 RooRealSumPdf.cxx:308
 RooRealSumPdf.cxx:309
 RooRealSumPdf.cxx:310
 RooRealSumPdf.cxx:311
 RooRealSumPdf.cxx:312
 RooRealSumPdf.cxx:313
 RooRealSumPdf.cxx:314
 RooRealSumPdf.cxx:315
 RooRealSumPdf.cxx:316
 RooRealSumPdf.cxx:317
 RooRealSumPdf.cxx:318
 RooRealSumPdf.cxx:319
 RooRealSumPdf.cxx:320
 RooRealSumPdf.cxx:321
 RooRealSumPdf.cxx:322
 RooRealSumPdf.cxx:323
 RooRealSumPdf.cxx:324
 RooRealSumPdf.cxx:325
 RooRealSumPdf.cxx:326
 RooRealSumPdf.cxx:327
 RooRealSumPdf.cxx:328
 RooRealSumPdf.cxx:329
 RooRealSumPdf.cxx:330
 RooRealSumPdf.cxx:331
 RooRealSumPdf.cxx:332
 RooRealSumPdf.cxx:333
 RooRealSumPdf.cxx:334
 RooRealSumPdf.cxx:335
 RooRealSumPdf.cxx:336
 RooRealSumPdf.cxx:337
 RooRealSumPdf.cxx:338
 RooRealSumPdf.cxx:339
 RooRealSumPdf.cxx:340
 RooRealSumPdf.cxx:341
 RooRealSumPdf.cxx:342
 RooRealSumPdf.cxx:343
 RooRealSumPdf.cxx:344
 RooRealSumPdf.cxx:345
 RooRealSumPdf.cxx:346
 RooRealSumPdf.cxx:347
 RooRealSumPdf.cxx:348
 RooRealSumPdf.cxx:349
 RooRealSumPdf.cxx:350
 RooRealSumPdf.cxx:351
 RooRealSumPdf.cxx:352
 RooRealSumPdf.cxx:353
 RooRealSumPdf.cxx:354
 RooRealSumPdf.cxx:355
 RooRealSumPdf.cxx:356
 RooRealSumPdf.cxx:357
 RooRealSumPdf.cxx:358
 RooRealSumPdf.cxx:359
 RooRealSumPdf.cxx:360
 RooRealSumPdf.cxx:361
 RooRealSumPdf.cxx:362
 RooRealSumPdf.cxx:363
 RooRealSumPdf.cxx:364
 RooRealSumPdf.cxx:365
 RooRealSumPdf.cxx:366
 RooRealSumPdf.cxx:367
 RooRealSumPdf.cxx:368
 RooRealSumPdf.cxx:369
 RooRealSumPdf.cxx:370
 RooRealSumPdf.cxx:371
 RooRealSumPdf.cxx:372
 RooRealSumPdf.cxx:373
 RooRealSumPdf.cxx:374
 RooRealSumPdf.cxx:375
 RooRealSumPdf.cxx:376
 RooRealSumPdf.cxx:377
 RooRealSumPdf.cxx:378
 RooRealSumPdf.cxx:379
 RooRealSumPdf.cxx:380
 RooRealSumPdf.cxx:381
 RooRealSumPdf.cxx:382
 RooRealSumPdf.cxx:383
 RooRealSumPdf.cxx:384
 RooRealSumPdf.cxx:385
 RooRealSumPdf.cxx:386
 RooRealSumPdf.cxx:387
 RooRealSumPdf.cxx:388
 RooRealSumPdf.cxx:389
 RooRealSumPdf.cxx:390
 RooRealSumPdf.cxx:391
 RooRealSumPdf.cxx:392
 RooRealSumPdf.cxx:393
 RooRealSumPdf.cxx:394
 RooRealSumPdf.cxx:395
 RooRealSumPdf.cxx:396
 RooRealSumPdf.cxx:397
 RooRealSumPdf.cxx:398
 RooRealSumPdf.cxx:399
 RooRealSumPdf.cxx:400
 RooRealSumPdf.cxx:401
 RooRealSumPdf.cxx:402
 RooRealSumPdf.cxx:403
 RooRealSumPdf.cxx:404
 RooRealSumPdf.cxx:405
 RooRealSumPdf.cxx:406
 RooRealSumPdf.cxx:407
 RooRealSumPdf.cxx:408
 RooRealSumPdf.cxx:409
 RooRealSumPdf.cxx:410
 RooRealSumPdf.cxx:411
 RooRealSumPdf.cxx:412
 RooRealSumPdf.cxx:413
 RooRealSumPdf.cxx:414
 RooRealSumPdf.cxx:415
 RooRealSumPdf.cxx:416
 RooRealSumPdf.cxx:417
 RooRealSumPdf.cxx:418
 RooRealSumPdf.cxx:419
 RooRealSumPdf.cxx:420
 RooRealSumPdf.cxx:421
 RooRealSumPdf.cxx:422
 RooRealSumPdf.cxx:423
 RooRealSumPdf.cxx:424
 RooRealSumPdf.cxx:425
 RooRealSumPdf.cxx:426
 RooRealSumPdf.cxx:427
 RooRealSumPdf.cxx:428
 RooRealSumPdf.cxx:429
 RooRealSumPdf.cxx:430
 RooRealSumPdf.cxx:431
 RooRealSumPdf.cxx:432
 RooRealSumPdf.cxx:433
 RooRealSumPdf.cxx:434
 RooRealSumPdf.cxx:435
 RooRealSumPdf.cxx:436
 RooRealSumPdf.cxx:437
 RooRealSumPdf.cxx:438
 RooRealSumPdf.cxx:439
 RooRealSumPdf.cxx:440
 RooRealSumPdf.cxx:441
 RooRealSumPdf.cxx:442
 RooRealSumPdf.cxx:443
 RooRealSumPdf.cxx:444
 RooRealSumPdf.cxx:445
 RooRealSumPdf.cxx:446
 RooRealSumPdf.cxx:447
 RooRealSumPdf.cxx:448
 RooRealSumPdf.cxx:449
 RooRealSumPdf.cxx:450
 RooRealSumPdf.cxx:451
 RooRealSumPdf.cxx:452
 RooRealSumPdf.cxx:453
 RooRealSumPdf.cxx:454
 RooRealSumPdf.cxx:455
 RooRealSumPdf.cxx:456
 RooRealSumPdf.cxx:457
 RooRealSumPdf.cxx:458
 RooRealSumPdf.cxx:459
 RooRealSumPdf.cxx:460
 RooRealSumPdf.cxx:461
 RooRealSumPdf.cxx:462
 RooRealSumPdf.cxx:463
 RooRealSumPdf.cxx:464
 RooRealSumPdf.cxx:465
 RooRealSumPdf.cxx:466
 RooRealSumPdf.cxx:467
 RooRealSumPdf.cxx:468
 RooRealSumPdf.cxx:469
 RooRealSumPdf.cxx:470
 RooRealSumPdf.cxx:471
 RooRealSumPdf.cxx:472
 RooRealSumPdf.cxx:473
 RooRealSumPdf.cxx:474
 RooRealSumPdf.cxx:475
 RooRealSumPdf.cxx:476
 RooRealSumPdf.cxx:477
 RooRealSumPdf.cxx:478
 RooRealSumPdf.cxx:479
 RooRealSumPdf.cxx:480
 RooRealSumPdf.cxx:481
 RooRealSumPdf.cxx:482
 RooRealSumPdf.cxx:483
 RooRealSumPdf.cxx:484
 RooRealSumPdf.cxx:485
 RooRealSumPdf.cxx:486
 RooRealSumPdf.cxx:487
 RooRealSumPdf.cxx:488
 RooRealSumPdf.cxx:489
 RooRealSumPdf.cxx:490
 RooRealSumPdf.cxx:491
 RooRealSumPdf.cxx:492
 RooRealSumPdf.cxx:493
 RooRealSumPdf.cxx:494
 RooRealSumPdf.cxx:495
 RooRealSumPdf.cxx:496
 RooRealSumPdf.cxx:497
 RooRealSumPdf.cxx:498
 RooRealSumPdf.cxx:499
 RooRealSumPdf.cxx:500
 RooRealSumPdf.cxx:501
 RooRealSumPdf.cxx:502
 RooRealSumPdf.cxx:503
 RooRealSumPdf.cxx:504
 RooRealSumPdf.cxx:505
 RooRealSumPdf.cxx:506
 RooRealSumPdf.cxx:507
 RooRealSumPdf.cxx:508
 RooRealSumPdf.cxx:509
 RooRealSumPdf.cxx:510
 RooRealSumPdf.cxx:511
 RooRealSumPdf.cxx:512
 RooRealSumPdf.cxx:513
 RooRealSumPdf.cxx:514
 RooRealSumPdf.cxx:515
 RooRealSumPdf.cxx:516
 RooRealSumPdf.cxx:517
 RooRealSumPdf.cxx:518
 RooRealSumPdf.cxx:519
 RooRealSumPdf.cxx:520
 RooRealSumPdf.cxx:521
 RooRealSumPdf.cxx:522
 RooRealSumPdf.cxx:523
 RooRealSumPdf.cxx:524
 RooRealSumPdf.cxx:525
 RooRealSumPdf.cxx:526
 RooRealSumPdf.cxx:527
 RooRealSumPdf.cxx:528
 RooRealSumPdf.cxx:529
 RooRealSumPdf.cxx:530
 RooRealSumPdf.cxx:531
 RooRealSumPdf.cxx:532
 RooRealSumPdf.cxx:533
 RooRealSumPdf.cxx:534
 RooRealSumPdf.cxx:535
 RooRealSumPdf.cxx:536
 RooRealSumPdf.cxx:537
 RooRealSumPdf.cxx:538
 RooRealSumPdf.cxx:539
 RooRealSumPdf.cxx:540
 RooRealSumPdf.cxx:541
 RooRealSumPdf.cxx:542
 RooRealSumPdf.cxx:543
 RooRealSumPdf.cxx:544
 RooRealSumPdf.cxx:545
 RooRealSumPdf.cxx:546
 RooRealSumPdf.cxx:547
 RooRealSumPdf.cxx:548
 RooRealSumPdf.cxx:549
 RooRealSumPdf.cxx:550
 RooRealSumPdf.cxx:551
 RooRealSumPdf.cxx:552
 RooRealSumPdf.cxx:553
 RooRealSumPdf.cxx:554
 RooRealSumPdf.cxx:555
 RooRealSumPdf.cxx:556
 RooRealSumPdf.cxx:557
 RooRealSumPdf.cxx:558
 RooRealSumPdf.cxx:559
 RooRealSumPdf.cxx:560
 RooRealSumPdf.cxx:561
 RooRealSumPdf.cxx:562
 RooRealSumPdf.cxx:563
 RooRealSumPdf.cxx:564
 RooRealSumPdf.cxx:565
 RooRealSumPdf.cxx:566
 RooRealSumPdf.cxx:567
 RooRealSumPdf.cxx:568
 RooRealSumPdf.cxx:569
 RooRealSumPdf.cxx:570
 RooRealSumPdf.cxx:571
 RooRealSumPdf.cxx:572
 RooRealSumPdf.cxx:573
 RooRealSumPdf.cxx:574
 RooRealSumPdf.cxx:575
 RooRealSumPdf.cxx:576
 RooRealSumPdf.cxx:577
 RooRealSumPdf.cxx:578
 RooRealSumPdf.cxx:579
 RooRealSumPdf.cxx:580
 RooRealSumPdf.cxx:581
 RooRealSumPdf.cxx:582
 RooRealSumPdf.cxx:583
 RooRealSumPdf.cxx:584
 RooRealSumPdf.cxx:585
 RooRealSumPdf.cxx:586
 RooRealSumPdf.cxx:587
 RooRealSumPdf.cxx:588
 RooRealSumPdf.cxx:589
 RooRealSumPdf.cxx:590
 RooRealSumPdf.cxx:591
 RooRealSumPdf.cxx:592
 RooRealSumPdf.cxx:593
 RooRealSumPdf.cxx:594
 RooRealSumPdf.cxx:595
 RooRealSumPdf.cxx:596
 RooRealSumPdf.cxx:597
 RooRealSumPdf.cxx:598
 RooRealSumPdf.cxx:599
 RooRealSumPdf.cxx:600
 RooRealSumPdf.cxx:601
 RooRealSumPdf.cxx:602
 RooRealSumPdf.cxx:603
 RooRealSumPdf.cxx:604
 RooRealSumPdf.cxx:605
 RooRealSumPdf.cxx:606
 RooRealSumPdf.cxx:607
 RooRealSumPdf.cxx:608
 RooRealSumPdf.cxx:609
 RooRealSumPdf.cxx:610
 RooRealSumPdf.cxx:611
 RooRealSumPdf.cxx:612
 RooRealSumPdf.cxx:613
 RooRealSumPdf.cxx:614
 RooRealSumPdf.cxx:615
 RooRealSumPdf.cxx:616
 RooRealSumPdf.cxx:617
 RooRealSumPdf.cxx:618
 RooRealSumPdf.cxx:619
 RooRealSumPdf.cxx:620
 RooRealSumPdf.cxx:621
 RooRealSumPdf.cxx:622
 RooRealSumPdf.cxx:623
 RooRealSumPdf.cxx:624
 RooRealSumPdf.cxx:625
 RooRealSumPdf.cxx:626
 RooRealSumPdf.cxx:627
 RooRealSumPdf.cxx:628
 RooRealSumPdf.cxx:629
 RooRealSumPdf.cxx:630
 RooRealSumPdf.cxx:631