CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
cacheutils::CachingSimNLL Class Reference

#include <CachingNLL.h>

Inheritance diagram for cacheutils::CachingSimNLL:

Classes

class  SimpleGaussianConstraint
 

Public Member Functions

 CachingSimNLL (RooSimultaneous *pdf, RooAbsData *data, const RooArgSet *nuis=0)
 
 CachingSimNLL (const CachingSimNLL &other, const char *name=0)
 
void clearZeroPoint ()
 
virtual CachingSimNLLclone (const char *name=0) const
 
virtual Double_t defaultErrorLevel () const
 
virtual Double_t evaluate () const
 
virtual RooArgSet * getObservables (const RooArgSet *depList, Bool_t valueOnly=kTRUE) const
 
virtual RooArgSet * getParameters (const RooArgSet *depList, Bool_t stripDisconnected=kTRUE) const
 
virtual Bool_t isDerived () const
 
void setData (const RooAbsData &data)
 
void setZeroPoint ()
 
void splitWithWeights (const RooAbsData &data, const RooAbsCategory &splitCat, Bool_t createEmptyDataSets)
 
 ~CachingSimNLL ()
 

Static Public Member Functions

static void setNoDeepLogEvalError (bool noDeep)
 

Private Member Functions

void setup_ ()
 

Private Attributes

std::vector< RooAbsPdf * > constrainPdfs_
 
std::vector
< SimpleGaussianConstraint * > 
constrainPdfsFast_
 
std::vector< double > constrainZeroPoints_
 
std::vector< double > constrainZeroPointsFast_
 
const RooAbsData * dataOriginal_
 
std::auto_ptr< TList > dataSets_
 
std::vector< RooDataSet * > datasets_
 
std::auto_ptr< RooSimultaneous > factorizedPdf_
 
const RooArgSet * nuis_
 
RooSetProxy params_
 
RooSimultaneous * pdfOriginal_
 
std::vector< CachingAddNLL * > pdfs_
 
RooArgSet piecesForCloning_
 

Static Private Attributes

static bool hasError_ = false
 
static bool noDeepLEE_ = false
 

Friends

class CachingAddNLL
 

Detailed Description

Definition at line 104 of file CachingNLL.h.

Constructor & Destructor Documentation

cacheutils::CachingSimNLL::CachingSimNLL ( RooSimultaneous *  pdf,
RooAbsData *  data,
const RooArgSet *  nuis = 0 
)

Definition at line 464 of file CachingNLL.cc.

References setup_().

464  :
465  pdfOriginal_(pdf),
467  nuis_(nuis),
468  params_("params","parameters",this)
469 {
470  setup_();
471 }
RooSimultaneous * pdfOriginal_
Definition: CachingNLL.h:133
const RooAbsData * dataOriginal_
Definition: CachingNLL.h:134
const RooArgSet * nuis_
Definition: CachingNLL.h:135
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
cacheutils::CachingSimNLL::CachingSimNLL ( const CachingSimNLL other,
const char *  name = 0 
)

Definition at line 473 of file CachingNLL.cc.

References setup_().

473  :
474  pdfOriginal_(other.pdfOriginal_),
475  dataOriginal_(other.dataOriginal_),
476  nuis_(other.nuis_),
477  params_("params","parameters",this)
478 {
479  setup_();
480 }
RooSimultaneous * pdfOriginal_
Definition: CachingNLL.h:133
const RooAbsData * dataOriginal_
Definition: CachingNLL.h:134
const RooArgSet * nuis_
Definition: CachingNLL.h:135
cacheutils::CachingSimNLL::~CachingSimNLL ( )

Definition at line 488 of file CachingNLL.cc.

489 {
490  for (std::vector<SimpleGaussianConstraint*>::iterator it = constrainPdfsFast_.begin(), ed = constrainPdfsFast_.end(); it != ed; ++it) {
491  delete *it;
492  }
493 }
std::vector< SimpleGaussianConstraint * > constrainPdfsFast_
Definition: CachingNLL.h:140

Member Function Documentation

void cacheutils::CachingSimNLL::clearZeroPoint ( )

Definition at line 667 of file CachingNLL.cc.

References lumiContext::fill.

Referenced by CascadeMinimizer::improve(), and CascadeMinimizer::improveOnce().

667  {
668  for (std::vector<CachingAddNLL*>::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
669  if (*it != 0) (*it)->clearZeroPoint();
670  }
673  setValueDirty();
674 }
string fill
Definition: lumiContext.py:319
std::vector< double > constrainZeroPointsFast_
Definition: CachingNLL.h:147
std::vector< CachingAddNLL * > pdfs_
Definition: CachingNLL.h:141
std::vector< double > constrainZeroPoints_
Definition: CachingNLL.h:146
cacheutils::CachingSimNLL * cacheutils::CachingSimNLL::clone ( const char *  name = 0) const
virtual

