CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Chi2VertexFitter.cc
Go to the documentation of this file.
1 /* From SimpleFits Package
2  * Designed an written by
3  * author: Ian M. Nugent
4  * Humboldt Foundations
5  */
9 #include "Minuit2/FunctionMinimum.h"
10 #include "Minuit2/MnUserParameters.h"
11 #include "Minuit2/MnPrint.h"
12 #include "Minuit2/MnMigrad.h"
13 #include "Minuit2/MnSimplex.h"
14 #include "Minuit2/CombinedMinimizer.h"
15 #include "Minuit2/MnMinimize.h"
16 #include "Minuit2/MnMinos.h"
17 #include "Minuit2/MnHesse.h"
18 #include "Minuit2/MnContours.h"
19 #include "Minuit2/MnPlot.h"
20 #include "Minuit2/MinosError.h"
21 #include "Minuit2/ContoursError.h"
22 #include <iostream>
23 
24 using namespace tauImpactParameter;
25 
27  if (isFit_ == true)
28  return true; // do not refit
29  if (!isConfigured_)
30  return false; // do not fit if configuration failed
32  ROOT::Minuit2::MnUserParameters MnPar;
33  for (int i = 0; i < par_.GetNrows(); i++) {
34  TString name = freeParName(i);
35  // if not limited (vhigh <= vlow)
36  MnPar.Add(name.Data(),
37  par_(i),
38  sqrt(fabs(parcov_(i, i))),
39  par_(i) - nsigma_ * sqrt(fabs(parcov_(i, i))),
40  par_(i) + nsigma_ * sqrt(fabs(parcov_(i, i))));
41  }
42 
43  unsigned int max = 10;
44  int numberofcalls = 200 + par_.GetNrows() * 100 + par_.GetNrows() * par_.GetNrows() * 5;
45  double tolerance(0.01);
46  double edmMin(0.001 * updator.Up() * tolerance);
47 
48  ROOT::Minuit2::MnMinimize minimize(updator, MnPar);
49  ROOT::Minuit2::FunctionMinimum min = minimize(numberofcalls, tolerance);
50  for (unsigned int i = 0; i <= max && min.Edm() > edmMin; i++) {
51  if (i == max)
52  return false;
53  min = minimize(i * numberofcalls, tolerance);
54  }
55  // give return flag based on status
56  if (min.IsAboveMaxEdm()) {
57  edm::LogWarning("Chi2VertexFitter::Fit") << "Found Vertex that is above EDM " << std::endl;
58  return false;
59  }
60  if (!min.IsValid()) {
61  edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.IsValid()" << std::endl;
62  if (!min.HasValidParameters()) {
63  edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HasValidParameters()" << std::endl;
64  }
65  if (!min.HasValidCovariance()) {
66  edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HasValidCovariance()" << std::endl;
67  }
68  if (!min.HesseFailed()) {
69  edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HesseFailed()" << std::endl;
70  }
71  if (!min.HasReachedCallLimit()) {
72  edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HasReachedCallLimit()" << std::endl;
73  }
74  return false;
75  }
76  chi2_ = min.Fval();
77  // Get output parameters
78  for (int i = 0; i < par_.GetNrows(); i++) {
79  par_(i) = min.UserParameters().Value(i);
80  }
81  // Get output covariance
82  for (int i = 0; i < par_.GetNrows(); i++) {
83  for (int j = 0; j < par_.GetNrows(); j++) {
84  parcov_(i, j) = min.UserCovariance()(i, j);
85  }
86  }
87 
88  isFit_ = true;
89  return isFit_;
90 }
const double tolerance
T sqrt(T t)
Definition: SSEVec.h:19
Log< level::Warning, false > LogWarning