diff --git a/roofit/histfactory/src/HistFactoryModelUtils.cxx b/roofit/histfactory/src/HistFactoryModelUtils.cxx index 22b481b88cc1e..b307fe4b4c0c2 100644 --- a/roofit/histfactory/src/HistFactoryModelUtils.cxx +++ b/roofit/histfactory/src/HistFactoryModelUtils.cxx @@ -251,18 +251,16 @@ namespace HistFactory{ // loop over channels RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat()); - TIterator* iter = channelCat->typeIterator() ; - RooCatType* tt = NULL; - while((tt=(RooCatType*) iter->Next())) { + for (const auto& nameIdx : *channelCat) { // Get pdf associated with state from simpdf - RooAbsPdf* pdftmp = simPdf->getPdf(tt->GetName()) ; + RooAbsPdf* pdftmp = simPdf->getPdf(nameIdx.first.c_str()); std::string ChannelName = pdftmp->GetName(); //tt->GetName(); if(verbose) std::cout << "Getting data for channel: " << ChannelName << std::endl; ChannelBinDataMap[ ChannelName ] = std::vector(); - RooAbsData* dataForChan = (RooAbsData*) dataByCategory->FindObject(tt->GetName()); + RooAbsData* dataForChan = (RooAbsData*) dataByCategory->FindObject(nameIdx.first.c_str()); if(verbose) dataForChan->Print(); // Generate observables defined by the pdf associated with this state @@ -292,7 +290,6 @@ namespace HistFactory{ } // End Loop Over Categories - delete iter; return; } diff --git a/roofit/histfactory/src/HistFactoryNavigation.cxx b/roofit/histfactory/src/HistFactoryNavigation.cxx index e4811b60d730a..572044eb27554 100644 --- a/roofit/histfactory/src/HistFactoryNavigation.cxx +++ b/roofit/histfactory/src/HistFactoryNavigation.cxx @@ -787,10 +787,8 @@ namespace RooStats { // Iterate over the categories and get the // pdf and observables for each category - TIterator* iter = channelCat->typeIterator() ; - RooCatType* tt = NULL; - while((tt=(RooCatType*) iter->Next())) { - std::string ChannelName = tt->GetName(); + for (const auto& nameIdx : *channelCat) { + const std::string& ChannelName = nameIdx.first; fChannelNameVec.push_back( ChannelName ); RooAbsPdf* pdftmp = simPdf->getPdf(ChannelName.c_str()) ; RooArgSet* obstmp = pdftmp->getObservables(*observables) ; diff --git a/roofit/histfactory/src/RooBarlowBeestonLL.cxx b/roofit/histfactory/src/RooBarlowBeestonLL.cxx index 70b3fcaa8cc18..e164685680590 100644 --- a/roofit/histfactory/src/RooBarlowBeestonLL.cxx +++ b/roofit/histfactory/src/RooBarlowBeestonLL.cxx @@ -194,24 +194,11 @@ void RooStats::HistFactory::RooBarlowBeestonLL::initializeBarlowCache() { // Loop over the channels RooSimultaneous* simPdf = (RooSimultaneous*) _pdf; RooCategory* channelCat = (RooCategory*) (&simPdf->indexCat()); - TIterator* iter = channelCat->typeIterator() ; - RooCatType* tt = NULL; - while((tt=(RooCatType*) iter->Next())) { - /* - std::string ChannelName = tt->GetName(); - - HHChannel_hh_edit - - TIterator* iter_channels = channelsWithConstraints->createIterator(); - RooAbsPdf* channelPdf=NULL; - while(( channelPdf=(RooAbsPdf*)iter_channels->Next() )) { - - std::string channel_name = RooStats::channelNameFromPdf( channelPdf ); - */ + for (const auto& nameIdx : *channelCat) { // Warning: channel cat name is not necesarily the same name // as the pdf's (for example, if someone does edits) - RooAbsPdf* channelPdf = simPdf->getPdf(tt->GetName()); + RooAbsPdf* channelPdf = simPdf->getPdf(nameIdx.first.c_str()); std::string channel_name = channelPdf->GetName(); // First, we check if this channel uses Stat Uncertainties: diff --git a/roofit/roofitcore/CMakeLists.txt b/roofit/roofitcore/CMakeLists.txt index 68a8428bed4a5..92dc05edf7b16 100644 --- a/roofit/roofitcore/CMakeLists.txt +++ b/roofit/roofitcore/CMakeLists.txt @@ -131,7 +131,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore RooLinTransBinning.h RooList.h RooListProxy.h - RooMapCatEntry.h RooMappedCategory.h RooMath.h RooMCIntegrator.h @@ -199,7 +198,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore RooSetPair.h RooSetProxy.h RooSharedProperties.h - RooSharedPropertiesList.h RooSimGenContext.h RooSimPdfBuilder.h RooSimSplitGenContext.h @@ -350,7 +348,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore src/RooLinTransBinning.cxx src/RooList.cxx src/RooListProxy.cxx - src/RooMapCatEntry.cxx src/RooMappedCategory.cxx src/RooMath.cxx src/RooMCIntegrator.cxx @@ -416,7 +413,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore src/RooSetPair.cxx src/RooSetProxy.cxx src/RooSharedProperties.cxx - src/RooSharedPropertiesList.cxx src/RooSimGenContext.cxx src/RooSimPdfBuilder.cxx src/RooSimSplitGenContext.cxx diff --git a/roofit/roofitcore/inc/LinkDef.h b/roofit/roofitcore/inc/LinkDef.h index ecc92dd85fe3b..a4cbe8e71dc2e 100644 --- a/roofit/roofitcore/inc/LinkDef.h +++ b/roofit/roofitcore/inc/LinkDef.h @@ -135,7 +135,6 @@ #pragma link C++ class RooLinTransBinning+ ; #pragma link C++ class RooList+ ; #pragma link C++ class RooListProxy+ ; -#pragma link C++ class RooMapCatEntry+ ; #pragma link C++ class RooMappedCategory+ ; #pragma read sourceClass="RooMappedCategory" targetClass="RooMappedCategory" version="[1]" include="RooFitLegacy/RooCatTypeLegacy.h" source="RooCatType* _defCat" target="_defCat" code="{ _defCat = onfile._defCat->getVal(); }" #pragma link C++ class RooMappedCategory::Entry+; @@ -202,7 +201,6 @@ #pragma link C++ class RooSetPair+ ; #pragma link C++ class RooSetProxy+ ; #pragma link C++ class RooSharedProperties+ ; -#pragma link C++ class RooSharedPropertiesList+ ; #pragma link C++ class RooSimGenContext+ ; #pragma link C++ class RooSimSplitGenContext+ ; #pragma link C++ class RooStreamParser+ ; diff --git a/roofit/roofitcore/inc/RooAbsArg.h b/roofit/roofitcore/inc/RooAbsArg.h index 7f90fa68ddb6b..090ad9fcd8380 100644 --- a/roofit/roofitcore/inc/RooAbsArg.h +++ b/roofit/roofitcore/inc/RooAbsArg.h @@ -107,7 +107,13 @@ class RooAbsArg : public TNamed, public RooPrintable { Bool_t hasClients() const { return !_clientList.empty(); } //////////////////////////////////////////////////////////////////////////// - // Legacy iterators + /// \name Deprecated functions + /// Don't use these iterators, since they are inefficient. References to the + /// underlying containers can be obtained using `clients()` instead of `clientIterator()`, + /// `valueClients()` instead of `valueClientIterator()` etc. + /// These containers allow for range-based for loops and index access. This makes the + /// iterators in this section unnecessary. + /// @{ inline TIterator* clientIterator() const R__SUGGEST_ALTERNATIVE("Use clients() and begin(), end() or range-based loops.") { // Return iterator over all client RooAbsArgs @@ -138,10 +144,10 @@ class RooAbsArg : public TNamed, public RooPrintable { return RooFIter(std::unique_ptr(makeLegacyIterator(_clientListShape))); } inline RooFIter serverMIterator() const - R__SUGGEST_ALTERNATIVE("Use shapeClients() and begin(), end() or range-based loops.") { + R__SUGGEST_ALTERNATIVE("Use servers() and begin(), end() or range-based loops.") { return RooFIter(std::unique_ptr(makeLegacyIterator(_serverList))); } - + /// @} //////////////////////////////////////////////////////////////////////////// /// List of all clients of this object. diff --git a/roofit/roofitcore/inc/RooAbsCategoryLValue.h b/roofit/roofitcore/inc/RooAbsCategoryLValue.h index e1e7886d9966f..6b6be1dcf1b1e 100644 --- a/roofit/roofitcore/inc/RooAbsCategoryLValue.h +++ b/roofit/roofitcore/inc/RooAbsCategoryLValue.h @@ -31,13 +31,43 @@ class RooAbsCategoryLValue : public RooAbsCategory, public RooAbsLValue { // Value modifiers //////////////////////////////////////////////////////////////////////////////// - /// Set value by specifying the index code of the desired state. + /// Change category state by specifying the index code of the desired state. /// If printError is set, a message will be printed if /// the specified index does not represent a valid state. /// \return bool to signal an error. virtual bool setIndex(value_type index, bool printError = true) = 0; + //////////////////////////////////////////////////////////////////////////////// + /// Change category state to state specified by another category state. + /// If printError is set, a message will be printed if + /// the specified index does not represent a valid state. + /// \note The state name of the other category is ignored. + /// \return bool to signal an error. + bool setIndex(const std::pair& nameIdxPair, bool printError = true) { + return setIndex(nameIdxPair.second, printError); + } bool setOrdinal(unsigned int index); + + //////////////////////////////////////////////////////////////////////////////// + /// Change category state by specifying a state name. + /// If printError is set, a message will be printed if + /// the specified state name does not represent a valid state. + /// \return bool to signal an error. virtual bool setLabel(const char* label, Bool_t printError=kTRUE) = 0; + /// \copydoc setLabel(const char*, Bool_t) + bool setLabel(const std::string& label, bool printError = true) { + return setLabel(label.c_str(), printError); + } + //////////////////////////////////////////////////////////////////////////////// + /// Change category state to the state name of another category. + /// If printError is set, a message will be printed if + /// the specified state name does not represent a valid state. + /// \note The state index of the other category is ignored. + /// \return bool to signal an error. + bool setLabel(const std::pair& nameIdxPair, bool printError = true) { + return setLabel(nameIdxPair.first.c_str(), printError); + } + + RooAbsArg& operator=(int index) ; RooAbsArg& operator=(const char* label) ; RooAbsArg& operator=(const RooAbsCategory& other) ; diff --git a/roofit/roofitcore/inc/RooAbsCollection.h b/roofit/roofitcore/inc/RooAbsCollection.h index ab55eeb55899b..613fe6b5b741f 100644 --- a/roofit/roofitcore/inc/RooAbsCollection.h +++ b/roofit/roofitcore/inc/RooAbsCollection.h @@ -138,6 +138,14 @@ class RooAbsCollection : public TObject, public RooPrintable { return _list.end(); } + Storage_t::const_reverse_iterator rbegin() const { + return _list.rbegin(); + } + + Storage_t::const_reverse_iterator rend() const { + return _list.rend(); + } + Storage_t::size_type size() const { return _list.size(); } @@ -238,9 +246,6 @@ class RooAbsCollection : public TObject, public RooPrintable { virtual void RecursiveRemove(TObject *obj); protected: - - friend class RooMultiCatIter ; - Storage_t _list; // Actual object storage using LegacyIterator_t = TIteratorToSTLInterface; diff --git a/roofit/roofitcore/inc/RooCategory.h b/roofit/roofitcore/inc/RooCategory.h index a1cc88fd43a7c..91d9dff0ce86d 100644 --- a/roofit/roofitcore/inc/RooCategory.h +++ b/roofit/roofitcore/inc/RooCategory.h @@ -37,7 +37,9 @@ class RooCategory final : public RooAbsCategoryLValue { } virtual Bool_t setIndex(Int_t index, bool printError = true) override; + using RooAbsCategoryLValue::setIndex; virtual Bool_t setLabel(const char* label, bool printError = true) override; + using RooAbsCategoryLValue::setLabel; // I/O streaming interface (machine readable) virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) override; diff --git a/roofit/roofitcore/inc/RooMapCatEntry.h b/roofit/roofitcore/inc/RooMapCatEntry.h deleted file mode 100644 index cccfb1001adf0..0000000000000 --- a/roofit/roofitcore/inc/RooMapCatEntry.h +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************************** - * Project: RooFit * - * Package: RooFitCore * - * File: $Id: RooMapCatEntry.h,v 1.13 2007/05/11 09:11:30 verkerke Exp $ - * Authors: * - * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * - * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * - * * - * Copyright (c) 2000-2005, Regents of the University of California * - * and Stanford University. All rights reserved. * - * * - * Redistribution and use in source and binary forms, * - * with or without modification, are permitted according to the terms * - * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * - *****************************************************************************/ -#ifndef ROO_MAP_CAT_ENTRY -#define ROO_MAP_CAT_ENTRY - -#include "TNamed.h" -#include "TRegexp.h" -#include "RooCatType.h" - -class RooMapCatEntry : public TNamed { -public: - inline RooMapCatEntry() : TNamed(), _regexp(""), _cat() {} - virtual ~RooMapCatEntry() {} ; - RooMapCatEntry(const char* exp, const RooCatType* cat) ; - RooMapCatEntry(const RooMapCatEntry& other) ; - virtual TObject* Clone(const char* newName=0) const { - RooMapCatEntry* ca = new RooMapCatEntry(*this); - if (newName) { ca->SetName(newName) ; } - return ca ; - } - - inline Bool_t ok() { return (_regexp.Status()==TRegexp::kOK) ; } - Bool_t match(const char* testPattern) const ; - inline const RooCatType& outCat() const { return _cat ; } - -protected: - - TString mangle(const char* exp) const ; - - TRegexp _regexp ; - RooCatType _cat ; - - ClassDef(RooMapCatEntry,1) // Utility class, holding a map expression from a index label regexp to a RooCatType -} ; - - -#endif diff --git a/roofit/roofitcore/inc/RooRealIntegral.h b/roofit/roofitcore/inc/RooRealIntegral.h index c74a209d32c2d..b2bd1f754ba2a 100644 --- a/roofit/roofitcore/inc/RooRealIntegral.h +++ b/roofit/roofitcore/inc/RooRealIntegral.h @@ -123,7 +123,6 @@ class RooRealIntegral : public RooAbsReal { RooNumIntConfig* _iconfig ; mutable RooListProxy _sumCat ; //! do not persist - TIterator* _sumCatIter ; //! Int_t _mode ; IntOperMode _intOperMode ; // integration operation mode diff --git a/roofit/roofitcore/inc/RooSharedPropertiesList.h b/roofit/roofitcore/inc/RooSharedPropertiesList.h deleted file mode 100644 index b3b31e1fa39b7..0000000000000 --- a/roofit/roofitcore/inc/RooSharedPropertiesList.h +++ /dev/null @@ -1,42 +0,0 @@ -/***************************************************************************** - * Project: RooFit * - * Package: RooFitCore * - * File: $Id: RooSharedPropertiesList.h,v 1.2 2007/05/11 09:11:30 verkerke Exp $ - * Authors: * - * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * - * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * - * * - * Copyright (c) 2000-2005, Regents of the University of California * - * and Stanford University. All rights reserved. * - * * - * Redistribution and use in source and binary forms, * - * with or without modification, are permitted according to the terms * - * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * - *****************************************************************************/ -#ifndef ROO_SHARED_PROPERTY_LIST -#define ROO_SHARED_PROPERTY_LIST - -#include "TObject.h" -#include "RooRefCountList.h" -#include "RooSharedProperties.h" -#include - -class RooSharedPropertiesList : public TObject { -public: - - RooSharedPropertiesList() ; - virtual ~RooSharedPropertiesList() ; - - RooSharedProperties* registerProperties(RooSharedProperties*, Bool_t canDeleteIncoming=kTRUE) ; - void unregisterProperties(RooSharedProperties*) ; - -protected: - - RooRefCountList _propList ; - std::map _newPropList; - - ClassDef(RooSharedPropertiesList,0) // Manager for shared properties among clones of certain RooAbsArg-derived types -}; - - -#endif diff --git a/roofit/roofitcore/inc/RooSuperCategory.h b/roofit/roofitcore/inc/RooSuperCategory.h index 71a1b29141081..87bb35ee0bb10 100644 --- a/roofit/roofitcore/inc/RooSuperCategory.h +++ b/roofit/roofitcore/inc/RooSuperCategory.h @@ -34,7 +34,9 @@ class RooSuperCategory : public RooAbsCategoryLValue { virtual ~RooSuperCategory() { }; virtual bool setIndex(value_type index, bool printError = true) override ; + using RooAbsCategoryLValue::setIndex; virtual Bool_t setLabel(const char* label, Bool_t printError=kTRUE) override; + using RooAbsCategoryLValue::setLabel; // Printing interface (human readable) virtual void printMultiline(std::ostream& os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const override; diff --git a/roofit/roofitcore/src/Roo1DTable.cxx b/roofit/roofitcore/src/Roo1DTable.cxx index 2a2a97e24c5dd..39fea93b4956f 100644 --- a/roofit/roofitcore/src/Roo1DTable.cxx +++ b/roofit/roofitcore/src/Roo1DTable.cxx @@ -23,16 +23,20 @@ Roo1DTable implements a one-dimensional table. A table is the category equivalent of a plot. To create a table use the RooDataSet::table method. **/ -#include "RooFit.h" +#include "Roo1DTable.h" +#include "RooFit.h" #include "Riostream.h" -#include +#include "RooMsgService.h" +#include "RooFitLegacy/RooCatTypeLegacy.h" + #include "TString.h" #include "TMath.h" -#include "Roo1DTable.h" -#include "RooMsgService.h" #include "TClass.h" +#include + + using namespace std ; ClassImp(Roo1DTable); diff --git a/roofit/roofitcore/src/RooAbsArg.cxx b/roofit/roofitcore/src/RooAbsArg.cxx index 893ebfd5cf07c..de1855d5a50ee 100644 --- a/roofit/roofitcore/src/RooAbsArg.cxx +++ b/roofit/roofitcore/src/RooAbsArg.cxx @@ -996,20 +996,21 @@ Bool_t RooAbsArg::redirectServers(const RooAbsCollection& newSetOrig, Bool_t mus setShapeDirty() ; // Process the proxies - Bool_t allReplaced=kTRUE ; for (int i=0 ; ichangePointer(*newSet,nameChange,kFALSE) ; - allReplaced &= ret2 ; - } - if (mustReplaceAll && !allReplaced) { - coutE(LinkStateMgmt) << "RooAbsArg::redirectServers(" << GetName() - << "): ERROR, some proxies could not be adjusted" << endl ; - ret = kTRUE ; + if (mustReplaceAll && !ret2) { + auto ap = dynamic_cast(p); + coutE(LinkStateMgmt) << "RooAbsArg::redirectServers(" << GetName() + << "): ERROR, proxy '" << p->name() + << "' with arg '" << (ap ? ap->absArg()->GetName() : "") << "' could not be adjusted" << endl; + ret = kTRUE ; + } } + // Optional subclass post-processing for (Int_t i=0 ;iredirectServersHook(*newSet,mustReplaceAll,nameChange,isRecursionStep) ; diff --git a/roofit/roofitcore/src/RooAbsCategory.cxx b/roofit/roofitcore/src/RooAbsCategory.cxx index b98eebb54b15e..5cf527e3f8e69 100644 --- a/roofit/roofitcore/src/RooAbsCategory.cxx +++ b/roofit/roofitcore/src/RooAbsCategory.cxx @@ -273,7 +273,7 @@ void RooAbsCategory::clearTypes() //////////////////////////////////////////////////////////////////////////////// /// Find the index number corresponding to the state name. -/// \see isValidLabel() for checking if a given label has been defined. +/// \see hasLabel() for checking if a given label has been defined. /// \return Index of the category or std::numeric_limits::min() on failure. RooAbsCategory::value_type RooAbsCategory::lookupIndex(const std::string& stateName) const { const auto item = stateNames().find(stateName); diff --git a/roofit/roofitcore/src/RooAbsData.cxx b/roofit/roofitcore/src/RooAbsData.cxx index 55b2bcd68c424..87ef68d8ebca1 100644 --- a/roofit/roofitcore/src/RooAbsData.cxx +++ b/roofit/roofitcore/src/RooAbsData.cxx @@ -1529,13 +1529,10 @@ TList* RooAbsData::split(const RooAbsCategory& splitCat, Bool_t createEmptyDataS // If createEmptyDataSets is true, prepopulate with empty sets corresponding to all states if (createEmptyDataSets) { - TIterator* stateIter = cloneCat->typeIterator() ; - RooCatType* state ; - while ((state=(RooCatType*)stateIter->Next())) { - RooAbsData* subset = emptyClone(state->GetName(),state->GetName(),&subsetVars,(addWV?"weight":0)) ; + for (const auto& nameIdx : *cloneCat) { + RooAbsData* subset = emptyClone(nameIdx.first.c_str(), nameIdx.first.c_str(), &subsetVars,(addWV?"weight":0)) ; dsetList->Add((RooAbsArg*)subset) ; } - delete stateIter ; } @@ -2015,7 +2012,7 @@ RooPlot* RooAbsData::plotEffOn(RooPlot* frame, const RooAbsCategoryLValue& effCa // convert this histogram to a RooHist object on the heap RooHist *graph= new RooHist(*hist1,*hist2,0,1,o.etype,o.xErrorSize,kTRUE); - graph->setYAxisLabel(Form("Efficiency of %s=%s",effCat.GetName(),effCat.lookupType(1)->GetName())) ; + graph->setYAxisLabel(Form("Efficiency of %s=%s", effCat.GetName(), effCat.lookupName(1).c_str())); // initialize the frame's normalization setup, if necessary frame->updateNormVars(_vars); diff --git a/roofit/roofitcore/src/RooAbsTestStatistic.cxx b/roofit/roofitcore/src/RooAbsTestStatistic.cxx index da0898153d84e..be501d0e73714 100644 --- a/roofit/roofitcore/src/RooAbsTestStatistic.cxx +++ b/roofit/roofitcore/src/RooAbsTestStatistic.cxx @@ -513,12 +513,11 @@ void RooAbsTestStatistic::initSimMode(RooSimultaneous* simpdf, RooAbsData* data, // Count number of used states Int_t n = 0; _nGof = 0; - RooCatType* type; - TIterator* catIter = simCat.typeIterator(); - while ((type = (RooCatType*) catIter->Next())) { + + for (const auto& catState : simCat) { // Retrieve the PDF for this simCat state - RooAbsPdf* pdf = simpdf->getPdf(type->GetName()); - RooAbsData* dset = (RooAbsData*) dsetList->FindObject(type->GetName()); + RooAbsPdf* pdf = simpdf->getPdf(catState.first.c_str()); + RooAbsData* dset = (RooAbsData*) dsetList->FindObject(catState.first.c_str()); if (pdf && dset && (0. != dset->sumEntries() || processEmptyDataSets())) { ++_nGof; @@ -530,14 +529,14 @@ void RooAbsTestStatistic::initSimMode(RooSimultaneous* simpdf, RooAbsData* data, _gofSplitMode.resize(_nGof); // Create array of regular fit contexts, containing subset of data and single fitCat PDF - catIter->Reset(); - while ((type = (RooCatType*) catIter->Next())) { + for (const auto& catState : simCat) { + const std::string& catName = catState.first; // Retrieve the PDF for this simCat state - RooAbsPdf* pdf = simpdf->getPdf(type->GetName()); - RooAbsData* dset = (RooAbsData*) dsetList->FindObject(type->GetName()); + RooAbsPdf* pdf = simpdf->getPdf(catName.c_str()); + RooAbsData* dset = (RooAbsData*) dsetList->FindObject(catName.c_str()); if (pdf && dset && (0. != dset->sumEntries() || processEmptyDataSets())) { - ccoutI(Fitting) << "RooAbsTestStatistic::initSimMode: creating slave calculator #" << n << " for state " << type->GetName() + ccoutI(Fitting) << "RooAbsTestStatistic::initSimMode: creating slave calculator #" << n << " for state " << catName << " (" << dset->numEntries() << " dataset entries)" << endl; @@ -568,10 +567,10 @@ void RooAbsTestStatistic::initSimMode(RooSimultaneous* simpdf, RooAbsData* data, // Below here directly pass binnedPdf instead of PROD(binnedPdf,constraints) as constraints are evaluated elsewhere anyway // and omitting them reduces model complexity and associated handling/cloning times if (_splitRange && rangeName) { - _gofArray[n] = create(type->GetName(),type->GetName(),(binnedPdf?*binnedPdf:*pdf),*dset,*projDeps, - Form("%s_%s",rangeName,type->GetName()),addCoefRangeName,_nCPU*(_mpinterl?-1:1),_mpinterl,_verbose,_splitRange,binnedL); + _gofArray[n] = create(catName.c_str(), catName.c_str(),(binnedPdf?*binnedPdf:*pdf),*dset,*projDeps, + Form("%s_%s",rangeName,catName.c_str()),addCoefRangeName,_nCPU*(_mpinterl?-1:1),_mpinterl,_verbose,_splitRange,binnedL); } else { - _gofArray[n] = create(type->GetName(),type->GetName(),(binnedPdf?*binnedPdf:*pdf),*dset,*projDeps, + _gofArray[n] = create(catName.c_str(),catName.c_str(),(binnedPdf?*binnedPdf:*pdf),*dset,*projDeps, rangeName,addCoefRangeName,_nCPU,_mpinterl,_verbose,_splitRange,binnedL); } _gofArray[n]->setSimCount(_nGof); @@ -605,7 +604,7 @@ void RooAbsTestStatistic::initSimMode(RooSimultaneous* simpdf, RooAbsData* data, } else { if ((!dset || (0. != dset->sumEntries() && !processEmptyDataSets())) && pdf) { if (_verbose) { - ccoutD(Fitting) << "RooAbsTestStatistic::initSimMode: state " << type->GetName() + ccoutD(Fitting) << "RooAbsTestStatistic::initSimMode: state " << catName << " has no data entries, no slave calculator created" << endl; } } @@ -615,7 +614,6 @@ void RooAbsTestStatistic::initSimMode(RooSimultaneous* simpdf, RooAbsData* data, dsetList->Delete(); // delete the content. delete dsetList; - delete catIter; } diff --git a/roofit/roofitcore/src/RooAddition.cxx b/roofit/roofitcore/src/RooAddition.cxx index 11600c5ef2939..e90c8f11cdd3f 100644 --- a/roofit/roofitcore/src/RooAddition.cxx +++ b/roofit/roofitcore/src/RooAddition.cxx @@ -21,8 +21,7 @@ RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets, it sums the product of the terms -in the two sets. This class does not (yet) do any smart handling of integrals, -i.e. all integrals of the product are handled numerically. +in the two sets. **/ diff --git a/roofit/roofitcore/src/RooBinningCategory.cxx b/roofit/roofitcore/src/RooBinningCategory.cxx index a5b120d2289ba..aed697f4e10d2 100644 --- a/roofit/roofitcore/src/RooBinningCategory.cxx +++ b/roofit/roofitcore/src/RooBinningCategory.cxx @@ -99,7 +99,7 @@ RooAbsCategory::value_type RooBinningCategory::evaluate() const if (!hasIndex(ibin)) { string name = (_bname.Length()>0) ? Form("%s_%s_bin%d",_inputVar.arg().GetName(),_bname.Data(),ibin) : Form("%s_bin%d",_inputVar.arg().GetName(),ibin) ; - const_cast(this)->defineState(name.c_str(),ibin); + const_cast(this)->defineState(name,ibin); } return ibin; diff --git a/roofit/roofitcore/src/RooCategory.cxx b/roofit/roofitcore/src/RooCategory.cxx index 979776ac8570d..1251e62e8fa1e 100644 --- a/roofit/roofitcore/src/RooCategory.cxx +++ b/roofit/roofitcore/src/RooCategory.cxx @@ -19,12 +19,16 @@ \class RooCategory \ingroup Roofitcore -RooCategory represents a fundamental (non-derived) discrete category object. "Fundamental" means that -it can be written into a dataset. (Objects in datasets cannot depend on other objects' values, -they need to have their own value). A category object can be used to *e.g.* conduct a simultaneous fit of -the same observable in multiple categories -The states of the category can be denoted by integers (faster) or state names. +RooCategory is an object to represent discrete states. +States have names and index numbers, and the index numbers can be written into datasets and +used in calculations. +A category is "fundamental", i.e., its value doesn't depend on the value of other objects. +(Objects in datasets cannot depend on other objects' values, they need to be self-consistent.) +A category object can be used to *e.g.* conduct a simultaneous fit of +the same observable in multiple categories. + +### Setting up a category A category can be set up like this: ~~~{.cpp} RooCategory myCat("myCat", "Lepton multiplicity category", { @@ -33,6 +37,12 @@ RooCategory myCat("myCat", "Lepton multiplicity category", { {"2Lep", 2}, {"3Lep", 3} }); +~~~{.cpp} +Like this: +~~~ +RooCategory myCat("myCat", "Asymmetry"); +myCat["left"] = -1; +myCat["right"] = 1; ~~~ Or like this: ~~~{.cpp} @@ -40,10 +50,21 @@ RooCategory myCat("myCat", "Asymmetry"); myCat.defineType("left", -1); myCat.defineType("right", 1); ~~~ -Inspect the pairs of index number and state names like this: +Inspect the pairs of state names and state numbers like this: +~~~{.cpp} +for (const auto& nameIdx : myCat) { + std::cout << nameIdx.first << " --> " << nameIdx.second << std::endl; +} +~~~ + +### Changing category states +Category states can be modified either by using the index state (faster) or state names. +For example: ~~~{.cpp} -for (const auto& idxAndName : myCat) { - std::cout << idxAndName.first << " --> " << idxAndName.second << std::endl; +myCat.setIndex(5); +myCat.setLabel("left"); +for (const auto& otherNameIdx : otherCat) { + myCat.setIndex(otherNameIdx); } ~~~ diff --git a/roofit/roofitcore/src/RooCompositeDataStore.cxx b/roofit/roofitcore/src/RooCompositeDataStore.cxx index 42c728e875f1f..e9c0db1e67170 100644 --- a/roofit/roofitcore/src/RooCompositeDataStore.cxx +++ b/roofit/roofitcore/src/RooCompositeDataStore.cxx @@ -28,19 +28,21 @@ dataset to RooFit operations. A category tag will define which dataset has to be When iterated from start to finish, datasets will be traversed in the order of the category index. **/ -#include "RooFit.h" -#include "RooMsgService.h" #include "RooCompositeDataStore.h" +#include "RooFit.h" +#include "RooMsgService.h" #include "Riostream.h" -#include "TTree.h" -#include "TChain.h" -#include "TDirectory.h" -#include "TROOT.h" #include "RooFormulaVar.h" #include "RooRealVar.h" #include "RooTrace.h" #include "RooCategory.h" + +#include "TTree.h" +#include "TChain.h" +#include "TDirectory.h" +#include "TROOT.h" + #include using namespace std ; @@ -63,8 +65,9 @@ RooCompositeDataStore::RooCompositeDataStore() : _indexCat(0), _curStore(0), _cu RooCompositeDataStore::RooCompositeDataStore(const char* name, const char* title, const RooArgSet& vars, RooCategory& indexCat,map inputData) : RooAbsDataStore(name,title,RooArgSet(vars,indexCat)), _indexCat(&indexCat), _curStore(0), _curIndex(0), _ownComps(kFALSE) { - for (map::iterator iter=inputData.begin() ; iter!=inputData.end() ; ++iter) { - _dataMap[indexCat.lookupType(iter->first.c_str())->getVal()] = iter->second ; + for (const auto& iter : inputData) { + const RooAbsCategory::value_type idx = indexCat.lookupIndex(iter.first); + _dataMap[idx] = iter.second; } TRACE_CREATE } diff --git a/roofit/roofitcore/src/RooDataHist.cxx b/roofit/roofitcore/src/RooDataHist.cxx index d3d2bca6f79fa..d13fbad887f44 100644 --- a/roofit/roofitcore/src/RooDataHist.cxx +++ b/roofit/roofitcore/src/RooDataHist.cxx @@ -452,11 +452,11 @@ void RooDataHist::importTH1Set(const RooArgList& vars, RooCategory& indexCat, ma } // Define state labels in index category (both in provided indexCat and in internal copy in dataset) if (!indexCat.lookupType(hiter->first.c_str())) { - indexCat.defineType(hiter->first.c_str()) ; + indexCat.defineType(hiter->first) ; coutI(InputArguments) << "RooDataHist::importTH1Set(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat.GetName() << endl ; } if (!icat->lookupType(hiter->first.c_str())) { - icat->defineType(hiter->first.c_str()) ; + icat->defineType(hiter->first) ; } } @@ -544,11 +544,11 @@ void RooDataHist::importDHistSet(const RooArgList& /*vars*/, RooCategory& indexC // Define state labels in index category (both in provided indexCat and in internal copy in dataset) if (!indexCat.lookupType(diter->first.c_str())) { - indexCat.defineType(diter->first.c_str()) ; + indexCat.defineType(diter->first) ; coutI(InputArguments) << "RooDataHist::importDHistSet(" << GetName() << ") defining state \"" << diter->first << "\" in index category " << indexCat.GetName() << endl ; } if (!icat->lookupType(diter->first.c_str())) { - icat->defineType(diter->first.c_str()) ; + icat->defineType(diter->first) ; } } diff --git a/roofit/roofitcore/src/RooDataProjBinding.cxx b/roofit/roofitcore/src/RooDataProjBinding.cxx index f224874ef1da6..5ddc9a778e14c 100644 --- a/roofit/roofitcore/src/RooDataProjBinding.cxx +++ b/roofit/roofitcore/src/RooDataProjBinding.cxx @@ -106,20 +106,17 @@ Double_t RooDataProjBinding::operator()(const Double_t xvector[]) const if (_catTable) { // Data contains only categories, sum over weighted supercategory states - TIterator* iter = _superCat->typeIterator() ; - RooCatType* type ; - while((type=(RooCatType*)iter->Next())) { + for (const auto& nameIdx : *_superCat) { // Backprop state to data set so that _real takes appropriate value - _superCat->setIndex(type->getVal()) ; + _superCat->setIndex(nameIdx) ; // Add weighted sum - Double_t wgt = _catTable->get(type->GetName()) ; + Double_t wgt = _catTable->get(nameIdx.first.c_str()); if (wgt) { result += wgt * _real->getVal(_nset) ; wgtSum += wgt ; } } - delete iter ; } else { diff --git a/roofit/roofitcore/src/RooDataSet.cxx b/roofit/roofitcore/src/RooDataSet.cxx index 7f22da52da1f6..81629a199a42c 100644 --- a/roofit/roofitcore/src/RooDataSet.cxx +++ b/roofit/roofitcore/src/RooDataSet.cxx @@ -298,12 +298,12 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var } for (map::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) { // Define state labels in index category (both in provided indexCat and in internal copy in dataset) - if (indexCat && !indexCat->lookupType(hiter->first.c_str())) { - indexCat->defineType(hiter->first.c_str()) ; + if (indexCat && !indexCat->hasLabel(hiter->first)) { + indexCat->defineType(hiter->first) ; coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ; } - if (icat && !icat->lookupType(hiter->first.c_str())) { - icat->defineType(hiter->first.c_str()) ; + if (icat && !icat->hasLabel(hiter->first)) { + icat->defineType(hiter->first) ; } icat->setLabel(hiter->first.c_str()) ; storeMap[icat->getCurrentLabel()]=hiter->second->store() ; @@ -431,12 +431,12 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ; for (map::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) { // Define state labels in index category (both in provided indexCat and in internal copy in dataset) - if (!indexCat->lookupType(hiter->first.c_str())) { - indexCat->defineType(hiter->first.c_str()) ; + if (!indexCat->hasLabel(hiter->first)) { + indexCat->defineType(hiter->first) ; coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ; } - if (!icat->lookupType(hiter->first.c_str())) { - icat->defineType(hiter->first.c_str()) ; + if (!icat->hasLabel(hiter->first)) { + icat->defineType(hiter->first) ; } icat->setLabel(hiter->first.c_str()) ; @@ -495,12 +495,12 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ; for (map::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) { // Define state labels in index category (both in provided indexCat and in internal copy in dataset) - if (!indexCat->lookupType(hiter->first.c_str())) { - indexCat->defineType(hiter->first.c_str()) ; + if (!indexCat->hasLabel(hiter->first)) { + indexCat->defineType(hiter->first) ; coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ; } - if (!icat->lookupType(hiter->first.c_str())) { - icat->defineType(hiter->first.c_str()) ; + if (!icat->hasLabel(hiter->first)) { + icat->defineType(hiter->first) ; } icat->setLabel(hiter->first.c_str()) ; _dstore->loadValues(hiter->second->store(),cutVar,cutRange) ; @@ -550,19 +550,18 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ; for (map::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) { // Define state labels in index category (both in provided indexCat and in internal copy in dataset) - if (!indexCat->lookupType(hiter->first.c_str())) { - indexCat->defineType(hiter->first.c_str()) ; + if (!indexCat->hasLabel(hiter->first)) { + indexCat->defineType(hiter->first) ; coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ; } - if (!icat->lookupType(hiter->first.c_str())) { - icat->defineType(hiter->first.c_str()) ; + if (!icat->hasLabel(hiter->first)) { + icat->defineType(hiter->first) ; } icat->setLabel(hiter->first.c_str()) ; // Case 2c --- Import multiple RooDataSets as slices _dstore->loadValues(hiter->second->store(),0,cutRange) ; } - } else if (impData) { // Case 3c --- Import RooDataSet _dstore->loadValues(impData->store(),0,cutRange); @@ -1776,10 +1775,9 @@ RooDataSet *RooDataSet::read(const char *fileList, const RooArgList &varList, // Use user category name if provided catname++ ; - const RooCatType* type = indexCat->lookupType(catname,kFALSE) ; - if (type) { + if (indexCat->hasLabel(catname)) { // Use existing category index - indexCat->setIndex(type->getVal()) ; + indexCat->setLabel(catname); } else { // Register cat name indexCat->defineType(catname,fileSeqNum) ; @@ -1859,9 +1857,10 @@ RooDataSet *RooDataSet::read(const char *fileList, const RooArgList &varList, if (indexCat) { // Copy dynamically defined types from new data set to indexCat in original list - RooCategory* origIndexCat = (RooCategory*) variables.find(indexCatName) ; - for (const auto& type : *indexCat) { - origIndexCat->defineType(type.first, type.second); + assert(dynamic_cast(variables.find(indexCatName))); + const auto origIndexCat = static_cast(variables.find(indexCatName)); + for (const auto& nameIdx : *indexCat) { + origIndexCat->defineType(nameIdx.first, nameIdx.second); } } oocoutI(data.get(),DataHandling) << "RooDataSet::read: read " << data->numEntries() diff --git a/roofit/roofitcore/src/RooFormula.cxx b/roofit/roofitcore/src/RooFormula.cxx index 632a043ecc9ca..0135b185622a6 100644 --- a/roofit/roofitcore/src/RooFormula.cxx +++ b/roofit/roofitcore/src/RooFormula.cxx @@ -172,13 +172,12 @@ std::string RooFormula::processFormula(std::string formula) const { continue; } - const RooCatType* catType = catVariable->lookupType(catState.c_str(), false); - if (!catType) { + if (!catVariable->hasLabel(catState)) { coutE(InputArguments) << "Formula " << GetName() << " uses '::' to reference a category state as '" << fullMatch << "' but the category '" << catName << "' does not seem to have the state '" << catState << "'." << endl; throw std::invalid_argument(formula); } - const int catNum = catType->getVal(); + const int catNum = catVariable->lookupIndex(catState); categoryStates[fullMatch] = catNum; cxcoutD(InputArguments) << "\n\t" << fullMatch << "\tname=" << catName << "\tstate=" << catState << "=" << catNum; diff --git a/roofit/roofitcore/src/RooMapCatEntry.cxx b/roofit/roofitcore/src/RooMapCatEntry.cxx deleted file mode 100644 index a055e02153814..0000000000000 --- a/roofit/roofitcore/src/RooMapCatEntry.cxx +++ /dev/null @@ -1,63 +0,0 @@ -/***************************************************************************** - * Project: RooFit * - * Package: RooFitCore * - * @(#)root/roofitcore:$Id$ - * Authors: * - * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * - * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * - * * - * Copyright (c) 2000-2005, Regents of the University of California * - * and Stanford University. All rights reserved. * - * * - * Redistribution and use in source and binary forms, * - * with or without modification, are permitted according to the terms * - * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * - *****************************************************************************/ - -// -- CLASS DESCRIPTION [AUX] -- -// RooMapCatEntry is an auxilary class for RooMappedCategory and defines a -// a mapping. A mapping consists of a wildcard regular expression, that -// can be matched against the input category state label and an output -// category state (RooCatType), which should be assign if the match is successfull. - -#include "RooFit.h" - -#include "RooMapCatEntry.h" -#include "TString.h" - -using namespace std; - -ClassImp(RooMapCatEntry); -; - -RooMapCatEntry::RooMapCatEntry(const char* exp, const RooCatType* cat) : - TNamed(exp,mangle(exp).Data()), _regexp(mangle(exp),kTRUE), _cat(*cat) -{ -} - - -RooMapCatEntry::RooMapCatEntry(const RooMapCatEntry& other) : - TNamed(other), _regexp(other.GetTitle(),kTRUE), _cat(other._cat) -{ -} - - -Bool_t RooMapCatEntry::match(const char* testPattern) const -{ - return (TString(testPattern).Index(_regexp)>=0) ; -} - - - -TString RooMapCatEntry::mangle(const char* exp) const -{ - // Mangle name : escape regexp character '+' - TString t ; - const char *c = exp ; - while(*c) { - if (*c=='+') t.Append('\\') ; - t.Append(*c) ; - c++ ; - } - return t ; -} diff --git a/roofit/roofitcore/src/RooNumGenConfig.cxx b/roofit/roofitcore/src/RooNumGenConfig.cxx index a17499dcb3bcd..211f9c8b6ed22 100644 --- a/roofit/roofitcore/src/RooNumGenConfig.cxx +++ b/roofit/roofitcore/src/RooNumGenConfig.cxx @@ -245,7 +245,7 @@ const RooCategory& RooNumGenConfig::methodND(Bool_t cond, Bool_t cat) const Bool_t RooNumGenConfig::addConfigSection(const RooAbsNumGenerator* proto, const RooArgSet& inDefaultConfig) { - TString name = proto->IsA()->GetName() ; + std::string name = proto->IsA()->GetName(); // Register integrator for appropriate dimensionalities @@ -272,7 +272,7 @@ Bool_t RooNumGenConfig::addConfigSection(const RooAbsNumGenerator* proto, const // Store default configuration parameters RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ; - config->setName(name) ; + config->setName(name.c_str()); _configSets.Add(config) ; return kFALSE ; diff --git a/roofit/roofitcore/src/RooNumIntConfig.cxx b/roofit/roofitcore/src/RooNumIntConfig.cxx index 04624ad233e60..314c23c24e42b 100644 --- a/roofit/roofitcore/src/RooNumIntConfig.cxx +++ b/roofit/roofitcore/src/RooNumIntConfig.cxx @@ -173,7 +173,7 @@ RooNumIntConfig& RooNumIntConfig::operator=(const RooNumIntConfig& other) Bool_t RooNumIntConfig::addConfigSection(const RooAbsIntegrator* proto, const RooArgSet& inDefaultConfig) { - TString name = proto->IsA()->GetName() ; + std::string name = proto->IsA()->GetName() ; // Register integrator for appropriate dimensionalities if (proto->canIntegrate1D()) { @@ -199,7 +199,7 @@ Bool_t RooNumIntConfig::addConfigSection(const RooAbsIntegrator* proto, const Ro // Store default configuration parameters RooArgSet* config = (RooArgSet*) inDefaultConfig.snapshot() ; - config->setName(name) ; + config->setName(name.c_str()); _configSets.Add(config) ; return kFALSE ; diff --git a/roofit/roofitcore/src/RooRealIntegral.cxx b/roofit/roofitcore/src/RooRealIntegral.cxx index abf5f1edd6546..dead019658a1a 100644 --- a/roofit/roofitcore/src/RooRealIntegral.cxx +++ b/roofit/roofitcore/src/RooRealIntegral.cxx @@ -65,7 +65,6 @@ RooRealIntegral::RooRealIntegral() : _respectCompSelect(true), _funcNormSet(0), _iconfig(0), - _sumCatIter(0), _mode(0), _intOperMode(Hybrid), _restartNumIntEngine(kFALSE), @@ -105,7 +104,6 @@ RooRealIntegral::RooRealIntegral(const char *name, const char *title, const_cast(function),kFALSE,kFALSE), _iconfig((RooNumIntConfig*)config), _sumCat("!sumCat","SuperCategory for summation",this,kFALSE,kFALSE), - _sumCatIter(0), _mode(0), _intOperMode(Hybrid), _restartNumIntEngine(kFALSE), @@ -549,7 +547,6 @@ RooRealIntegral::RooRealIntegral(const char *name, const char *title, if (_sumList.getSize()>0) { RooSuperCategory *sumCat = new RooSuperCategory(Form("%s_sumCat",GetName()),"sumCat",_sumList) ; - _sumCatIter = sumCat->typeIterator() ; _sumCat.addOwned(*sumCat) ; } @@ -697,7 +694,6 @@ RooRealIntegral::RooRealIntegral(const RooRealIntegral& other, const char* name) _function("!func",this,other._function), _iconfig(other._iconfig), _sumCat("!sumCat",this,other._sumCat), - _sumCatIter(0), _mode(other._mode), _intOperMode(other._intOperMode), _restartNumIntEngine(kFALSE), @@ -732,7 +728,6 @@ RooRealIntegral::~RooRealIntegral() if (_numIntEngine) delete _numIntEngine ; if (_numIntegrand) delete _numIntegrand ; if (_funcNormSet) delete _funcNormSet ; - if (_sumCatIter) delete _sumCatIter ; if (_params) delete _params ; TRACE_DESTROY @@ -955,13 +950,11 @@ Double_t RooRealIntegral::sum() const // Add integrals for all permutations of categories summed over Double_t total(0) ; - _sumCatIter->Reset() ; - RooCatType* type ; RooSuperCategory* sumCat = (RooSuperCategory*) _sumCat.first() ; - while((type=(RooCatType*)_sumCatIter->Next())) { - sumCat->setIndex(type->getVal()) ; + for (const auto& nameIdx : *sumCat) { + sumCat->setIndex(nameIdx); if (!_rangeName || sumCat->inRange(RooNameReg::str(_rangeName))) { - total += integrate() / jacobianProduct() ; + total += integrate() / jacobianProduct() ; } } diff --git a/roofit/roofitcore/src/RooSharedPropertiesList.cxx b/roofit/roofitcore/src/RooSharedPropertiesList.cxx deleted file mode 100644 index 9c9eef894dea2..0000000000000 --- a/roofit/roofitcore/src/RooSharedPropertiesList.cxx +++ /dev/null @@ -1,138 +0,0 @@ -/***************************************************************************** - * Project: RooFit * - * Package: RooFitCore * - * @(#)root/roofitcore:$Id$ - * Authors: * - * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * - * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * - * * - * Copyright (c) 2000-2005, Regents of the University of California * - * and Stanford University. All rights reserved. * - * * - * Redistribution and use in source and binary forms, * - * with or without modification, are permitted according to the terms * - * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * - *****************************************************************************/ - -/** -\file RooSharedPropertiesList.cxx -\class RooSharedPropertiesList -\ingroup Roofitcore - -Class RooSharedPropertiesList maintains the properties of RooRealVars -and RooCategories that are clones of each other. -**/ - -#include "RooFit.h" -#include "RooSharedPropertiesList.h" -#include "RooSharedProperties.h" -#include "RooLinkedListIter.h" -#include "TIterator.h" -#include "RooMsgService.h" -#include "Riostream.h" -using std::cout ; -using std::endl ; - -using namespace std; - -ClassImp(RooSharedPropertiesList); -; - - - -//////////////////////////////////////////////////////////////////////////////// -/// Constructor - -RooSharedPropertiesList::RooSharedPropertiesList() -{ - _propList.setHashTableSize(1000); -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor - -RooSharedPropertiesList::~RooSharedPropertiesList() -{ - // Delete all objects in property list - RooFIter iter = _propList.fwdIterator() ; - RooSharedProperties* prop ; - while((prop=(RooSharedProperties*)iter.next())) { - delete prop ; - } -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Register property into list and take ownership. -/// -/// If an existing entry has a UUID that identical to that of the argument prop, -/// the argument prop is deleted and a pointer to the already stored is returned to -/// eliminate the duplication of instances with a unique identity. -/// -/// The caller should therefore not refer anymore to the input argument pointer as -/// as the object cannot be assumed to be live. - -RooSharedProperties* RooSharedPropertiesList::registerProperties(RooSharedProperties* prop, Bool_t canDeleteIncoming) -{ - if (prop==0) { - oocoutE((TObject*)0,InputArguments) << "RooSharedPropertiesList::ERROR null pointer!:" << endl ; - return 0 ; - } - - - // If the reference count is non-zero, it is already in the list, so no need - // to look it up anymore - if (prop->inSharedList()) { - prop->increaseRefCount() ; - return prop ; - } - - //std::cout << "REGISTER properties " << prop->asString() << " - list size = " << _propList.GetSize() << std::endl; - RooSharedProperties* tmp ; - - std::map::iterator it; - - it = _newPropList.find(prop->asString().Data()); - if (it != _newPropList.end() ) { - tmp = it->second; - if (tmp != prop) { - // found another instance with same UUID - if (canDeleteIncoming) delete prop; - } - tmp->increaseRefCount(); - return tmp; - } - prop->setInSharedList() ; - prop->increaseRefCount() ; - _newPropList[prop->asString().Data()] = prop; - - return prop ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Decrease reference count of property. If reference count is at zero, -/// delete the propery - -void RooSharedPropertiesList::unregisterProperties(RooSharedProperties* prop) -{ - prop->decreaseRefCount() ; - - if (prop->refCount()==0) { - _propList.Remove(prop) ; - - std::map::iterator it; - it = _newPropList.find(prop->asString().Data()); - if (it != _newPropList.end() ) _newPropList.erase(it); - - // We own object if ref-counted list. If count drops to zero, delete object - delete prop ; - } - -} - - diff --git a/roofit/roofitcore/src/RooSimGenContext.cxx b/roofit/roofitcore/src/RooSimGenContext.cxx index 29c226570ffc4..be20ed3831460 100644 --- a/roofit/roofitcore/src/RooSimGenContext.cxx +++ b/roofit/roofitcore/src/RooSimGenContext.cxx @@ -137,7 +137,7 @@ RooSimGenContext::RooSimGenContext(const RooSimultaneous &model, const RooArgSet // Name the context after the associated state and add to list cx->SetName(proxy->name()) ; _gcList.push_back(cx) ; - _gcIndex.push_back(idxCat->lookupType(proxy->name())->getVal()) ; + _gcIndex.push_back(idxCat->lookupIndex(proxy->name())); // Fill fraction threshold array _fracThresh[i] = _fracThresh[i-1] + (_haveIdxProto?0:pdf->expectedEvents(&allPdfVars)) ; @@ -232,23 +232,16 @@ RooDataSet* RooSimGenContext::createDataSet(const char* name, const char* title, if (!_protoData) { map dmap ; - RooCatType* state ; - TIterator* iter = _idxCat->typeIterator() ; - while((state=(RooCatType*)iter->Next())) { - RooAbsPdf* slicePdf = _pdf->getPdf(state->GetName()) ; + for (const auto& nameIdx : *_idxCat) { + RooAbsPdf* slicePdf = _pdf->getPdf(nameIdx.first.c_str()); RooArgSet* sliceObs = slicePdf->getObservables(obs) ; - std::string sliceName = Form("%s_slice_%s",name,state->GetName()) ; - std::string sliceTitle = Form("%s (index slice %s)",title,state->GetName()) ; + std::string sliceName = Form("%s_slice_%s", name, nameIdx.first.c_str()); + std::string sliceTitle = Form("%s (index slice %s)", title, nameIdx.first.c_str()); RooDataSet* dset = new RooDataSet(sliceName.c_str(),sliceTitle.c_str(),*sliceObs) ; - dmap[state->GetName()] = dset ; + dmap[nameIdx.first] = dset ; delete sliceObs ; } - delete iter ; _protoData = new RooDataSet(name, title, obs, Index((RooCategory&)*_idxCat), Link(dmap), OwnLinked()) ; - -// RooDataSet* tmp = _protoData ; -// _protoData = 0 ; -// return tmp ; } RooDataSet* emptyClone = new RooDataSet(*_protoData,name) ; diff --git a/roofit/roofitcore/src/RooSimPdfBuilder.cxx b/roofit/roofitcore/src/RooSimPdfBuilder.cxx index c3db434a11639..56b2fb6a67bc0 100644 --- a/roofit/roofitcore/src/RooSimPdfBuilder.cxx +++ b/roofit/roofitcore/src/RooSimPdfBuilder.cxx @@ -880,7 +880,7 @@ RooSimultaneous* RooSimPdfBuilder::buildPdf(const RooArgSet& buildConfig, const // If fractional split is specified, check that remainder state is a valid state of this split cat if (remainderState) { - if (!splitCat->lookupType(remainderState)) { + if (!splitCat->hasLabel(remainderState)) { coutE(InputArguments) << "RooSimPdfBuilder::buildPdf: ERROR fraction split of parameter " << paramName << " has invalid remainder state name: " << remainderState << endl ; delete paramList ; diff --git a/roofit/roofitcore/src/RooSimSplitGenContext.cxx b/roofit/roofitcore/src/RooSimSplitGenContext.cxx index 2678b71d0a562..34ecd76bfdeb7 100644 --- a/roofit/roofitcore/src/RooSimSplitGenContext.cxx +++ b/roofit/roofitcore/src/RooSimSplitGenContext.cxx @@ -127,11 +127,11 @@ RooSimSplitGenContext::RooSimSplitGenContext(const RooSimultaneous &model, const RooAbsGenContext* cx = pdf->autoGenContext(*compVars,0,0,verbose,autoBinned,binnedTag) ; delete compVars ; - const RooCatType* state = idxCat->lookupType(proxy->name()) ; + const auto state = idxCat->lookupIndex(proxy->name()); cx->SetName(proxy->name()) ; _gcList.push_back(cx) ; - _gcIndex.push_back(state->getVal()) ; + _gcIndex.push_back(state); // Fill fraction threshold array _fracThresh[i] = _fracThresh[i-1] + pdf->expectedEvents(&allPdfVars) ; diff --git a/roofit/roofitcore/src/RooSimWSTool.cxx b/roofit/roofitcore/src/RooSimWSTool.cxx index 9195377dc24da..246fcc21f45b7 100644 --- a/roofit/roofitcore/src/RooSimWSTool.cxx +++ b/roofit/roofitcore/src/RooSimWSTool.cxx @@ -102,12 +102,13 @@ #include "RooFit.h" #include "RooSimWSTool.h" + +#include "RooFitLegacy/RooCatTypeLegacy.h" #include "RooMsgService.h" #include "RooCategory.h" #include "RooRealVar.h" #include "RooAbsPdf.h" #include "RooSuperCategory.h" -#include "RooCatType.h" #include "RooCustomizer.h" #include "RooMultiCategory.h" #include "RooSimultaneous.h" @@ -478,7 +479,7 @@ RooSimultaneous* RooSimWSTool::executeBuild(const char* simPdfName, ObjBuildConf if(splitIter->second.second.size()>0) { // Check that specified split name is in fact valid - if (!splitCat->lookupType(splitIter->second.second.c_str())) { + if (!splitCat->hasLabel(splitIter->second.second)) { coutE(InputArguments) << "RooSimWSTool::executeBuild(" << GetName() << ") ERROR: name of remainder state for constrained split, '" << splitIter->second.second << "' , does not match any state name of (composite) split category " << splitCat->GetName() << endl ; return 0 ; diff --git a/roofit/roofitcore/src/RooSimultaneous.cxx b/roofit/roofitcore/src/RooSimultaneous.cxx index 4f186d2331e6c..eb04930ad7e67 100644 --- a/roofit/roofitcore/src/RooSimultaneous.cxx +++ b/roofit/roofitcore/src/RooSimultaneous.cxx @@ -104,8 +104,10 @@ RooSimultaneous::RooSimultaneous(const char *name, const char *title, //////////////////////////////////////////////////////////////////////////////// /// Constructor from index category and full list of PDFs. /// In this constructor form, a PDF must be supplied for each indexCat state -/// to avoid ambiguities. The PDFs are associated in order with the state of the -/// index category as listed by the index categories type iterator. +/// to avoid ambiguities. The PDFs are associated with the states of the +/// index category as they appear when iterating through the category states +/// with RooAbsCategory::begin() and RooAbsCategory::end(). This usually means +/// they are associated by ascending index numbers. /// /// PDFs may not overlap (i.e. share any variables) with the index category (function) @@ -118,24 +120,19 @@ RooSimultaneous::RooSimultaneous(const char *name, const char *title, _indexCat("indexCat","Index category",this,inIndexCat), _numPdf(0) { - if (inPdfList.getSize() != inIndexCat.numTypes()) { + if (inPdfList.size() != inIndexCat.size()) { coutE(InputArguments) << "RooSimultaneous::ctor(" << GetName() << " ERROR: Number PDF list entries must match number of index category states, no PDFs added" << endl ; return ; } map pdfMap ; - // Iterator over PDFs and index cat states and add each pair - TIterator* pIter = inPdfList.createIterator() ; - TIterator* cIter = inIndexCat.typeIterator() ; - RooAbsPdf* pdf ; - RooCatType* type(0) ; - while ((pdf=(RooAbsPdf*)pIter->Next())) { - type = (RooCatType*) cIter->Next() ; - pdfMap[string(type->GetName())] = pdf ; + auto indexCatIt = inIndexCat.begin(); + for (unsigned int i=0; i < inPdfList.size(); ++i) { + auto pdf = static_cast(&inPdfList[i]); + const auto& nameIdx = (*indexCatIt++); + pdfMap[nameIdx.first] = pdf; } - delete pIter ; - delete cIter ; initialize(inIndexCat,pdfMap) ; } @@ -242,9 +239,9 @@ void RooSimultaneous::initialize(RooAbsCategoryLValue& inIndexCat, std::mapgetCurrentLabel() ; failure |= addPdf(*citer->second.pdf,superLabel.c_str()) ; @@ -285,9 +282,9 @@ void RooSimultaneous::initialize(RooAbsCategoryLValue& inIndexCat, std::mapsecond.subIndex) { const_cast(citer->second.subIndex)->setLabel(stype.first.c_str()); - for (const auto& rtype : repliSuperCat) { - repliSuperCat.setLabel(rtype.first.c_str()) ; - string superLabel = superIndex->getCurrentLabel() ; + for (const auto& nameIdx : repliSuperCat) { + repliSuperCat.setLabel(nameIdx.first) ; + const string superLabel = superIndex->getCurrentLabel() ; RooAbsPdf* compPdf = citer->second.simPdf->getPdf(stype.first.c_str()); if (compPdf) { failure |= addPdf(*compPdf,superLabel.c_str()) ; @@ -1101,16 +1098,11 @@ RooDataSet* RooSimultaneous::generateSimGlobal(const RooArgSet& whatVars, Int_t RooDataSet* data = new RooDataSet("gensimglobal","gensimglobal",whatVars) ; - // Construct iterator over index types - TIterator* iter = indexCat().typeIterator() ; - for (Int_t i=0 ; iReset() ; - RooCatType* tt ; - while((tt=(RooCatType*) iter->Next())) { + for (const auto& nameIdx : indexCat()) { // Get pdf associated with state from simpdf - RooAbsPdf* pdftmp = getPdf(tt->GetName()) ; + RooAbsPdf* pdftmp = getPdf(nameIdx.first.c_str()); // Generate only global variables defined by the pdf associated with this state RooArgSet* globtmp = pdftmp->getObservables(whatVars) ; @@ -1126,8 +1118,6 @@ RooDataSet* RooSimultaneous::generateSimGlobal(const RooArgSet& whatVars, Int_t data->add(*globClone) ; } - - delete iter ; delete globClone ; return data ; } diff --git a/roofit/roofitcore/src/RooUnitTest.cxx b/roofit/roofitcore/src/RooUnitTest.cxx index d77730e52a646..571a9abfdd2c3 100644 --- a/roofit/roofitcore/src/RooUnitTest.cxx +++ b/roofit/roofitcore/src/RooUnitTest.cxx @@ -435,9 +435,13 @@ Bool_t RooUnitTest::runCompTests() } if (!iter4->first->isIdentical(*bmark)) { - cout << "RooUnitTest ERROR: comparison of object " << iter4->first->IsA()->GetName() << "::" << iter4->first->GetName() - << " fails comparison with counterpart in reference RooTable " << bmark->GetName() << endl ; - ret = kFALSE ; + cout << "RooUnitTest ERROR: comparison of object " << iter4->first->IsA()->GetName() << "::" << iter4->first->GetName() + << " fails comparison with counterpart in reference RooTable " << bmark->GetName() << endl ; + if (_verb) { + iter4->first->Print("V"); + bmark->Print("V"); + } + ret = false; } // Delete RooTable when comparison is finished to avoid noise in leak checking diff --git a/test/stressRooFit.cxx b/test/stressRooFit.cxx index fe2a3e1cf3cf1..63a21fbcb2d91 100644 --- a/test/stressRooFit.cxx +++ b/test/stressRooFit.cxx @@ -312,7 +312,7 @@ int main(int argc,const char *argv[]) doDump=kTRUE ; } - if (arg=="-h") { + if (arg=="-h" || arg == "--help") { cout << "usage: stressRooFit [ options ] " << endl ; cout << "" << endl ; cout << " -f : use given reference file instead of default (" << refFileName << ")" << endl ; diff --git a/tutorials/roofit/rf401_importttreethx.C b/tutorials/roofit/rf401_importttreethx.C index 3142887d8b2fd..093ceb92376ec 100644 --- a/tutorials/roofit/rf401_importttreethx.C +++ b/tutorials/roofit/rf401_importttreethx.C @@ -45,10 +45,7 @@ void rf401_importttreethx() RooRealVar x("x", "x", -10, 10); // Create category observable c that serves as index for the ROOT histograms - RooCategory c("c", "c"); - c.defineType("SampleA"); - c.defineType("SampleB"); - c.defineType("SampleC"); + RooCategory c("c", "c", {{"SampleA",0}, {"SampleB",1}, {"SampleC",2}}); // Create a binned dataset that imports contents of all TH1 mapped by index category c RooDataHist *dh = new RooDataHist("dh", "dh", x, Index(c), Import("SampleA", *hh_1), Import("SampleB", *hh_2), @@ -56,7 +53,7 @@ void rf401_importttreethx() dh->Print(); // Alternative constructor form for importing multiple histograms - map hmap; + std::map hmap; hmap["SampleA"] = hh_1; hmap["SampleB"] = hh_2; hmap["SampleC"] = hh_3; diff --git a/tutorials/roofit/rf404_categories.C b/tutorials/roofit/rf404_categories.C index b1a1c48fe48db..eff4feff586e0 100644 --- a/tutorials/roofit/rf404_categories.C +++ b/tutorials/roofit/rf404_categories.C @@ -20,6 +20,7 @@ #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" +#include using namespace RooFit; void rf404_categories() @@ -36,14 +37,53 @@ void rf404_categories() tagCat.defineType("NetTagger-2"); tagCat.Print(); - // C o n s t r u c t a c a t e g o r y w i t h l a b e l s a n d i n d e c e s + // C o n s t r u c t a c a t e g o r y w i t h l a b e l s a n d i n d i c e s // ---------------------------------------------------------------------------------------- // Define a category with explicitly numbered states RooCategory b0flav("b0flav", "B0 flavour eigenstate"); - b0flav.defineType("B0", -1); - b0flav.defineType("B0bar", 1); - b0flav.Print(); + b0flav["B0"] = -1; + b0flav["B0bar"] = 1; + // Print it in "verbose" mode to see all states. + b0flav.Print("V"); + + + // Alternatively, define many states at once. The function takes + // a map with std::string --> index mapping. + RooCategory largeCat("largeCat", "A category with many states"); + largeCat.defineTypes({ + {"A", 0}, {"b", 2}, {"c", 8}, {"dee", 4}, + {"F", 133}, {"g", 15}, {"H", -20} + }); + + + // I t e r a t e, q u e r y a n d s e t s t a t e s + // -------------------------------------------------------- + + // One can iterate through the {index,name} pair of category objects + std::cout << "\nThis is the for loop over states of 'largeCat':"; + for (const auto& idxAndName : largeCat) + std::cout << "\n\t" << idxAndName.first << "\t" << idxAndName.second; + std::cout << '\n' << std::endl; + + // To ask whether a state is valid use: + std::cout << "Has label 'A': " << largeCat.hasLabel("A"); + std::cout << "\nHas index '-20': " << largeCat.hasIndex(-20); + + // To retrieve names or state numbers: + std::cout << "\nLabel corresponding to '2' is " << largeCat.lookupName(2); + std::cout << "\nIndex corresponding to 'A' is " << largeCat.lookupIndex("A"); + + // To get the current state: + std::cout << "\nCurrent index is " << largeCat.getCurrentIndex(); + std::cout << "\nCurrent label is " << largeCat.getCurrentLabel(); + std::cout << std::endl; + + // To set the state, use one of the two: + largeCat.setIndex(8); + largeCat.setLabel("c"); + + // G e n e r a t e d u m m y d a t a f o r t a b u l a t i o n d e m o // ---------------------------------------------------------------------------- @@ -52,6 +92,7 @@ void rf404_categories() RooRealVar x("x", "x", 0, 10); RooDataSet *data = RooPolynomial("p", "p", x).generate(RooArgSet(x, b0flav, tagCat), 10000); + // P r i n t t a b l e s o f c a t e g o r y c o n t e n t s o f d a t a s e t s // ------------------------------------------------------------------------------------------ @@ -72,11 +113,11 @@ void rf404_categories() // Retrieve number of events from table // Number can be non-integer if source dataset has weighed events Double_t nb0 = btable->get("B0"); - cout << "Number of events with B0 flavor is " << nb0 << endl; + std::cout << "Number of events with B0 flavor is " << nb0 << std::endl; // Retrieve fraction of events with "Lepton" tag Double_t fracLep = ttable->getFrac("Lepton"); - cout << "Fraction of events tagged with Lepton tag is " << fracLep << endl; + std::cout << "Fraction of events tagged with Lepton tag is " << fracLep << std::endl; // D e f i n i n g r a n g e s f o r p l o t t i n g , f i t t i n g o n c a t e g o r i e s // ------------------------------------------------------------------------------------------------------ diff --git a/tutorials/roofit/rf514_RooCustomizer.C b/tutorials/roofit/rf514_RooCustomizer.C index b4c3a9b37c17e..8e114be32c792 100644 --- a/tutorials/roofit/rf514_RooCustomizer.C +++ b/tutorials/roofit/rf514_RooCustomizer.C @@ -47,9 +47,9 @@ void rf514_RooCustomizer() { // Build the categories RooCategory sample("sample","sample"); - sample.defineType("Sample1"); - sample.defineType("Sample2"); - sample.defineType("Sample3"); + sample["Sample1"] = 1; + sample["Sample2"] = 2; + sample["Sample3"] = 3; // Start to customise the proto model that was defined above. diff --git a/tutorials/roofit/rf701_efficiencyfit.C b/tutorials/roofit/rf701_efficiencyfit.C index e73dd9c627f97..2eb26ce732a08 100644 --- a/tutorials/roofit/rf701_efficiencyfit.C +++ b/tutorials/roofit/rf701_efficiencyfit.C @@ -46,9 +46,7 @@ void rf701_efficiencyfit() // ------------------------------------------------------------------------------------------ // Acceptance state cut (1 or 0) - RooCategory cut("cut", "cutr"); - cut.defineType("accept", 1); - cut.defineType("reject", 0); + RooCategory cut("cut", "cutr", { {"accept", 1}, {"reject", 0} }); // Construct efficiency p.d.f eff(cut|x) RooEfficiency effPdf("effPdf", "effPdf", effFunc, cut, "accept"); diff --git a/tutorials/roofit/rf702_efficiencyfit_2D.C b/tutorials/roofit/rf702_efficiencyfit_2D.C index a7b08420ba524..76c171a8e41f9 100644 --- a/tutorials/roofit/rf702_efficiencyfit_2D.C +++ b/tutorials/roofit/rf702_efficiencyfit_2D.C @@ -50,9 +50,7 @@ void rf702_efficiencyfit_2D(Bool_t flat = kFALSE) RooArgList(ax, bx, cx, x, ay, by, cy, y)); // Acceptance state cut (1 or 0) - RooCategory cut("cut", "cutr"); - cut.defineType("accept", 1); - cut.defineType("reject", 0); + RooCategory cut("cut", "cutr", { {"accept", 1}, {"reject", 0} }); // C o n s t r u c t c o n d i t i o n a l e f f i c i e n c y p d f E ( c u t | x , y ) // ---------------------------------------------------------------------------------------------