Skip to content
Snippets Groups Projects
Commit d702089e authored by Bertram Kopf's avatar Bertram Kopf
Browse files

added abstract FCN class

parent f876c222
No related branches found
No related tags found
No related merge requests found
//************************************************************************//
// //
// Copyright 2013 Bertram Kopf (bertram@ep1.rub.de) //
// Julian Pychy (julian@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 <boost/timer/timer.hpp>
#include "Minuit2/MnUserParameters.h"
#include "PwaUtils/AbsFcn.hh"
#include "PwaUtils/AbsLh.hh"
#include "PwaUtils/NetworkServer.hh"
#include "ErrLogger/ErrLogger.hh"
using namespace ROOT::Minuit2;
boost::timer::cpu_timer theTimer1;
AbsFcn::AbsFcn(boost::shared_ptr<FitParamsBase> fitParamsBase, std::string suffix) :
_fitParamsBasePtr(fitParamsBase)
, _fcnCounter(0)
, _currentResFileName("currentResult"+suffix+".dat")
{
}
AbsFcn::~AbsFcn()
{
}
double AbsFcn::Up() const
{
return .5;
}
void AbsFcn::printTimer() const{
theTimer1.stop();
boost::timer::cpu_times elapsed(theTimer1.elapsed());
if(elapsed.wall > 0){
Info << "Wall time: " << elapsed.wall / 1E9 << "s User: "
<< elapsed.user/1E9 << "s System: " << elapsed.system/1E9 << "s\n" << endmsg;
}
theTimer1.start();
}
void AbsFcn::printFitParams(const std::vector<double>& par) const{
if ( _fcnCounter%100 == 0) {
fitParams theFitParmValTmp=_defaultFitValParms;
_fitParamsBasePtr->getFitParamVal(par, theFitParmValTmp);
_fitParamsBasePtr->printParams(theFitParmValTmp);
}
}
void AbsFcn::dumpFitParams(const std::vector<double>& par) const{
if ( _fcnCounter%200 == 0) {
fitParams theFitParmValTmp=_defaultFitValParms;
_fitParamsBasePtr->getFitParamVal(par, theFitParmValTmp);
std::ofstream theStream (_currentResFileName.c_str());
_fitParamsBasePtr->dumpParams(theStream, theFitParmValTmp, (fitParams&)_defaultFitErrParms);
}
}
//************************************************************************//
// //
// Copyright 2013 Bertram Kopf (bertram@ep1.rub.de) //
// Julian Pychy (julian@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 <boost/shared_ptr.hpp>
#include "Minuit2/FCNBase.h"
#include "PwaUtils/DataUtils.hh"
#include "PwaUtils/FitParamsBase.hh"
#include "Minuit2/MnUserParameters.h"
namespace ROOT {
namespace Minuit2 {
class AbsFcn : public FCNBase {
public:
AbsFcn(boost::shared_ptr<FitParamsBase> fitParamsBase, std::string suffix="");
virtual ~AbsFcn();
virtual double operator()(const std::vector<double>& par) const=0;
virtual double Up() const;
protected:
boost::shared_ptr<FitParamsBase> _fitParamsBasePtr;
mutable unsigned int _fcnCounter;
fitParams _defaultFitValParms;
fitParams _defaultFitErrParms;
std::string _currentResFileName;
virtual void printTimer() const;
virtual void printFitParams(const std::vector<double>& par) const;
virtual void dumpFitParams(const std::vector<double>& par) const;
private:
};
} // namespace Minuit2
} // namespace ROOT
......@@ -34,13 +34,10 @@
using namespace ROOT::Minuit2;
//boost::timer::cpu_timer theTimer;
PwaFcnBase::PwaFcnBase(boost::shared_ptr<AbsLh> absLh, boost::shared_ptr<FitParamsBase> fitParamsBase, std::string suffix) :
_absLhPtr(absLh)
, _fitParamsBasePtr(fitParamsBase)
, _fcnCounter(0)
, _currentResFileName("currentResult"+suffix+".dat")
AbsFcn(fitParamsBase, suffix)
,_absLhPtr(absLh)
{
if (0==_absLhPtr) { Alert << "AbsLh* _absLhPtr pointer is 0 !!!!" << endmsg; exit(1); }
_absLhPtr->getDefaultParams(_defaultFitValParms, _defaultFitErrParms);
......@@ -64,33 +61,13 @@ double PwaFcnBase::operator()(const std::vector<double>& par) const
_fcnCounter++;
// theTimer.stop();
// boost::timer::cpu_times elapsed(theTimer.elapsed());
// if(elapsed.wall > 0){
// Info << "Wall time: " << elapsed.wall / 1E9 << "s User: "
// << elapsed.user/1E9 << "s System: " << elapsed.system/1E9 << "s\n" << endmsg;
// }
// theTimer.start();
// }
if ( _fcnCounter%100 == 0) {
_fitParamsBasePtr->printParams(theFitParmValTmp);
}
if ( _fcnCounter%200 == 0) {
std::ofstream theStream (_currentResFileName.c_str());
_fitParamsBasePtr->dumpParams(theStream, theFitParmValTmp, (fitParams&)_defaultFitErrParms);
}
if(_fcnCounter%20 == 0) printTimer();
printFitParams(par);
dumpFitParams(par);
return result;
}
double PwaFcnBase::Up() const
{
return .5;
}
......@@ -29,35 +29,24 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include "Minuit2/FCNBase.h"
//#include "PwaUtils/EvtDataBaseList.hh"
#include "PwaUtils/DataUtils.hh"
#include "PwaUtils/FitParamsBase.hh"
#include "Minuit2/MnUserParameters.h"
#include "PwaUtils/AbsFcn.hh"
class AbsLh;
class NetworkServer;
namespace ROOT {
namespace Minuit2 {
class PwaFcnBase : public FCNBase {
class PwaFcnBase : public AbsFcn {
public:
PwaFcnBase(boost::shared_ptr<AbsLh> absLh,
boost::shared_ptr<FitParamsBase> fitParamsBase, std::string suffix="");
virtual ~PwaFcnBase();
double operator()(const std::vector<double>& par) const;
double Up() const;
virtual double operator()(const std::vector<double>& par) const;
private:
boost::shared_ptr<AbsLh> _absLhPtr;
boost::shared_ptr<FitParamsBase> _fitParamsBasePtr;
boost::shared_ptr<NetworkServer> _networkServerPtr;
mutable unsigned int _fcnCounter;
fitParams _defaultFitValParms;
fitParams _defaultFitErrParms;
std::string _currentResFileName;
};
} // namespace Minuit2
} // namespace ROOT
......@@ -23,9 +23,6 @@
#include <math.h>
#include <stdio.h>
#include <boost/timer/timer.hpp>
#include "Minuit2/MnUserParameters.h"
#include "PwaUtils/PwaFcnServer.hh"
#include "PwaUtils/AbsLh.hh"
......@@ -34,14 +31,10 @@
using namespace ROOT::Minuit2;
boost::timer::cpu_timer theTimer;
PwaFcnServer::PwaFcnServer(boost::shared_ptr<AbsLh> absLh, boost::shared_ptr<FitParamsBase> fitParamsBase, boost::shared_ptr<NetworkServer> netServer, std::string suffix) :
_absLhPtr(absLh)
, _fitParamsBasePtr(fitParamsBase)
AbsFcn(fitParamsBase, suffix)
, _absLhPtr(absLh)
, _networkServerPtr(netServer)
, _fcnCounter(0)
, _currentResFileName("currentResult"+suffix+".dat")
{
if (0==_absLhPtr) { Alert << "AbsLh* _absLhPtr pointer is 0 !!!!" << endmsg; exit(1); }
_absLhPtr->getDefaultParams(_defaultFitValParms, _defaultFitErrParms);
......@@ -65,34 +58,14 @@ double PwaFcnServer::operator()(const std::vector<double>& par) const
_fcnCounter++;
if(_fcnCounter%20 == 0){
theTimer.stop();
boost::timer::cpu_times elapsed(theTimer.elapsed());
if(elapsed.wall > 0){
Info << "Wall time: " << elapsed.wall / 1E9 << "s User: "
<< elapsed.user/1E9 << "s System: " << elapsed.system/1E9 << "s\n" << endmsg;
}
theTimer.start();
}
if ( _fcnCounter%100 == 0) {
fitParams theFitParmValTmp=_defaultFitValParms;
_fitParamsBasePtr->getFitParamVal(par, theFitParmValTmp);
_fitParamsBasePtr->printParams(theFitParmValTmp);
if ( _fcnCounter%200 == 0) {
std::ofstream theStream (_currentResFileName.c_str());
_fitParamsBasePtr->dumpParams(theStream, theFitParmValTmp, (fitParams&)_defaultFitErrParms);
}
}
if(_fcnCounter%20 == 0) printTimer();
printFitParams(par);
dumpFitParams(par);
return result;
}
double PwaFcnServer::Up() const
{
return .5;
}
......@@ -29,36 +29,25 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include "Minuit2/FCNBase.h"
//#include "PwaUtils/EvtDataBaseList.hh"
#include "PwaUtils/DataUtils.hh"
#include "PwaUtils/FitParamsBase.hh"
#include "Minuit2/MnUserParameters.h"
#include "PwaUtils/AbsFcn.hh"
class AbsLh;
class NetworkServer;
namespace ROOT {
namespace Minuit2 {
class PwaFcnServer : public FCNBase {
class PwaFcnServer : public AbsFcn {
public:
PwaFcnServer(boost::shared_ptr<AbsLh> absLh,
boost::shared_ptr<FitParamsBase> fitParamsBase, boost::shared_ptr<NetworkServer> netServer, std::string suffix="");
virtual ~PwaFcnServer();
double operator()(const std::vector<double>& par) const;
double Up() const;
// void SetServerMode(boost::shared_ptr<NetworkServer> networkServerPtr);
virtual double operator()(const std::vector<double>& par) const;
private:
protected:
boost::shared_ptr<AbsLh> _absLhPtr;
boost::shared_ptr<FitParamsBase> _fitParamsBasePtr;
boost::shared_ptr<NetworkServer> _networkServerPtr;
mutable unsigned int _fcnCounter;
fitParams _defaultFitValParms;
fitParams _defaultFitErrParms;
std::string _currentResFileName;
};
} // namespace Minuit2
} // namespace ROOT
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment