CMS 3D CMS Logo

Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends

cacheutils::CachingSimNLL Class Reference

#include <CachingNLL.h>

List of all members.

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_().

                                                                                                    :
    pdfOriginal_(pdf),
    dataOriginal_(data),
    nuis_(nuis),
    params_("params","parameters",this)
{
    setup_();
}
cacheutils::CachingSimNLL::CachingSimNLL ( const CachingSimNLL other,
const char *  name = 0 
)

Definition at line 473 of file CachingNLL.cc.

References setup_().

                                                                                   :
    pdfOriginal_(other.pdfOriginal_),
    dataOriginal_(other.dataOriginal_),
    nuis_(other.nuis_),
    params_("params","parameters",this)
{
    setup_();
}
cacheutils::CachingSimNLL::~CachingSimNLL ( )

Definition at line 488 of file CachingNLL.cc.

{
    for (std::vector<SimpleGaussianConstraint*>::iterator it = constrainPdfsFast_.begin(), ed = constrainPdfsFast_.end(); it != ed; ++it) {
        delete *it;
    }
}

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().

                                             {
    for (std::vector<CachingAddNLL*>::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
        if (*it != 0) (*it)->clearZeroPoint();
    }
    std::fill(constrainZeroPoints_.begin(), constrainZeroPoints_.end(), 0.0);
    std::fill(constrainZeroPointsFast_.begin(), constrainZeroPointsFast_.end(), 0.0);
    setValueDirty();
}
cacheutils::CachingSimNLL * cacheutils::CachingSimNLL::clone ( const char *  name = 0) const [virtual]

Definition at line 483 of file CachingNLL.cc.

{
    return new cacheutils::CachingSimNLL(*this, name);
}
virtual Double_t cacheutils::CachingSimNLL::defaultErrorLevel ( ) const [inline, virtual]

Definition at line 112 of file CachingNLL.h.

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

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

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

Definition at line 568 of file CachingNLL.cc.

References Clusterizer1DCommons::add(), alignCSCRings::e, funct::log(), run_regression::ret, TRACE_NLL, and TRACE_POINT.

{
    TRACE_POINT(params_)
#ifdef DEBUG_CACHE
    PerfCounter::add("CachingSimNLL::evaluate called");
#endif
    double ret = 0;
    for (std::vector<CachingAddNLL*>::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
        if (*it != 0) {
            double nllval = (*it)->getVal();
            // what sanity check could I put here?
            ret += nllval;
        }
    }
    if (!constrainPdfs_.empty()) {
        std::vector<double>::const_iterator itz = constrainZeroPoints_.begin();
        for (std::vector<RooAbsPdf *>::const_iterator it = constrainPdfs_.begin(), ed = constrainPdfs_.end(); it != ed; ++it, ++itz) { 
            double pdfval = (*it)->getVal(nuis_);
            if (!isnormal(pdfval) || pdfval <= 0) {
                if (!noDeepLEE_) logEvalError((std::string("Constraint pdf ")+(*it)->GetName()+" evaluated to zero, negative or error").c_str());
                pdfval = 1e-9;
            }
            ret -= (log(pdfval) + *itz);
        }
        itz = constrainZeroPointsFast_.begin();
        for (std::vector<SimpleGaussianConstraint*>::const_iterator it = constrainPdfsFast_.begin(), ed = constrainPdfsFast_.end(); it != ed; ++it, ++itz) { 
            double logpdfval = (*it)->getLogValFast();
            ret -= (logpdfval + *itz);
        }
    }
#ifdef TRACE_NLL_EVALS
    static unsigned long _trace_ = 0; _trace_++;
    if (_trace_ % 10 == 0)  { putchar('.'); fflush(stdout); }
    //if (_trace_ % 250 == 0) { printf("               NLL % 10.4f after %10lu evals.\n", ret, _trace_); fflush(stdout); }
#endif
    TRACE_NLL("SimNLL for " << GetName() << ": " << ret)
    return ret;
}
RooArgSet * cacheutils::CachingSimNLL::getObservables ( const RooArgSet *  depList,
Bool_t  valueOnly = kTRUE 
) const [virtual]

Definition at line 677 of file CachingNLL.cc.

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

Definition at line 683 of file CachingNLL.cc.

{
    return new RooArgSet(params_); 
}
virtual Bool_t cacheutils::CachingSimNLL::isDerived ( ) const [inline, virtual]

Definition at line 111 of file CachingNLL.h.

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

