16 const std::vector<RefCountedKinematicParticle>& initialParticles,
17 const std::vector<KinematicState>& finalStates,
20 if (!vertex->vertexIsValid()) {
21 LogDebug(
"ConstrainedTreeBuilder") <<
"Vertex is invalid\n";
25 vtx(0) = vertex->position().x();
26 vtx(1) = vertex->position().y();
27 vtx(2) = vertex->position().z();
36 virtualPartPar(0) = vertex->position().x();
37 virtualPartPar(1) = vertex->position().y();
38 virtualPartPar(2) = vertex->position().z();
43 ROOT::Math::SMatrix<double, 7, 7, ROOT::Math::MatRepStd<double, 7, 7> > aMatrix;
48 ROOT::Math::SMatrix<double, 7, 3, ROOT::Math::MatRepStd<double, 7, 3> > bMatrix;
53 ROOT::Math::SMatrix<double, 3, 7, ROOT::Math::MatRepStd<double, 3, 7> > vtxTrackCov;
56 std::vector<RefCountedKinematicParticle>::const_iterator
i = initialParticles.begin();
57 std::vector<KinematicState>::const_iterator iStates = finalStates.begin();
58 std::vector<RefCountedKinematicParticle> rParticles;
60 for (; i != initialParticles.end() && iStates != finalStates.end(); ++
i, ++iStates) {
62 double a = -iStates->particleCharge() * iStates->magneticField()->inInverseGeV(iStates->globalPosition()).
z();
71 trackParCov = asSMatrix<7, 7>(fullCov.sub(4 + n * 7, 10 + n * 7, 4 + n * 7, 10 + n * 7));
72 vtxTrackCov = asSMatrix<3, 7>(fullCov.sub(1, 3, 4 + n * 7, 10 + n * 7));
74 nCovariance = aMatrix * trackParCov * ROOT::Math::Transpose(aMatrix) +
75 aMatrix * ROOT::Math::Transpose(vtxTrackCov) * ROOT::Math::Transpose(bMatrix) +
76 bMatrix * vtxTrackCov * ROOT::Math::Transpose(aMatrix) +
77 bMatrix * vertexCov * ROOT::Math::Transpose(bMatrix);
81 iStates->particleCharge(),
82 iStates->magneticField());
83 rParticles.push_back((*i)->refittedParticle(stateAtVertex, vertex->chiSquared(), vertex->degreesOfFreedom()));
85 virtualPartPar(3) += par(3);
86 virtualPartPar(4) += par(4);
87 virtualPartPar(5) += par(5);
88 ent +=
sqrt(par(6) * par(6) + par(3) * par(3) + par(4) * par(4) + par(5) * par(5));
89 charge += iStates->particleCharge();
95 double differ = ent * ent - (virtualPartPar(3) * virtualPartPar(3) + virtualPartPar(5) * virtualPartPar(5) +
96 virtualPartPar(4) * virtualPartPar(4));
98 virtualPartPar(6) =
sqrt(differ);
100 LogDebug(
"ConstrainedTreeBuilder") <<
"Fit failed: Current precision does not allow to calculate the mass\n";
111 initialParticles[0]->magneticField());
114 float chi2 = vertex->chiSquared();
115 float ndf = vertex->degreesOfFreedom();
119 return buildTree(virtualParticle, vertex, rParticles);
125 const std::vector<RefCountedKinematicParticle>&
particles)
const {
131 resTree->addParticle(fVertex, vtx, virtualParticle);
134 for (std::vector<RefCountedKinematicParticle>::const_iterator il = particles.begin(); il != particles.end(); il++) {
135 if ((*il)->previousParticle()->correspondingTree() !=
nullptr) {
140 resTree->addTree(cdVertex, tree);
143 resTree->addParticle(vtx, ffVertex, *il);
156 int size = rPart.size();
164 for (std::vector<RefCountedKinematicParticle>::const_iterator
i = rPart.begin();
i != rPart.end();
i++) {
166 double a_i = -(*i)->currentState().particleCharge() *
167 (*i)->magneticField()->inInverseGeV((*i)->currentState().globalPosition()).
z();
176 jac.sub(1, 4 + i_int * 7, upper);
182 diagonal(2, 4) = a_i;
183 diagonal(1, 5) = -a_i;
184 jac.sub(4 + i_int * 7, 4 + i_int * 7, diagonal);
194 int vSize = rPart.size();
196 for (
int i = 1;
i < 7 * vSize + 4; ++
i) {
197 for (
int j = 1;
j < 7 * vSize + 4; ++
j) {
199 fit_cov_sym(
i,
j) = fitCov(
i,
j);
216 for (
int i = 1;
i < 8; ++
i) {
217 for (
int j = 1;
j < 8; ++
j) {
228 reduced.sub(1, 1, reduced_tm);
232 double energy_global =
233 sqrt(newPar(3) * newPar(3) + newPar(4) * newPar(4) + newPar(5) * newPar(5) + newPar(6) * newPar(6));
234 for (std::vector<RefCountedKinematicParticle>::const_iterator rs = rPart.begin(); rs != rPart.end(); rs++) {
242 AlgebraicVector7 l_Par = (*rs)->currentState().kinematicParameters().vector();
243 double energy_local =
sqrt(l_Par(6) * l_Par(6) + l_Par(3) * l_Par(3) + l_Par(4) * l_Par(4) + l_Par(5) * l_Par(5));
244 jc_el(4, 4) = energy_global * l_Par(6) / (newPar(6) * energy_local);
245 jc_el(4, 1) = ((energy_global * l_Par(3) / energy_local) - newPar(3)) / newPar(6);
246 jc_el(4, 2) = ((energy_global * l_Par(4) / energy_local) - newPar(4)) / newPar(6);
247 jc_el(4, 3) = ((energy_global * l_Par(5) / energy_local) - newPar(5)) / newPar(6);
248 jac_t.sub(4, il_int * 4 + 4, jc_el);
256 for (
int i = 1;
i <
size;
i++) {
261 for (
int l1 = 1; l1 < 4; ++l1) {
262 for (
int l2 = 1; l2 < 5; ++l2) {
263 transform_sub1(l1, l2) =
transform(3 + l1, 6 + 7 *
i + l2);
267 for (
int l1 = 1; l1 < 5; ++l1) {
268 for (
int l2 = 1; l2 < 4; ++l2) {
269 transform_sub2(l1, l2) =
transform(6 + 7 *
i + l1, 3 + l2);
274 for (
int l1 = 1; l1 < 5; ++l1) {
275 for (
int l2 = 1; l2 < 5; ++l2) {
276 transform_sub3(l1, l2) =
transform(6 + 7 *
i + l1, 6 + 7 *
i + l2);
280 reduced.sub(1, 4 + 4 *
i, transform_sub1);
281 reduced.sub(4 + 4 *
i, 1, transform_sub2);
284 reduced.sub(4 + 4 *
i, 4 + 4 *
i, transform_sub3);
287 for (
int j = 1;
j <
size;
j++) {
290 for (
int l1 = 1; l1 < 5; ++l1) {
291 for (
int l2 = 1; l2 < 5; ++l2) {
292 transform_sub4(l1, l2) =
transform(6 + 7 * (
i - 1) + l1, 6 + 7 *
j + l2);
293 transform_sub5(l1, l2) =
transform(6 + 7 *
j + l1, 6 + 7 * (
i - 1) + l2);
296 reduced.sub(4 + 4 * (
i - 1), 4 + 4 *
j, transform_sub4);
297 reduced.sub(4 + 4 *
j, 4 + 4 * (
i - 1), transform_sub5);
301 return jac_t * reduced * jac_t.T();
void replaceCurrentParticle(RefCountedKinematicParticle newPart) const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
ROOT::Math::SVector< double, 7 > AlgebraicVector7
KinematicVertexFactory * vFactory
RefCountedKinematicTree buildTree(const std::vector< RefCountedKinematicParticle > &initialParticles, const std::vector< KinematicState > &finalStates, const RefCountedKinematicVertex vtx, const AlgebraicMatrix &fCov) const
ROOT::Math::SMatrix< double, 7, 7, ROOT::Math::MatRepStd< double, 7, 7 > > AlgebraicMatrix77
CLHEP::HepMatrix AlgebraicMatrix
void movePointerToTheTop() const
RefCountedKinematicParticle particle(const KinematicState &kineState, float &chiSquared, float °reesOfFr, ReferenceCountingPointer< KinematicParticle > previousParticle, KinematicConstraint *lastConstraint=nullptr) const
AlgebraicMatrix covarianceMatrix(const std::vector< RefCountedKinematicParticle > &rPart, const AlgebraicVector7 &newPar, const AlgebraicMatrix &fitCov) const
ROOT::Math::SMatrix< double, 7, 7, ROOT::Math::MatRepSym< double, 7 > > AlgebraicSymMatrix77
ROOT::Math::SVector< double, 3 > AlgebraicVector3
CLHEP::HepSymMatrix AlgebraicSymMatrix
static RefCountedKinematicVertex vertex(const VertexState &state, float totalChiSq, float degreesOfFr)
VirtualKinematicParticleFactory * pFactory
tuple size
Write out results.
~ConstrainedTreeBuilder()