CMS 3D CMS Logo

Classes | Functions | Variables

utils Namespace Reference

Classes

class  BinToBin
class  BinToBin1percent
struct  CheapValueSnapshot
class  Chi2
class  KS
class  StatisticalTest
class  unpickler

Functions

def ask_ok
bool checkModel (const RooStats::ModelConfig &model, bool throwOnFail=false)
void copyAttributes (const RooAbsArg &from, RooAbsArg &to)
void factorizeFunc (const RooArgSet &observables, RooAbsReal &pdf, RooArgList &obsTerms, RooArgList &otherTerms, bool debug=false)
 factorize a RooAbsReal
void factorizePdf (RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints, bool debug=false)
 collect factors depending on observables in obsTerms, and all others in constraints
void factorizePdf (const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints, bool debug=false)
RooAbsPdf * factorizePdf (const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &constraints)
RooAbsReal * fullCloneFunc (const RooAbsReal *pdf, RooArgSet &holder, bool cloneLeafNodes=false)
RooAbsPdf * fullClonePdf (const RooAbsPdf *pdf, RooArgSet &holder, bool cloneLeafNodes=false)
def get_relval_cmssw_version
def get_relval_id
def get_relval_max_version
def get_relval_version
 ------------------- Make files pairs: RelVal utils ---------------------
def get_relvaldata_cmssw_version
def get_relvaldata_id
 ----------------- Make files pairs: RelValData utils --------------------
def get_relvaldata_max_version
def get_relvaldata_version
void getClients (const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients)
 add to 'clients' all object within allObjects that *directly* depend on values
def getNbins
void guessChannelMode (RooSimultaneous &simPdf, RooAbsData &simData, bool verbose=false)
def is_empty
def is_relvaldata
 ------------------------- Make files pairs --------------------------
def is_sparse
def literal2root
def logger
def make_files_pairs
RooAbsPdf * makeNuisancePdf (RooAbsPdf &pdf, const RooArgSet &observables, const char *name="nuisancePdf")
RooAbsPdf * makeNuisancePdf (RooStats::ModelConfig &model, const char *name="nuisancePdf")
RooAbsPdf * makeObsOnlyPdf (RooStats::ModelConfig &model, const char *name="obsPdf")
 Note: doesn't recompose Simultaneous pdfs properly, for that use factorizePdf method.
std::vector< RooPlot * > makePlots (const RooAbsPdf &pdf, const RooAbsData &data, const char *signalSel=0, const char *backgroundSel=0, float rebinFactor=1.0)
 make plots, if possible
void printPdf (RooWorkspace *w, const char *pdfName)
void printPdf (RooStats::ModelConfig &model)
void printPdf (RooAbsPdf *pdf)
void printRAD (const RooAbsData *d)
void printRDH (RooAbsData *data)
def profile2histo
RooSimultaneous * rebuildSimPdf (const RooArgSet &observables, RooSimultaneous *pdf)
bool setAllConstant (const RooAbsCollection &coll, bool constant=true)
 set all RooRealVars to constants. return true if at least one changed status
def setTDRStyle
void tdrStyle ()
 set style for plots
def wget

Variables

int _log_level = 10
 theargv = sys.argv

Function Documentation

def utils::ask_ok (   prompt,
  retries = 4,
  complaint = 'yes or no' 
)

Definition at line 423 of file utils.py.

00424                                                     :
00425     while True:
00426         ok = raw_input(prompt)
00427         if ok in ('y', 'ye', 'yes'):
00428             return True
00429         if ok in ('n', 'no'):
00430             return False
00431         retries = retries - 1
00432         if retries < 0:
00433             raise IOError('refusenik user')
00434         print complaint
00435 
00436 #-------------------------------------------------------------------------------

bool utils::checkModel ( const RooStats::ModelConfig &  model,
bool  throwOnFail = false 
)

Performs the following checks:

  • global observables, if any, are RooRealVars and are const
  • nuisances, if any, are RooRealVars and are floating
  • parameters of interest are all RooRealVars and are floating
  • there are no other floating parameters except observables, nuisances and POI

Definition at line 261 of file utils.cc.

References a, gather_cfg::cout, benchmark_cfg::errors, convertSQLiteXML::ok, and v.

