15#include "CbmKFTrack.h"
16#include "CbmStsTrack.h"
21#include "FairRunAna.h"
96 cout <<
"InitStatus MpdMotherFitterPart::Init\n\n";
98 FairField* magField = FairRunAna::Instance()->GetField();
99 if (!magField ||
TMath::Abs(magField->GetBz(0, 0, 0)) < 0.01) {
100 cout <<
" -I- MpdMotherFitterPart::Init - Using the default constant magnetic field Bz = 5 kG " << endl;
160 Int_t nDaught = vDaught.size();
173 Int_t charge = 0, ndf = 0;
176 for (
Int_t i = 0;
i < nDaught; ++
i) {
191 mother->
Setx(vDaught[0]->Getx());
202 qm(0, 0) = mom3.
X() / mom3.
Z();
203 qm(1, 0) = mom3.
Y() / mom3.
Z();
205 qm(2, 0) = mom3.
Mag();
207 qm(2, 0) = charge / mom3.
Mag();
220 for (
Int_t i = 0;
i < nDaught; ++
i) {
291 vector<MpdHelix> vhel;
293 // Create 2 helices and cross them
294 for (Int_t itr = 0; itr < 2; ++itr) {
295 Double_t rad = vTracks[itr]->GetPosNew();
297 if (rad > 1.e-6) phi = (*vTracks[itr]->GetParam())(0, 0) / rad;
298 vhel.push_back(MpdHelix(vTracks[itr]->Momentum3(),
299 TVector3(rad * TMath::Cos(phi), rad * TMath::Sin(phi), (*vTracks[itr]->GetParam())(1, 0)),
300 vTracks[itr]->Charge()));
302 pair<Double_t, Double_t> paths = vhel[0].pathLengths(vhel[1]);
304 Double_t xyz[3] = {0};
305 Int_t ntr = vTracks.size();
307 if (paths.first < 100.0 || paths.second < 100.0) {
309 // hit.SetType(MpdKalmanHit::kFixedR);
310 cross = vhel[0].at(paths.first);
311 cross += vhel[1].at(paths.second);
315 for (Int_t itr = 0; itr < ntr; ++itr) {
316 //Double_t s = vhel[itr].pathLength(cross);
317 //TVector3 pca = vhel[itr].at(s);
318 //hit.SetPos(pca.Pt());
319 //fKF->PropagateToHit(vTacks[itr],&hit,kFALSE);
324 // xyz[0] = xyz[1] = xyz[2] = 0;
325 for (Int_t itr = 0; itr < ntr; ++itr) {
326 fKF->FindPca(vTracks[itr], xyz);
327 vTracks[itr]->SetParam(*vTracks[itr]->GetParamNew());
328 vTracks[itr]->Weight2Cov(); // AZ
329 vDaught.push_back(new MpdParticle(*vTracks[itr], -1, 0.1396, xyz));
331 Double_t chi2 = BuildMother(mother, vDaught);
332 // Bring back to master frame in transverse plane
333 for (Int_t j = 0; j < 2; ++j) mother->Getx()(j, 0) += xyz[j];
345 int nDaught = vDaught.size();
351 for (
int iter = 0; iter < niter; ++iter) {
353 vector<FairTrackParam> vParams;
357 for (
int ip = 0; ip < nDaught; ++ip) {
363 for (
int ip = 0; ip < nDaught; ++ip) {
371 vParams.push_back(par);
378 for (
int ip = 0; ip < nDaught; ++ip) {
381 for (
int ip1 = ip + 1; ip1 < nDaught; ++ip1) {
382 Double_t ty1 = vParams[ip1].GetTy();
384 Double_t dz = vParams[ip1].GetY() - vParams[ip].GetY();
385 dz /= (vParams[ip].GetTy() - vParams[ip1].GetTy());
394 if (ierr != 0 || ierr1 != 0)
400 fVtx[2] = (npairs) ? zzz / npairs : 0.0;
431 for (
int ip = 0; ip < nDaught; ++ip) {
440 fVtx[0] += par.GetX();
441 fVtx[1] += par.GetY();
458 const Int_t nPass = 3;
464 Int_t nDaught = vDaught.size();
465 TMatrixD c(3, 3), cov(3, 3), xk0(3, 1), xk(3, 1), ck0(5, 1);
470 xk.SetMatrixArray(
fVtx);
472 c(0, 0) = c(1, 1) = c(2, 2) = 1;
474 for (
Int_t ipass = 0; ipass < nPass; ++ipass) {
479 c(0, 0) = c(1, 1) = c(2, 2) = 100;
483 Int_t ibeg = 0, iend = nDaught, istep = 1;
490 for (
Int_t itr = ibeg; itr != iend; itr += istep) {
563 if (chi21(0, 0) < 0 || chi22(0, 0) < 0) {
564 cout <<
" !!! Chi2 < 0 " << chi21(0, 0) <<
" " << chi22(0, 0) <<
" " << ipass <<
" " << itr <<
" "
571 if (chi2 > cutChi2 || chi21(0, 0) < 0 || chi22(0, 0) < 0) {
602 int err =
Smooth(vDaught);
613 TMatrixD c(3, 3), xk(3, 1), ck0(5, 1);
616 xk.SetMatrixArray(
fVtx);
617 Int_t nDaught = vDaught.size();
620 for (
Int_t itr = 0; itr < nDaught; ++itr) {
706 return ComputeAB0(xk0, part, a, b, ck0, flag);
738 vert0[
i - 1] -= shift;
752 for (
Int_t j = 0; j < 5; ++j) {
782 for (
Int_t k = 0; k < 5; ++k) {
797 for (
int i = 0;
i < 5; ++
i)
853 vert0[
i - 1] -= shift;
867 for (
Int_t j = 0; j < 5; ++j) {
901 for (
Int_t k = 0; k < 5; ++k) {
935 for (
int i = 2;
i < 5; ++
i)
952 TMatrixD qc(3, 3), qn(3, 3), qnc(3, 3);
953 Int_t nDaught = vDaught.size();
957 for (
Int_t i = 0;
i < nDaught; ++
i) {
960 for (
Int_t j = 0; j < nDaught; ++j) {
989 for (
Int_t i = 0;
i < nDaught; ++
i) {
994 for (
Int_t j = 0; j < nDaught; ++j) {
1030 TMatrixD xk(3, 1), xk0(3, 1), ck0(5, 1), a(5, 3), b(5, 3), c(3, 3);
1104 Double_t x[3] = {pos0[2], pos1[2], pos2[2]};
1105 Double_t y[3] = {pos0[0], pos1[0], pos2[0]};
1107 Double_t denom = (x[0] - x[1]) * (x[0] - x[2]) * (x[1] - x[2]);
1111 Double_t a = x[2] * dy10 + x[1] * dy02 + x[0] * dy21;
1113 Double_t b = -x[0] * x[0] * dy21 - x[2] * x[2] * dy10 - x[1] * x[1] * dy02;
1115 Double_t c = x[1] * x[1] * (x[2] * y[0] - x[0] * y[2]) + x[1] * (x[0] * x[0] * y[2] - x[2] * x[2] * y[0])
1116 + x[0] * x[2] * (x[2] - x[0]) * y[1];
TMatrixT< Double_t > TMatrixD
TMatrixTSym< Float_t > TMatrixFSym
Kalman filter mother particle fitter for the BM@N detector.
virtual ~BmnMotherFitterPart()
Destructor.
Bool_t ComputeAB0(const TMatrixD &xk0, const BmnParticle &part, TMatrixD &a, TMatrixD &b, TMatrixD &ck0, Bool_t flag)
Double_t fVtx[3]
decay vertex position
Double_t Chi2Vertex(BmnParticle *part, const CbmVertex *vtx)
compute Chi2 w.r.t. vertex
virtual void Exec(Option_t *option)
TMatrixD ComputeQmatr(vector< BmnParticle * > vDaught)
virtual InitStatus ReInit()
Bool_t ComputeAandB(const TMatrixD &xk0, const BmnParticle &part, TMatrixD &a, TMatrixD &b, TMatrixD &ck0, Bool_t flag=kTRUE)
TH1D * fTestHist
histogram for testing
TMatrixD & GetCovariance()
static BmnMotherFitterPart * Instance()
get singleton instance
static void DestroyInstance()
Double_t BuildMother(BmnParticle *mother, vector< BmnParticle * > &vDaught)
static BmnMotherFitterPart * fgMF
Bool_t EvalVertex(vector< BmnParticle * > vDaught)
BmnMotherFitterPart()
Default ctor.
TMatrixD fCovar
covariance matrix
virtual InitStatus Init()
Bool_t Smooth(vector< BmnParticle * > vDaught)
Double_t FindVertex(vector< BmnParticle * > vDaught, TVector3 &vtx)
TVector3 Parabola(TVector3 &pos0, TVector3 &pos1, TVector3 &pos2)
Double_t fieldConst
mag. field constant
Particle object in BM@N (to work with decays).
void SetCovD(TMatrixD &matr)
Double_t GetMeas(Int_t i) const
void SetG(TMatrixD &matr)
void SetW(TMatrixD &matr)
CbmKFTrack GetKFTrack() const
void SetCharge(Int_t charge)
void SetChi2(Double_t chi2)
void SetA(TMatrixD &matr)
int GetNDF() const
Accessors.
TVector3 Momentum3() const
void SetMass(Double_t mass=-2.0)
void SetCovE(TMatrixD &matr)
void SetB(TMatrixD &matr)
void Setq(TMatrixD &matr)
void FillJinv(TVector3 &mom3)
void AddDaughter(Int_t indx)
Double_t GetXY(Int_t i) const
void Setx(TMatrixD &matr)
void SetC(TMatrixD &matr)
static Int_t indexS(Int_t i, Int_t j)
Int_t Propagate(Double_t z_out, Double_t QP0, Bool_t line=false)
Int_t Extrapolate(Double_t z, Double_t *QP0=0, Bool_t line=false)
Access to i-th hit.
void GetTrackParam(FairTrackParam &track)
Double_t * GetTrack()
Is it electron.
Double_t * GetCovMatrix()
array[6] of track parameters(x,y,tx,ty,qp,z)
static CbmKF * Instance()
void CovMatrix(TMatrixFSym &covMat) const
Double_t GetX() const
Accessors.
TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *option="") override
TMatrixTSym< Element > & Invert(Double_t *det=nullptr)
const Element * GetMatrixArray() const override
TMatrixT< Element > & Invert(Double_t *det=nullptr)
void Modified(Bool_t flag=true) override
Double_t Min(Double_t a, Double_t b)
Double_t Sign(Double_t a, Double_t b)
Double_t Sqrt(Double_t x)
Double_t Max(Double_t a, Double_t b)