Definition at line 483 of file CachingNLL.cc.

virtual Double_t cacheutils::CachingSimNLL::defaultErrorLevel ( ) const
inlinevirtual

Definition at line 112 of file CachingNLL.h.

112 { return 0.5; }
Double_t cacheutils::CachingSimNLL::evaluate ( ) const
virtual

============= GENERIC CONSTRAINTS =========

============= FAST GAUSSIAN CONSTRAINTS =========

Definition at line 568 of file CachingNLL.cc.

References PerfCounter::add(), alignCSCRings::e, create_public_lumi_plots::log, run_regression::ret, TRACE_NLL, and TRACE_POINT.

569 {
571 #ifdef DEBUG_CACHE
572  PerfCounter::add("CachingSimNLL::evaluate called");
573 #endif
574  double ret = 0;
575  for (std::vector<CachingAddNLL*>::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
576  if (*it != 0) {
577  double nllval = (*it)->getVal();
578  // what sanity check could I put here?
579  ret += nllval;
580  }
581  }
582  if (!constrainPdfs_.empty()) {
584  std::vector<double>::const_iterator itz = constrainZeroPoints_.begin();
585  for (std::vector<RooAbsPdf *>::const_iterator it = constrainPdfs_.begin(), ed = constrainPdfs_.end(); it != ed; ++it, ++itz) {
586  double pdfval = (*it)->getVal(nuis_);
587  if (!isnormal(pdfval) || pdfval <= 0) {
588  if (!noDeepLEE_) logEvalError((std::string("Constraint pdf ")+(*it)->GetName()+" evaluated to zero, negative or error").c_str());
589  pdfval = 1e-9;
590  }
591  ret -= (log(pdfval) + *itz);
592  }
594  itz = constrainZeroPointsFast_.begin();
595  for (std::vector<SimpleGaussianConstraint*>::const_iterator it = constrainPdfsFast_.begin(), ed = constrainPdfsFast_.end(); it != ed; ++it, ++itz) {
596  double logpdfval = (*it)->getLogValFast();
597  ret -= (logpdfval + *itz);
598  }
599  }
600 #ifdef TRACE_NLL_EVALS
601  static unsigned long _trace_ = 0; _trace_++;
602  if (_trace_ % 10 == 0) { putchar('.'); fflush(stdout); }
603  //if (_trace_ % 250 == 0) { printf(" NLL % 10.4f after %10lu evals.\n", ret, _trace_); fflush(stdout); }
604 #endif
605  TRACE_NLL("SimNLL for " << GetName() << ": " << ret)
606  return ret;
607 }
#define TRACE_NLL(x)
Definition: CachingNLL.cc:59
void add(double increment=1.0)
std::vector< RooAbsPdf * > constrainPdfs_
Definition: CachingNLL.h:139
std::vector< SimpleGaussianConstraint * > constrainPdfsFast_
Definition: CachingNLL.h:140
std::vector< double > constrainZeroPointsFast_
Definition: CachingNLL.h:147
std::vector< CachingAddNLL * > pdfs_
Definition: CachingNLL.h:141
#define TRACE_POINT(x)
Definition: CachingNLL.cc:58
std::vector< double > constrainZeroPoints_
Definition: CachingNLL.h:146
const RooArgSet * nuis_
Definition: CachingNLL.h:135
RooArgSet * cacheutils::CachingSimNLL::getObservables ( const RooArgSet *  depList,
Bool_t  valueOnly = kTRUE 
) const
virtual

Definition at line 677 of file CachingNLL.cc.

678 {
679  return new RooArgSet();
680 }
RooArgSet * cacheutils::CachingSimNLL::getParameters ( const RooArgSet *  depList,
Bool_t  stripDisconnected = kTRUE 
) const
virtual

Definition at line 683 of file CachingNLL.cc.

684 {
685  return new RooArgSet(params_);
686 }
virtual Bool_t cacheutils::CachingSimNLL::isDerived ( ) const
inlinevirtual

Definition at line 111 of file CachingNLL.h.

111 { return kTRUE; }
void cacheutils::CachingSimNLL::setData ( const RooAbsData &  data)

Definition at line 610 of file CachingNLL.cc.

References data, and cacheutils::CachingAddNLL::setData().