Referenced by Combine::run().

                                                                         {
    bool ok = true; std::ostringstream errors; 
    std::auto_ptr<TIterator> iter;
    RooAbsPdf *pdf = model.GetPdf(); if (pdf == 0) throw std::invalid_argument("Model without Pdf");
    RooArgSet allowedToFloat; 
    if (model.GetObservables() == 0) { 
        ok = false; errors << "ERROR: model does not define observables.\n"; 
        std::cout << errors.str() << std::endl;
        if (throwOnFail) throw std::invalid_argument(errors.str()); else return false; 
    } else {
        allowedToFloat.add(*model.GetObservables());
    }
    if (model.GetParametersOfInterest() == 0) { 
        ok = false; errors << "ERROR: model does not define parameters of interest.\n";  
    } else {
        iter.reset(model.GetParametersOfInterest()->createIterator());
        for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
            RooRealVar *v = dynamic_cast<RooRealVar *>(a);
            if (!v) { ok = false; errors << "ERROR: parameter of interest " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; }
            if (v->isConstant()) { ok = false; errors << "ERROR: parameter of interest " << a->GetName() << " is constant\n"; continue; }
            if (!pdf->dependsOn(*v)) { ok = false; errors << "ERROR: pdf does not depend on parameter of interest " << a->GetName() << "\n"; continue; }
            allowedToFloat.add(*v);
        }
    }
    if (model.GetNuisanceParameters() != 0) { 
        iter.reset(model.GetNuisanceParameters()->createIterator());
        for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
            RooRealVar *v = dynamic_cast<RooRealVar *>(a);
            if (!v) { ok = false; errors << "ERROR: nuisance parameter " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; }
            if (v->isConstant()) { ok = false; errors << "ERROR: nuisance parameter " << a->GetName() << " is constant\n"; continue; }
            if (!pdf->dependsOn(*v)) { errors << "WARNING: pdf does not depend on nuisance parameter " << a->GetName() << "\n"; continue; }
            allowedToFloat.add(*v);
        }
    }
    if (model.GetGlobalObservables() != 0) { 
        iter.reset(model.GetGlobalObservables()->createIterator());
        for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
            RooRealVar *v = dynamic_cast<RooRealVar *>(a);
            if (!v) { ok = false; errors << "ERROR: global observable " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; }
            if (!v->isConstant()) { ok = false; errors << "ERROR: global observable " << a->GetName() << " is not constant\n"; continue; }
            if (!pdf->dependsOn(*v)) { errors << "WARNING: pdf does not depend on global observable " << a->GetName() << "\n"; continue; }
        }
    }
    std::auto_ptr<RooArgSet> params(pdf->getParameters(*model.GetObservables()));
    iter.reset(params->createIterator());
    for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
        if (a->getAttribute("flatParam") && a->isConstant()) {
            ok = false; errors << "ERROR: parameter " << a->GetName() << " is declared as flatParam but is constant.\n";
        }
        if (a->isConstant() || allowedToFloat.contains(*a)) continue;
        if (a->getAttribute("flatParam")) {
            RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
            if (rrv->getVal() > rrv->getMax() || rrv->getVal() < rrv->getMin()) {
                ok = false; errors << "ERROR: flatParam " << rrv->GetName() << " has a value " << rrv->getVal() << 
                                      " outside of the defined range [" << rrv->getMin() << ", " << rrv->getMax() << "]\n";
            }
        } else {
            errors << "WARNING: pdf parameter " << a->GetName() << " (type " << a->ClassName() << ") is not allowed to float (it's not nuisance, poi, observable or global observable\n"; 
        }
    }
    iter.reset();
    std::cout << errors.str() << std::endl;
    if (!ok && throwOnFail) throw std::invalid_argument(errors.str()); 
    return ok;
}
void utils::copyAttributes ( const RooAbsArg &  from,
RooAbsArg &  to 
)

Definition at line 364 of file utils.cc.

Referenced by factorizePdf(), and rebuildSimPdf().

                                                               {
    if (&from == &to) return;
    const std::set<std::string> attribs = from.attributes();
    if (!attribs.empty()) {
        for (std::set<std::string>::const_iterator it = attribs.begin(), ed = attribs.end(); it != ed; ++it) to.setAttribute(it->c_str());
    }
    const std::map<std::string, std::string> strattribs = from.stringAttributes();
    if (!strattribs.empty()) {
        for (std::map<std::string,std::string>::const_iterator it = strattribs.begin(), ed = strattribs.end(); it != ed; ++it) to.setStringAttribute(it->first.c_str(), it->second.c_str());
    }
}
void utils::factorizeFunc ( const RooArgSet &  observables,
RooAbsReal &  pdf,
RooArgList &  obsTerms,
RooArgList &  otherTerms,
bool  debug = false 
)

factorize a RooAbsReal

Definition at line 177 of file utils.cc.

References makeMuonMisalignmentScenario::components, factorizePdf(), and parseEventContent::prod.

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

                                                                                                                                   {
    RooAbsPdf *pdf = dynamic_cast<RooAbsPdf *>(&func);
    if (pdf != 0) { 
        factorizePdf(observables, *pdf, obsTerms, constraints, debug); 
        return; 
    }
    const std::type_info & id = typeid(func);
    if (id == typeid(RooProduct)) {
        RooProduct *prod = dynamic_cast<RooProduct *>(&func);
        RooArgSet components(prod->components());
        //std::cout << "Function " << func.GetName() << " is a RooProduct with " << components.getSize() << " components." << std::endl;
        std::auto_ptr<TIterator> iter(components.createIterator());
        for (RooAbsReal *funci = (RooAbsReal *) iter->Next(); funci != 0; funci = (RooAbsReal *) iter->Next()) {
            //std::cout << "  component " << funci->GetName() << " of type " << funci->ClassName() << std::endl;
            factorizeFunc(observables, *funci, obsTerms, constraints);
        }
    } else if (func.dependsOn(observables)) {
        if (!obsTerms.contains(func)) obsTerms.add(func);
    } else {
        if (!constraints.contains(func)) constraints.add(func);
    }
}
void utils::factorizePdf ( RooStats::ModelConfig &  model,
RooAbsPdf &  pdf,
RooArgList &  obsTerms,
RooArgList &  constraints,
bool  debug = false 
)

collect factors depending on observables in obsTerms, and all others in constraints

Definition at line 149 of file utils.cc.

References createBeamHaloJobs::constraints, debug, and factorizePdf().

                                                                                                                              {
    return factorizePdf(*model.GetObservables(), pdf, obsTerms, constraints, debug);
}
void utils::factorizePdf ( const RooArgSet &  observables,
RooAbsPdf &  pdf,
RooArgList &  obsTerms,
RooArgList &  constraints,
bool  debug = false 
)

Definition at line 152 of file utils.cc.

