Public Member Functions | Protected Attributes | Private Attributes | List of all members
fnex::FitAlg_ROOTFactoryFit Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/FNEX/fitter/FitAlg_ROOTFactoryFit.h"

Inheritance diagram for fnex::FitAlg_ROOTFactoryFit:
fnex::FitAlgorithm

Public Member Functions

 FitAlg_ROOTFactoryFit (fhicl::ParameterSet const &pset)
 
virtual ~FitAlg_ROOTFactoryFit ()
 
void Reconfigure (fhicl::ParameterSet const &pset)
 
bool FillGlobalVariables (EventListMap const &fEventLists, InputPoint const &pInputPoint)
 
bool InitializeMinimizer ()
 
bool SetInitialValues ()
 
bool SetConstraints ()
 
bool Minimize ()
 
bool LoadFinalResults (PointResult &pPointResult)
 
bool Fit (EventListMap const &fEventLists, InputPoint const &pInputPoint, PointResult &pPointResult)
 
bool IsConfigured ()
 
MultiExperiment const & ListMultiExperiment () const
 
void DrawPlots (art::TFileDirectory *plotDir) const
 

Protected Attributes

bool fIsConfigured
 
MultiExperiment fMultiExperiment
 

Private Attributes

std::string fMinName
 
std::string fAlgoName
 
unsigned int fMaxFunctionCalls
 
unsigned int fMaxIterations
 
double fTolerance
 
double fPrecision
 
int fStrategyCode
 Use 0 for faster fits, 1 for better errors. More...
 
int fPrintLevel
 3 is default, more output would be 4 More...
 

Detailed Description

Definition at line 19 of file FitAlg_ROOTFactoryFit.h.

Constructor & Destructor Documentation

fnex::FitAlg_ROOTFactoryFit::FitAlg_ROOTFactoryFit ( fhicl::ParameterSet const &  pset)

Definition at line 75 of file FitAlg_ROOTFactoryFit.cxx.

References Reconfigure().

76  : FitAlgorithm(pset)
77  {
78  this->Reconfigure(pset);
79  gFFVals = std::make_unique<std::vector<double> >(0);
80  gFFNames = std::make_unique<std::vector<std::string> >(0);
81  }
void Reconfigure(fhicl::ParameterSet const &pset)
std::unique_ptr< std::vector< std::string > > gFFNames
std::unique_ptr< std::vector< double > > gFFVals
FitAlgorithm(fhicl::ParameterSet const &pset)
Definition: FitAlgorithm.cxx:6
virtual fnex::FitAlg_ROOTFactoryFit::~FitAlg_ROOTFactoryFit ( )
inlinevirtual

Member Function Documentation

void fnex::FitAlgorithm::DrawPlots ( art::TFileDirectory plotDir) const
inherited

Definition at line 20 of file FitAlgorithm.cxx.

References fnex::MultiExperiment::DrawFitterProgressGraphs(), fnex::MultiExperiment::DrawParallelPlots(), fnex::MultiExperiment::DrawPlots(), and fnex::FitAlgorithm::fMultiExperiment.

Referenced by fnex::FitAlgorithm::ListMultiExperiment().

21  {
22  fMultiExperiment.DrawPlots(plotDir);
25  }
MultiExperiment fMultiExperiment
Definition: FitAlgorithm.h:50
void DrawParallelPlots(art::TFileDirectory *plotDir) const
void DrawFitterProgressGraphs(art::TFileDirectory *plotDir) const
void DrawPlots(art::TFileDirectory *plotDir) const
bool fnex::FitAlg_ROOTFactoryFit::FillGlobalVariables ( EventListMap const &  fEventLists,
InputPoint const &  pInputPoint 
)

Definition at line 149 of file FitAlg_ROOTFactoryFit.cxx.

References fnex::ConvertPointToVectors(), fnex::FitAlgorithm::fMultiExperiment, and fnex::MultiExperiment::SetEventListMap().

Referenced by Fit(), and ~FitAlg_ROOTFactoryFit().

