Skip to content

Commit

Permalink
Next chunk of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Dec 4, 2023
1 parent cd88314 commit c960b9b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 46 deletions.
3 changes: 1 addition & 2 deletions src/CachingNLL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ cacheutils::CachingAddNLL::setup_()
}

std::unique_ptr<RooArgSet> params(pdf_->getParameters(*data_));
std::unique_ptr<TIterator> iter(params->createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : *params) {
if (dynamic_cast<RooRealVar *>(a)) params_.add(*a);
else if (dynamic_cast<RooCategory *>(a)) catParams_.add(*a);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Combine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <TFile.h>
#include <TFileCacheRead.h>
#include <TGraphErrors.h>
#include <TIterator.h>
#include <TLine.h>
#include <TMath.h>
#include <TString.h>
Expand Down Expand Up @@ -974,8 +973,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
// print the values of the parameters used to generate the toy
if (verbose > 2) {
CombineLogger::instance().log("Combine.cc",__LINE__, "Generate Asimov toy from parameter values ... ",__func__);
std::unique_ptr<TIterator> iter(genPdf->getParameters((const RooArgSet*)0)->createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{genPdf->getParameters((const RooArgSet*)0)}) {
TString varstring = utils::printRooArgAsString(a);
CombineLogger::instance().log("Combine.cc",__LINE__,varstring.Data(),__func__);
}
Expand Down Expand Up @@ -1071,8 +1069,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
std::cout << "Generate toy " << iToy << "/" << nToys << std::endl;
if (verbose > 2) {
CombineLogger::instance().log("Combine.cc",__LINE__, std::string(Form("Generating toy %d/%d, from parameter values ... ",iToy,nToys)),__func__);
std::unique_ptr<TIterator> iter(genPdf->getParameters((const RooArgSet*)0)->createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{genPdf->getParameters((const RooArgSet*)0)}) {
TString varstring = utils::printRooArgAsString(a);
CombineLogger::instance().log("Combine.cc" ,__LINE__,varstring.Data(),__func__);
}
Expand Down
9 changes: 3 additions & 6 deletions src/MultiDimFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) {
RooArgSet mcNuis(*mc_s->GetNuisanceParameters());
if(saveSpecifiedNuis_=="all"){
specifiedNuis_.clear();
RooLinkedListIter iterN = mc_s->GetNuisanceParameters()->iterator();
for (RooAbsArg *a = (RooAbsArg*) iterN.Next(); a != 0; a = (RooAbsArg*) iterN.Next()) {
for (RooAbsArg *a : *mc_s->GetNuisanceParameters()) {
if (poiList_.contains(*a)) continue;
specifiedNuis_.push_back(a->GetName());
}
Expand All @@ -382,8 +381,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) {
while(token) {
const RooArgSet* group = mc_s->GetWS()->set((std::string("group_") + token).data());
if (group){
RooLinkedListIter iterN = group->iterator();
for (RooAbsArg *a = (RooAbsArg*) iterN.Next(); a != 0; a = (RooAbsArg*) iterN.Next()) {
for (RooAbsArg *a : *group) {
specifiedNuis_.push_back(a->GetName());
}
}else if (!poiList_.find(token)){
Expand All @@ -404,8 +402,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) {
}
}
if(saveInactivePOI_){
RooLinkedListIter iterP = mc_s->GetParametersOfInterest()->iterator();
for (RooAbsArg *a = (RooAbsArg*) iterP.Next(); a != 0; a = (RooAbsArg*) iterP.Next()) {
for (RooAbsArg *a : *mc_s->GetParametersOfInterest()) {
if (poiList_.contains(*a)) continue;
if (specifiedList_.contains(*a)) continue;
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
Expand Down
34 changes: 13 additions & 21 deletions src/RooRealFlooredSumPdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,14 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet*
assert(cache != 0);
}

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

// N funcs, N-1 coefficients
Double_t lastCoef(1);
while ((coef = (RooAbsReal*)coefIter.next())) {
funcInt = (RooAbsReal*)funcIntIter.next();
func = (RooAbsReal*)funcIter.next();
for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) {
RooAbsReal *coef = &static_cast<RooAbsReal&>(_coefList[iCoef]);
RooAbsReal *func = &static_cast<RooAbsReal&>(_funcList[iCoef]);
RooAbsReal *funcInt = &static_cast<RooAbsReal&>(cache->_funcIntList[iCoef]);
Double_t coefVal = coef->getVal(normSet2);
if (coefVal) {
assert(func);
Expand All @@ -333,7 +330,7 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet*

if (!_haveLastCoef) {
// Add last func with correct coefficient
funcInt = (RooAbsReal*)funcIntIter.next();
RooAbsReal *funcInt = &static_cast<RooAbsReal&>(cache->_funcIntList[_coefList.getSize()]);
assert(funcInt);
value += funcInt->getVal()*lastCoef;

Expand All @@ -350,11 +347,9 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet*
normVal = 0;

// N funcs, N-1 coefficients
RooAbsReal* funcNorm;
RooFIter funcNormIter = cache->_funcNormList.fwdIterator();
RooFIter coefIter2 = _coefList.fwdIterator();
while ((coef = (RooAbsReal*)coefIter2.next())) {
funcNorm = (RooAbsReal*)funcNormIter.next();
for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) {
RooAbsReal *coef = &static_cast<RooAbsReal&>(_coefList[iCoef]);
RooAbsReal *funcNorm = &static_cast<RooAbsReal&>(cache->_funcNormList[iCoef]);
Double_t coefVal = coef->getVal(normSet2);
if (coefVal) {
assert(funcNorm);
Expand All @@ -364,7 +359,7 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet*

// Add last func with correct coefficient
if (!_haveLastCoef) {
funcNorm = (RooAbsReal*)funcNormIter.next();
RooAbsReal *funcNorm = &static_cast<RooAbsReal&>(cache->_funcNormList[_coefList.getSize()]);
assert(funcNorm);
normVal += funcNorm->getVal()*lastCoef;
}
Expand Down Expand Up @@ -399,10 +394,9 @@ std::list<Double_t>* RooRealFlooredSumPdf::binBoundaries(RooAbsRealLValue& obs,
list<Double_t>* sumBinB = 0;
Bool_t needClean(kFALSE);

RooFIter iter = _funcList.fwdIterator();
RooAbsReal* func;
// Loop over components pdf
while ((func = (RooAbsReal*)iter.next())) {
for (RooAbsArg *funcAbsArg : _funcList) {
RooAbsReal *func = static_cast<RooAbsReal*>(funcAbsArg);

list<Double_t>* funcBinB = func->binBoundaries(obs, xlo, xhi);

Expand Down Expand Up @@ -463,10 +457,9 @@ std::list<Double_t>* RooRealFlooredSumPdf::plotSamplingHint(RooAbsRealLValue& ob
list<Double_t>* sumHint = 0;
Bool_t needClean(kFALSE);

RooFIter iter = _funcList.fwdIterator();
RooAbsReal* func;
// Loop over components pdf
while ((func = (RooAbsReal*)iter.next())) {
for (RooAbsArg *funcAbsArg : _funcList) {
RooAbsReal *func = static_cast<RooAbsReal*>(funcAbsArg);

list<Double_t>* funcHint = func->plotSamplingHint(obs, xlo, xhi);

Expand Down Expand Up @@ -513,7 +506,6 @@ void RooRealFlooredSumPdf::printMetaArgs(ostream& os) const

Bool_t first(kTRUE);

RooAbsArg* coef, *func;
if (_coefList.getSize() != 0) {
for (int iCoef = 0; iCoef <= _coefList.getSize(); ++iCoef) {
RooAbsArg *coef = &_coefList[iCoef];
Expand Down
23 changes: 11 additions & 12 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ RooAbsReal *utils::fullCloneFunc(const RooAbsReal *pdf, const RooArgSet &obs, Ro
void utils::getClients(const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients) {
for (RooAbsArg *v : values) {
if (typeid(*v) != typeid(RooRealVar) && typeid(*v) != typeid(RooCategory)) continue;
std::unique_ptr<TIterator> clientIter(v->clientIterator());
for (RooAbsArg *a = (RooAbsArg *) clientIter->Next(); a != 0; a = (RooAbsArg *) clientIter->Next()) {
for (RooAbsArg *a : v->clients()) {
if (allObjects.containsInstance(*a) && !clients.containsInstance(*a)) clients.add(*a);
}
}
Expand Down Expand Up @@ -628,8 +627,8 @@ void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) {
src_ = &src;
values_.resize(src.getSize());
}
RooLinkedListIter iter = src.iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
for (int i = 0; i < src.getSize(); ++i) {
RooAbsArg *a = src[i];
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
if (rrv == 0) {
RooCategory *rc = dynamic_cast<RooCategory *>(a);
Expand All @@ -645,8 +644,8 @@ void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) {

void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const {
if (&src == src_) {
RooLinkedListIter iter = src.iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
for (int i = 0; i < src.getSize(); ++i) {
RooAbsArg *a = src[i];
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
if (rrv!=0) rrv->setVal(values_[i]);
else {
Expand All @@ -655,8 +654,8 @@ void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const {
}
}
} else {
RooLinkedListIter iter = src_->iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
for (int i = 0; i < src_->getSize(); ++i) {
RooAbsArg *a = (*src_)[i];
RooAbsArg *a2 = src.find(a->GetName()); if (a2 == 0) continue;
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a2);
if (rrv!=0) rrv->setVal(values_[i]);
Expand All @@ -671,8 +670,8 @@ void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const {
void utils::CheapValueSnapshot::Print(const char *fmt) const {
if (src_ == 0) { printf("<NIL>\n"); return; }
if (fmt[0] == 'V') {
RooLinkedListIter iter = src_->iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
for (int i = 0; i < src_->getSize(); ++i) {
RooAbsArg *a = (*src_)[i];
printf(" %3d) %-30s = %9.6g\n", i, a->GetName(), values_[i]);
}
printf("\n");
Expand Down Expand Up @@ -992,8 +991,8 @@ bool utils::anyParameterAtBoundaries( const RooArgSet &params, int verbosity ){
static std::unordered_map<std::string, unsigned char> timesFoundAtBoundary;
bool isAnyBad = false;

RooLinkedListIter iter = params.iterator(); int i = 0;
for (RooRealVar *a = (RooRealVar *) iter.Next(); a != 0; a = (RooRealVar *) iter.Next(), ++i) {
for (RooAbsArg *aAbsArg : params) {
RooRealVar *a = static_cast<RooRealVar*>(aAbsArg);

bool isBad = isParameterAtBoundary(*a);

Expand Down

0 comments on commit c960b9b

Please sign in to comment.