References factorizePdf(), i, list(), n, and parseEventContent::prod.

                                                                                                                                {
    assert(&pdf);
    const std::type_info & id = typeid(pdf);
    if (id == typeid(RooProdPdf)) {
        RooProdPdf *prod = dynamic_cast<RooProdPdf *>(&pdf);
        RooArgList list(prod->pdfList());
        for (int i = 0, n = list.getSize(); i < n; ++i) {
            RooAbsPdf *pdfi = (RooAbsPdf *) list.at(i);
            factorizePdf(observables, *pdfi, obsTerms, constraints);
        }
    } else if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) {
        RooSimultaneous *sim  = dynamic_cast<RooSimultaneous *>(&pdf);
        RooAbsCategoryLValue *cat = (RooAbsCategoryLValue *) sim->indexCat().Clone();
        for (int ic = 0, nc = cat->numBins((const char *)0); ic < nc; ++ic) {
            cat->setBin(ic);
            RooAbsPdf *pdfi = sim->getPdf(cat->getLabel());
            if (pdfi != 0) factorizePdf(observables, *pdfi, obsTerms, constraints);
        }
        delete cat;
    } else if (pdf.dependsOn(observables)) {
        if (!obsTerms.contains(pdf)) obsTerms.add(pdf);
    } else {
        if (!constraints.contains(pdf)) constraints.add(pdf);
    }
}
RooAbsPdf * utils::factorizePdf ( const RooArgSet &  observables,
RooAbsPdf &  pdf,
RooArgList &  constraints 
)

Create a pdf which depends only on observables, and collect the other constraint terms Will return 0 if it's all constraints, &pdf if it's all observables, or a new pdf if it's something mixed In the last case, you're the owner of the returned pdf.

Definition at line 80 of file utils.cc.

References copyAttributes(), i, list(), n, pileupCalc::nbins, parseEventContent::prod, and run_regression::ret.

Referenced by HybridNew::create(), factorizeFunc(), factorizePdf(), makeNuisancePdf(), makeObsOnlyPdf(), makePlots(), rebuildSimPdf(), GoodnessOfFit::runSaturatedModel(), cacheutils::CachingSimNLL::setup_(), toymcoptutils::SimPdfGenInfo::SimPdfGenInfo(), and SimplerLikelihoodRatioTestStatOpt::SimplerLikelihoodRatioTestStatOpt().

                                                                                                    {
    assert(&pdf);
    const std::type_info & id = typeid(pdf);
    if (id == typeid(RooProdPdf)) {
        //std::cout << " pdf is product pdf " << pdf.GetName() << std::endl;
        RooProdPdf *prod = dynamic_cast<RooProdPdf *>(&pdf);
        RooArgList newFactors; RooArgSet newOwned;
        RooArgList list(prod->pdfList());
        bool needNew = false;
        for (int i = 0, n = list.getSize(); i < n; ++i) {
            RooAbsPdf *pdfi = (RooAbsPdf *) list.at(i);
            RooAbsPdf *newpdf = factorizePdf(observables, *pdfi, constraints);
            //std::cout << "    for " << pdfi->GetName() << "   newpdf  " << (newpdf == 0 ? "null" : (newpdf == pdfi ? "old" : "new"))  << std::endl;
            if (newpdf == 0) { needNew = true; continue; }
            if (newpdf != pdfi) { needNew = true; newOwned.add(*newpdf); }
            newFactors.add(*newpdf);
        }
        if (!needNew) { copyAttributes(pdf, *prod); return prod; }
        else if (newFactors.getSize() == 0) return 0;
        else if (newFactors.getSize() == 1) {
            RooAbsPdf *ret = (RooAbsPdf *) newFactors.first()->Clone(TString::Format("%s_obsOnly", pdf.GetName()));
            copyAttributes(pdf, *ret);
            return ret;
        }
        RooProdPdf *ret = new RooProdPdf(TString::Format("%s_obsOnly", pdf.GetName()), "", newFactors);
        ret->addOwnedComponents(newOwned);
        copyAttributes(pdf, *ret);
        return ret;
    } else if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) {
        RooSimultaneous *sim  = dynamic_cast<RooSimultaneous *>(&pdf);
        RooAbsCategoryLValue *cat = (RooAbsCategoryLValue *) sim->indexCat().Clone();
        int nbins = cat->numBins((const char *)0);
        TObjArray factorizedPdfs(nbins); RooArgSet newOwned;
        bool needNew = false;
        for (int ic = 0, nc = nbins; ic < nc; ++ic) {
            cat->setBin(ic);
            RooAbsPdf *pdfi = sim->getPdf(cat->getLabel());
            RooAbsPdf *newpdf = factorizePdf(observables, *pdfi, constraints);
            factorizedPdfs[ic] = newpdf;
            if (newpdf == 0) { throw std::runtime_error(std::string("ERROR: channel ") + cat->getLabel() + " factorized to zero."); }
            if (newpdf != pdfi) { needNew = true; newOwned.add(*newpdf); }
        }
        RooSimultaneous *ret = sim;
        if (needNew) {
            ret = new RooSimultaneous(TString::Format("%s_obsOnly", pdf.GetName()), "", (RooAbsCategoryLValue&) sim->indexCat());
            for (int ic = 0, nc = nbins; ic < nc; ++ic) {
                cat->setBin(ic);
                RooAbsPdf *newpdf = (RooAbsPdf *) factorizedPdfs[ic];
                if (newpdf) ret->addPdf(*newpdf, cat->getLabel());
            }
            ret->addOwnedComponents(newOwned);
        }
        delete cat;
        if (id == typeid(RooSimultaneousOpt)) {
            RooSimultaneousOpt *newret = new RooSimultaneousOpt(*ret);
            newret->addOwnedComponents(RooArgSet(*ret));
            ret = newret;
        }
        copyAttributes(pdf, *ret);
        return ret;
    } else if (pdf.dependsOn(observables)) {
        return &pdf;
    } else {
        if (!constraints.contains(pdf)) constraints.add(pdf);
        return 0;
    }

}
RooAbsReal * utils::fullCloneFunc ( const RooAbsReal *  pdf,
RooArgSet &  holder,
bool  cloneLeafNodes = false 
)

Definition at line 226 of file utils.cc.