611 {
612  dataOriginal_ = &data;
613  //std::cout << "combined data has " << data.numEntries() << " dataset entries (sumw " << data.sumEntries() << ", weighted " << data.isWeighted() << ")" << std::endl;
614  //utils::printRAD(&data);
615  //dataSets_.reset(dataOriginal_->split(pdfOriginal_->indexCat(), true));
616  splitWithWeights(*dataOriginal_, pdfOriginal_->indexCat(), true);
617  for (int ib = 0, nb = pdfs_.size(); ib < nb; ++ib) {
618  CachingAddNLL *canll = pdfs_[ib];
619  if (canll == 0) continue;
620  RooAbsData *data = datasets_[ib];
621  //RooAbsData *data = (RooAbsData *) dataSets_->FindObject(canll->GetName());
622  if (data == 0) { throw std::logic_error("Error: no data"); }
623  //std::cout << " bin " << ib << " (label " << canll->GetName() << ") has pdf " << canll->pdf()->GetName() << " of type " << canll->pdf()->ClassName() <<
624  // " and " << (data ? data->numEntries() : -1) << " dataset entries (sumw " << data->sumEntries() << ", weighted " << data->isWeighted() << ")" << std::endl;
625  canll->setData(*data);
626  }
627 }
void splitWithWeights(const RooAbsData &data, const RooAbsCategory &splitCat, Bool_t createEmptyDataSets)
Definition: CachingNLL.cc:629
RooSimultaneous * pdfOriginal_
Definition: CachingNLL.h:133
const RooAbsData * dataOriginal_
Definition: CachingNLL.h:134
std::vector< RooDataSet * > datasets_
Definition: CachingNLL.h:143
std::vector< CachingAddNLL * > pdfs_
Definition: CachingNLL.h:141
friend class CachingAddNLL
Definition: CachingNLL.h:120
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static void cacheutils::CachingSimNLL::setNoDeepLogEvalError ( bool  noDeep)
inlinestatic

Definition at line 117 of file CachingNLL.h.

References noDeepLEE_.

117 { noDeepLEE_ = noDeep; }
void cacheutils::CachingSimNLL::setup_ ( )
private

Definition at line 496 of file CachingNLL.cc.

References dtNoiseDBValidation_cfg::cerr, createBeamHaloJobs::constraints, gather_cfg::cout, data, utils::factorizePdf(), runtimedef::get(), i, n, and NULL.

Referenced by CachingSimNLL().

