From 85d5ad39c495b0b0efc973ed22431fa656f6bb99 Mon Sep 17 00:00:00 2001 From: Adrien Blanchet Date: Thu, 25 May 2023 16:53:18 +0200 Subject: [PATCH 1/3] Don't write convergence lines when in light mode --- src/Applications/CMakeLists.txt | 2 +- src/Applications/src/gundamFitter.cxx | 2 +- src/Applications/src/gundamRoot.cxx | 4 ++++ src/Fitter/include/FitterEngine.h | 2 -- src/Fitter/src/FitterEngine.cpp | 7 ++----- src/Fitter/src/LikelihoodInterface.cpp | 17 +++++++++-------- src/Utils/include/GlobalVariables.h | 4 ++++ src/Utils/src/GlobalVariables.cpp | 3 +++ 8 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Applications/CMakeLists.txt b/src/Applications/CMakeLists.txt index 18e79d7b9..5e7a2e29d 100644 --- a/src/Applications/CMakeLists.txt +++ b/src/Applications/CMakeLists.txt @@ -84,7 +84,7 @@ if( WITH_GUNDAM_ROOT_APP ) #target_sources( gundamRoot PRIVATE G__GundamRootDict.cxx ) #target_link_libraries( gundamRoot GundamPropagator ) target_link_libraries( gundamRoot - GundamRootDict + GundamRootDict GundamUtils # GundamPropagator ) endif () diff --git a/src/Applications/src/gundamFitter.cxx b/src/Applications/src/gundamFitter.cxx index 5d7943746..ffa942538 100644 --- a/src/Applications/src/gundamFitter.cxx +++ b/src/Applications/src/gundamFitter.cxx @@ -301,7 +301,7 @@ int main(int argc, char** argv){ fitter.setGenerateOneSigmaPlots( clParser.isOptionTriggered("generateOneSigmaPlots") ); // --light-mode - fitter.setLightMode( clParser.isOptionTriggered("lightOutputMode") ); + GlobalVariables::setLightOutputMode( clParser.isOptionTriggered("lightOutputMode") ); // injectParameterPath if( not injectParameterPath.empty() ){ diff --git a/src/Applications/src/gundamRoot.cxx b/src/Applications/src/gundamRoot.cxx index 040c284d0..365fbf6e1 100644 --- a/src/Applications/src/gundamRoot.cxx +++ b/src/Applications/src/gundamRoot.cxx @@ -1,6 +1,9 @@ // // Created by Adrien BLANCHET on 23/10/2022. // + +#include "GundamUtils.h" + #include "Logger.h" #include "TRint.h" @@ -28,6 +31,7 @@ int main(int argc, char **argv) { int argcInterpreter = int( cstrings.size() ); char** argvInterpreter{ cstrings.data() }; + LogInfo << "gundamRoot build against: " << GundamUtils::getVersionFullStr() << std::endl; LogInfo << "Creating ROOT interpreter..." << std::endl; auto *theApp = new TRint( "Rint" diff --git a/src/Fitter/include/FitterEngine.h b/src/Fitter/include/FitterEngine.h index e6009662a..401d62b30 100644 --- a/src/Fitter/include/FitterEngine.h +++ b/src/Fitter/include/FitterEngine.h @@ -33,7 +33,6 @@ class FitterEngine : public JsonBaseClass { void setSaveDir(TDirectory *saveDir); void setIsDryRun(bool isDryRun_); void setEnablePca(bool enablePca_); - void setLightMode(bool lightMode_); void setEnablePreFitScan(bool enablePreFitScan); void setEnablePostFitScan(bool enablePostFitScan); void setEnablePreFitToPostFitLineScan(bool enablePreFitToPostFitScan); @@ -80,7 +79,6 @@ class FitterEngine : public JsonBaseClass { // Parameters bool _isDryRun_{false}; bool _enablePca_{false}; - bool _lightMode_{false}; bool _throwMcBeforeFit_{false}; bool _enablePreFitScan_{false}; bool _enablePostFitScan_{false}; diff --git a/src/Fitter/src/FitterEngine.cpp b/src/Fitter/src/FitterEngine.cpp index c5d71f9a9..14c9297b0 100644 --- a/src/Fitter/src/FitterEngine.cpp +++ b/src/Fitter/src/FitterEngine.cpp @@ -88,7 +88,7 @@ void FitterEngine::initializeImpl(){ LogThrowIf(_config_.empty(), "Config is not set."); LogThrowIf(_saveDir_== nullptr); - if( _lightMode_ ){ + if( GlobalVariables::isLightOutputMode() ){ LogWarning << "Light mode enabled, wiping plot gen config..." << std::endl; _propagator_.getPlotGenerator().readConfig(nlohmann::json()); } @@ -217,7 +217,7 @@ void FitterEngine::initializeImpl(){ this->_propagator_.updateLlhCache(); - if( not _lightMode_ ){ + if( not GlobalVariables::isLightOutputMode() ){ _propagator_.getTreeWriter().writeSamples(GenericToolbox::mkdirTFile(_saveDir_, "preFit/events")); } @@ -235,9 +235,6 @@ void FitterEngine::setIsDryRun(bool isDryRun_){ void FitterEngine::setEnablePca(bool enablePca_){ _enablePca_ = enablePca_; } -void FitterEngine::setLightMode(bool lightMode_){ - _lightMode_ = lightMode_; -} void FitterEngine::setEnablePreFitScan(bool enablePreFitScan) { _enablePreFitScan_ = enablePreFitScan; } diff --git a/src/Fitter/src/LikelihoodInterface.cpp b/src/Fitter/src/LikelihoodInterface.cpp index f29ce4f1b..5bb1ac184 100644 --- a/src/Fitter/src/LikelihoodInterface.cpp +++ b/src/Fitter/src/LikelihoodInterface.cpp @@ -89,6 +89,9 @@ void LikelihoodInterface::saveGradientSteps(){ ParScanner::muteLogger(); }, [&](){ + FitParameterSet::muteLogger(); + Propagator::muteLogger(); + ParScanner::muteLogger(); _owner_->getPropagator().injectParameterValues( currentParState ); FitParameterSet::unmuteLogger(); Propagator::unmuteLogger(); @@ -107,17 +110,15 @@ void LikelihoodInterface::saveGradientSteps(){ _owner_->getPropagator().injectParameterValues(_gradientMonitor_[iGradStep].parState ); _owner_->getPropagator().updateLlhCache(); - auto outDir = GenericToolbox::mkdirTFile(_owner_->getSaveDir(), Form("fit/gradient/step_%i", int(iGradStep))); - GenericToolbox::writeInTFile( outDir, TNamed("parState", GenericToolbox::Json::toReadableString(_gradientMonitor_[iGradStep].parState).c_str()) ); - GenericToolbox::writeInTFile( outDir, TNamed("llhState", _owner_->getPropagator().getLlhBufferSummary().c_str()) ); + if( not GlobalVariables::isLightOutputMode() ) { + auto outDir = GenericToolbox::mkdirTFile(_owner_->getSaveDir(), Form("fit/gradient/step_%i", int(iGradStep))); + GenericToolbox::writeInTFile(outDir, TNamed("parState", GenericToolbox::Json::toReadableString(_gradientMonitor_[iGradStep].parState).c_str())); + GenericToolbox::writeInTFile(outDir, TNamed("llhState", _owner_->getPropagator().getLlhBufferSummary().c_str())); + } // line scan from previous point - _owner_->getPropagator().getParScanner().scanSegment( - GenericToolbox::mkdirTFile(outDir, "lineScan"), - _gradientMonitor_[iGradStep].parState, lastParStep, 10 - ); + _owner_->getPropagator().getParScanner().scanSegment( nullptr, _gradientMonitor_[iGradStep].parState, lastParStep, 8 ); lastParStep = _gradientMonitor_[iGradStep].parState; - GenericToolbox::triggerTFileWrite(outDir); if( globalGraphList.empty() ){ // copy diff --git a/src/Utils/include/GlobalVariables.h b/src/Utils/include/GlobalVariables.h index 94fcd7e6e..993c9e754 100644 --- a/src/Utils/include/GlobalVariables.h +++ b/src/Utils/include/GlobalVariables.h @@ -42,6 +42,7 @@ class GlobalVariables{ // Setters static void setEnableCacheManager(bool enable = true); + static void setLightOutputMode(bool enable_); static void setDisableDialCache(bool disableDialCache_); static void setVerboseLevel(VerboseLevel verboseLevel_); static void setVerboseLevel(int verboseLevel_); @@ -51,6 +52,7 @@ class GlobalVariables{ static bool isEnableDevMode(); static bool getEnableCacheManager(); static bool isDisableDialCache(); + static bool isLightOutputMode(); static VerboseLevel getVerboseLevel(); static const int& getNbThreads(); static std::mutex& getThreadMutex(); @@ -63,6 +65,7 @@ class GlobalVariables{ static bool _enableDevMode_; static bool _disableDialCache_; static bool _enableCacheManager_; + static bool _lightOutputMode_; static int _nbThreads_; static std::mutex _threadMutex_; static std::map _boolMap_; @@ -70,6 +73,7 @@ class GlobalVariables{ static VerboseLevel _verboseLevel_; static GenericToolbox::ParallelWorker _threadPool_; + }; #endif diff --git a/src/Utils/src/GlobalVariables.cpp b/src/Utils/src/GlobalVariables.cpp index 51ae75b56..7b6c5494d 100644 --- a/src/Utils/src/GlobalVariables.cpp +++ b/src/Utils/src/GlobalVariables.cpp @@ -15,6 +15,7 @@ LoggerInit([]{ bool GlobalVariables::_enableDevMode_{false}; bool GlobalVariables::_disableDialCache_{false}; bool GlobalVariables::_enableCacheManager_{false}; +bool GlobalVariables::_lightOutputMode_{false}; int GlobalVariables::_nbThreads_ = 1; std::mutex GlobalVariables::_threadMutex_; std::map GlobalVariables::_boolMap_; @@ -39,8 +40,10 @@ void GlobalVariables::setNbThreads(int nbThreads_){ void GlobalVariables::setEnableCacheManager(bool enable) {_enableCacheManager_ = enable;} void GlobalVariables::setDisableDialCache(bool disableDialCache_){ _disableDialCache_ = disableDialCache_; } +void GlobalVariables::setLightOutputMode(bool enable_){ _lightOutputMode_ = enable_; } bool GlobalVariables::getEnableCacheManager() {return _enableCacheManager_;} bool GlobalVariables::isDisableDialCache(){ return _disableDialCache_; } +bool GlobalVariables::isLightOutputMode(){ return _lightOutputMode_; } bool GlobalVariables::isEnableDevMode(){ return _enableDevMode_; } VerboseLevel GlobalVariables::getVerboseLevel(){ return _verboseLevel_; } const int& GlobalVariables::getNbThreads(){ return _nbThreads_; } From 950213c3a9244b1d7c953d27bb19e9afa4b8fbd5 Mon Sep 17 00:00:00 2001 From: Adrien Blanchet Date: Thu, 25 May 2023 16:59:46 +0200 Subject: [PATCH 2/3] Don't write convergence by default (lighter output files) --- src/Fitter/src/MinimizerInterface.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Fitter/src/MinimizerInterface.cpp b/src/Fitter/src/MinimizerInterface.cpp index 7414adf97..355b62f59 100644 --- a/src/Fitter/src/MinimizerInterface.cpp +++ b/src/Fitter/src/MinimizerInterface.cpp @@ -52,6 +52,12 @@ void MinimizerInterface::readConfigImpl(){ _generatedPostFitEigenBreakdown_ = GenericToolbox::Json::fetchValue(_config_, "generatedPostFitEigenBreakdown", _generatedPostFitEigenBreakdown_); _stepSizeScaling_ = GenericToolbox::Json::fetchValue(_config_, "stepSizeScaling", _stepSizeScaling_); + + if( GenericToolbox::Json::doKeyExist( _config_, "monitorGradientDescent" ) ){ + LogInfo << "Will monitor the gradient descent." << std::endl; + getLikelihood().setMonitorGradientDescent(GenericToolbox::Json::fetchValue( _config_, "monitorGradientDescent" )); + } + } void MinimizerInterface::initializeImpl(){ MinimizerBase::initializeImpl(); @@ -103,16 +109,6 @@ void MinimizerInterface::initializeImpl(){ } } - if( GenericToolbox::Json::doKeyExist( _config_, "monitorGradientDescent" ) ){ - getLikelihood().setMonitorGradientDescent(GenericToolbox::Json::fetchValue( _config_, "monitorGradientDescent" )); - } - else if( GenericToolbox::toLowerCase(getLikelihood().getMinimizerType()) == "minuit" - or GenericToolbox::toLowerCase(getLikelihood().getMinimizerType()) == "minuit2" - ){ - LogInfo << "Monitoring gradient as minimizer is Minuit" << std::endl; - getLikelihood().setMonitorGradientDescent( true ); - } - } bool MinimizerInterface::isFitHasConverged() const { From bfc486506a43d4ec89faa07e1819e667569ca8d0 Mon Sep 17 00:00:00 2001 From: Adrien Blanchet Date: Thu, 25 May 2023 17:08:00 +0200 Subject: [PATCH 3/3] removing useless printouts --- src/Fitter/src/LikelihoodInterface.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Fitter/src/LikelihoodInterface.cpp b/src/Fitter/src/LikelihoodInterface.cpp index 5bb1ac184..aa79682d8 100644 --- a/src/Fitter/src/LikelihoodInterface.cpp +++ b/src/Fitter/src/LikelihoodInterface.cpp @@ -85,13 +85,12 @@ void LikelihoodInterface::saveGradientSteps(){ // make sure the parameter states get restored as we leave nlohmann::json currentParState{_owner_->getPropagator().exportParameterInjectorConfig()}; GenericToolbox::ScopedGuard g{ - [&](){ - ParScanner::muteLogger(); - }, [&](){ FitParameterSet::muteLogger(); Propagator::muteLogger(); ParScanner::muteLogger(); + }, + [&](){ _owner_->getPropagator().injectParameterValues( currentParState ); FitParameterSet::unmuteLogger(); Propagator::unmuteLogger(); @@ -101,8 +100,6 @@ void LikelihoodInterface::saveGradientSteps(){ // load starting point auto lastParStep{_owner_->getPreFitParState()}; - _owner_->getPropagator().injectParameterValues( lastParStep ); - _owner_->getPropagator().updateLlhCache(); std::vector globalGraphList; for(size_t iGradStep = 0 ; iGradStep < _gradientMonitor_.size() ; iGradStep++ ){