References tmp.

                                                                                              {
  // Clone all FUNC compents by copying all branch nodes
  RooArgSet tmp("RealBranchNodeList") ;
  pdf->branchNodeServerList(&tmp);
  tmp.snapshot(holder, cloneLeafNodes); 
  // Find the top level FUNC in the snapshot list
  return (RooAbsReal*) holder.find(pdf->GetName());
}
RooAbsPdf * utils::fullClonePdf ( const RooAbsPdf *  pdf,
RooArgSet &  holder,
bool  cloneLeafNodes = false 
)

Definition at line 218 of file utils.cc.

References tmp.

Referenced by SimplerLikelihoodRatioTestStatOpt::SimplerLikelihoodRatioTestStatOpt().

                                                                                           {
  // Clone all FUNC compents by copying all branch nodes
  RooArgSet tmp("RealBranchNodeList") ;
  pdf->branchNodeServerList(&tmp);
  tmp.snapshot(holder, cloneLeafNodes); 
  // Find the top level FUNC in the snapshot list
  return (RooAbsPdf*) holder.find(pdf->GetName());
}
def utils::get_relval_cmssw_version (   file)

Definition at line 536 of file utils.py.

00537                                   :
00538     cmssw_release = re.findall('(CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?)-', file)
00539     gr_r_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-([\w\d]*)_V\d*\w?(_[\w\d]*)?-v', file)
00540     if cmssw_release and gr_r_version:
00541         return (cmssw_release[0], gr_r_version[0])

def utils::get_relval_id (   file)
Returns unique relval ID (dataset name) for a given file.

Definition at line 542 of file utils.py.

00543                        :
00544     """Returns unique relval ID (dataset name) for a given file."""
00545     dataset_name = re.findall('R\d{9}__([\w\d]*)__CMSSW_', file)
00546     return dataset_name[0]

def utils::get_relval_max_version (   files)
Returns file with maximum version at a) beggining of the file,
e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.

Definition at line 524 of file utils.py.

00525                                  :
00526     """Returns file with maximum version at a) beggining of the file,
00527     e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max."""
00528     max_file = files[0]
00529     max_v = get_relval_version(files[0])
00530     for file in files:
00531         file_v = get_relval_version(file)
00532         if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])):
00533             max_file = file
00534             max_v = file_v
00535     return max_file

def utils::get_relval_version (   file)

------------------- Make files pairs: RelVal utils ---------------------

Returns tuple (CMSSW version, run version) for specified file.

Definition at line 517 of file utils.py.

00518                             :
00519     """Returns tuple (CMSSW version, run version) for specified file."""
00520     cmssw_version = re.findall('DQM_V(\d*)_', file)
00521     run_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-[\w\d]*_V\d*\w?(?:_[\w\d]*)?-v(\d*)__', file)
00522     if cmssw_version and run_version:
00523         return (int(cmssw_version[0]), int(run_version[0]))

def utils::get_relvaldata_cmssw_version (   file)
Returns tuple (CMSSW release, GR_R version) for specified RelValData file.

Definition at line 486 of file utils.py.

00487                                       :
00488     """Returns tuple (CMSSW release, GR_R version) for specified RelValData file."""
00489     cmssw_release = re.findall('(CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?)-', file)
00490     gr_r_version = re.findall('-(GR_R_\d*_V\d*\w?)(?:_RelVal)?_', file)
00491     if not gr_r_version:
00492         gr_r_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-(\w*)_RelVal_', file)
00493     if cmssw_release and gr_r_version:
00494         return (cmssw_release[0], gr_r_version[0])

def utils::get_relvaldata_id (   file)

----------------- Make files pairs: RelValData utils --------------------

Returns unique relvaldata ID for a given file.

Definition at line 476 of file utils.py.

00477                            :
00478     """Returns unique relvaldata ID for a given file."""
00479     run_id = re.search('R\d{9}', file)
00480     run = re.search('_RelVal_([\w\d]*)-v\d__', file)
00481     if not run:
00482         run = re.search('GR_R_\d*_V\d*C?_([\w\d]*)-v\d__', file)
00483     if run_id and run:
00484         return (run_id.group(), run.group(1))
00485     return None

def utils::get_relvaldata_max_version (   files)
Returns file with maximum version at a) beggining of the file,
e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.

Definition at line 504 of file utils.py.

00505                                      :
00506     """Returns file with maximum version at a) beggining of the file,
00507     e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max."""
00508     max_file = files[0]
00509     max_v = get_relvaldata_version(files[0])
00510     for file in files:
00511         file_v = get_relvaldata_version(file)
00512         if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])):
00513             max_file = file
00514             max_v = file_v
00515     return max_file

def utils::get_relvaldata_version (   file)
Returns tuple (CMSSW version, run version) for specified file.

Definition at line 495 of file utils.py.

00496                                 :
00497     """Returns tuple (CMSSW version, run version) for specified file."""
00498     cmssw_version = re.findall('DQM_V(\d*)_', file)
00499     run_version = re.findall('_RelVal_[\w\d]*-v(\d)__', file)
00500     if not run_version:
00501         run_version = re.findall('GR_R_\d*_V\d*C?_[\w\d]*-v(\d)__', file)
00502     if cmssw_version and run_version:
00503         return (int(cmssw_version[0]), int(run_version[0]))

void utils::getClients ( const RooAbsCollection &  values,
const RooAbsCollection &  allObjects,
RooAbsCollection &  clients 
)

add to 'clients' all object within allObjects that *directly* depend on values

Definition at line 236 of file utils.cc.

References a, and v.

Referenced by SimplerLikelihoodRatioTestStatOpt::SimplerLikelihoodRatioTestStatOpt().

                                                                                                                    {
    std::auto_ptr<TIterator> iterAll(allObjects.createIterator());
    std::auto_ptr<TIterator> iterVal(values.createIterator());
    for (RooAbsArg *v = (RooAbsArg *) iterVal->Next(); v != 0; v = (RooAbsArg *) iterVal->Next()) {
        if (typeid(*v) != typeid(RooRealVar)) continue;
        std::auto_ptr<TIterator> clientIter(v->clientIterator());
        for (RooAbsArg *a = (RooAbsArg *) clientIter->Next(); a != 0; a = (RooAbsArg *) clientIter->Next()) {
            if (allObjects.containsInstance(*a) && !clients.containsInstance(*a)) clients.add(*a);
        }
    }
}
def utils::getNbins (   h)

