English Français

Documentation / Manuel développeur

Modules disponibles

Calibration,  DataServer,  Launcher,  MetaModelOptim,  Modeler,  Optimizer,  ReLauncher,  Reliability,  ReOptimizer,  Sampler,  Sensitivity,  UncertModeler,  XmlProblem,   Uranie / Optimizer: TFCNCode.h Source File
Uranie / Optimizer v4.9.0
/* @license-end */
TFCNCode.h
Go to the documentation of this file.
1
2// Copyright (C) 2013-2024 CEA/DES
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as published
6// by the Free Software Foundation, either version 3 of the License, or any
7// later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
18// $Id$
19// $Author$
20// $Date$
21// $Revision
22// $State$
24
42#ifndef TFCNCODE_H
43#define TFCNCODE_H
44
45#include "TH1.h"
46#include "TF1.h"
47#include "TFile.h"
48#include "TPad.h"
49#include "TRandom3.h"
50#include "TVirtualFitter.h"
51#include "TStyle.h"
52#include "Minuit2/FCNBase.h"
53//#include "TFitterMinuit.h"
54#include "TSystem.h"
55
56#include <vector>
57#include <iostream>
58
59// URANIE
60#include "Optimizer.h"
61#include "TCode.h"
62#include "TDataServer.h"
63
64namespace URANIE
65{
66namespace Optimizer
67{
68class TFCNCode: public ROOT::Minuit2::FCNBase
69{
70
71public:
73 _ninput(0), _noutput(0), _soutput(""), _tds(NULL), _code(NULL)
74 {
75 }
77 TFCNCode(URANIE::DataServer::TDataServer *tds,
78 URANIE::Launcher::TCode *code, TString scost) :
79 _sCost(scost), _tds(tds), _code(code)
80 {
81 init();
82 }
83
85 {
86 _dinputValue = NULL;
87 delete[] _dinputValue;
88 _doutputValue = NULL;
89 delete[] _doutputValue;
90
91 }
92
93 void init();
94
95 double operator()(const vector<double> & par) const
96 {
97 Int_t niter = _tds->getTuple()->GetEntries();
98 double fval = 0.1;
99 if (_code->getLog())
100 cout << "iter[" << niter << "]" << endl;
101 if (_code != NULL)
102 {
103 _dinputValue[0] = 1.0 + niter;
104 // Remark: If we want to save all computations, we need a constant Bool_t _bSave,
105 // and call the the method _code->init() at each new computation.
106 _code->init();
107 // Pretraitment of the data
108 for (int i = 0; i < _ninput; i++)
109 {
110 _dinputValue[1 + i] = par[i];
111 if (_code->getLog())
112 cout << "**** input i[" << i << "] val["
113 << _dinputValue[1 + i] << "]" << endl;
114 }
115 int ind = 1;
116 _code->preTraitment(ind, _dinputValue);
117 // Lancement du code
118 _code->run();
119 // Post-traitment of the data
120 ind = 0;
121 _code->postTraitment(ind, _doutputValue);
122 if (_code->getLog())
123 {
124 cout << endl << "*************************************" << endl
125 << " *** TFCNCode operator () _nCost[" << _nCost << "]"
126 << endl;
127 for (Int_t ii = 0; ii <= _nCost; ii++)
128 cout << " ** ii(" << ii << "/" << _nCost << ") val("
129 << _doutputValue[ii] << ")" << endl;
130 cout << " *** End Of TFCNCode operator ()" << endl
131 << "*************************************" << endl;
132 }
133 fval = _doutputValue[_nCost];
134 if (_code->getLog())
135 cout << " *** output _nCost[" << _nCost << "] val[" << fval
136 << "]" << endl;
137
138 //Fill the output values in the input vector
139 // +1 because the first value is the index
140 for (int i = 1; i <= _noutput; i++)
142 _tds->getTuple()->Fill(_dinputValue);
143
144 // Visualisation
145 if (niter % 10)
146 {
147 // _ntd->Draw("val:x", "", "lp");
148 _tds->draw(
149 Form("%s:%s", _sCost.Data(), _tds->getIteratorName()),
150 "", "lp");
151 gPad->Modified();
152 gPad->Update();
153 // save the TNtuple in a TFile
154// TString srootfile = _code->getWorkingDirectory(); // getReferenceDirectory();
155// srootfile += "/UranieResults/uranielauncher.root";
156// TFile rootfile(srootfile, "recreate");
157// _tds->getTuple()->Write();
158// rootfile.Close();
159 }
160 }
161
162 return fval;
163 }
164
165 double Up() const
166 {
167 return 1.;
168 }
169
170 void clean();
171
172private:
174 double * _dinputValue;
176 TString _soutput;
177 double * _doutputValue;
178 TString _sCost;
179 Int_t _nCost;
180 URANIE::DataServer::TDataServer *_tds;
181 URANIE::Launcher::TCode *_code;
182
183 ClassDef(URANIE::Optimizer::TFCNCode, ID_OPTIMIZER)
184 //Classe de
185
186};
187} // Fin du namespace Optimizer
188} // Fin du namespace URANIE
189#endif
Definition TFCNCode.h:69
double operator()(const vector< double > &par) const
Definition TFCNCode.h:95
double Up() const
Definition TFCNCode.h:165
TFCNCode()
Definition TFCNCode.h:72
URANIE::DataServer::TDataServer * _tds
Definition TFCNCode.h:180
double * _doutputValue
The output attribute name.
Definition TFCNCode.h:177
int _ninput
Definition TFCNCode.h:173
~TFCNCode()
Definition TFCNCode.h:84
Int_t _nCost
the current position for the selected cost in the output list of attribute
Definition TFCNCode.h:179
int _noutput
Definition TFCNCode.h:175
TString _soutput
Name of the output attributes.
Definition TFCNCode.h:176
URANIE::Launcher::TCode * _code
Pointeur vers un TDS.
Definition TFCNCode.h:181
TString _sCost
The name of the selected cost (the number must be equal to 1)
Definition TFCNCode.h:178
TFCNCode(URANIE::DataServer::TDataServer *tds, URANIE::Launcher::TCode *code, TString scost)
Constructor with a dataserver.
Definition TFCNCode.h:77
double * _dinputValue
Definition TFCNCode.h:174
Rosenbrock's function (n=2) with first and second order derivatives.
Definition TBestEstimate.h:58