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 3, 2023
1 parent afc34ef commit 181bd3c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 45 deletions.
15 changes: 6 additions & 9 deletions src/HybridNew.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,8 @@ bool HybridNew::runSignificance(RooWorkspace *w, RooStats::ModelConfig *mc_s, Ro
}
if (saveHybridResult_) {
TString name = TString::Format("HypoTestResult_mh%g",mass_);
RooLinkedListIter it = rValues_.iterator();
for (RooRealVar *rIn = (RooRealVar*) it.Next(); rIn != 0; rIn = (RooRealVar*) it.Next()) {
name += Form("_%s%g", rIn->GetName(), rIn->getVal());
for (RooAbsArg *rIn : rValues_) {
name += Form("_%s%g", rIn->GetName(), static_cast<RooRealVar*>(rIn)->getVal());
}
name += Form("_%u", RooRandom::integer(std::numeric_limits<UInt_t>::max() - 1));
writeToysHere->WriteTObject(new HypoTestResult(*hcResult), name);
Expand Down Expand Up @@ -692,8 +691,8 @@ std::pair<double, double> HybridNew::eval(RooWorkspace *w, RooStats::ModelConfig
}

HybridNew::Setup setup;
RooLinkedListIter it = rVals.iterator();
for (RooRealVar *rIn = (RooRealVar*) it.Next(); rIn != 0; rIn = (RooRealVar*) it.Next()) {
for (RooAbsArg *rInAbsArg : rVals) {
RooRealVar *rIn = static_cast<RooRealVar*>(rInAbsArg);
RooRealVar *r = dynamic_cast<RooRealVar *>(mc_s->GetParametersOfInterest()->find(rIn->GetName()));
r->setVal(rIn->getVal());
if (verbose) std::cout << " " << r->GetName() << " = " << rIn->getVal() << " +/- " << r->getError() << std::endl;
Expand Down Expand Up @@ -807,8 +806,7 @@ std::unique_ptr<RooStats::HybridCalculator> HybridNew::create(RooWorkspace *w, R
// print the values of the parameters used to generate the toy
if (verbose > 2) {
Logger::instance().log(std::string(Form("HybridNew.cc: %d -- Using the following (post-fit) parameters for No signal hypothesis ",__LINE__)),Logger::kLogLevelInfo,__func__);
std::unique_ptr<TIterator> iter(paramsToFit->createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : *paramsToFit) {
TString varstring = utils::printRooArgAsString(a);
Logger::instance().log(std::string(Form("HybridNew.cc: %d -- %s",__LINE__,varstring.Data())),Logger::kLogLevelInfo,__func__);
}
Expand All @@ -835,8 +833,7 @@ std::unique_ptr<RooStats::HybridCalculator> HybridNew::create(RooWorkspace *w, R
Logger::instance().log(std::string(Form("HybridNew.cc: %d -- Using the following (post-fit) parameters for S+B hypothesis ",__LINE__)),Logger::kLogLevelInfo,__func__);
RooArgSet reportParams;
reportParams.add(*paramsToFit); reportParams.add(poi);
std::unique_ptr<TIterator> iter(reportParams.createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : reportParams) {
TString varstring = utils::printRooArgAsString(a);
Logger::instance().log(std::string(Form("HybridNew.cc: %d -- %s",__LINE__,varstring.Data())),Logger::kLogLevelInfo,__func__);
}
Expand Down
6 changes: 1 addition & 5 deletions src/RooMorphingPdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ RooMorphingPdf::RooMorphingPdf(const char* name, const char* title,
mh_lo_(0.),
mh_hi_(0.) {
SetAxisInfo();
TIterator* pdf_iter = pdfs.createIterator();
RooAbsArg* pdf;
while ((pdf = reinterpret_cast<RooAbsArg*>(pdf_iter->Next())))
pdfs_.add(*pdf);
delete pdf_iter;
pdfs_.add(pdfs);
}

RooMorphingPdf::RooMorphingPdf(const RooMorphingPdf& other, const char* name)
Expand Down
10 changes: 2 additions & 8 deletions src/RooParametricHist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#include "RooFit.h"

#include "TFile.h"
#include "TIterator.h"

//using namespace RooFit ;

ClassImp(RooParametricHist)

Expand Down Expand Up @@ -96,11 +93,8 @@ RooArgList & RooParametricHist::getAllBinVars() const {

double RooParametricHist::getFullSum() const {
double sum=0;
TIterator *varIter=pars.createIterator();
RooAbsReal *fVar;
int i=0;
while ( (fVar = (RooAbsReal*) varIter->Next()) ){
double thisVal = fVar->getVal();
for (int i = 0; i < pars.getSize(); ++i) {
double thisVal = static_cast<RooAbsReal&>(pars[i]).getVal();
if (_hasMorphs) thisVal*=evaluateMorphFunction(i);
sum+=thisVal;
i++;
Expand Down
7 changes: 2 additions & 5 deletions src/RooParametricHist2D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,10 @@ void RooParametricHist2D::initializeBins(const TH2 &shape) const {
}

double RooParametricHist2D::getFullSum() const {
//std::cout << "Getting full sum" << std::endl;
double sum=0;

TIterator *varIter=pars.createIterator();
RooAbsReal *fVar;
while ( (fVar = (RooAbsReal*)varIter->Next()) ){
sum+=fVar->getVal();
for (RooAbsArg *arg : pars) {
sum += static_cast<RooAbsReal*>(arg)->getVal();
}

return sum;
Expand Down
6 changes: 1 addition & 5 deletions src/RooPiecewisePolynomial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <cmath>
#include "TVectorD.h"
#include "TMatrixD.h"
#include "TIterator.h"


using namespace std;
Expand Down Expand Up @@ -43,16 +42,13 @@ RooPiecewisePolynomial::RooPiecewisePolynomial(const char* name, const char* tit
{
assert((nfcn>2 && polyndof>=2) || (nfcn==2 && polyndof>=1) || (nfcn==1 && polyndof>=0));

TIterator* coefIter = parList_.createIterator();
RooAbsArg* func;
while ((func = (RooAbsArg*) coefIter->Next())) {
for (RooAbsArg *func : parList_) {
if (!dynamic_cast<RooAbsReal*>(func)) {
cerr << "RooPiecewisePolynomial::RooPiecewisePolynomial(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << endl;
assert(0);
}
parList.add(*func);
}
delete coefIter;
}
RooPiecewisePolynomial::RooPiecewisePolynomial(RooPiecewisePolynomial const& other, const char* name) :
RooAbsReal(other, name),
Expand Down
19 changes: 6 additions & 13 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ RooAbsPdf *utils::factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, Roo
}
if (id == typeid(RooSimultaneousOpt)) {
RooSimultaneousOpt &o = dynamic_cast<RooSimultaneousOpt &>(pdf);
RooLinkedListIter iter = o.extraConstraints().iterator();
if (o.extraConstraints().getSize() > 0) needNew = true;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
for (RooAbsArg *a : o.extraConstraints()) {
if (!constraints.contains(*a) && (!a->getAttribute("ignoreConstraint")) ) constraints.add(*a);
}
}
Expand Down Expand Up @@ -196,8 +195,7 @@ void utils::factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgLis
} else if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) {
if (id == typeid(RooSimultaneousOpt)) {
RooSimultaneousOpt &o = dynamic_cast<RooSimultaneousOpt &>(pdf);
RooLinkedListIter iter = o.extraConstraints().iterator();
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
for (RooAbsArg *a : o.extraConstraints()) {
if (!constraints.contains(*a) && (!a->getAttribute("ignoreConstraint"))) constraints.add(*a);
}
}
Expand Down Expand Up @@ -282,8 +280,7 @@ RooAbsReal *utils::fullCloneFunc(const RooAbsReal *pdf, const RooArgSet &obs, Ro
RooArgSet tmp("RealBranchNodeList"), toClone;
pdf->branchNodeServerList(&tmp);
unsigned int nitems = tmp.getSize();
RooFIter iter = tmp.fwdIterator();
for (RooAbsArg *a = iter.next(); a != 0; a = iter.next()) {
for (RooAbsArg *a : tmp) {
if (a == pdf) toClone.add(*a);
else if (a->dependsOn(obs)) toClone.add(*a);
}
Expand All @@ -298,9 +295,7 @@ RooAbsReal *utils::fullCloneFunc(const RooAbsReal *pdf, const RooArgSet &obs, Ro


void utils::getClients(const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients) {
std::unique_ptr<TIterator> iterAll(allObjects.createIterator());
std::unique_ptr<TIterator> iterVal(values.createIterator());
for (RooAbsArg *v = (RooAbsArg *) iterVal->Next(); v != 0; v = (RooAbsArg *) iterVal->Next()) {
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()) {
Expand Down Expand Up @@ -1029,8 +1024,7 @@ bool utils::anyParameterAtBoundaries( const RooArgSet &params, int verbosity ){

int utils::countFloating(const RooArgSet &params){
int count=0;
RooLinkedListIter iter = params.iterator(); int i = 0;
for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
for (RooAbsArg *a : params) {
if (!a->isConstant()) count++;
}
return count;
Expand All @@ -1051,8 +1045,7 @@ bool utils::freezeAllDisassociatedRooMultiPdfParameters(const RooArgSet & multiP
// For each multiPdf, get the active pdf and remove its parameters
// from this list of params and then freeze the remaining ones

RooLinkedListIter iter = multiPdfs.iterator();
for (RooAbsArg *P = (RooAbsArg *) iter.Next(); P != 0; P = (RooAbsArg *) iter.Next()) {
for (RooAbsArg *P : multiPdfs) {
RooMultiPdf *mpdf = dynamic_cast<RooMultiPdf *>(P);
RooAbsPdf *pdf = (RooAbsPdf*)mpdf->getCurrentPdf();
if (freezeDisassParams_verb) std::cout << " Current active PDF - " << pdf->GetName() <<std::endl;
Expand Down

0 comments on commit 181bd3c

Please sign in to comment.