Definition at line 92 of file utils.py.

00093                :
00094   biny=h.GetNbinsY()
00095   if biny>1:biny+=1
00096   binz=h.GetNbinsZ()
00097   if binz>1:binz+=1
00098   return (h.GetNbinsX()+1)*(biny)*(binz)
00099 
00100 #-------------------------------------------------------------------------------
00101 

void utils::guessChannelMode ( RooSimultaneous &  simPdf,
RooAbsData &  simData,
bool  verbose = false 
)

Definition at line 376 of file utils.cc.

References gather_cfg::cout, i, n, and split.

Referenced by Combine::run().

{
    RooAbsCategoryLValue &cat = const_cast<RooAbsCategoryLValue &>(simPdf.indexCat());
    TList *split = simData.split(cat, kTRUE);
    for (int i = 0, n = cat.numBins((const char *)0); i < n; ++i) {
        cat.setBin(i);
        RooAbsPdf *pdf = simPdf.getPdf(cat.getLabel());
        if (pdf->getAttribute("forceGenBinned") || pdf->getAttribute("forceGenUnbinned")) {
            if (verbose) std::cout << " - " << cat.getLabel() << " has generation mode already set" << std::endl;
            continue;
        }
        RooAbsData *spl = (RooAbsData *) split->FindObject(cat.getLabel());
        if (spl == 0) { 
            if (verbose) std::cout << " - " << cat.getLabel() << " has no dataset, cannot guess" << std::endl; 
            continue;
        }
        if (spl->numEntries() != spl->sumEntries()) {
            if (verbose) std::cout << " - " << cat.getLabel() << " has " << spl->numEntries() << " num entries of sum " << spl->sumEntries() << ", mark as binned" << std::endl;
            pdf->setAttribute("forceGenBinned");
        } else {
            if (verbose) std::cout << " - " << cat.getLabel() << " has " << spl->numEntries() << " num entries of sum " << spl->sumEntries() << ", mark as unbinned" << std::endl;
            pdf->setAttribute("forceGenUnbinned");
        }
    }
}
def utils::is_empty (   h)

Definition at line 171 of file utils.py.

Referenced by DTSectColl::addTSTheta(), DEcompare< T >::get_ncand(), and DEcompare< T >::SortCollections().

00172                :
00173   for i in xrange(1,getNbins(h)):
00174     if h.GetBinContent(i)!=0: return False
00175   return True
00176   #return h.GetSumOfWeights()==0
00177 
00178 #-------------------------------------------------------------------------------

def utils::is_relvaldata (   files)

------------------------- Make files pairs --------------------------

Definition at line 548 of file utils.py.

00549                         :
00550     is_relvaldata_re = re.compile('_RelVal_')
00551     return any([is_relvaldata_re.search(filename) for filename in files])

def utils::is_sparse (   h)

Definition at line 179 of file utils.py.

00180                 :
00181   filled_bins=0.
00182   nbins=h.GetNbinsX()
00183   for ibin in xrange(nbins):
00184     if h.GetBinContent(ibin)>0:
00185       filled_bins+=1
00186   #print "%s %s --> %s" %(filled_bins,nbins,filled_bins/nbins)
00187   if filled_bins/nbins < .5:
00188     return True
00189   else:
00190     return False
00191 
00192 #-------------------------------------------------------------------------------

def utils::literal2root (   literal,
  rootType 
)

Definition at line 69 of file utils.py.

00070                                    :
00071   bitsarray = array.array('B')
00072   bitsarray.fromstring(literal.decode('hex'))
00073 
00074   tbuffer=0
00075   try:  
00076       tbuffer = TBufferFile(TBufferFile.kRead, len(bitsarray), bitsarray, False,0)
00077   except:
00078       print "could not transform to object array:"
00079       print [ i for i in  bitsarray ]
00080   
00081   # replace a couple of shortcuts with the real root class name
00082   if rootType == 'TPROF':
00083       rootType = 'TProfile'
00084   if rootType == 'TPROF2D':
00085       rootType = 'TProfile2D'
00086   
00087   root_class=eval(rootType+'.Class()')
00088   
00089   return tbuffer.ReadObject(root_class)
00090   
00091 #-------------------------------------------------------------------------------

def utils::logger (   msg_level,
  message 
)

Definition at line 47 of file utils.py.

00048                              :
00049   if msg_level>=_log_level:
00050     print "[%s] %s" %(asctime(),message)
00051 
#-------------------------------------------------------------------------------
def utils::make_files_pairs (   files,
  verbose = True 
)

Definition at line 552 of file utils.py.