Definition at line 610 of file CachingNLL.cc.

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

{
    dataOriginal_ = &data;
    //std::cout << "combined data has " << data.numEntries() << " dataset entries (sumw " << data.sumEntries() << ", weighted " << data.isWeighted() << ")" << std::endl;
    //utils::printRAD(&data);
    //dataSets_.reset(dataOriginal_->split(pdfOriginal_->indexCat(), true));
    splitWithWeights(*dataOriginal_, pdfOriginal_->indexCat(), true);
    for (int ib = 0, nb = pdfs_.size(); ib < nb; ++ib) {
        CachingAddNLL *canll = pdfs_[ib];
        if (canll == 0) continue;
        RooAbsData *data = datasets_[ib];
        //RooAbsData *data = (RooAbsData *) dataSets_->FindObject(canll->GetName());
        if (data == 0) { throw std::logic_error("Error: no data"); }
        //std::cout << "   bin " << ib << " (label " << canll->GetName() << ") has pdf " << canll->pdf()->GetName() << " of type " << canll->pdf()->ClassName() <<
        //             " and " << (data ? data->numEntries() : -1) << " dataset entries (sumw " << data->sumEntries() << ", weighted " << data->isWeighted() << ")" << std::endl;
        canll->setData(*data);
    }
}
static void cacheutils::CachingSimNLL::setNoDeepLogEvalError ( bool  noDeep) [inline, static]

Definition at line 117 of file CachingNLL.h.

References noDeepLEE_.

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

Definition at line 496 of file CachingNLL.cc.

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

Referenced by CachingSimNLL().

{
    // Allow runtime-flag to switch off logEvalErrors
    noDeepLEE_ = runtimedef::get("SIMNLL_NO_LEE");

    //RooAbsPdf *pdfclone = runtimedef::get("SIMNLL_CLONE") ? pdfOriginal_  : utils::fullClonePdf(pdfOriginal_, piecesForCloning_);
    RooAbsPdf *pdfclone = pdfOriginal_; // never clone

    //---- Instead of getting the parameters here, we get them from the individual constraint terms and single pdfs ----
    //---- This seems to save memory.
    //std::auto_ptr<RooArgSet> params(pdfclone->getParameters(*dataOriginal_));
    //params_.add(*params);

    RooArgList constraints;
    factorizedPdf_.reset(dynamic_cast<RooSimultaneous *>(utils::factorizePdf(*dataOriginal_->get(), *pdfclone, constraints)));
    
    RooSimultaneous *simpdf = factorizedPdf_.get();
    constrainPdfs_.clear(); 
    if (constraints.getSize()) {
        bool FastConstraints = runtimedef::get("SIMNLL_FASTGAUSS");
        //constrainPdfs_.push_back(new RooProdPdf("constraints","constraints", constraints));
        for (int i = 0, n = constraints.getSize(); i < n; ++i) {
            RooAbsPdf *pdfi = dynamic_cast<RooAbsPdf*>(constraints.at(i));
            if (FastConstraints && typeid(*pdfi) == typeid(RooGaussian)) {
                constrainPdfsFast_.push_back(new SimpleGaussianConstraint(dynamic_cast<const RooGaussian&>(*pdfi)));
                constrainZeroPointsFast_.push_back(0);
            } else {
                constrainPdfs_.push_back(pdfi);
                constrainZeroPoints_.push_back(0);
            }
            //std::cout << "Constraint pdf: " << constraints.at(i)->GetName() << std::endl;
            std::auto_ptr<RooArgSet> params(pdfi->getParameters(*dataOriginal_));
            params_.add(*params, false);
        }
    } else {
        std::cerr << "PDF didn't factorize!" << std::endl;
        std::cout << "Parameters: " << std::endl;
        std::auto_ptr<RooArgSet> params(pdfclone->getParameters(*dataOriginal_));
        params->Print("V");
        std::cout << "Obs: " << std::endl;
        dataOriginal_->get()->Print("V");
        factorizedPdf_.release();
        simpdf = dynamic_cast<RooSimultaneous *>(pdfclone);
    }

    
    std::auto_ptr<RooAbsCategoryLValue> catClone((RooAbsCategoryLValue*) simpdf->indexCat().Clone());
    pdfs_.resize(catClone->numBins(NULL), 0);
    //dataSets_.reset(dataOriginal_->split(pdfOriginal_->indexCat(), true));
    datasets_.resize(pdfs_.size(), 0);
    splitWithWeights(*dataOriginal_, simpdf->indexCat(), true);
    //std::cout << "Pdf " << simpdf->GetName() <<" is a SimPdf over category " << catClone->GetName() << ", with " << pdfs_.size() << " bins" << std::endl;
    for (int ib = 0, nb = pdfs_.size(); ib < nb; ++ib) {
        catClone->setBin(ib);
        RooAbsPdf *pdf = simpdf->getPdf(catClone->getLabel());
        if (pdf != 0) {
            RooAbsData *data = (RooAbsData *) datasets_[ib]; //dataSets_->FindObject(catClone->getLabel());
            //RooAbsData *data = (RooAbsData *) dataSets_->FindObject(catClone->getLabel());
            //std::cout << "   bin " << ib << " (label " << catClone->getLabel() << ") has pdf " << pdf->GetName() << " of type " << pdf->ClassName() << " and " << (data ? data->numEntries() : -1) << " dataset entries" << std::endl;
            if (data == 0) { throw std::logic_error("Error: no data"); }
            pdfs_[ib] = new CachingAddNLL(catClone->getLabel(), "", pdf, data);
            params_.add(pdfs_[ib]->params(), /*silent=*/true); 
        } else { 
            pdfs_[ib] = 0; 
            //std::cout << "   bin " << ib << " (label " << catClone->getLabel() << ") has no pdf" << std::endl;
        }
    }   

    setValueDirty();
}
void cacheutils::CachingSimNLL::setZeroPoint ( )

