CMS 3D CMS Logo

KinematicConstrainedVertexFitterT.h
Go to the documentation of this file.
1 #ifndef KinematicConstrainedVertexFitterT_H
2 #define KinematicConstrainedVertexFitterT_H
3 
9 
11 
14 
24 template <int nTrk, int nConstraint>
26 public:
30  explicit KinematicConstrainedVertexFitterT(const MagneticField* ifield);
31 
36 
38 
44  void setParameters(const edm::ParameterSet& pSet);
45 
50  RefCountedKinematicTree fit(const std::vector<RefCountedKinematicParticle>& part) { return fit(part, 0, 0); }
51 
55  RefCountedKinematicTree fit(const std::vector<RefCountedKinematicParticle>& part,
57  return fit(part, cs, nullptr);
58  };
59 
63  RefCountedKinematicTree fit(const std::vector<RefCountedKinematicParticle>& part,
65  GlobalPoint* pt);
66 
67  //return the number of iterations
68  int getNit() const;
69  //return the value of the constraint equation
70  float getCSum() const;
71 
72 private:
73  void defaultParameters();
74 
80 
81  float theMaxDelta; //maximum (delta parameter)^2/(sigma parameter)^2 per iteration for convergence
83  float theMaxReducedChiSq; //max of initial (after 2 iterations) chisq/dof value
84  float theMinChiSqImprovement; //minimum required improvement in chisq to avoid fit termination for cases exceeding theMaxReducedChiSq
85 
87  float csum;
88 };
89 
94 
95 template <int nTrk, int nConstraint>
97  : field(ifield) {
103  iterations = -1;
104  csum = -1000.0;
105 }
106 
107 template <int nTrk, int nConstraint>
109  const MagneticField* ifield, const LinearizationPointFinder& fnd)
110  : field(ifield) {
111  finder = fnd.clone();
116  iterations = -1;
117  csum = -1000.0;
118 }
119 
120 template <int nTrk, int nConstraint>
122  delete finder;
123  delete vCons;
124  delete updator;
125  delete tBuilder;
126 }
127 
128 template <int nTrk, int nConstraint>
130  theMaxDelta = pSet.getParameter<double>("maxDelta");
131  theMaxStep = pSet.getParameter<int>("maxNbrOfIterations");
132  theMaxReducedChiSq = pSet.getParameter<double>("maxReducedChiSq");
133  theMinChiSqImprovement = pSet.getParameter<double>("minChiSqImprovement");
134 }
135 
136 template <int nTrk, int nConstraint>
138  theMaxDelta = 0.01;
139  theMaxStep = 1000;
140  theMaxReducedChiSq = 225.;
141  theMinChiSqImprovement = 50.;
142 }
143 
144 template <int nTrk, int nConstraint>
146  const std::vector<RefCountedKinematicParticle>& part,
148  GlobalPoint* pt) {
149  assert(nConstraint == 0 || cs != nullptr);
150  if (part.size() != nTrk)
151  throw VertexException("KinematicConstrainedVertexFitterT::input states are not nTrk");
152 
153  //sorting out the input particles
154  InputSort iSort;
155  std::pair<std::vector<RefCountedKinematicParticle>, std::vector<FreeTrajectoryState> > input = iSort.sort(part);
156  const std::vector<RefCountedKinematicParticle>& particles = input.first;
157  const std::vector<FreeTrajectoryState>& fStates = input.second;
158 
159  // linearization point:
160  GlobalPoint linPoint = (pt != nullptr) ? *pt : finder->getLinearizationPoint(fStates);
161 
162  //initial parameters:
163  ROOT::Math::SVector<double, 3 + 7 * nTrk> inPar; //3+ 7*ntracks
164  ROOT::Math::SVector<double, 3 + 7 * nTrk> finPar; //3+ 7*ntracks
165 
166  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> > inCov;
167 
168  //making initial vector of parameters and initial particle-related covariance
169  int nSt = 0;
170  std::vector<KinematicState> lStates(nTrk);
171  for (std::vector<RefCountedKinematicParticle>::const_iterator i = particles.begin(); i != particles.end(); i++) {
172  lStates[nSt] = (*i)->stateAtPoint(linPoint);
173  KinematicState const& state = lStates[nSt];
174  if (!state.isValid()) {
175  LogDebug("KinematicConstrainedVertexFitter") << "State is invalid at point: " << linPoint << std::endl;
177  }
178  inPar.Place_at(state.kinematicParameters().vector(), 3 + 7 * nSt);
179  inCov.Place_at(state.kinematicParametersError().matrix(), 3 + 7 * nSt, 3 + 7 * nSt);
180  ++nSt;
181  }
182 
183  //initial vertex error matrix components (huge error method)
184  //and vertex related initial vector components
185  double in_er = 100.;
186  inCov(0, 0) = in_er;
187  inCov(1, 1) = in_er;
188  inCov(2, 2) = in_er;
189 
190  inPar(0) = linPoint.x();
191  inPar(1) = linPoint.y();
192  inPar(2) = linPoint.z();
193 
194  //constraint equations value and number of iterations
195  double eq;
196  int nit = 0;
197  iterations = 0;
198  csum = 0.0;
199 
200  GlobalPoint lPoint = linPoint;
202  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> > refCCov =
203  ROOT::Math::SMatrixNoInit();
204 
205  double chisq = 1e6;
206  bool convergence = false;
207 
208  //iterarions over the updator: each time updated parameters
209  //are taken as new linearization point
210  do {
211  eq = 0.;
212  refCCov = inCov;
213  std::vector<KinematicState> oldStates = lStates;
214  GlobalVector mf = field->inInverseGeV(lPoint);
215  rVtx = updator->update(inPar, refCCov, lStates, lPoint, mf, cs);
216  if (particles.size() != lStates.size() || rVtx == nullptr) {
217  LogDebug("KinematicConstrainedVertexFitter") << "updator failure\n";
219  }
220 
221  double newchisq = rVtx->chiSquared();
222  if (nit > 2 && newchisq > theMaxReducedChiSq * rVtx->degreesOfFreedom() &&
223  (newchisq - chisq) > (-theMinChiSqImprovement)) {
224  LogDebug("KinematicConstrainedVertexFitter") << "bad chisq and insufficient improvement, bailing\n";
226  }
227  chisq = newchisq;
228 
229  const GlobalPoint& newPoint = rVtx->position();
230 
231  double maxDelta = 0.0;
232 
233  double deltapos[3];
234  deltapos[0] = newPoint.x() - lPoint.x();
235  deltapos[1] = newPoint.y() - lPoint.y();
236  deltapos[2] = newPoint.z() - lPoint.z();
237  for (int i = 0; i < 3; ++i) {
238  double delta = deltapos[i] * deltapos[i] / rVtx->error().matrix()(i, i);
239  if (delta > maxDelta)
240  maxDelta = delta;
241  }
242 
243  for (std::vector<KinematicState>::const_iterator itold = oldStates.begin(), itnew = lStates.begin();
244  itnew != lStates.end();
245  ++itold, ++itnew) {
246  for (int i = 0; i < 7; ++i) {
247  double deltapar = itnew->kinematicParameters()(i) - itold->kinematicParameters()(i);
248  double delta = deltapar * deltapar / itnew->kinematicParametersError().matrix()(i, i);
249  if (delta > maxDelta)
250  maxDelta = delta;
251  }
252  }
253 
254  lPoint = newPoint;
255 
256  nit++;
257  convergence = maxDelta < theMaxDelta || (nit == theMaxStep && maxDelta < 4.0 * theMaxDelta);
258 
259  } while (nit < theMaxStep && !convergence);
260 
261  if (!convergence) {
263  }
264 
265  // std::cout << "new full cov matrix" << std::endl;
266  // std::cout << refCCov << std::endl;
267 
268  iterations = nit;
269  csum = eq;
270 
271  return tBuilder->buildTree<nTrk>(particles, lStates, rVtx, refCCov);
272 }
273 
274 template <int nTrk, int nConstraint>
276  return iterations;
277 }
278 
279 template <int nTrk, int nConstraint>
281  return csum;
282 }
283 
284 #endif
Vector3DBase
Definition: Vector3DBase.h:8
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
InputSort
Definition: InputSort.h:14
KinematicConstrainedVertexFitterT::theMaxReducedChiSq
float theMaxReducedChiSq
Definition: KinematicConstrainedVertexFitterT.h:83
HLT_FULL_cff.finder
finder
Definition: HLT_FULL_cff.py:51924
VertexException
Common base class.
Definition: VertexException.h:12
MultiTrackKinematicConstraintT.h
KinematicConstrainedVertexFitterT::theMaxStep
int theMaxStep
Definition: KinematicConstrainedVertexFitterT.h:82
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
KinematicConstrainedVertexFitterT::csum
float csum
Definition: KinematicConstrainedVertexFitterT.h:87
KinematicState
Definition: KinematicState.h:17
KinematicConstrainedVertexUpdatorT.h
KinematicConstrainedVertexFitterT::fit
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part, MultiTrackKinematicConstraintT< nTrk, nConstraint > *cs)
Definition: KinematicConstrainedVertexFitterT.h:55
KinematicConstrainedVertexFitterT::fit
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
Definition: KinematicConstrainedVertexFitterT.h:50
KinematicConstrainedVertexFitterT::getCSum
float getCSum() const
Definition: KinematicConstrainedVertexFitterT.h:280
KinematicTree
Definition: KinematicTree.h:36
cms::cuda::assert
assert(be >=bs)
ReferenceCountingPointer< KinematicTree >
KinematicConstrainedVertexFitterT::vCons
VertexKinematicConstraintT * vCons
Definition: KinematicConstrainedVertexFitterT.h:78
allConversions_cfi.maxDelta
maxDelta
Definition: allConversions_cfi.py:44
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
KinematicVertexFactory.h
KinematicConstrainedVertexFitterT::defaultParameters
void defaultParameters()
Definition: KinematicConstrainedVertexFitterT.h:137
KinematicConstrainedVertexFitterT::getNit
int getNit() const
Definition: KinematicConstrainedVertexFitterT.h:275
KinematicConstrainedVertexFitterT::finder
LinearizationPointFinder * finder
Definition: KinematicConstrainedVertexFitterT.h:76
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
VertexKinematicConstraintT.h
ConstrainedTreeBuilderT.h
part
part
Definition: HCALResponse.h:20
DefaultLinearizationPointFinder.h
LinearizationPointFinder
Definition: LinearizationPointFinder.h:12
MultiTrackKinematicConstraintT
Definition: MultiTrackKinematicConstraintT.h:39
Point3DBase< float, GlobalTag >
HLT_FULL_cff.updator
updator
Definition: HLT_FULL_cff.py:123
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
ConstrainedTreeBuilderT
Definition: ConstrainedTreeBuilderT.h:15
KinematicConstrainedVertexFitterT::updator
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator
Definition: KinematicConstrainedVertexFitterT.h:77
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
KinematicConstrainedVertexFitterT::theMaxDelta
float theMaxDelta
Definition: KinematicConstrainedVertexFitterT.h:81
KinematicConstrainedVertexFitterT::~KinematicConstrainedVertexFitterT
~KinematicConstrainedVertexFitterT()
Definition: KinematicConstrainedVertexFitterT.h:121
MagneticField.h
DefaultLinearizationPointFinder
Definition: DefaultLinearizationPointFinder.h:13
LinearizationPointFinder.h
KinematicConstrainedVertexUpdatorT
Definition: KinematicConstrainedVertexUpdatorT.h:34
InputSort.h
KinematicConstrainedVertexFitterT::setParameters
void setParameters(const edm::ParameterSet &pSet)
Definition: KinematicConstrainedVertexFitterT.h:129
KinematicConstrainedVertexFitterT::KinematicConstrainedVertexFitterT
KinematicConstrainedVertexFitterT(const MagneticField *ifield)
Definition: KinematicConstrainedVertexFitterT.h:96
LinearizationPointFinder::clone
virtual LinearizationPointFinder * clone() const =0
VertexKinematicConstraintT
Definition: VertexKinematicConstraintT.h:14
KinematicConstrainedVertexFitterT::tBuilder
ConstrainedTreeBuilderT * tBuilder
Definition: KinematicConstrainedVertexFitterT.h:79
InputSort::sort
std::pair< std::vector< RefCountedKinematicParticle >, std::vector< FreeTrajectoryState > > sort(const std::vector< RefCountedKinematicParticle > &particles) const
Definition: InputSort.cc:5
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
KinematicConstrainedVertexFitterT::iterations
int iterations
Definition: KinematicConstrainedVertexFitterT.h:86
KinematicConstrainedVertexFitterT::theMinChiSqImprovement
float theMinChiSqImprovement
Definition: KinematicConstrainedVertexFitterT.h:84
RefCountedKinematicTree.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
MagneticField
Definition: MagneticField.h:19
KinematicConstrainedVertexFitterT
Definition: KinematicConstrainedVertexFitterT.h:25
KinematicConstrainedVertexFitterT::field
const MagneticField * field
Definition: KinematicConstrainedVertexFitterT.h:75