497 {
498  // Allow runtime-flag to switch off logEvalErrors
499  noDeepLEE_ = runtimedef::get("SIMNLL_NO_LEE");
500 
501  //RooAbsPdf *pdfclone = runtimedef::get("SIMNLL_CLONE") ? pdfOriginal_ : utils::fullClonePdf(pdfOriginal_, piecesForCloning_);
502  RooAbsPdf *pdfclone = pdfOriginal_; // never clone
503 
504  //---- Instead of getting the parameters here, we get them from the individual constraint terms and single pdfs ----
505  //---- This seems to save memory.
506  //std::auto_ptr<RooArgSet> params(pdfclone->getParameters(*dataOriginal_));
507  //params_.add(*params);
508 
509  RooArgList constraints;
510  factorizedPdf_.reset(dynamic_cast<RooSimultaneous *>(utils::factorizePdf(*dataOriginal_->get(), *pdfclone, constraints)));
511 
512  RooSimultaneous *simpdf = factorizedPdf_.get();
513  constrainPdfs_.clear();
514  if (constraints.getSize()) {
515  bool FastConstraints = runtimedef::get("SIMNLL_FASTGAUSS");
516  //constrainPdfs_.push_back(new RooProdPdf("constraints","constraints", constraints));
517  for (int i = 0, n = constraints.getSize(); i < n; ++i) {
518  RooAbsPdf *pdfi = dynamic_cast<RooAbsPdf*>(constraints.at(i));
519  if (FastConstraints && typeid(*pdfi) == typeid(RooGaussian)) {
520  constrainPdfsFast_.push_back(new SimpleGaussianConstraint(dynamic_cast<const RooGaussian&>(*pdfi)));
521  constrainZeroPointsFast_.push_back(0);
522  } else {
523  constrainPdfs_.push_back(pdfi);
524  constrainZeroPoints_.push_back(0);
525  }
526  //std::cout << "Constraint pdf: " << constraints.at(i)->GetName() << std::endl;
527  std::auto_ptr<RooArgSet> params(pdfi->getParameters(*dataOriginal_));
528  params_.add(*params, false);
529  }
530  } else {
531  std::cerr << "PDF didn't factorize!" << std::endl;
532  std::cout << "Parameters: " << std::endl;
533  std::auto_ptr<RooArgSet> params(pdfclone->getParameters(*dataOriginal_));
534  params->Print("V");
535  std::cout << "Obs: " << std::endl;
536  dataOriginal_->get()->Print("V");
537  factorizedPdf_.release();
538  simpdf = dynamic_cast<RooSimultaneous *>(pdfclone);
539  }
540 
541 
542  std::auto_ptr<RooAbsCategoryLValue> catClone((RooAbsCategoryLValue*) simpdf->indexCat().Clone());
543  pdfs_.resize(catClone->numBins(NULL), 0);
544  //dataSets_.reset(dataOriginal_->split(pdfOriginal_->indexCat(), true));
545  datasets_.resize(pdfs_.size(), 0);
546  splitWithWeights(*dataOriginal_, simpdf->indexCat(), true);
547  //std::cout << "Pdf " << simpdf->GetName() <<" is a SimPdf over category " << catClone->GetName() << ", with " << pdfs_.size() << " bins" << std::endl;
548  for (int ib = 0, nb = pdfs_.size(); ib < nb; ++ib) {
549  catClone->setBin(ib);
550  RooAbsPdf *pdf = simpdf->getPdf(catClone->getLabel());
551  if (pdf != 0) {
552  RooAbsData *data = (RooAbsData *) datasets_[ib]; //dataSets_->FindObject(catClone->getLabel());
553  //RooAbsData *data = (RooAbsData *) dataSets_->FindObject(catClone->getLabel());
554  //std::cout << " bin " << ib << " (label " << catClone->getLabel() << ") has pdf " << pdf->GetName() << " of type " << pdf->ClassName() << " and " << (data ? data->numEntries() : -1) << " dataset entries" << std::endl;
555  if (data == 0) { throw std::logic_error("Error: no data"); }
556  pdfs_[ib] = new CachingAddNLL(catClone->getLabel(), "", pdf, data);
557  params_.add(pdfs_[ib]->params(), /*silent=*/true);
558  } else {
559  pdfs_[ib] = 0;
560  //std::cout << " bin " << ib << " (label " << catClone->getLabel() << ") has no pdf" << std::endl;
561  }
562  }
563 
564  setValueDirty();
565 }
int i
Definition: DBlmapReader.cc:9
std::vector< RooAbsPdf * > constrainPdfs_
Definition: CachingNLL.h:139
int get(const char *name)
void splitWithWeights(const RooAbsData &data, const RooAbsCategory &splitCat, Bool_t createEmptyDataSets)
Definition: CachingNLL.cc:629
std::vector< SimpleGaussianConstraint * > constrainPdfsFast_
Definition: CachingNLL.h:140
std::auto_ptr< RooSimultaneous > factorizedPdf_
Definition: CachingNLL.h:138
#define NULL
Definition: scimark2.h:8
std::vector< double > constrainZeroPointsFast_
Definition: CachingNLL.h:147
RooSimultaneous * pdfOriginal_
Definition: CachingNLL.h:133
const RooAbsData * dataOriginal_
Definition: CachingNLL.h:134
std::vector< RooDataSet * > datasets_
Definition: CachingNLL.h:143
RooAbsPdf * factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &constraints)
Definition: utils.cc:80
std::vector< CachingAddNLL * > pdfs_
Definition: CachingNLL.h:141
std::vector< double > constrainZeroPoints_
Definition: CachingNLL.h:146
friend class CachingAddNLL
Definition: CachingNLL.h:120
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121
void cacheutils::CachingSimNLL::setZeroPoint ( )

Definition at line 650 of file CachingNLL.cc.

References create_public_lumi_plots::log.

Referenced by CascadeMinimizer::improveOnce().

650  {
651  for (std::vector<CachingAddNLL*>::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
652  if (*it != 0) (*it)->setZeroPoint();
653  }
654  std::vector<double>::iterator itz = constrainZeroPoints_.begin();
655  for (std::vector<RooAbsPdf *>::const_iterator it = constrainPdfs_.begin(), ed = constrainPdfs_.end(); it != ed; ++it, ++itz) {
656  double pdfval = (*it)->getVal(nuis_);
657  if (isnormal(pdfval) || pdfval > 0) *itz = -log(pdfval);
658  }
659  itz = constrainZeroPointsFast_.begin();
660  for (std::vector<SimpleGaussianConstraint*>::const_iterator it = constrainPdfsFast_.begin(), ed = constrainPdfsFast_.end(); it != ed; ++it, ++itz) {
661  double logpdfval = (*it)->getLogValFast();
662  *itz = -logpdfval;
663  }
664  setValueDirty();
665 }
std::vector< RooAbsPdf * > constrainPdfs_
Definition: CachingNLL.h:139
std::vector< SimpleGaussianConstraint * > constrainPdfsFast_
Definition: CachingNLL.h:140
std::vector< double > constrainZeroPointsFast_
Definition: CachingNLL.h:147
std::vector< CachingAddNLL * > pdfs_
Definition: CachingNLL.h:141
std::vector< double > constrainZeroPoints_
Definition: CachingNLL.h:146
const RooArgSet * nuis_
Definition: CachingNLL.h:135
void cacheutils::CachingSimNLL::splitWithWeights ( const RooAbsData &  data,
const RooAbsCategory &  splitCat,
Bool_t  createEmptyDataSets 
)