Definition at line 650 of file CachingNLL.cc.

References funct::log().

Referenced by CascadeMinimizer::improveOnce().

                                           {
    for (std::vector<CachingAddNLL*>::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
        if (*it != 0) (*it)->setZeroPoint();
    }
    std::vector<double>::iterator itz = constrainZeroPoints_.begin();
    for (std::vector<RooAbsPdf *>::const_iterator it = constrainPdfs_.begin(), ed = constrainPdfs_.end(); it != ed; ++it, ++itz) {
        double pdfval = (*it)->getVal(nuis_);
        if (isnormal(pdfval) || pdfval > 0) *itz = -log(pdfval);
    }
    itz = constrainZeroPointsFast_.begin();
    for (std::vector<SimpleGaussianConstraint*>::const_iterator it = constrainPdfsFast_.begin(), ed = constrainPdfsFast_.end(); it != ed; ++it, ++itz) {
        double logpdfval = (*it)->getLogValFast();
        *itz = -logpdfval;
    }
    setValueDirty();
}
void cacheutils::CachingSimNLL::splitWithWeights ( const RooAbsData &  data,
const RooAbsCategory &  splitCat,
Bool_t  createEmptyDataSets 
)

Definition at line 629 of file CachingNLL.cc.

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

                                                                                                                                 {
    RooCategory *cat = dynamic_cast<RooCategory *>(data.get()->find(splitCat.GetName()));
    if (cat == 0) throw std::logic_error("Error: no category");
    int nb = cat->numBins((const char *)0), ne = data.numEntries();
    RooArgSet obs(*data.get()); obs.remove(*cat, true, true);
    RooRealVar weight("_weight_","",1);
    RooArgSet obsplus(obs); obsplus.add(weight);
    if (nb != int(datasets_.size())) throw std::logic_error("Number of categories changed"); // this can happen due to bugs in RooDataSet
    for (int ib = 0; ib < nb; ++ib) {
        if (datasets_[ib] == 0) datasets_[ib] = new RooDataSet("", "", obsplus, "_weight_");
        else datasets_[ib]->reset();
    }
    //utils::printRDH((RooAbsData*)&data);
    for (int i = 0; i < ne; ++i) {
        data.get(i); if (data.weight() == 0) continue;
        int ib = cat->getBin();
        //std::cout << "Event " << i << " of weight " << data.weight() << " is in bin " << ib << " label " << cat->getLabel() << std::endl;
        if (data.weight() > 0) datasets_[ib]->add(obs, data.weight());
    }
}

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.

Definition at line 140 of file CachingNLL.h.

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

Definition at line 146 of file CachingNLL.h.

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 [static, private]

Definition at line 145 of file CachingNLL.h.

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

bool cacheutils::CachingSimNLL::noDeepLEE_ = false [static, private]

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.

Definition at line 141 of file CachingNLL.h.

Definition at line 137 of file CachingNLL.h.