00553                                          :
00554     ## Select functions to use
00555     if is_relvaldata(files):
00556         is_relval_data = True
00557         get_cmssw_version = get_relvaldata_cmssw_version
00558         get_id = get_relvaldata_id
00559         get_max_version = get_relvaldata_max_version
00560         # print 'Pairing Data RelVal files.'
00561     else:
00562         is_relval_data = False
00563         get_cmssw_version = get_relval_cmssw_version
00564         get_id = get_relval_id
00565         get_max_version = get_relval_max_version
00566         # print 'Pairing Monte Carlo RelVal files.'
00567 
00568     ## Divide files into groups
00569     versions_files = dict()
00570     for file in files:
00571         version = get_cmssw_version(file)
00572         if versions_files.has_key(version):
00573             versions_files[version].append(file)
00574         else:
00575             versions_files[version] = [file]
00576 
00577     ## Print the division into groups
00578     if verbose:
00579         print '\nFound versions:'
00580         for version in versions_files:
00581             print '%s: %d files' % (str(version),  len(versions_files[version]))
00582 
00583     if len(versions_files.keys()) <= 1:
00584         print '\nFound too little versions, there is nothing to pair. Exiting...\n'
00585         exit()
00586 
00587     ## Select two biggest groups.
00588     versions = versions_files.keys()
00589     sizes = [len(value) for value in versions_files.values()]
00590     v1 = versions[sizes.index(max(sizes))]
00591     versions.remove(v1)
00592     sizes.remove(max(sizes))
00593     v2 = versions[sizes.index(max(sizes))]
00594 
00595     ## Print two biggest groups.
00596     if verbose:
00597         print '\nPairing %s (%d files) and %s (%d files)' % (str(v1),
00598                 len(versions_files[v1]), str(v2), len(versions_files[v2]))
00599 
00600     ## Pairing two versions
00601     print '\nGot pairs:'
00602     pairs = []
00603     for unique_id in set([get_id(file) for file in versions_files[v1]]):
00604         if is_relval_data:
00605             dataset_re = re.compile(unique_id[0]+'_')
00606             run_re = re.compile(unique_id[1])
00607             c1_files = [file for file in versions_files[v1] if dataset_re.search(file) and run_re.search(file)]
00608             c2_files = [file for file in versions_files[v2] if dataset_re.search(file) and run_re.search(file)]
00609         else:
00610             dataset_re = re.compile(unique_id+'_')
00611             c1_files = [file for file in versions_files[v1] if dataset_re.search(file)]
00612             c2_files = [file for file in versions_files[v2] if dataset_re.search(file)]
00613 
00614         if len(c1_files) > 0 and len(c2_files) > 0:
00615             first_file = get_max_version(c1_files)
00616             second_file = get_max_version(c2_files)
00617             print '%s\n%s\n' % (first_file, second_file)
00618             pairs.extend((first_file, second_file))
00619     if verbose:
00620         print "Paired and got %d files.\n" % len(pairs)
00621     return pairs
RooAbsPdf * utils::makeNuisancePdf ( RooAbsPdf &  pdf,
const RooArgSet &  observables,
const char *  name = "nuisancePdf" 
)

Definition at line 204 of file utils.cc.

References createBeamHaloJobs::constraints, and factorizePdf().

                                                                                                { 
    assert(&pdf);
    RooArgList obsTerms, constraints;
    factorizePdf(observables, pdf, obsTerms, constraints);
    if (constraints.getSize() == 0) return 0;
    return new RooProdPdf(name,"", constraints);
}
RooAbsPdf * utils::makeNuisancePdf ( RooStats::ModelConfig &  model,
const char *  name = "nuisancePdf" 
)
RooAbsPdf * utils::makeObsOnlyPdf ( RooStats::ModelConfig &  model,
const char *  name = "obsPdf" 
)

Note: doesn't recompose Simultaneous pdfs properly, for that use factorizePdf method.

Definition at line 212 of file utils.cc.

References createBeamHaloJobs::constraints, and factorizePdf().

                                                                             { 
    RooArgList obsTerms, constraints;
    factorizePdf(model, *model.GetPdf(), obsTerms, constraints);
    return new RooProdPdf(name,"", obsTerms);
}
std::vector< RooPlot * > utils::makePlots ( const RooAbsPdf &  pdf,
const RooAbsData &  data,
const char *  signalSel = 0,
const char *  backgroundSel = 0,
float  rebinFactor = 1.0 
)

make plots, if possible

Definition at line 403 of file utils.cc.

References createBeamHaloJobs::constraints, RecoTau_DiTaus_pt_20-420_cfg::datasets, factorizePdf(), pileupCalc::nbins, GetRecoTauVFromDQM_MC_cff::next, run_regression::ret, and x.

                                                                                                                                  {
    std::vector<RooPlot *> ret;
    RooArgList constraints;
    RooAbsPdf *facpdf = factorizePdf(*data.get(0), const_cast<RooAbsPdf &>(pdf), constraints);

    const std::type_info & id = typeid(*facpdf);
    if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) {
        const RooSimultaneous *sim  = dynamic_cast<const RooSimultaneous *>(&pdf);
        const RooAbsCategoryLValue &cat = (RooAbsCategoryLValue &) sim->indexCat();
        TList *datasets = data.split(cat, true);
        TIter next(datasets);
        for (RooAbsData *ds = (RooAbsData *) next(); ds != 0; ds = (RooAbsData *) next()) {
            RooAbsPdf *pdfi  = sim->getPdf(ds->GetName());
            std::auto_ptr<RooArgSet> obs(pdfi->getObservables(ds));
            if (obs->getSize() == 0) break;
            RooRealVar *x = dynamic_cast<RooRealVar *>(obs->first());
            if (x == 0) continue;
            int nbins = x->numBins(); if (nbins == 0) nbins = 100;
            if (nbins/rebinFactor > 6) nbins = ceil(nbins/rebinFactor);
            ret.push_back(x->frame(RooFit::Title(ds->GetName()), RooFit::Bins(nbins)));
            ret.back()->SetName(ds->GetName());
            ds->plotOn(ret.back());
            if (signalSel && strlen(signalSel))         pdfi->plotOn(ret.back(), RooFit::LineColor(209), RooFit::Components(signalSel));
            if (backgroundSel && strlen(backgroundSel)) pdfi->plotOn(ret.back(), RooFit::LineColor(206), RooFit::Components(backgroundSel));
            pdfi->plotOn(ret.back());
            delete ds;
        }
        delete datasets;
    } else if (pdf.canBeExtended()) {
        std::auto_ptr<RooArgSet> obs(pdf.getObservables(&data));
        RooRealVar *x = dynamic_cast<RooRealVar *>(obs->first());
        if (x != 0) {
            ret.push_back(x->frame());
            ret.back()->SetName("data");
            data.plotOn(ret.back());
            if (signalSel && strlen(signalSel))         pdf.plotOn(ret.back(), RooFit::LineColor(209), RooFit::Components(signalSel));
            if (backgroundSel && strlen(backgroundSel)) pdf.plotOn(ret.back(), RooFit::LineColor(206), RooFit::Components(backgroundSel));
            pdf.plotOn(ret.back());
        }
    }
    if (facpdf != &pdf) { delete facpdf; }
    return ret;

}
void utils::printPdf ( RooWorkspace *  w,
const char *  pdfName 
)

