CMS 3D CMS Logo

KinematicConstrainedVertexFitter.cc
Go to the documentation of this file.
6 
13  iterations = -1;
14  csum = -1000.0;
15 }
16 
18  finder = fnd.clone();
23  iterations = -1;
24  csum = -1000.0;
25 }
26 
28  delete finder;
29  delete vCons;
30  delete updator;
31  delete tBuilder;
32 }
33 
35  theMaxDelta = pSet.getParameter<double>("maxDelta");
36  theMaxStep = pSet.getParameter<int>("maxNbrOfIterations");
37  theMaxReducedChiSq = pSet.getParameter<double>("maxReducedChiSq");
38  theMinChiSqImprovement = pSet.getParameter<double>("minChiSqImprovement");
39 }
40 
42  theMaxDelta = 0.01;
43  theMaxStep = 1000;
44  theMaxReducedChiSq = 225.;
46 }
47 
48 RefCountedKinematicTree KinematicConstrainedVertexFitter::fit(const std::vector<RefCountedKinematicParticle> &part,
50  GlobalPoint *pt) {
51  if (part.size() < 2)
52  throw VertexException("KinematicConstrainedVertexFitter::input states are less than 2");
53 
54  //sorting out the input particles
55  InputSort iSort;
56  std::pair<std::vector<RefCountedKinematicParticle>, std::vector<FreeTrajectoryState> > input = iSort.sort(part);
57  const std::vector<RefCountedKinematicParticle> &particles = input.first;
58  const std::vector<FreeTrajectoryState> &fStates = input.second;
59 
60  // linearization point
61  // (only compute it using the linearization point finder if no point was passed to the fit function):
62  GlobalPoint linPoint;
63  if (pt != nullptr) {
64  linPoint = *pt;
65  } else {
66  linPoint = finder->getLinearizationPoint(fStates);
67  }
68 
69  //initial parameters:
70  int vSize = particles.size();
71  AlgebraicVector inPar(3 + 7 * vSize, 0);
72 
73  //final parameters
74  AlgebraicVector finPar(3 + 7 * vSize, 0);
75 
76  //initial covariance
77  AlgebraicMatrix inCov(3 + 7 * vSize, 3 + 7 * vSize, 0);
78 
79  //making initial vector of parameters and initial particle-related covariance
80  int nSt = 0;
81  std::vector<KinematicState> inStates;
82  for (std::vector<RefCountedKinematicParticle>::const_iterator i = particles.begin(); i != particles.end(); i++) {
83  KinematicState state = (*i)->stateAtPoint(linPoint);
84  if (!state.isValid()) {
85  LogDebug("KinematicConstrainedVertexFitter") << "State is invalid at point: " << linPoint << std::endl;
87  }
88  AlgebraicVector prPar = asHepVector<7>(state.kinematicParameters().vector());
89  for (int j = 1; j < 8; j++) {
90  inPar(3 + 7 * nSt + j) = prPar(j);
91  }
92  AlgebraicSymMatrix l_cov = asHepMatrix<7>(state.kinematicParametersError().matrix());
93  inCov.sub(4 + 7 * nSt, 4 + 7 * nSt, l_cov);
94  inStates.push_back(state);
95  ++nSt;
96  }
97 
98  //initial vertex error matrix components (huge error method)
99  //and vertex related initial vector components
100  double in_er = 100.;
101  inCov(1, 1) = in_er;
102  inCov(2, 2) = in_er;
103  inCov(3, 3) = in_er;
104 
105  inPar(1) = linPoint.x();
106  inPar(2) = linPoint.y();
107  inPar(3) = linPoint.z();
108 
109  //constraint equations value and number of iterations
110  double eq;
111  int nit = 0;
112  iterations = 0;
113  csum = 0.0;
114 
115  std::vector<KinematicState> lStates = inStates;
116  GlobalPoint lPoint = linPoint;
118  AlgebraicMatrix refCCov;
119 
120  double chisq = 1e6;
121  bool convergence = false;
122  //iterarions over the updator: each time updated parameters
123  //are taken as new linearization point
124  do {
125  eq = 0.;
126  std::pair<std::pair<std::vector<KinematicState>, AlgebraicMatrix>, RefCountedKinematicVertex> lRes =
127  updator->update(inPar, inCov, lStates, lPoint, cs);
128 
129  const std::vector<KinematicState> &newStates = lRes.first.first;
130 
131  if (particles.size() != newStates.size()) {
132  LogDebug("KinematicConstrainedVertexFitter") << "updator failure\n";
134  }
135 
136  rVtx = lRes.second;
137 
138  double newchisq = rVtx->chiSquared();
139  if (nit > 2 && newchisq > theMaxReducedChiSq * rVtx->degreesOfFreedom() &&
140  (newchisq - chisq) > (-theMinChiSqImprovement)) {
141  LogDebug("KinematicConstrainedVertexFitter") << "bad chisq and insufficient improvement, bailing\n";
143  }
144  chisq = newchisq;
145 
146  const GlobalPoint &newPoint = rVtx->position();
147 
148  double maxDelta = 0.0;
149 
150  double deltapos[3];
151  deltapos[0] = newPoint.x() - lPoint.x();
152  deltapos[1] = newPoint.y() - lPoint.y();
153  deltapos[2] = newPoint.z() - lPoint.z();
154  for (int i = 0; i < 3; ++i) {
155  double delta = deltapos[i] * deltapos[i] / rVtx->error().matrix()(i, i);
156  if (delta > maxDelta)
157  maxDelta = delta;
158  }
159 
160  for (std::vector<KinematicState>::const_iterator itold = lStates.begin(), itnew = newStates.begin();
161  itnew != newStates.end();
162  ++itold, ++itnew) {
163  for (int i = 0; i < 7; ++i) {
164  double deltapar = itnew->kinematicParameters()(i) - itold->kinematicParameters()(i);
165  double delta = deltapar * deltapar / itnew->kinematicParametersError().matrix()(i, i);
166  if (delta > maxDelta)
167  maxDelta = delta;
168  }
169  }
170 
171  lStates = newStates;
172  lPoint = newPoint;
173 
174  refCCov = lRes.first.second;
175  nit++;
176  convergence = maxDelta < theMaxDelta || (nit == theMaxStep && maxDelta < 4.0 * theMaxDelta);
177 
178  } while (nit < theMaxStep && !convergence);
179 
180  if (!convergence) {
182  }
183 
184  // std::cout << "old full cov matrix" << std::endl;
185  // std::cout << refCCov << std::endl;
186 
187  // cout<<"number of relinearizations "<<nit<<endl;
188  // cout<<"value obtained: "<<eq<<endl;
189  iterations = nit;
190  csum = eq;
191 
192  return tBuilder->buildTree(particles, lStates, rVtx, refCCov);
193 }
194 
196 
KinematicConstrainedVertexFitter::updator
KinematicConstrainedVertexUpdator * updator
Definition: KinematicConstrainedVertexFitter.h:77
mps_fire.i
i
Definition: mps_fire.py:355
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
InputSort
Definition: InputSort.h:14
ConstrainedTreeBuilder
Definition: ConstrainedTreeBuilder.h:15
KinematicConstrainedVertexFitter::setParameters
void setParameters(const edm::ParameterSet &pSet)
Definition: KinematicConstrainedVertexFitter.cc:34
VertexException
Common base class.
Definition: VertexException.h:12
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:45
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
KinematicState
Definition: KinematicState.h:17
KinematicConstrainedVertexFitter::~KinematicConstrainedVertexFitter
~KinematicConstrainedVertexFitter()
Definition: KinematicConstrainedVertexFitter.cc:27
KinematicTree
Definition: KinematicTree.h:36
MultiTrackKinematicConstraint
Definition: MultiTrackKinematicConstraint.h:23
KinematicConstrainedVertexFitter::theMinChiSqImprovement
float theMinChiSqImprovement
Definition: KinematicConstrainedVertexFitter.h:75
ReferenceCountingPointer< KinematicTree >
allConversions_cfi.maxDelta
maxDelta
Definition: allConversions_cfi.py:44
KinematicConstrainedVertexFitter::getCSum
float getCSum() const
Definition: KinematicConstrainedVertexFitter.cc:197
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
KinematicVertexFactory.h
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
KinematicConstrainedVertexUpdator
Definition: KinematicConstrainedVertexUpdator.h:13
KinematicConstrainedVertexFitter::fit
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
Definition: KinematicConstrainedVertexFitter.h:46
KinematicConstrainedVertexFitter::KinematicConstrainedVertexFitter
KinematicConstrainedVertexFitter()
Definition: KinematicConstrainedVertexFitter.cc:7
part
part
Definition: HCALResponse.h:20
DefaultLinearizationPointFinder.h
AlgebraicVector
CLHEP::HepVector AlgebraicVector
Definition: AlgebraicObjects.h:13
LinearizationPointFinder
Definition: LinearizationPointFinder.h:12
KinematicConstrainedVertexFitter::iterations
int iterations
Definition: KinematicConstrainedVertexFitter.h:80
KinematicState::kinematicParametersError
KinematicParametersError const & kinematicParametersError() const
Definition: KinematicState.h:63
Point3DBase< float, GlobalTag >
KinematicConstrainedVertexFitter::theMaxStep
int theMaxStep
Definition: KinematicConstrainedVertexFitter.h:73
KinematicConstrainedVertexFitter::vCons
VertexKinematicConstraint * vCons
Definition: KinematicConstrainedVertexFitter.h:78
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
KinematicConstrainedVertexFitter::defaultParameters
void defaultParameters()
Definition: KinematicConstrainedVertexFitter.cc:41
KinematicConstrainedVertexFitter::theMaxReducedChiSq
float theMaxReducedChiSq
Definition: KinematicConstrainedVertexFitter.h:74
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
KinematicParametersError::matrix
AlgebraicSymMatrix77 const & matrix() const
Definition: KinematicParametersError.h:36
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
KinematicConstrainedVertexFitter::finder
LinearizationPointFinder * finder
Definition: KinematicConstrainedVertexFitter.h:76
VertexKinematicConstraint
Definition: VertexKinematicConstraint.h:14
KinematicConstrainedVertexFitter::csum
float csum
Definition: KinematicConstrainedVertexFitter.h:81
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
ConstrainedTreeBuilder::buildTree
RefCountedKinematicTree buildTree(const std::vector< RefCountedKinematicParticle > &initialParticles, const std::vector< KinematicState > &finalStates, const RefCountedKinematicVertex vtx, const AlgebraicMatrix &fCov) const
Definition: ConstrainedTreeBuilder.cc:15
KinematicState::isValid
bool isValid() const
Definition: KinematicState.h:79
edm::eq
bool eq(const ELstring &s1, const ELstring s2)
Definition: ELstring.cc:39
DefaultLinearizationPointFinder
Definition: DefaultLinearizationPointFinder.h:13
InputSort.h
KinematicConstrainedVertexFitter::getNit
int getNit() const
Definition: KinematicConstrainedVertexFitter.cc:195
KinematicConstrainedVertexFitter::tBuilder
ConstrainedTreeBuilder * tBuilder
Definition: KinematicConstrainedVertexFitter.h:79
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
LinearizationPointFinder::clone
virtual LinearizationPointFinder * clone() const =0
KinematicConstrainedVertexUpdator::update
std::pair< std::pair< std::vector< KinematicState >, AlgebraicMatrix >, RefCountedKinematicVertex > update(const AlgebraicVector &inState, const AlgebraicMatrix &inCov, const std::vector< KinematicState > &lStates, const GlobalPoint &lPoint, MultiTrackKinematicConstraint *cs) const
Definition: KinematicConstrainedVertexUpdator.cc:16
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
KinematicConstrainedVertexFitter.h
InputSort::sort
std::pair< std::vector< RefCountedKinematicParticle >, std::vector< FreeTrajectoryState > > sort(const std::vector< RefCountedKinematicParticle > &particles) const
Definition: InputSort.cc:5
KinematicParameters::vector
AlgebraicVector7 const & vector() const
The full vector (7 elements)
Definition: KinematicParameters.h:31
KinematicConstrainedVertexFitter::theMaxDelta
float theMaxDelta
Definition: KinematicConstrainedVertexFitter.h:72
LinearizationPointFinder::getLinearizationPoint
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
KinematicState::kinematicParameters
KinematicParameters const & kinematicParameters() const
Definition: KinematicState.h:61
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66