Skip to content

Commit

Permalink
Merge pull request #340 from gundam-organization/feature/fitInfoAddit…
Browse files Browse the repository at this point in the history
…ions

Lighter outputs before tagging 1.7.1
  • Loading branch information
nadrino authored May 25, 2023
2 parents f87ad97 + bfc4865 commit cbcbf2a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
2 changes: 1 addition & 1 deletion src/Applications/src/gundamFitter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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() ){
Expand Down
4 changes: 4 additions & 0 deletions src/Applications/src/gundamRoot.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//
// Created by Adrien BLANCHET on 23/10/2022.
//

#include "GundamUtils.h"

#include "Logger.h"

#include "TRint.h"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions src/Fitter/include/FitterEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand Down
7 changes: 2 additions & 5 deletions src/Fitter/src/FitterEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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"));
}

Expand All @@ -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;
}
Expand Down
18 changes: 8 additions & 10 deletions src/Fitter/src/LikelihoodInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void LikelihoodInterface::saveGradientSteps(){
nlohmann::json currentParState{_owner_->getPropagator().exportParameterInjectorConfig()};
GenericToolbox::ScopedGuard g{
[&](){
FitParameterSet::muteLogger();
Propagator::muteLogger();
ParScanner::muteLogger();
},
[&](){
Expand All @@ -98,26 +100,22 @@ void LikelihoodInterface::saveGradientSteps(){

// load starting point
auto lastParStep{_owner_->getPreFitParState()};
_owner_->getPropagator().injectParameterValues( lastParStep );
_owner_->getPropagator().updateLlhCache();

std::vector<GraphEntry> globalGraphList;
for(size_t iGradStep = 0 ; iGradStep < _gradientMonitor_.size() ; iGradStep++ ){
FitParameterSet::muteLogger(); Propagator::muteLogger();
_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
Expand Down
16 changes: 6 additions & 10 deletions src/Fitter/src/MinimizerInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>( _config_, "monitorGradientDescent" ));
}

}
void MinimizerInterface::initializeImpl(){
MinimizerBase::initializeImpl();
Expand Down Expand Up @@ -103,16 +109,6 @@ void MinimizerInterface::initializeImpl(){
}
}

if( GenericToolbox::Json::doKeyExist( _config_, "monitorGradientDescent" ) ){
getLikelihood().setMonitorGradientDescent(GenericToolbox::Json::fetchValue<bool>( _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 {
Expand Down
4 changes: 4 additions & 0 deletions src/Utils/include/GlobalVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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();
Expand All @@ -63,13 +65,15 @@ class GlobalVariables{
static bool _enableDevMode_;
static bool _disableDialCache_;
static bool _enableCacheManager_;
static bool _lightOutputMode_;
static int _nbThreads_;
static std::mutex _threadMutex_;
static std::map<std::string, bool> _boolMap_;
static std::vector<TChain*> _chainList_;
static VerboseLevel _verboseLevel_;
static GenericToolbox::ParallelWorker _threadPool_;


};

#endif
3 changes: 3 additions & 0 deletions src/Utils/src/GlobalVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, bool> GlobalVariables::_boolMap_;
Expand All @@ -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_; }
Expand Down

0 comments on commit cbcbf2a

Please sign in to comment.