Definition at line 74 of file utils.cc.

References gather_cfg::cout.

                                                         {
  std::cout << "PDF " << pdfName << " parameters." << std::endl;
  std::auto_ptr<RooArgSet> params(w->pdf(pdfName)->getVariables());
  params->Print("V");
}
void utils::printPdf ( RooStats::ModelConfig &  model)

Definition at line 68 of file utils.cc.

References gather_cfg::cout.

                                            {
  std::cout << "ModelConfig " << mc.GetName() << " (" << mc.GetTitle() << "): pdf parameters." << std::endl;
  std::auto_ptr<RooArgSet> params(mc.GetPdf()->getVariables());
  params->Print("V");
}
void utils::printPdf ( RooAbsPdf *  pdf)

Definition at line 61 of file utils.cc.

References gather_cfg::cout.

Referenced by Combine::run().

                                   {
  std::cout << "Pdf " << pdf->GetName() << " parameters." << std::endl;
  std::auto_ptr<RooArgSet> params(pdf->getVariables());
  params->Print("V");
}
void utils::printRAD ( const RooAbsData *  d)

Definition at line 56 of file utils.cc.

References printRDH().

Referenced by Combine::run().

                                        {
  if (d->InheritsFrom("RooDataHist") || d->numEntries() != 1) printRDH(const_cast<RooAbsData*>(d));
  else d->get(0)->Print("V");
}
void utils::printRDH ( RooAbsData *  data)

Definition at line 30 of file utils.cc.

References a, newFWLiteAna::bin, i, and j.

Referenced by GoodnessOfFit::makeSaturatedPdf(), and printRAD().

                                     {
  std::vector<std::string> varnames, catnames;
  const RooArgSet *b0 = data->get();
  TIterator *iter = b0->createIterator();
  for (RooAbsArg *a = 0; (a = (RooAbsArg *)iter->Next()) != 0; ) {
    if (a->InheritsFrom("RooRealVar")) {
      varnames.push_back(a->GetName());
    } else if (a->InheritsFrom("RooCategory")) {
      catnames.push_back(a->GetName());
    }
  }
  delete iter;
  size_t nv = varnames.size(), nc = catnames.size();
  printf(" bin  ");
  for (size_t j = 0; j < nv; ++j) { printf("%16.16s  ", varnames[j].c_str()); }
  for (size_t j = 0; j < nc; ++j) { printf("%16.16s  ", catnames[j].c_str()); }
  printf("  weight\n");
  for (int i = 0, nb = data->numEntries(); i < nb; ++i) {
    const RooArgSet *bin = data->get(i);
    printf("%4d  ",i);
    for (size_t j = 0; j < nv; ++j) { printf("%16g  ",    bin->getRealValue(varnames[j].c_str())); }
    for (size_t j = 0; j < nc; ++j) { printf("%16.16s  ", bin->getCatLabel(catnames[j].c_str())); }
    printf("%8.3f\n", data->weight());
  }
}
def utils::profile2histo (   profile)

Definition at line 220 of file utils.py.

00221                           :
00222   if not profile.InheritsFrom("TH1"):
00223     return profile
00224     
00225   bin_low_edges=[]
00226   n_bins=profile.GetNbinsX()
00227   
00228   for ibin in xrange(1,n_bins+2):
00229     bin_low_edges.append(profile.GetBinLowEdge(ibin))
00230   bin_low_edges=array.array('f',bin_low_edges)
00231   histo=TH1F(profile.GetName(),profile.GetTitle(),n_bins,bin_low_edges)
00232   for ibin in xrange(0,n_bins+1):
00233     histo.SetBinContent(ibin,profile.GetBinContent(ibin))
00234     histo.SetBinError(ibin,profile.GetBinError(ibin))    
00235   
00236   return histo
00237 #-------------------------------------------------------------------------------

RooSimultaneous * utils::rebuildSimPdf ( const RooArgSet &  observables,
RooSimultaneous *  pdf 
)

Definition at line 327 of file utils.cc.

References createBeamHaloJobs::constraints, copyAttributes(), factorizePdf(), pileupCalc::nbins, and run_regression::ret.

Referenced by Combine::run().

                                                                                         {
    RooArgList constraints;
    RooAbsCategoryLValue *cat = (RooAbsCategoryLValue *) sim->indexCat().Clone();
    int nbins = cat->numBins((const char *)0);
    TObjArray factorizedPdfs(nbins); 
    RooArgSet newOwned;
    for (int ic = 0, nc = nbins; ic < nc; ++ic) {
        cat->setBin(ic);
        RooAbsPdf *pdfi = sim->getPdf(cat->getLabel());
        if (pdfi == 0) { factorizedPdfs[ic] = 0; continue; }
        RooAbsPdf *newpdf = factorizePdf(observables, *pdfi, constraints);
        factorizedPdfs[ic] = newpdf;
        if (newpdf == 0) { continue; }
        if (newpdf != pdfi) { newOwned.add(*newpdf);  }
    }
    RooSimultaneous *ret = new RooSimultaneous(TString::Format("%s_reloaded", sim->GetName()), "", (RooAbsCategoryLValue&) sim->indexCat());
    for (int ic = 0, nc = nbins; ic < nc; ++ic) {
        cat->setBin(ic);
        RooAbsPdf *newpdf = (RooAbsPdf *) factorizedPdfs[ic];
        if (newpdf) {
            if (constraints.getSize() > 0) {
                RooArgList allfactors(constraints); allfactors.add(*newpdf);
                RooProdPdf *newerpdf = new RooProdPdf(TString::Format("%s_plus_constr", newpdf->GetName()), "", allfactors);
                ret->addPdf(*newerpdf, cat->getLabel());
                copyAttributes(*newpdf, *newerpdf);
                newOwned.add(*newerpdf);
            } else {
                ret->addPdf(*newpdf, cat->getLabel());
            }
        }
    }
    ret->addOwnedComponents(newOwned);
    copyAttributes(*sim, *ret);
    delete cat;
    return ret;
}
bool utils::setAllConstant ( const RooAbsCollection &  coll,
bool  constant = true 
)

