CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
tauImpactParameter::LagrangeMultipliersFitter Class Referenceabstract

#include <LagrangeMultipliersFitter.h>

Public Types

enum  ConvergeProc { ConstraintMin =0, Chi2Min, Chi2AndConstaintMin }
 
enum  Parameters {
  par_vx =0, par_vy, par_vz, par_px,
  par_py, par_pz, par_m, npardim
}
 
enum  Position { pos_x =0, pos_y, pos_z, nposdim }
 

Public Member Functions

virtual double chiSquare ()
 
virtual double cSum ()
 
virtual bool fit ()
 
virtual LorentzVectorParticle getMother ()=0
 
virtual std::vector
< LorentzVectorParticle
getRefitDaughters ()=0
 
virtual bool isConfigured ()
 
virtual bool isConverged ()
 
 LagrangeMultipliersFitter ()
 
virtual double nConstraints ()=0
 
virtual int nDaughters ()=0
 
virtual double ndf ()=0
 
virtual double nIter ()
 
virtual void setMaxDelta (double MaxDelta)
 
virtual void setNIterMax (int Nitermax)
 
virtual void setWeight (double weight)
 
virtual ~LagrangeMultipliersFitter ()
 

Protected Member Functions

virtual TVectorD value (const TVectorD &v)=0
 

Protected Attributes

TMatrixTSym< double > cov_
 
TMatrixTSym< double > cov_0_
 
bool isConfigured_
 
bool isFit_
 
TVectorD par_
 
TVectorD par_0_
 

Private Member Functions

bool applyLagrangianConstraints ()
 
double chiSquare (const TVectorT< double > &delta_alpha, const TVectorT< double > &lambda, const TMatrixT< double > &D, const TVectorT< double > &d)
 
double chiSquareUsingInitalPoint (const TVectorT< double > &alpha, const TVectorT< double > &lambda)
 
TMatrixT< double > computeVariance ()
 
double constraintDelta (const TVectorT< double > &par)
 
TMatrixT< double > derivative ()
 

Private Attributes

double chi2_
 
double chi2prev_
 
TMatrixT< double > D_
 
double delta_
 
double epsilon_
 
double maxDelta_
 
double niter_
 
double nitermax_
 
double ScaleFactor_
 
TMatrixTSym< double > V_alpha0_inv_
 
TMatrixT< double > V_corr_prev_
 
TMatrixTSym< double > V_D_
 
double weight_
 

Detailed Description

Definition at line 18 of file LagrangeMultipliersFitter.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

LagrangeMultipliersFitter::LagrangeMultipliersFitter ( )
virtual tauImpactParameter::LagrangeMultipliersFitter::~LagrangeMultipliersFitter ( )
inlinevirtual

Definition at line 25 of file LagrangeMultipliersFitter.h.

25 {};

Member Function Documentation

bool LagrangeMultipliersFitter::applyLagrangianConstraints ( )
private

Definition at line 47 of file LagrangeMultipliersFitter.cc.

References alpha, funct::C, chi2_, Chi2AndConstaintMin, chi2prev_, chiSquareUsingInitalPoint(), constraintDelta(), ConstraintMin, cov_0_, ztail::d, D_, delta_, derivative(), diffTreeTool::diff, GeomDetEnumerators::DT, epsilon_, prof2calltree::l, maxDelta_, nConstraints(), par_, par_0_, alignCSCRings::s, ScaleFactor_, V_D_, and value().

Referenced by fit().

47  {
48  if(V_D_.GetNrows()!=nConstraints()) V_D_.ResizeTo(nConstraints(),nConstraints());
49  if(D_.GetNrows()!=nConstraints() || D_.GetNcols()!=par_.GetNrows()) D_.ResizeTo(nConstraints(),par_.GetNrows());
50 
51  // Setup intial values
52  TVectorT<double> alpha_A=par_;
53  TVectorT<double> alpha_0=par_0_;
54  TVectorT<double> delta_alpha_A=alpha_A-alpha_0;
55  D_=derivative();
56  TVectorT<double> d=value(par_);
57  TVectorT<double> C=D_*delta_alpha_A-d;
58  TMatrixTSym<double> V_alpha0=cov_0_;
59  TMatrixTSym<double> V_D_inv=V_alpha0;
60  V_D_inv.Similarity(D_);
61  double det = V_D_inv.Determinant();
62  TDecompBK Inverter(V_D_inv);
63  if(fabs(det)>1e40){
64  edm::LogWarning("LagrangeMultipliersFitter::Fit") << "Fit failed: unable to invert SYM gain matrix LARGE Determinant" << det << " \n" << std::endl;
65  return false;
66  }
67  if(!Inverter.Decompose()){
68  edm::LogWarning("LagrangeMultipliersFitter::Fit") << "Fit failed: unable to invert SYM gain matrix " << det << " \n" << std::endl;
69  return false;
70  }
71  V_D_=Inverter.Invert();
72 
73  // solve equations
74  TVectorT<double> lambda=-1.0*V_D_*C;
75  TMatrixT<double> DT=D_; DT.T();
76  TVectorT<double> alpha=alpha_0-V_alpha0*DT*lambda;
77 
78  // do while loop to see if the convergance criteria are satisfied
79  double s(1), stepscale(0.01);
81  double currentchi2(chiSquareUsingInitalPoint(alpha_A,lambda)), currentdelta(constraintDelta(par_));
82  TVectorT<double> alpha_s=alpha;
83  // convergence in 2 step procedure to minimize chi2 within MaxDelta_ of the constriants
84  // 1) Get within 5x MaxDelta_
85  // 2) converge based on improving chi2 and constrianed delta
86  unsigned int Proc=ConstraintMin;
88  int NIter=(int)(1.0/stepscale);
89  for(int iter=0;iter<NIter;iter++){
90  // compute safty cutoff for numberical constraint
91  double diff=0;
92  for(int l=0;l<alpha_s.GetNrows();l++){
93  if(diff<alpha_s(l)-alpha_A(l))diff=alpha_s(l)-alpha_A(l);
94  }
95  double delta_alpha_s=constraintDelta(alpha_s);
96  if(Proc==ConstraintMin){
97  if(delta_alpha_s<currentdelta || iter==NIter || diff<100*epsilon_){currentchi2=chiSquareUsingInitalPoint(alpha_s,lambda); currentdelta=delta_alpha_s; ScaleFactor_=s; break;}
98  }
99  else if(Proc==Chi2AndConstaintMin){
100  double chi2_s=chiSquareUsingInitalPoint(alpha_s,lambda);
101  if((delta_alpha_s<currentdelta/*+maxDelta_*/ && chi2_s<currentchi2) || iter==NIter || diff<100*epsilon_){currentchi2=chi2_s; currentdelta=delta_alpha_s; ScaleFactor_=s; break;}
102  }
103  s-=stepscale;
104  alpha_s=alpha_A+s*(alpha-alpha_A);
105  }
106  // set chi2
107  chi2_=currentchi2;
108  //set delta
109  delta_=currentdelta;
110  par_=alpha_s;
111  return true;
112 }
float alpha
Definition: AMPTWrapper.h:95
virtual TVectorD value(const TVectorD &v)=0
tuple d
Definition: ztail.py:151
double chiSquareUsingInitalPoint(const TVectorT< double > &alpha, const TVectorT< double > &lambda)
double constraintDelta(const TVectorT< double > &par)
virtual double tauImpactParameter::LagrangeMultipliersFitter::chiSquare ( )
inlinevirtual

Definition at line 34 of file LagrangeMultipliersFitter.h.

References chi2_.

double LagrangeMultipliersFitter::chiSquare ( const TVectorT< double > &  delta_alpha,
const TVectorT< double > &  lambda,
const TMatrixT< double > &  D,
const TVectorT< double > &  d 
)
private

Definition at line 140 of file LagrangeMultipliersFitter.cc.

References counter::c2, and ztail::d.

