CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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) return true;// do not refit
28  if(!isConfigured_) return false; // do not fit if configuration failed
30  ROOT::Minuit2::MnUserParameters MnPar;
31  for(int i=0;i<par_.GetNrows();i++){
32  TString name=freeParName(i);
33  // if not limited (vhigh <= vlow)
34  MnPar.Add(name.Data(),par_(i),sqrt(fabs(parcov_(i,i))),par_(i)-nsigma_*sqrt(fabs(parcov_(i,i))),par_(i)+nsigma_*sqrt(fabs(parcov_(i,i))));
35  }
36 
37  unsigned int max=10;
38  int numberofcalls=200+par_.GetNrows()*100+par_.GetNrows()*par_.GetNrows()*5;
39  double tolerance(0.01);
40  double edmMin(0.001*updator.Up()*tolerance);
41 
42  ROOT::Minuit2::MnMinimize minimize(updator,MnPar);
43  ROOT::Minuit2::FunctionMinimum min= minimize(numberofcalls,tolerance);
44  for(unsigned int i=0;i<=max && min.Edm()>edmMin;i++){
45  if(i==max) return false;
46  min = minimize(i*numberofcalls,tolerance);
47  }
48  // give return flag based on status
49  if(min.IsAboveMaxEdm()){edm::LogWarning("Chi2VertexFitter::Fit") << "Found Vertex that is above EDM " << std::endl; return false;}
50  if(!min.IsValid()){
51  edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.IsValid()" << std::endl;
52  if(!min.HasValidParameters()){edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HasValidParameters()" << std::endl; }
53  if(!min.HasValidCovariance()){edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HasValidCovariance()" << std::endl; }
54  if(!min.HesseFailed()){edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HesseFailed()" << std::endl; }
55  if(!min.HasReachedCallLimit()){edm::LogWarning("Chi2VertexFitter::Fit") << "Failed min.HasReachedCallLimit()" << std::endl; }
56  return false;
57  }
58  chi2_=min.Fval();
59  // Get output parameters
60  for(int i=0;i<par_.GetNrows();i++){ par_(i)=min.UserParameters().Value(i);}
61  // Get output covariance
62  for(int i=0;i<par_.GetNrows();i++){
63  for(int j=0;j<par_.GetNrows();j++){
64  parcov_(i,j)=min.UserCovariance()(i,j);
65  }
66  }
67 
68  isFit_=true;
69  return isFit_;
70 }
int i
Definition: DBlmapReader.cc:9
T sqrt(T t)
Definition: SSEVec.h:48
int j
Definition: DBlmapReader.cc:9
T min(T a, T b)
Definition: MathUtil.h:58