150  {
151 
152  // Send the event list to the multiexperiment
153  //LOG_VERBATIM("ROOTFactoryFit") << "WTF HERE 0\n";
154  fMultiExperiment.SetEventListMap(fEventLists);
155 
156  // Set the input multiexperiment to the global used by the FitValue function
157  //LOG_VERBATIM("ROOTFactoryFit") << "WTF HERE 1\n";
159 
160  //LOG_VERBATIM("ROOTFactoryFit") << "WTF HERE 2\n";
161  gPoint = new InputPoint(pInputPoint);
162 
163  //LOG_VERBATIM("ROOTFactoryFit") << "WTF HERE 3\n";
164  ConvertPointToVectors(pInputPoint, *gFFVals, *gFFNames);
165 
166  // We're done here
167  return true;
168  }
fnex::MultiExperiment * gRFFMultiExperiment
InputPoint * gPoint
bool SetEventListMap(EventListMap const &pEventListMap)
std::unique_ptr< std::vector< std::string > > gFFNames
MultiExperiment fMultiExperiment
Definition: FitAlgorithm.h:50
std::unique_ptr< std::vector< double > > gFFVals
void ConvertPointToVectors(InputPoint const &pPoint, std::vector< double > &pVals, std::vector< std::string > &pNames)
bool fnex::FitAlg_ROOTFactoryFit::Fit ( EventListMap const &  fEventLists,
InputPoint const &  pInputPoint,
PointResult pPointResult 
)
virtual

Implements fnex::FitAlgorithm.

Definition at line 109 of file FitAlg_ROOTFactoryFit.cxx.

References FillGlobalVariables(), InitializeMinimizer(), LoadFinalResults(), LOG_VERBATIM, Minimize(), SetConstraints(), and SetInitialValues().

Referenced by ~FitAlg_ROOTFactoryFit().

111  {
112 
113 
114  // Run through the fit sequence
115  //std::vector<double> guessVals = *gFFVals;
116  //for (int i = 0;i < gFFVals->size();i++)
117  //{
118  // LOG_VERBATIM("ROOTFactoryFit") << guessVals[i];
119  //}
120 
121  LOG_VERBATIM("ROOTFactoryFit") << "Fit::Going to fill global variables\n";
122  FillGlobalVariables(fEventLists, pInputPoint);
123 
124  LOG_VERBATIM("ROOTFactoryFit") << "Fit::Going to initialize minimizer\n";
126 
127  LOG_VERBATIM("ROOTFactoryFit") << "Fit::Going to set initial values\n";
129 
130  LOG_VERBATIM("ROOTFactoryFit") << "Fit::Going to set constraints\n";
131  SetConstraints();
132 
133  LOG_VERBATIM("ROOTFactoryFit") << "Fit::About to minimize\n";
134  bool tConverged = Minimize();
135 
136  LOG_VERBATIM("ROOTFactoryFit") << "Fit::Going to load final results\n";
137  LoadFinalResults(pPointResult);
138 
139  // Return true if the fit was successful; else false
140  return tConverged;
141 
142  }
bool LoadFinalResults(PointResult &pPointResult)
#define LOG_VERBATIM(category)
bool FillGlobalVariables(EventListMap const &fEventLists, InputPoint const &pInputPoint)
bool fnex::FitAlg_ROOTFactoryFit::InitializeMinimizer ( )

Definition at line 174 of file FitAlg_ROOTFactoryFit.cxx.

References MakeMiniprodValidationCuts::f, fAlgoName, fnex::FitFunction_ForROOT(), fMaxFunctionCalls, fMaxIterations, fMinName, fPrecision, fPrintLevel, fStrategyCode, fTolerance, MECModelEnuComparisons::i, and LOG_VERBATIM.

Referenced by Fit(), and ~FitAlg_ROOTFactoryFit().