set all RooRealVars to constants. return true if at least one changed status

Definition at line 248 of file utils.cc.

References a, and v.

Referenced by Asymptotic::asimovDataset(), asimovutils::asimovDatasetWithFit(), HybridNew::create(), ProfiledLikelihoodTestStatOpt::Evaluate(), and Combine::run().

                                                                      {
    bool changed = false;
    std::auto_ptr<TIterator> iter(coll.createIterator());
    for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
        RooRealVar *v = dynamic_cast<RooRealVar *>(a);
        if (v && (v->isConstant() != constant)) {
            changed = true;
            v->setConstant(constant);
        }
    }
    return changed;
}
def utils::setTDRStyle ( )

Definition at line 52 of file utils.py.

References plotscripts::tdrStyle.

Referenced by FlavourHistograms< T >::plot().

00052                  :  
00053   this_dir=dirname(this_module_name)
00054   this_dir_one_up=this_dir[:this_dir.rfind("/")+1]
00055   #this_dir_two_up=this_dir_one_up[:this_dir_one_up.rfind("/")+1]
00056   style_file=''
00057   if os.environ.has_key("RELMON_SA"):
00058     style_file=this_dir_one_up+"data/tdrstyle_mod.C"
00059   else:
00060     style_file="%s/src/Utilities/RelMon/data/tdrstyle_mod.C"%(os.environ["CMSSW_BASE"])
00061   try:
00062     gROOT.ProcessLine(".L %s" %style_file)
00063     gROOT.ProcessLine("setTDRStyle()")
00064   except:
00065     "Print could not set the TDR style. File %s not found?" %style_file
00066     
00067 
00068 #-------------------------------------------------------------------------------
void utils::tdrStyle ( )

set style for plots

---> gStyle->SetStatFontSize(0.025);

Definition at line 4 of file tdrstyle.cc.

                     {
    gStyle->SetPadTopMargin(0.05);
    gStyle->SetPadBottomMargin(0.13);
    gStyle->SetPadLeftMargin(0.16);
    gStyle->SetPadRightMargin(0.04);
    gStyle->SetPalette(1);
    gStyle->SetHistMinimumZero(1);
    gStyle->SetCanvasBorderMode(0);
    gStyle->SetCanvasColor(kWhite);
    gStyle->SetPadBorderMode(0);
    gStyle->SetPadColor(kWhite);
    gStyle->SetFrameBorderMode(0);
    gStyle->SetFrameBorderSize(1);
    gStyle->SetFrameFillColor(0);
    gStyle->SetStatColor(kWhite);
    gStyle->SetTitleColor(1);
    gStyle->SetTitleFillColor(10);

    gStyle->SetOptTitle(0);

    gStyle->SetStatFont(42);
    gStyle->SetStatFontSize(0.04);
    gStyle->SetTitleColor(1, "XYZ");
    gStyle->SetTitleFont(42, "XYZ");
    gStyle->SetTitleSize(0.06, "XYZ");
    // gStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
    // gStyle->SetTitleYSize(Float_t size = 0.02);
    gStyle->SetTitleXOffset(0.9);
    gStyle->SetTitleYOffset(1.25);
    // gStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset

    // For the axis labels:

    gStyle->SetLabelColor(1, "XYZ");
    gStyle->SetLabelFont(42, "XYZ");
    gStyle->SetLabelOffset(0.007, "XYZ");
    gStyle->SetLabelSize(0.05, "XYZ");

    // For the axis:
    gStyle->SetAxisColor(1, "XYZ");
    gStyle->SetStripDecimals(kTRUE);
    gStyle->SetTickLength(0.03, "XYZ");
    gStyle->SetNdivisions(510, "XYZ");
    gStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
    gStyle->SetPadTickY(1);
}
def utils::wget (   url)
Fetch the WHOLE file, not in bunches... To be optimised.

Definition at line 451 of file utils.py.

00452              :
00453   """ Fetch the WHOLE file, not in bunches... To be optimised.
00454   """
00455   opener=build_opener(X509CertOpen())  
00456   datareq = Request(url)
00457   datareq.add_header('authenticated_wget', "The ultimate wgetter")    
00458   bin_content=None
00459   try:
00460     filename=basename(url)  
00461     print "Checking existence of file %s on disk..."%filename
00462     if not isfile("./%s"%filename):      
00463       bin_content=opener.open(datareq).read()
00464     else:
00465       print "File %s exists, skipping.." %filename
00466   except ValueError:
00467     print "Error: Unknown url %s" %url
00468   
00469   if bin_content!=None:  
00470     ofile = open(filename, 'wb')
00471     ofile.write(bin_content)
00472     ofile.close()
00473 
#-------------------------------------------------------------------------------

Variable Documentation

Definition at line 46 of file utils.py.

utils::theargv = sys.argv

Definition at line 24 of file utils.py.