Definition at line 629 of file CachingNLL.cc.

References Clusterizer1DCommons::add(), i, Vispa.Plugins.EdmBrowser.EdmDataAccessor::ne(), and CommonMethods::weight().

629  {
630  RooCategory *cat = dynamic_cast<RooCategory *>(data.get()->find(splitCat.GetName()));
631  if (cat == 0) throw std::logic_error("Error: no category");
632  int nb = cat->numBins((const char *)0), ne = data.numEntries();
633  RooArgSet obs(*data.get()); obs.remove(*cat, true, true);
634  RooRealVar weight("_weight_","",1);
635  RooArgSet obsplus(obs); obsplus.add(weight);
636  if (nb != int(datasets_.size())) throw std::logic_error("Number of categories changed"); // this can happen due to bugs in RooDataSet
637  for (int ib = 0; ib < nb; ++ib) {
638  if (datasets_[ib] == 0) datasets_[ib] = new RooDataSet("", "", obsplus, "_weight_");
639  else datasets_[ib]->reset();
640  }
641  //utils::printRDH((RooAbsData*)&data);
642  for (int i = 0; i < ne; ++i) {
643  data.get(i); if (data.weight() == 0) continue;
644  int ib = cat->getBin();
645  //std::cout << "Event " << i << " of weight " << data.weight() << " is in bin " << ib << " label " << cat->getLabel() << std::endl;
646  if (data.weight() > 0) datasets_[ib]->add(obs, data.weight());
647  }
648 }
int i
Definition: DBlmapReader.cc:9
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
std::vector< RooDataSet * > datasets_
Definition: CachingNLL.h:143
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82

Friends And Related Function Documentation

friend class CachingAddNLL
friend

Definition at line 120 of file CachingNLL.h.

Member Data Documentation

std::vector<RooAbsPdf *> cacheutils::CachingSimNLL::constrainPdfs_
private

Definition at line 139 of file CachingNLL.h.

std::vector<SimpleGaussianConstraint *> cacheutils::CachingSimNLL::constrainPdfsFast_
private

Definition at line 140 of file CachingNLL.h.

std::vector<double> cacheutils::CachingSimNLL::constrainZeroPoints_
private

Definition at line 146 of file CachingNLL.h.

std::vector<double> cacheutils::CachingSimNLL::constrainZeroPointsFast_
private

Definition at line 147 of file CachingNLL.h.

const RooAbsData* cacheutils::CachingSimNLL::dataOriginal_
private

Definition at line 134 of file CachingNLL.h.

std::auto_ptr<TList> cacheutils::CachingSimNLL::dataSets_
private

Definition at line 142 of file CachingNLL.h.

std::vector<RooDataSet *> cacheutils::CachingSimNLL::datasets_
private

Definition at line 143 of file CachingNLL.h.

std::auto_ptr<RooSimultaneous> cacheutils::CachingSimNLL::factorizedPdf_
private

Definition at line 138 of file CachingNLL.h.

bool cacheutils::CachingSimNLL::hasError_ = false
staticprivate

Definition at line 145 of file CachingNLL.h.

Referenced by cacheutils::CachingAddNLL::evaluate().

bool cacheutils::CachingSimNLL::noDeepLEE_ = false
staticprivate

Definition at line 144 of file CachingNLL.h.

Referenced by cacheutils::CachingAddNLL::evaluate(), and setNoDeepLogEvalError().

const RooArgSet* cacheutils::CachingSimNLL::nuis_
private

Definition at line 135 of file CachingNLL.h.

RooSetProxy cacheutils::CachingSimNLL::params_
private

Definition at line 136 of file CachingNLL.h.

RooSimultaneous* cacheutils::CachingSimNLL::pdfOriginal_
private

Definition at line 133 of file CachingNLL.h.

std::vector<CachingAddNLL*> cacheutils::CachingSimNLL::pdfs_
private

Definition at line 141 of file CachingNLL.h.

RooArgSet cacheutils::CachingSimNLL::piecesForCloning_
private

Definition at line 137 of file CachingNLL.h.