174  {
175 
176  // Make the minimizer object
177  gFFMin = ROOT::Math::Factory::CreateMinimizer(fMinName.data(), fAlgoName.data());
178 
179  // Set up the minimizer particulars
180  gFFMin->SetMaxFunctionCalls(fMaxFunctionCalls);
181  gFFMin->SetMaxIterations(fMaxIterations);
182  gFFMin->SetStrategy(fStrategyCode);
183  if(fTolerance > 0) gFFMin->SetTolerance(fTolerance);
184  if(fPrecision > 0) gFFMin->SetPrecision(fPrecision);
185  gFFMin->SetPrintLevel(fPrintLevel);
186 
187  // Vector sizes for bookkeeping
188  size_t numFloatables = gFFNames->size();
189  LOG_VERBATIM("ROOTFactoryFit")
190  << "\nNum floatables: " << numFloatables
191  << "\nMax function calls: " << fMaxFunctionCalls
192  << "\nMax iterations: " << fMaxIterations
193  << "\nTolerance: " << fTolerance;
194  LOG_VERBATIM("ROOTFactoryFit")
195  << "Initial guess: ";
196  for(size_t i = 0; i < gFFNames->size(); ++i){
197  LOG_VERBATIM("ROOTFactoryFit")
198  << "\n" << (*gFFNames)[i]
199  << " : " << (*gFFVals)[i];
200  }
201 
202  // Link in the function to be minimized
203  ROOT::Math::Functor * f = new ROOT::Math::Functor(&FitFunction_ForROOT,numFloatables);
204  gFFMin->SetFunction(*f);
205 
206  // We're done here
207  return true;
208  }
int fStrategyCode
Use 0 for faster fits, 1 for better errors.
std::unique_ptr< std::vector< std::string > > gFFNames
ROOT::Math::Minimizer * gFFMin
int fPrintLevel
3 is default, more output would be 4
double FitFunction_ForROOT(const double *params)
#define LOG_VERBATIM(category)
bool fnex::FitAlgorithm::IsConfigured ( )
inherited

Definition at line 13 of file FitAlgorithm.cxx.

References fnex::FitAlgorithm::fIsConfigured.

Referenced by fnex::FitAlgorithm::~FitAlgorithm().

14  {
15  return fIsConfigured;
16  }
MultiExperiment const& fnex::FitAlgorithm::ListMultiExperiment ( ) const
inlineinherited

Definition at line 41 of file FitAlgorithm.h.

References fnex::FitAlgorithm::DrawPlots(), and fnex::FitAlgorithm::fMultiExperiment.

41 { return fMultiExperiment; }
MultiExperiment fMultiExperiment
Definition: FitAlgorithm.h:50
bool fnex::FitAlg_ROOTFactoryFit::LoadFinalResults ( PointResult pPointResult)

Definition at line 293 of file FitAlg_ROOTFactoryFit.cxx.

References fnex::MultiExperiment::ApplyPoint(), fnex::ConvertVectorsToPoint(), fnex::gFFVals, fnex::gPoint, MECModelEnuComparisons::i, fnex::InputPoint::ParameterSpaceLocation(), fabricate::status, and fnex::InputPoint::SystematicPulls().

Referenced by Fit(), and ~FitAlg_ROOTFactoryFit().

