diff --git a/AppUtils/AppBase.cc b/AppUtils/AppBase.cc index 81bd3dee18681f611d52a1591b155e98049046fa..f8d9ec4137bd9641cedde0567404b37eb52e9210 100644 --- a/AppUtils/AppBase.cc +++ b/AppUtils/AppBase.cc @@ -73,6 +73,7 @@ #include "MinFunctions/PwaFcnBase.hh" #include "MinFunctions/PwaFcnServer.hh" +#include "MinFunctions/PwaFcnServerGradNumSlow.hh" #include "MinFunctions/AbsPawianMinimizer.hh" #include "MinFunctions/EvoMinimizer.hh" #include "MinFunctions/MinuitMinimizer.hh" @@ -881,14 +882,17 @@ void AppBase::fitServerMode(std::shared_ptr<AbsPawianParameters> upar){ InfoMsg << "Closing server." << endmsg; } - else if(GlobalEnv::instance()->parser()->mode()=="serverGradientNum"){ + else if(GlobalEnv::instance()->parser()->mode()=="serverGradientNum" || GlobalEnv::instance()->parser()->mode()=="serverGradientNumSlow"){ std::shared_ptr<AbsFcn<FCNGradientBase>> absFcn; std::shared_ptr<NetworkServer> theServer(new NetworkServer(GlobalEnv::instance()->parser()->serverPort(), GlobalEnv::instance()->parser()->noOfClients(), numEventMap, GlobalEnv::instance()->parser()-> clientNumberWeights())); - absFcn=std::shared_ptr<AbsFcn<FCNGradientBase>>(new PwaFcnServer<FCNGradientBase>(theServer)); + if (GlobalEnv::instance()->parser()->mode()=="serverGradientNum") absFcn=std::shared_ptr<AbsFcn<FCNGradientBase>>(new PwaFcnServer<FCNGradientBase>(theServer)); + else absFcn=std::shared_ptr<AbsFcn<FCNGradientBase>>(new PwaFcnServerGradNumSlow(theServer)); + + theServer->WaitForFirstClientLogin(); std::shared_ptr<AbsPawianMinimizer<FCNGradientBase>> absMinimizerPtr; diff --git a/ConfigParser/ParserBase.cc b/ConfigParser/ParserBase.cc index a256ff36f1d9633bbc44102f734024430eec7a2b..bb541fe15f54835a07ad45a60aa7e35dfe05044a 100644 --- a/ConfigParser/ParserBase.cc +++ b/ConfigParser/ParserBase.cc @@ -139,7 +139,7 @@ ParserBase::ParserBase(int argc,char **argv) ("serializationFile", po::value<string>(&_serializationFile), "serialized pwa i/o file") ("serverAddress", po::value<string>(&_serverAddress), "server address for client mode") ("clientNumberWeights", po::value<string>(&_clientNumberWeights), "weights to assign client numbers to channels") - ("mode",po::value<string>(&_mode), "modes are: pwa, dumpDefaultParams, dumpRandomParams, qaMode, plotmode, spinDensity") + ("mode",po::value<string>(&_mode), "modes are: pwa, evo (only for single channel fits), server, serverGradientNum, serverGradientNumSlow, evoserver (for single and coupled channel fits each), dumpDefaultParams, dumpRandomParams, qaMode, qaModeSimple, qaModeEffCorrection, plotmode, spinDensity") ("noOfThreads",po::value<int>(&_noOfThreads), "number of threads for multi threaded mode") ("noOfClients",po::value<int>(&_noOfClients), "number of clients/worker nodes for server mode") ("serverPort",po::value<int>(&_serverPort), "port for client/server mode") diff --git a/MinFunctions/PwaFcnServerGradNumSlow.cc b/MinFunctions/PwaFcnServerGradNumSlow.cc new file mode 100644 index 0000000000000000000000000000000000000000..5203088d4819088a68be96fcba0cf6c5819fed88 --- /dev/null +++ b/MinFunctions/PwaFcnServerGradNumSlow.cc @@ -0,0 +1,104 @@ +//************************************************************************// +// // +// Copyright 2024 Bertram Kopf (bertram@ep1.rub.de) // +// - Ruhr-Universität Bochum // +// // +// This file is part of Pawian. // +// // +// Pawian is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// (at your option) any later version. // +// // +// Pawian is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with Pawian. If not, see <http://www.gnu.org/licenses/>. // +// // +//************************************************************************// + +#include <math.h> +#include <stdio.h> +#include <iomanip> +#include "Minuit2/FCNBase.h" +#include "Minuit2/FCNGradientBase.h" + +#include "MinFunctions/PwaFcnServerGradNumSlow.hh" +#include "FitParams/ParamDepHandler.hh" +#include "PwaUtils/GlobalEnv.hh" +#include "PwaUtils/AbsChannelEnv.hh" +#include "PwaUtils/AbsLh.hh" +#include "PwaUtils/DataUtils.hh" +#include "PwaUtils/NetworkServer.hh" +#include "Utils/PawianConstants.hh" +#include "ConfigParser/ParserBase.hh" +#include "ErrLogger/ErrLogger.hh" + +using namespace ROOT::Minuit2; + +PwaFcnServerGradNumSlow::PwaFcnServerGradNumSlow(std::shared_ptr<NetworkServer> netServer) : + PwaFcnServer<FCNGradientBase>(netServer) +{ +} + +PwaFcnServerGradNumSlow::~PwaFcnServerGradNumSlow() +{ +} + +std::vector<double> PwaFcnServerGradNumSlow::Gradient(const std::vector<double>& par) const{ + std::vector<double> resultVec; + resultVec.resize(par.size()); + this->_currentPawianParms->SetAllValues(par); + ParamDepHandler::instance()->ApplyDependencies(this->_currentPawianParms); + double LHBase=collectLH(); + double epsilon; + + for(unsigned int i=0; i<par.size(); ++i){ + if(this->_currentPawianParms->IsFixed(i)) resultVec.at(i)=0.; + else{ + double currentVal=this->_currentPawianParms->Value(i); + epsilon=_numStepSize*std::abs(currentVal); + if ((this->_currentPawianParms->GetName(i)).substr( (this->_currentPawianParms->GetName(i)).length() - 3 ) == "Phi"){ + epsilon=_numStepSize*PawianConstants::pi; + } + else if (std::abs(currentVal)<1.e-10) epsilon=_numStepSize*1.e-10; + double dx=(currentVal+epsilon)-currentVal; + + double Lh_high=0.; + double Lh_low=0.; + if(!(this->_currentPawianParms->HasLimits(i)) || (std::abs(currentVal-this->_currentPawianParms->UpperLimit(i))>epsilon && std::abs(currentVal-this->_currentPawianParms->LowerLimit(i))>epsilon) ){ + this->_currentPawianParms->SetValue(i, currentVal+epsilon); + ParamDepHandler::instance()->ApplyDependencies(this->_currentPawianParms); + Lh_high=collectLH(); + this->_currentPawianParms->SetValue(i, currentVal-epsilon); + ParamDepHandler::instance()->ApplyDependencies(this->_currentPawianParms); + Lh_low=collectLH(); + resultVec.at(i)=(Lh_high-Lh_low)/(2.*dx); + } + else{ + if(std::abs(currentVal-this->_currentPawianParms->UpperLimit(i))<epsilon){ + this->_currentPawianParms->SetValue(i, currentVal-epsilon); + ParamDepHandler::instance()->ApplyDependencies(this->_currentPawianParms); + Lh_low=collectLH(); + resultVec.at(i)=(LHBase-Lh_low)/dx; + } + else{ + this->_currentPawianParms->SetValue(i, currentVal+epsilon); + ParamDepHandler::instance()->ApplyDependencies(this->_currentPawianParms); + Lh_high=collectLH(); + resultVec.at(i)=(Lh_high-LHBase)/dx; + } + } + this->_currentPawianParms->SetValue(i, currentVal); + } + } + return resultVec; +} + + + + + diff --git a/MinFunctions/PwaFcnServerGradNumSlow.hh b/MinFunctions/PwaFcnServerGradNumSlow.hh new file mode 100644 index 0000000000000000000000000000000000000000..a1cf103a0ef18a92e97044fc29462878b6351eca --- /dev/null +++ b/MinFunctions/PwaFcnServerGradNumSlow.hh @@ -0,0 +1,46 @@ +//************************************************************************// +// // +// Copyright 2024 Bertram Kopf (bertram@ep1.rub.de) // +// - Ruhr-Universität Bochum // +// // +// This file is part of Pawian. // +// // +// Pawian is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// (at your option) any later version. // +// // +// Pawian is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with Pawian. If not, see <http://www.gnu.org/licenses/>. // +// // +//************************************************************************// + +#pragma once + +#include <iostream> +#include <fstream> +#include <vector> +#include <string> +#include <memory> + +#include "MinFunctions/PwaFcnServer.hh" + +namespace ROOT { + namespace Minuit2 { + class PwaFcnServerGradNumSlow : public PwaFcnServer<FCNGradientBase> { + + public: + PwaFcnServerGradNumSlow(std::shared_ptr<NetworkServer> netServer); + virtual ~PwaFcnServerGradNumSlow(); + + virtual std::vector<double> Gradient(const std::vector<double>& par) const; + + protected: + }; + } // namespace Minuit2 +} // namespace ROOT diff --git a/PwaApps/coupledChannelApp.cc b/PwaApps/coupledChannelApp.cc index f46bb3cf52ab93b6571a13159adad115010a89bc..feff405c92a96392dd0939e095aeead7b4acf580 100644 --- a/PwaApps/coupledChannelApp.cc +++ b/PwaApps/coupledChannelApp.cc @@ -160,7 +160,7 @@ int main(int __argc,char *__argv[]){ return 1; } - if(mode == "server" || mode == "serverGradientNum" || mode == "evoserver" || mode=="serverQA"){ + if(mode == "server" || mode == "serverGradientNum" || mode == "serverGradientNumSlow" || mode == "evoserver" || mode=="serverQA"){ theAppBase.fitServerMode(startPawianParams); return 1; } diff --git a/PwaApps/singleChannelApp.cc b/PwaApps/singleChannelApp.cc index 0d241f603d950fe39831fbc72775f3ee8d6845bc..a945cdb7e6871d8f519154562610cb2443c7cf05 100644 --- a/PwaApps/singleChannelApp.cc +++ b/PwaApps/singleChannelApp.cc @@ -201,7 +201,7 @@ int main(int __argc,char *__argv[]){ // Disable output buffering setvbuf(stdout, NULL, _IONBF, 0); - if(mode == "server" || mode == "serverGradientNum" || mode == "evoserver"){ + if(mode == "server" || mode == "serverGradientNum" || mode == "serverGradientNumSlow" || mode == "evoserver"){ theAppBase.fitServerMode(startPawianParams); return 1; }