140  {
141  double c2=lambda*(D*delta_alpha+d);
142  return c2;
143 }
tuple d
Definition: ztail.py:151
tuple c2
Definition: counter.py:145
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
double LagrangeMultipliersFitter::chiSquareUsingInitalPoint ( const TVectorT< double > &  alpha,
const TVectorT< double > &  lambda 
)
private

Definition at line 145 of file LagrangeMultipliersFitter.cc.

References alpha, counter::c2, cov_0_, i, j, par_, par_0_, V_alpha0_inv_, and value().

Referenced by applyLagrangianConstraints().

145  {
146  if(cov_0_.GetNrows()!=V_alpha0_inv_.GetNrows()){
147  TMatrixTSym<double> V_alpha0=cov_0_;
148  V_alpha0_inv_.ResizeTo(cov_0_.GetNrows(),cov_0_.GetNrows());
149  TDecompBK Inverter(V_alpha0);
150  if(!Inverter.Decompose()){ // handle rare case where inversion is not possible (ie assume diagonal)
151  edm::LogWarning("LagrangeMultipliersFitter::chiSquareUsingInitalPoint") << "Error non-invertable Matrix... Calculating under assumption that correlations can be neglected!!!" << std::endl;
152  for(int j=0;j<par_.GetNrows();j++){
153  for(int i=0;i<par_.GetNrows();i++){
154  if(i==j) V_alpha0_inv_(i,j)=1.0/V_alpha0(i,j);
155  else V_alpha0_inv_(i,j)=0.0;
156  }
157  }
158  } else {
159  V_alpha0_inv_=Inverter.Invert();
160  }
161  }
162 
163  TVectorT<double> alpha_0=par_0_;
164  TVectorT<double> dalpha=alpha-alpha_0;
165  double c2_var=dalpha*(V_alpha0_inv_*dalpha);
166  TVectorT<double> alpha_v=alpha;
167  double c2_constraints=lambda*value(alpha_v);
168  double c2=c2_var+c2_constraints;
169  return c2;
170 }
int i
Definition: DBlmapReader.cc:9
float alpha
Definition: AMPTWrapper.h:95
virtual TVectorD value(const TVectorD &v)=0
tuple c2
Definition: counter.py:145
int j
Definition: DBlmapReader.cc:9
TMatrixT< double > LagrangeMultipliersFitter::computeVariance ( )
private

Definition at line 181 of file LagrangeMultipliersFitter.cc.

References cov_, cov_0_, D_, i, j, ScaleFactor_, V_corr_prev_, and V_D_.

Referenced by fit().

181  {
182  TMatrixTSym<double> V_alpha0=cov_0_;
183  TMatrixTSym<double> DTV_DD=V_D_.SimilarityT(D_);
184  TMatrixT<double> DTV_DDV=DTV_DD*V_alpha0;
185  TMatrixT<double> VDTV_DDV=V_alpha0*DTV_DDV;
186  TMatrixT<double> CovCor=VDTV_DDV;
187  //CovCor*=ScaleFactor_;
188  if(V_corr_prev_.GetNrows()!=V_alpha0.GetNrows()){
189  V_corr_prev_.ResizeTo(V_alpha0.GetNrows(),V_alpha0.GetNrows());
190  V_corr_prev_=CovCor;
191  }
192  else{
194  CovCor+=V_corr_prev_;
195  V_corr_prev_=CovCor;
196  }
197 
198  TMatrixT<double> V_alpha = V_alpha0-CovCor;
199  for(int i=0; i<cov_.GetNrows();i++){
200  for(int j=0; j<=i;j++){
201  cov_(i,j)=V_alpha(i,j);
202  }
203  }
204  return cov_;
205 }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
double LagrangeMultipliersFitter::constraintDelta ( const TVectorT< double > &  par)
private

Definition at line 172 of file LagrangeMultipliersFitter.cc.

References i, and value().

Referenced by applyLagrangianConstraints().

172  {
173  TVectorD d_par=value(par);
174  double delta_d(0);
175  for(int i = 0; i<d_par.GetNrows(); i++){
176  delta_d+=fabs(d_par(i));
177  }
178  return delta_d;
179 }
int i
Definition: DBlmapReader.cc:9
virtual TVectorD value(const TVectorD &v)=0
virtual double tauImpactParameter::LagrangeMultipliersFitter::cSum ( )
inlinevirtual

Definition at line 35 of file LagrangeMultipliersFitter.h.

References delta_.

TMatrixD LagrangeMultipliersFitter::derivative ( )
private

Definition at line 114 of file LagrangeMultipliersFitter.cc.

References epsilon_, i, j, nConstraints(), par_, and value().

Referenced by applyLagrangianConstraints().

114  { // alway evaluated at current par
115  TMatrixD Derivatives(nConstraints(),par_.GetNrows());
116  TVectorD par_plus(par_.GetNrows());
117  TVectorD value_par(nConstraints());
118  TVectorD value_par_plus(nConstraints());
119  for(int j=0;j<par_.GetNrows();j++){
120  for(int i=0;i<par_.GetNrows();i++){
121  par_plus(i)=par_(i);
122  if(i==j) par_plus(i)=par_(i)+epsilon_;
123  }
124  value_par=value(par_);
125  value_par_plus=value(par_plus);
126  for(int i=0; i<nConstraints();i++){
127  Derivatives(i,j)=(value_par_plus(i)-value_par(i))/epsilon_;
128  }
129  }
130  return Derivatives;
131 }
int i
Definition: DBlmapReader.cc:9
virtual TVectorD value(const TVectorD &v)=0
int j
Definition: DBlmapReader.cc:9
AlgebraicMatrix Derivatives
Definition: Definitions.h:37
bool LagrangeMultipliersFitter::fit ( void  )
virtual

Definition at line 25 of file LagrangeMultipliersFitter.cc.

References applyLagrangianConstraints(), computeVariance(), cov_, cov_0_, delta_, isConfigured_, isConverged(), isFit_, maxDelta_, niter_, nitermax_, and par_0_.

25  {
26  if(cov_.GetNrows()!=par_0_.GetNrows()){
27  // set cov to cov_0 until value is computed
28  cov_.ResizeTo(par_0_.GetNrows(),par_0_.GetNrows());
29  cov_=cov_0_;
30  }
31  if(!isConfigured_) return false;
32  if(isFit_)return isConverged();
33  isFit_=true;
34  niter_=0;
35  for(niter_=0;niter_<=nitermax_;niter_++){
36  bool passed=applyLagrangianConstraints();
37  if (!passed || (niter_==nitermax_ && delta_>=4.0*maxDelta_)) {
38  edm::LogWarning("LagrangeMultipliersFitter::Fit") << "Reached Maximum number of iterations..." << niter_ << std::endl;
39  return false;
40  }
41  if(isConverged()) break;
42  }
44  return true;
45 }
virtual LorentzVectorParticle tauImpactParameter::LagrangeMultipliersFitter::getMother ( )
pure virtual
virtual std::vector<LorentzVectorParticle> tauImpactParameter::LagrangeMultipliersFitter::getRefitDaughters ( )
pure virtual
virtual bool tauImpactParameter::LagrangeMultipliersFitter::isConfigured ( )
inlinevirtual
bool LagrangeMultipliersFitter::isConverged ( )
virtual

Definition at line 133 of file LagrangeMultipliersFitter.cc.

References delta_, and maxDelta_.

Referenced by fit().

133  {
134  if(delta_<maxDelta_){
135  return true;
136  }
137  return false;
138 }
virtual double tauImpactParameter::LagrangeMultipliersFitter::nConstraints ( )
pure virtual
virtual int tauImpactParameter::LagrangeMultipliersFitter::nDaughters ( )
pure virtual
virtual double tauImpactParameter::LagrangeMultipliersFitter::ndf ( )
pure virtual
virtual double tauImpactParameter::LagrangeMultipliersFitter::nIter ( )
inlinevirtual

Definition at line 36 of file LagrangeMultipliersFitter.h.

References niter_.

virtual void tauImpactParameter::LagrangeMultipliersFitter::setMaxDelta ( double  MaxDelta)
inlinevirtual

Definition at line 28 of file LagrangeMultipliersFitter.h.

References maxDelta_.

virtual void tauImpactParameter::LagrangeMultipliersFitter::setNIterMax ( int  Nitermax)
inlinevirtual

Definition at line 29 of file LagrangeMultipliersFitter.h.

References nitermax_.

virtual void tauImpactParameter::LagrangeMultipliersFitter::setWeight ( double  weight)
inlinevirtual
virtual TVectorD tauImpactParameter::LagrangeMultipliersFitter::value ( const TVectorD &  v)
protectedpure virtual

Member Data Documentation

double tauImpactParameter::LagrangeMultipliersFitter::chi2_
private

Definition at line 66 of file LagrangeMultipliersFitter.h.

Referenced by applyLagrangianConstraints(), and chiSquare().

double tauImpactParameter::LagrangeMultipliersFitter::chi2prev_
private

Definition at line 66 of file LagrangeMultipliersFitter.h.

Referenced by applyLagrangianConstraints().

TMatrixTSym<double> tauImpactParameter::LagrangeMultipliersFitter::cov_
protected

Definition at line 50 of file LagrangeMultipliersFitter.h.

Referenced by computeVariance(), and fit().

TMatrixTSym<double> tauImpactParameter::LagrangeMultipliersFitter::cov_0_
protected
TMatrixT<double> tauImpactParameter::LagrangeMultipliersFitter::D_
private

Definition at line 70 of file LagrangeMultipliersFitter.h.

Referenced by applyLagrangianConstraints(), and computeVariance().

double tauImpactParameter::LagrangeMultipliersFitter::delta_
private

Definition at line 66 of file LagrangeMultipliersFitter.h.

Referenced by applyLagrangianConstraints(), cSum(), fit(), and isConverged().

double tauImpactParameter::LagrangeMultipliersFitter::epsilon_
private

Definition at line 63 of file LagrangeMultipliersFitter.h.

Referenced by applyLagrangianConstraints(), and derivative().

bool tauImpactParameter::LagrangeMultipliersFitter::isConfigured_
protected

Definition at line 51 of file LagrangeMultipliersFitter.h.

Referenced by fit(), and isConfigured().

bool tauImpactParameter::LagrangeMultipliersFitter::isFit_
protected

Definition at line 52 of file LagrangeMultipliersFitter.h.

Referenced by fit().

double tauImpactParameter::LagrangeMultipliersFitter::maxDelta_
private
double tauImpactParameter::LagrangeMultipliersFitter::niter_
private

Definition at line 66 of file LagrangeMultipliersFitter.h.

Referenced by fit(), and nIter().

double tauImpactParameter::LagrangeMultipliersFitter::nitermax_
private

Definition at line 63 of file LagrangeMultipliersFitter.h.

Referenced by fit(), and setNIterMax().

TVectorD tauImpactParameter::LagrangeMultipliersFitter::par_
protected
TVectorD tauImpactParameter::LagrangeMultipliersFitter::par_0_
protected
double tauImpactParameter::LagrangeMultipliersFitter::ScaleFactor_
private

Definition at line 72 of file LagrangeMultipliersFitter.h.

Referenced by applyLagrangianConstraints(), and computeVariance().

TMatrixTSym<double> tauImpactParameter::LagrangeMultipliersFitter::V_alpha0_inv_
private

Definition at line 69 of file LagrangeMultipliersFitter.h.

Referenced by chiSquareUsingInitalPoint().

TMatrixT<double> tauImpactParameter::LagrangeMultipliersFitter::V_corr_prev_
private

Definition at line 73 of file LagrangeMultipliersFitter.h.

Referenced by computeVariance().

TMatrixTSym<double> tauImpactParameter::LagrangeMultipliersFitter::V_D_
private

Definition at line 71 of file LagrangeMultipliersFitter.h.

Referenced by applyLagrangianConstraints(), and computeVariance().

double tauImpactParameter::LagrangeMultipliersFitter::weight_
private

Definition at line 63 of file LagrangeMultipliersFitter.h.

Referenced by setWeight().