293  {
294 
295  // Fill the PointResult object to contain the converged-upon point
296  const double * vals = gFFMin->X();
297  std::vector<double> fitVals = *gFFVals;
298  for(size_t i = 0; i < gFFVals->size(); ++i){
299  fitVals[i] = vals[i];
300  }
301  //const double * errs = gFFMin->Errors();
302 
303  //Add a 2.*TMath::Pi() if the dcp < 0.
304  std::vector<double> guessVals = *gFFVals;
305  for(size_t i = 0; i < gFFVals->size(); ++i){
306  guessVals[i] = fitVals[i];
307 
308  if((*gFFNames)[i].compare("dCP") == 0 && guessVals[i] < 0)
309  guessVals[i] = guessVals[i] + 2.*TMath::Pi();
310  }
311 
312  // Now make a new InputPoint
313  InputPoint newPoint = *gPoint;
314  ConvertVectorsToPoint(guessVals, *gFFNames, newPoint);
315  gRFFMultiExperiment->ApplyPoint(newPoint);
316 
317  int status = gFFMin->Status();
318  double chisq = gFFMin->MinValue();
319 
320  //InputPoint newPoint = *gPoint;
321  //ConvertVectorsToPoint(fitVals, *gFFNames, newPoint);
322  pPointResult = PointResult(chisq, status, newPoint.ParameterSpaceLocation(), newPoint.SystematicPulls());
323 
324  return true;
325  }
int status
Definition: fabricate.py:1613
fnex::MultiExperiment * gRFFMultiExperiment
InputPoint * gPoint
std::unique_ptr< std::vector< std::string > > gFFNames
ROOT::Math::Minimizer * gFFMin
void ConvertVectorsToPoint(std::vector< double > const &pVals, std::vector< std::string > const &pNames, InputPoint &pPoint)
void ApplyPoint(InputPoint &pInputPoint)
std::unique_ptr< std::vector< double > > gFFVals
bool fnex::FitAlg_ROOTFactoryFit::Minimize ( )

Definition at line 284 of file FitAlg_ROOTFactoryFit.cxx.

Referenced by Fit(), and ~FitAlg_ROOTFactoryFit().

284  {
285  //LOG_VERBATIM("ROOTFactoryFit") << "In Minimize. Calling ROOTFactorFit->Minimize()\n";
286  return gFFMin->Minimize();
287  }
ROOT::Math::Minimizer * gFFMin
void fnex::FitAlg_ROOTFactoryFit::Reconfigure ( fhicl::ParameterSet const &  pset)
virtual

Implements fnex::FitAlgorithm.

Definition at line 86 of file FitAlg_ROOTFactoryFit.cxx.

References fAlgoName, fnex::FitAlgorithm::fIsConfigured, fMaxFunctionCalls, fMaxIterations, fMinName, fPrecision, fPrintLevel, fStrategyCode, fTolerance, fhicl::ParameterSet::get(), and string.

Referenced by FitAlg_ROOTFactoryFit(), and ~FitAlg_ROOTFactoryFit().

86  {
87 
88  // Look for minName and algoName (following ROOT factory nomenclature,
89  // see NumericalMinimization.C in ROOT fit documentation,
90  // root.cern.ch/root/html/tutorials/fit/
91  // NumericalMinimization.C.html
92  // Default here is set to Minuit2 && Migrad
93  fMinName = pset.get< std::string >("MinName", "Minuit2");
94  fAlgoName = pset.get< std::string >("AlgoName", "Migrad");
95  fMaxFunctionCalls = pset.get< unsigned int >("MaxFunctionCalls", 1000);
96  fMaxIterations = pset.get< unsigned int >("MaxIterations", 1000);
97  fTolerance = pset.get< double >("Tolerance", 0);
98  fPrecision = pset.get< double >("Precision", 0);
99  fStrategyCode = pset.get< int >("StrategyCode", 0);
100  fPrintLevel = pset.get< int >("MINUITPrintLevel", 3);
101 
102  // The MultiExperiment is configured by the baseclass ctor.
103 
104  // We're done here
105  fIsConfigured = true;
106  }
int fStrategyCode
Use 0 for faster fits, 1 for better errors.
int fPrintLevel
3 is default, more output would be 4
enum BeamMode string
bool fnex::FitAlg_ROOTFactoryFit::SetConstraints ( )

Definition at line 231 of file FitAlg_ROOTFactoryFit.cxx.

References fnex::ParameterConstraints::Constraints(), mkDefs::constraints, allTimeWatchdog::endl, fnex::ConstraintInfo::HiValue(), fnex::ParameterConstraints::Instance(), findDuplicateFiles::key, LOG_DEBUG, LOG_VERBATIM, fnex::ConstraintInfo::LoValue(), fnex::ParameterConstraints::Print(), and string.

