Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Factory.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Fri Dec 22 14:43:33 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Implementation file for class MinimizerFactory
12
13#include "Math/Factory.h"
14#include "Math/Error.h"
15
16#include "RConfigure.h"
17
18#include "Math/Minimizer.h"
20
21#include "Math/DistSampler.h"
23
24// uncomment these if you dont want to use the plugin manager
25// but you need to link also the needed minimization libraries (e.g Minuit and/or Minuit2)
26// #define MATH_NO_PLUGIN_MANAGER
27// #define HAS_MINUIT
28// #define HAS_MINUIT2
29
30#ifndef MATH_NO_PLUGIN_MANAGER
31// use ROOT Plug-in manager
32#include "TPluginManager.h"
33#include "TROOT.h"
34#include "TVirtualMutex.h"
35#else
36// all the minimizer implementation classes
37//#define HAS_MINUIT2
38#ifdef HAS_MINUIT2
40#endif
41#ifdef HAS_MINUIT
42#include "TMinuitMinimizer.h"
43#endif
44#ifdef R__HAS_MATHMORE
45#include "Math/GSLMinimizer.h"
48#endif
49
50#endif
51
52#include <algorithm>
53#include <cassert>
54
55//#define DEBUG
56#ifdef DEBUG
57#include <iostream>
58#endif
59
60#ifndef MATH_NO_PLUGIN_MANAGER
61// use ROOT Plugin Manager to create Minimizer concrete classes
62
63ROOT::Math::Minimizer * ROOT::Math::Factory::CreateMinimizer(const std::string & minimizerType,const std::string & algoType)
64{
65 // create Minimizer using the plug-in manager given the type of Minimizer (MINUIT, MINUIT2, FUMILI, etc..) and
66 // algorithm (MIGRAD, SIMPLEX, etc..)
67
68 const char * minim = minimizerType.c_str();
69 const char * algo = algoType.c_str();
70
71 //case of fumili2
72 std::string s1,s2;
73 if (minimizerType == "Fumili2" ) {
74 s1 = "Minuit2";
75 s2 = "fumili";
76 minim = s1.c_str();
77 algo = s2.c_str();
78 }
79 if (minimizerType == "TMinuit") {
80 s1 = "Minuit";
81 minim = s1.c_str();
82 }
83
84 if (minimizerType.empty() ) minim = ROOT::Math::MinimizerOptions::DefaultMinimizerType().c_str();
85
87
88 // create Minimizer using the PM
90 //gDebug = 3;
91 if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::Minimizer",minim ))) {
92 if (h->LoadPlugin() == -1) {
93#ifdef DEBUG
94 std::cout << "Error Loading ROOT::Math::Minimizer " << minim << std::endl;
95#endif
96 return nullptr;
97 }
98
99 // create plug-in with required algorithm
100 ROOT::Math::Minimizer * min = reinterpret_cast<ROOT::Math::Minimizer *>( h->ExecPlugin(1,algo ) );
101#ifdef DEBUG
102 if (min != 0)
103 std::cout << "Loaded Minimizer " << minimizerType << " " << algoType << std::endl;
104 else
105 std::cout << "Error creating Minimizer " << minimizerType << " " << algoType << std::endl;
106#endif
107
108 return min;
109 }
110 return nullptr;
111
112}
113
114#else
115
116// use directly classes instances
117
118ROOT::Math::Minimizer * ROOT::Math::Factory::CreateMinimizer(const std::string & minimizerType, const std::string & algoType)
119{
120 // static method to create a minimizer .
121 // not using PM so direct dependency on all libraries (Minuit, Minuit2, MathMore, etc...)
122 // The default is the Minuit2 minimizer or GSL Minimizer
123
124 // should use enumerations instead of string ?
125
126 Minimizer * min = 0;
127 std::string algo = algoType;
128
129
130#ifdef HAS_MINUIT2
131 if (minimizerType == "Minuit2")
132 min = new ROOT::Minuit2::Minuit2Minimizer(algoType.c_str());
133 if (minimizerType == "Fumili2")
134 min = new ROOT::Minuit2::Minuit2Minimizer("fumili");
135#endif
136
137#ifdef HAS_MINUIT
138 // use TMinuit
139 if (minimizerType == "Minuit" || minimizerType == "TMinuit")
140 min = new TMinuitMinimizer(algoType.c_str());
141#endif
142
143#ifdef R__HAS_MATHMORE
144 // use GSL minimizer
145 if (minimizerType == "GSL")
146 min = new ROOT::Math::GSLMinimizer(algoType.c_str());
147
148 else if (minimizerType == "GSL_NLS")
149 min = new ROOT::Math::GSLNLSMinimizer();
150
151 else if (minimizerType == "GSL_SIMAN")
153#endif
154
155
156#ifdef HAS_MINUIT2
157 // DEFAULT IS MINUIT2 based on MIGRAD id minuit2 exists
158 else
160#endif
161
162 return min;
163}
164
165#endif
166
168#ifdef MATH_NO_PLUGIN_MANAGER
169 MATH_ERROR_MSG("Factory::CreateDistSampler","ROOT plug-in manager not available");
170 return 0;
171#else
172 // create a DistSampler class using the ROOT plug-in manager
173 const char * typeName = type.c_str();
174 if (type.empty() ) typeName = ROOT::Math::DistSamplerOptions::DefaultSampler().c_str();
175
177
178 TPluginManager *pm = gROOT->GetPluginManager();
179 assert(pm != nullptr);
180 TPluginHandler *h = pm->FindHandler("ROOT::Math::DistSampler", typeName );
181 if (h != nullptr) {
182 if (h->LoadPlugin() == -1) {
183 MATH_ERROR_MSG("Factory::CreateDistSampler","Error loading DistSampler plug-in");
184 return nullptr;
185 }
186
187 ROOT::Math::DistSampler * smp = reinterpret_cast<ROOT::Math::DistSampler *>( h->ExecPlugin(0) );
188 assert(smp != nullptr);
189 return smp;
190 }
191 MATH_ERROR_MSGVAL("Factory::CreateDistSampler","Error finding DistSampler plug-in",typeName);
192 return nullptr;
193#endif
194}
195
196
#define MATH_ERROR_MSGVAL(loc, txt, x)
Definition Error.h:109
#define MATH_ERROR_MSG(loc, str)
Definition Error.h:83
#define s1(x)
Definition RSha256.hxx:91
#define h(i)
Definition RSha256.hxx:106
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:407
#define R__LOCKGUARD(mutex)
static const std::string & DefaultSampler()
Interface class for generic sampling of a distribution, i.e.
Definition DistSampler.h:57
static ROOT::Math::Minimizer * CreateMinimizer(const std::string &minimizerType="", const std::string &algoType="")
static method to create the corresponding Minimizer given the string Supported Minimizers types are: ...
Definition Factory.cxx:63
static ROOT::Math::DistSampler * CreateDistSampler(const std::string &samplerType="")
static method to create the distribution sampler class given a string specifying the type Supported s...
Definition Factory.cxx:167
GSLMinimizer class.
GSLNLSMinimizer class for Non Linear Least Square fitting It Uses the Levemberg-Marquardt algorithm f...
GSLSimAnMinimizer class for minimization using simulated annealing using the algorithm from GSL.
static const std::string & DefaultMinimizerType()
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition Minimizer.h:117
Minuit2Minimizer class implementing the ROOT::Math::Minimizer interface for Minuit2 minimization algo...
TMinuitMinimizer class: ROOT::Math::Minimizer implementation based on TMinuit.
This class implements a plugin library manager.
TPluginHandler * FindHandler(const char *base, const char *uri=nullptr)
Returns the handler if there exists a handler for the specified URI.