Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
ParamHistFunc.cxx
Go to the documentation of this file.
1 // @(#)root/roostats:$Id: cranmer $
2 // Author: Kyle Cranmer, George Lewis
3 /*************************************************************************
4  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 ////////////////////////////////////////////////////////////////////////////////
12 
13 /** \class ParamHistFunc
14  * \ingroup HistFactory
15  * A class which maps the current values of a RooRealVar
16  * (or a set of RooRealVars) to one of a number of RooRealVars:
17  *
18  * `ParamHistFunc: {val1, val2, ...} -> {gamma (RooRealVar)}`
19  *
20  * The intended interpretation is that each parameter in the
21  * range represent the height of a bin over the domain
22  * space.
23  *
24  * The 'createParamSet' is an easy way to create these
25  * parameters from a set of observables. They are
26  * stored using the "TH1" ordering convention (as compared
27  * to the RooDataHist convention, which is used internally
28  * and one must map between the two).
29  *
30  * All indices include '0':<br>
31  * \f$ \gamma_{i,j} \f$ = `paramSet[ size(i)*j + i ]`
32  *
33  * ie assuming the dimensions are 5*5:<br>
34  * \f$ \gamma_{2,1} \f$ = `paramSet[ 5*1 + 2 ] = paramSet[7]`
35  */
36 
37 
38 #include <sstream>
39 #include <math.h>
40 #include <stdexcept>
41 
42 #include "TMath.h"
43 #include "TH1.h"
44 
45 #include "Riostream.h"
46 #include "Riostream.h"
47 
48 
49 #include "RooFit.h"
51 #include "RooAbsReal.h"
52 #include "RooAbsPdf.h"
53 
54 #include "RooConstVar.h"
55 #include "RooBinning.h"
56 #include "RooErrorHandler.h"
57 
58 #include "RooGaussian.h"
59 #include "RooHistFunc.h"
60 #include "RooArgSet.h"
61 #include "RooNLLVar.h"
62 #include "RooChi2Var.h"
63 #include "RooMsgService.h"
64 
65 // Forward declared:
66 #include "RooRealVar.h"
67 #include "RooArgList.h"
68 #include "RooWorkspace.h"
69 #include "RooBinning.h"
70 
71 //using namespace std;
72 
73 ClassImp(ParamHistFunc);
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 
78 ParamHistFunc::ParamHistFunc() : _numBins(0)
79 {
80  _dataSet.removeSelfFromDir(); // files must not delete _dataSet.
81 }
82 
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Create a function which returns binewise-values
86 /// This class contains N RooRealVar's, one for each
87 /// bin from the given RooRealVar.
88 ///
89 /// The value of the function in the ith bin is
90 /// given by:
91 ///
92 /// F(i) = gamma_i * nominal(i)
93 ///
94 /// Where the nominal values are simply fixed
95 /// numbers (default = 1.0 for all i)
96 ParamHistFunc::ParamHistFunc(const char* name, const char* title,
97  const RooArgList& vars, const RooArgList& paramSet) :
98  RooAbsReal(name, title),
99  _dataVars("!dataVars","data Vars", this),
100  _paramSet("!paramSet","bin parameters", this),
101  _numBins(0),
102  _dataSet( (std::string(name)+"_dataSet").c_str(), "", vars)
103 {
104 
105  // Create the dataset that stores the binning info:
106 
107  // _dataSet = RooDataSet("
108 
109  _dataSet.removeSelfFromDir(); // files must not delete _dataSet.
110 
111  // Set the binning
112  // //_binning = var.getBinning().clone() ;
113 
114  // Create the set of parameters
115  // controlling the height of each bin
116 
117  // Get the number of bins
118  _numBins = GetNumBins( vars );
119 
120  // Add the parameters (with checking)
121  addVarSet( vars );
122  addParamSet( paramSet );
123 }
124 
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 /// Create a function which returns bin-wise values.
128 /// This class contains N RooRealVars, one for each
129 /// bin from the given RooRealVar.
130 ///
131 /// The value of the function in the ith bin is
132 /// given by:
133 ///
134 /// F(i) = gamma_i * nominal(i)
135 ///
136 /// Where the nominal values are taken from the histogram.
137 ParamHistFunc::ParamHistFunc(const char* name, const char* title,
138  const RooArgList& vars, const RooArgList& paramSet,
139  const TH1* Hist ) :
140  RooAbsReal(name, title),
141  // _dataVar("!dataVar","data Var", this, (RooRealVar&) var),
142  _dataVars("!dataVars","data Vars", this),
143  _paramSet("!paramSet","bin parameters", this),
144  _numBins(0),
145  _dataSet( (std::string(name)+"_dataSet").c_str(), "", vars, Hist)
146 {
147 
148  _dataSet.removeSelfFromDir(); // files must not delete _dataSet.
149 
150  // Get the number of bins
151  _numBins = GetNumBins( vars );
152 
153  // Add the parameters (with checking)
154  addVarSet( vars );
155  addParamSet( paramSet );
156 
157 }
158 
159 
160 Int_t ParamHistFunc::GetNumBins( const RooArgSet& vars ) {
161 
162  // A helper method to get the number of bins
163 
164  if( vars.getSize() == 0 ) return 0;
165 
166  Int_t numBins = 1;
167 
168  RooFIter varIter = vars.fwdIterator() ;
169  RooAbsArg* comp ;
170  while((comp = (RooAbsArg*) varIter.next())) {
171  if (!dynamic_cast<RooRealVar*>(comp)) {
172  std::cout << "ParamHistFunc::GetNumBins" << vars.GetName() << ") ERROR: component "
173  << comp->GetName()
174  << " in vars list is not of type RooRealVar" << std::endl ;
175  RooErrorHandler::softAbort() ;
176  return -1;
177  }
178  RooRealVar* var = (RooRealVar*) comp;
179 
180  Int_t varNumBins = var->numBins();
181  numBins *= varNumBins;
182  }
183 
184  return numBins;
185 
186 }
187 
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 
191 ParamHistFunc::ParamHistFunc(const ParamHistFunc& other, const char* name) :
192  RooAbsReal(other, name),
193  _dataVars("!dataVars", this, other._dataVars ),
194  _paramSet("!paramSet", this, other._paramSet),
195  _numBins( other._numBins ),
196  _binMap( other._binMap ),
197  _dataSet( other._dataSet )
198 {
199  _dataSet.removeSelfFromDir(); // files must not delete _dataSet.
200 
201  // Copy constructor
202  // Member _ownedList is intentionally not copy-constructed -- ownership is not transferred
203 }
204 
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 
208 ParamHistFunc::~ParamHistFunc()
209 {
210  ;
211 }
212 
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Get the index of the gamma parameter associated
216 /// with the current bin.
217 /// This number is the "RooDataSet" style index
218 /// and it must be because it uses the RooDataSet method directly
219 /// This is intended to be fed into the getParameter(Int_t) method:
220 ///
221 /// RooRealVar currentParam = getParameter( getCurrentBin() );
222 Int_t ParamHistFunc::getCurrentBin() const {
223  Int_t dataSetIndex = _dataSet.getIndex( _dataVars ); // calcTreeIndex();
224  return dataSetIndex;
225 
226 }
227 
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Get the parameter associate with the the
231 /// input RooDataHist style index
232 /// It uses the binMap to convert the RooDataSet style index
233 /// into the TH1 style index (which is how they are stored
234 /// internally in the '_paramSet' vector
235 RooRealVar& ParamHistFunc::getParameter( Int_t index ) const {
236  Int_t gammaIndex = -1;
237  if( _binMap.find( index ) != _binMap.end() ) {
238  gammaIndex = _binMap[ index ];
239  }
240  else {
241  std::cout << "Error: ParamHistFunc internal bin index map "
242  << "not properly configured" << std::endl;
243  throw -1;
244  }
245 
246  return (RooRealVar&) _paramSet[gammaIndex];
247 }
248 
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 
252 RooRealVar& ParamHistFunc::getParameter() const {
253  Int_t index = getCurrentBin();
254  return getParameter( index );
255 }
256 
257 
258 void ParamHistFunc::setParamConst( Int_t index, Bool_t varConst ) {
259  RooRealVar& var = getParameter( index );
260  var.setConstant( varConst );
261 }
262 
263 
264 void ParamHistFunc::setConstant( bool constant ) {
265  for( int i=0; i < numBins(); ++i) {
266  setParamConst(i, constant);
267  }
268 }
269 
270 
271 ////////////////////////////////////////////////////////////////////////////////
272 
273 void ParamHistFunc::setShape( TH1* shape ) {
274  int num_hist_bins = shape->GetNbinsX()*shape->GetNbinsY()*shape->GetNbinsZ();
275 
276  if( num_hist_bins != numBins() ) {
277  std::cout << "Error - ParamHistFunc: cannot set Shape of ParamHistFunc: " << GetName()
278  << " using histogram: " << shape->GetName()
279  << ". Bins don't match" << std::endl;
280  throw std::runtime_error("setShape");
281  }
282 
283 
284  Int_t TH1BinNumber = 0;
285  for( Int_t i = 0; i < numBins(); ++i) {
286 
287  TH1BinNumber++;
288 
289  while( shape->IsBinUnderflow(TH1BinNumber) || shape->IsBinOverflow(TH1BinNumber) ){
290  TH1BinNumber++;
291  }
292 
293  //RooRealVar& var = dynamic_cast<RooRealVar&>(getParameter(i));
294  RooRealVar& var = dynamic_cast<RooRealVar&>(_paramSet[i]);
295  var.setVal( shape->GetBinContent(TH1BinNumber) );
296  }
297 
298 }
299 
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Create the list of RooRealVar
303 /// parameters which represent the
304 /// height of the histogram bins.
305 /// The list 'vars' represents the
306 /// observables (corresponding to histogram bins)
307 /// that these newly created parameters will
308 /// be mapped to. (ie, we create one parameter
309 /// per observable in vars and per bin in each observable)
310 
311 /// Store them in a list using:
312 /// _paramSet.add( createParamSet() );
313 /// This list is stored in the "TH1" index order
314 RooArgList ParamHistFunc::createParamSet(RooWorkspace& w, const std::string& Prefix,
315  const RooArgList& vars) {
316 
317 
318  // Get the number of bins
319  // in the nominal histogram
320 
321  RooArgList paramSet;
322 
323  Int_t numVars = vars.getSize();
324  Int_t numBins = GetNumBins( vars );
325 
326  if( numVars == 0 ) {
327  std::cout << "Warning - ParamHistFunc::createParamSet() :"
328  << " No Variables provided. Not making constraint terms."
329  << std::endl;
330  return paramSet;
331  }
332 
333  else if( numVars == 1 ) {
334 
335  // For each bin, create a RooRealVar
336  for( Int_t i = 0; i < numBins; ++i) {
337 
338  std::stringstream VarNameStream;
339  VarNameStream << Prefix << "_bin_" << i;
340  std::string VarName = VarNameStream.str();
341 
342  RooRealVar gamma( VarName.c_str(), VarName.c_str(), 1.0 );
343  // "Hard-Code" a minimum of 0.0
344  gamma.setMin( 0.0 );
345  gamma.setConstant( false );
346 
347  w.import( gamma, RooFit::RecycleConflictNodes() );
348  RooRealVar* gamma_wspace = (RooRealVar*) w.var( VarName.c_str() );
349 
350  paramSet.add( *gamma_wspace );
351 
352  }
353  }
354 
355  else if( numVars == 2 ) {
356 
357  // Create a vector of indices
358  // all starting at 0
359  std::vector< Int_t > Indices(numVars, 0);
360 
361  RooRealVar* varx = (RooRealVar*) vars.at(0);
362  RooRealVar* vary = (RooRealVar*) vars.at(1);
363 
364  // For each bin, create a RooRealVar
365  for( Int_t j = 0; j < vary->numBins(); ++j) {
366  for( Int_t i = 0; i < varx->numBins(); ++i) {
367 
368  // Ordering is important:
369  // To match TH1, list goes over x bins
370  // first, then y
371 
372  std::stringstream VarNameStream;
373  VarNameStream << Prefix << "_bin_" << i << "_" << j;
374  std::string VarName = VarNameStream.str();
375 
376  RooRealVar gamma( VarName.c_str(), VarName.c_str(), 1.0 );
377  // "Hard-Code" a minimum of 0.0
378  gamma.setMin( 0.0 );
379  gamma.setConstant( false );
380 
381  w.import( gamma, RooFit::RecycleConflictNodes() );
382  RooRealVar* gamma_wspace = (RooRealVar*) w.var( VarName.c_str() );
383 
384  paramSet.add( *gamma_wspace );
385 
386  }
387  }
388  }
389 
390  else if( numVars == 3 ) {
391 
392  // Create a vector of indices
393  // all starting at 0
394  std::vector< Int_t > Indices(numVars, 0);
395 
396  RooRealVar* varx = (RooRealVar*) vars.at(0);
397  RooRealVar* vary = (RooRealVar*) vars.at(1);
398  RooRealVar* varz = (RooRealVar*) vars.at(2);
399 
400  // For each bin, create a RooRealVar
401  for( Int_t k = 0; k < varz->numBins(); ++k) {
402  for( Int_t j = 0; j < vary->numBins(); ++j) {
403  for( Int_t i = 0; i < varx->numBins(); ++i) {
404 
405  // Ordering is important:
406  // To match TH1, list goes over x bins
407  // first, then y, then z
408 
409  std::stringstream VarNameStream;
410  VarNameStream << Prefix << "_bin_" << i << "_" << j << "_" << k;
411  std::string VarName = VarNameStream.str();
412 
413  RooRealVar gamma( VarName.c_str(), VarName.c_str(), 1.0 );
414  // "Hard-Code" a minimum of 0.0
415  gamma.setMin( 0.0 );
416  gamma.setConstant( false );
417 
418  w.import( gamma, RooFit::RecycleConflictNodes() );
419  RooRealVar* gamma_wspace = (RooRealVar*) w.var( VarName.c_str() );
420 
421  paramSet.add( *gamma_wspace );
422 
423  }
424  }
425  }
426  }
427 
428  else {
429  std::cout << " Error: ParamHistFunc doesn't support dimensions > 3D " << std::endl;
430  }
431 
432  return paramSet;
433 
434 }
435 
436 
437 ////////////////////////////////////////////////////////////////////////////////
438 /// Create the list of RooRealVar
439 /// parameters which represent the
440 /// height of the histogram bins.
441 /// The list 'vars' represents the
442 /// observables (corresponding to histogram bins)
443 /// that these newly created parameters will
444 /// be mapped to. (ie, we create one parameter
445 /// per observable in vars and per bin in each observable)
446 
447 /// Store them in a list using:
448 /// _paramSet.add( createParamSet() );
449 /// This list is stored in the "TH1" index order
450 RooArgList ParamHistFunc::createParamSet(RooWorkspace& w, const std::string& Prefix,
451  const RooArgList& vars,
452  Double_t gamma_min, Double_t gamma_max) {
453 
454 
455  // Get the number of bins
456  // in the nominal histogram
457 
458  // We also set the parameters to have nominal min and max values
459 
460  RooArgList params = ParamHistFunc::createParamSet( w, Prefix, vars );
461 
462  for (auto comp : params) {
463 
464  RooRealVar* var = (RooRealVar*) comp;
465 
466  var->setMin( gamma_min );
467  var->setMax( gamma_max );
468  }
469 
470  return params;
471 
472 }
473 
474 
475 ////////////////////////////////////////////////////////////////////////////////
476 /// Create the list of RooRealVar
477 /// parameters which represent the
478 /// height of the histogram bins.
479 /// Store them in a list
480 RooArgList ParamHistFunc::createParamSet(const std::string& Prefix, Int_t numBins,
481  Double_t gamma_min, Double_t gamma_max) {
482 
483 
484  // _paramSet.add( createParamSet() );
485 
486  // Get the number of bins
487  // in the nominal histogram
488 
489  RooArgList paramSet;
490 
491  if( gamma_max <= gamma_min ) {
492 
493  std::cout << "Warning: gamma_min <= gamma_max: Using default values (0, 10)" << std::endl;
494 
495  gamma_min = 0.0;
496  gamma_max = 10.0;
497 
498  }
499 
500  Double_t gamma_nominal = 1.0;
501 
502  if( gamma_nominal < gamma_min ) {
503  gamma_nominal = gamma_min;
504  }
505 
506  if( gamma_nominal > gamma_max ) {
507  gamma_nominal = gamma_max;
508  }
509 
510  // For each bin, create a RooRealVar
511  for( Int_t i = 0; i < numBins; ++i) {
512 
513  std::stringstream VarNameStream;
514  VarNameStream << Prefix << "_bin_" << i;
515  std::string VarName = VarNameStream.str();
516 
517  RooRealVar* gamma = new RooRealVar( VarName.c_str(), VarName.c_str(),
518  gamma_nominal, gamma_min, gamma_max );
519  gamma->setConstant( false );
520  paramSet.add( *gamma );
521 
522  }
523 
524  return paramSet;
525 
526 }
527 
528 
529 ////////////////////////////////////////////////////////////////////////////////
530 /// return 0 for success
531 /// return 1 for failure
532 /// Check that the elements
533 /// are actually RooRealVar's
534 /// If so, add them to the
535 /// list of vars
536 Int_t ParamHistFunc::addVarSet( const RooArgList& vars ) {
537 
538 
539  int numVars = 0;
540 
541  RooFIter varIter = vars.fwdIterator() ;
542  RooAbsArg* comp ;
543  while((comp = (RooAbsArg*) varIter.next())) {
544  if (!dynamic_cast<RooRealVar*>(comp)) {
545  coutE(InputArguments) << "ParamHistFunc::(" << GetName() << ") ERROR: component "
546  << comp->GetName() << " in variables list is not of type RooRealVar"
547  << std::endl;
548  RooErrorHandler::softAbort() ;
549  return 1;
550  }
551 
552  _dataVars.add( *comp );
553  numVars++;
554 
555  }
556 
557  Int_t numBinsX = 1;
558  Int_t numBinsY = 1;
559  Int_t numBinsZ = 1;
560 
561  if( numVars == 1 ) {
562  RooRealVar* varX = (RooRealVar*) _dataVars.at(0);
563  numBinsX = varX->numBins();
564  numBinsY = 1;
565  numBinsZ = 1;
566  } else if( numVars == 2 ) {
567  RooRealVar* varX = (RooRealVar*) _dataVars.at(0);
568  RooRealVar* varY = (RooRealVar*) _dataVars.at(1);
569  numBinsX = varX->numBins();
570  numBinsY = varY->numBins();
571  numBinsZ = 1;
572  } else if( numVars == 3 ) {
573  RooRealVar* varX = (RooRealVar*) _dataVars.at(0);
574  RooRealVar* varY = (RooRealVar*) _dataVars.at(1);
575  RooRealVar* varZ = (RooRealVar*) _dataVars.at(2);
576  numBinsX = varX->numBins();
577  numBinsY = varY->numBins();
578  numBinsZ = varZ->numBins();
579  } else {
580  std::cout << "ParamHistFunc() - Only works for 1-3 variables (1d-3d)" << std::endl;
581  throw -1;
582  }
583 
584  // Fill the mapping between
585  // RooDataHist bins and TH1 Bins:
586 
587  // Clear the map
588  _binMap.clear();
589 
590  // Fill the map
591  for( Int_t i = 0; i < numBinsX; ++i ) {
592  for( Int_t j = 0; j < numBinsY; ++j ) {
593  for( Int_t k = 0; k < numBinsZ; ++k ) {
594 
595  Int_t RooDataSetBin = k + j*numBinsZ + i*numBinsY*numBinsZ;
596  Int_t TH1HistBin = i + j*numBinsX + k*numBinsX*numBinsY;
597 
598  _binMap[RooDataSetBin] = TH1HistBin;
599 
600  }
601  }
602  }
603 
604  return 0;
605 
606 }
607 
608 
609 ////////////////////////////////////////////////////////////////////////////////
610 
611 Int_t ParamHistFunc::addParamSet( const RooArgList& params ) {
612  // return 0 for success
613  // return 1 for failure
614 
615  // Check that the supplied list has
616  // the right number of arguments:
617 
618  Int_t numVarBins = _numBins;
619  Int_t numElements = params.getSize();
620 
621  if( numVarBins != numElements ) {
622  std::cout << "ParamHistFunc::addParamSet - ERROR - "
623  << "Supplied list of parameters " << params.GetName()
624  << " has " << numElements << " elements but the ParamHistFunc"
625  << GetName() << " has " << numVarBins << " bins."
626  << std::endl;
627  return 1;
628 
629  }
630 
631  // Check that the elements
632  // are actually RooRealVar's
633  // If so, add them to the
634  // list of params
635 
636  RooFIter paramIter = params.fwdIterator() ;
637  RooAbsArg* comp ;
638  while((comp = (RooAbsArg*) paramIter.next())) {
639  if (!dynamic_cast<RooRealVar*>(comp)) {
640  coutE(InputArguments) << "ParamHistFunc::(" << GetName() << ") ERROR: component "
641  << comp->GetName() << " in paramater list is not of type RooRealVar"
642  << std::endl;
643  RooErrorHandler::softAbort() ;
644  return 1;
645  }
646 
647  _paramSet.add( *comp );
648 
649  }
650 
651  return 0;
652 
653 }
654 
655 
656 ////////////////////////////////////////////////////////////////////////////////
657 
658 Double_t ParamHistFunc::evaluate() const
659 {
660  // Find the bin cooresponding to the current
661  // value of the RooRealVar:
662 
663  RooRealVar* param = (RooRealVar*) &(getParameter());
664  Double_t value = param->getVal();
665  return value;
666 
667 }
668 
669 
670 ////////////////////////////////////////////////////////////////////////////////
671 /// Advertise that all integrals can be handled internally.
672 
673 Int_t ParamHistFunc::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars,
674  const RooArgSet* normSet,
675  const char* /*rangeName*/) const
676 {
677  // Handle trivial no-integration scenario
678  if (allVars.getSize()==0) return 0 ;
679  if (_forceNumInt) return 0 ;
680 
681 
682  // Select subset of allVars that are actual dependents
683  analVars.add(allVars) ;
684 
685  // Check if this configuration was created before
686  Int_t sterileIdx(-1) ;
687  CacheElem* cache = (CacheElem*) _normIntMgr.getObj(normSet,&analVars,&sterileIdx,(const char*)0) ;
688  if (cache) {
689  return _normIntMgr.lastIndex()+1 ;
690  }
691 
692  // Create new cache element
693  cache = new CacheElem ;
694 
695  // Store cache element
696  Int_t code = _normIntMgr.setObj(normSet,&analVars,(RooAbsCacheElement*)cache,0) ;
697 
698  return code+1 ;
699 
700 }
701 
702 
703 ////////////////////////////////////////////////////////////////////////////////
704 /// Implement analytical integrations by doing appropriate weighting from component integrals
705 /// functions to integrators of components
706 
707 Double_t ParamHistFunc::analyticalIntegralWN(Int_t /*code*/, const RooArgSet* /*normSet2*/,
708  const char* /*rangeName*/) const
709 {
710  Double_t value(0) ;
711 
712  // Simply loop over bins,
713  // get the height, and
714  // multiply by the bind width
715 
716  RooFIter paramIter = _paramSet.fwdIterator();
717  RooRealVar* param = NULL;
718  Int_t nominalItr = 0;
719  while((param = (RooRealVar*) paramIter.next())) {
720 
721  // Get the gamma's value
722  Double_t paramVal = (*param).getVal();
723 
724  // Get the bin volume
725  _dataSet.get( nominalItr );
726  Double_t binVolumeDS = _dataSet.binVolume(); //_binning->binWidth( nominalItr );
727 
728  // Finally, get the subtotal
729  value += paramVal*binVolumeDS;
730 
731  ++nominalItr;
732 
733  /*
734  std::cout << "Integrating : "
735  << " bin: " << nomValue
736  << " binVolume: " << binVolumeDS
737  << " paramValue: " << paramVal
738  << " nomValue: " << nomValue
739  << " subTotal: " << value
740  << std::endl;
741  */
742 
743  }
744 
745  return value;
746 
747 }
748 
749 
750 
751 ////////////////////////////////////////////////////////////////////////////////
752 /// Return sampling hint for making curves of (projections) of this function
753 /// as the recursive division strategy of RooCurve cannot deal efficiently
754 /// with the vertical lines that occur in a non-interpolated histogram
755 
756 std::list<Double_t>* ParamHistFunc::plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo,
757  Double_t xhi) const
758 {
759  // copied and edited from RooHistFunc
760  RooAbsLValue* lvarg = &obs;
761 
762  // Retrieve position of all bin boundaries
763  const RooAbsBinning* binning = lvarg->getBinningPtr(0) ;
764  Double_t* boundaries = binning->array() ;
765 
766  std::list<Double_t>* hint = new std::list<Double_t> ;
767 
768  // Widen range slighty
769  xlo = xlo - 0.01*(xhi-xlo) ;
770  xhi = xhi + 0.01*(xhi-xlo) ;
771 
772  Double_t delta = (xhi-xlo)*1e-8 ;
773 
774  // Construct array with pairs of points positioned epsilon to the left and
775  // right of the bin boundaries
776  for (Int_t i=0 ; i<binning->numBoundaries() ; i++) {
777  if (boundaries[i]>=xlo && boundaries[i]<=xhi) {
778  hint->push_back(boundaries[i]-delta) ;
779  hint->push_back(boundaries[i]+delta) ;
780  }
781  }
782  return hint ;
783 }
784 
785 
786 ////////////////////////////////////////////////////////////////////////////////
787 /// Return sampling hint for making curves of (projections) of this function
788 /// as the recursive division strategy of RooCurve cannot deal efficiently
789 /// with the vertical lines that occur in a non-interpolated histogram
790 
791 std::list<Double_t>* ParamHistFunc::binBoundaries(RooAbsRealLValue& obs, Double_t xlo,
792  Double_t xhi) const
793 {
794  // copied and edited from RooHistFunc
795  RooAbsLValue* lvarg = &obs;
796 
797  // Retrieve position of all bin boundaries
798  const RooAbsBinning* binning = lvarg->getBinningPtr(0) ;
799  Double_t* boundaries = binning->array() ;
800 
801  std::list<Double_t>* hint = new std::list<Double_t> ;
802 
803  // Construct array with pairs of points positioned epsilon to the left and
804  // right of the bin boundaries
805  for (Int_t i=0 ; i<binning->numBoundaries() ; i++) {
806  if (boundaries[i]>=xlo && boundaries[i]<=xhi) {
807  hint->push_back(boundaries[i]) ;
808  }
809  }
810 
811  return hint ;
812 }