Referenced by Fit(), and ~FitAlg_ROOTFactoryFit().

232  {
233 
234  // Set constraints for all parameter space locations
237 
238  std::string key("");
239 
240  fnex::ConstraintInfo constraint;
241 
242  for(auto const & itr : constraints){
243 
244  key = itr.first;
245  constraint = itr.second;
246 
247  int ikey = -1;
248  for(size_t tkey = 0; tkey < gFFNames->size(); ++tkey){
249  if( (*gFFNames)[tkey] == key) ikey = tkey;
250  }
251  if(ikey == -1) continue;
252 
253  LOG_DEBUG("ROOTFactoryFit")
254  << " Key: " << key
255  << " IKey: " << ikey;
256 
257  if(constraint.LoValue() == constraint.HiValue()){
258  gFFMin->SetVariable(ikey,
259  (*gFFNames)[ikey],
260  constraint.LoValue(),
261  0.01);
262  gFFMin->FixVariable(ikey);
263  }else{
264  LOG_VERBATIM("ROOTFactoryFit")
265  << "Setting constraint on "
266  << std::setw(10) << key << " "
267  << std::setw(10) << constraint.LoValue()
268  << std::setw(10) << constraint.HiValue() << std::endl;
269  gFFMin->SetVariableLimits(ikey,
270  constraint.LoValue(),
271  constraint.HiValue());
272  }
273  }
274 
275  return true;
276  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
void Print(std::ostream &stream=std::cout)
double const LoValue() const
constraints
Definition: mkDefs.py:147
std::unique_ptr< std::vector< std::string > > gFFNames
ROOT::Math::Minimizer * gFFMin
std::map< std::string, ConstraintInfo > const & Constraints()
static ParameterConstraints * Instance()
double const HiValue() const
#define LOG_VERBATIM(category)
enum BeamMode string
bool fnex::FitAlg_ROOTFactoryFit::SetInitialValues ( )

Definition at line 211 of file FitAlg_ROOTFactoryFit.cxx.

Referenced by Fit(), and ~FitAlg_ROOTFactoryFit().

211  {
212 
213  // Set initial values for all parameterSpaceLocations
214  for(size_t ipar = 0; ipar < gFFNames->size(); ++ipar){
215  gFFMin->SetVariable(ipar,
216  (*gFFNames)[ipar],
217  (*gFFVals)[ipar],
218  0.01);
219  }
220 
221  // We're done here
222  return true;
223 
224  }
std::unique_ptr< std::vector< std::string > > gFFNames
ROOT::Math::Minimizer * gFFMin
std::unique_ptr< std::vector< double > > gFFVals

Member Data Documentation

std::string fnex::FitAlg_ROOTFactoryFit::fAlgoName
private

Definition at line 44 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().

bool fnex::FitAlgorithm::fIsConfigured
protectedinherited
unsigned int fnex::FitAlg_ROOTFactoryFit::fMaxFunctionCalls
private

Definition at line 45 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().

unsigned int fnex::FitAlg_ROOTFactoryFit::fMaxIterations
private

Definition at line 46 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().

std::string fnex::FitAlg_ROOTFactoryFit::fMinName
private

Definition at line 43 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().

MultiExperiment fnex::FitAlgorithm::fMultiExperiment
protectedinherited
double fnex::FitAlg_ROOTFactoryFit::fPrecision
private

Definition at line 48 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().

int fnex::FitAlg_ROOTFactoryFit::fPrintLevel
private

3 is default, more output would be 4

Definition at line 50 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().

int fnex::FitAlg_ROOTFactoryFit::fStrategyCode
private

Use 0 for faster fits, 1 for better errors.

Definition at line 49 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().

double fnex::FitAlg_ROOTFactoryFit::fTolerance
private

Definition at line 47 of file FitAlg_ROOTFactoryFit.h.

Referenced by InitializeMinimizer(), and Reconfigure().


The documentation for this class was generated from the following files: