7 #include "TClonesArray.h"
8 #include "FairRootManager.h"
9 #include "FairGeaneTrKalStt.h"
10 #include "TGeant3TGeo.h"
15 #include "TDatabasePDG.h"
20 #include "FairRunAna.h"
22 #include "FairTrackParH.h"
23 #include "FairTrackParP.h"
52 FairRootManager* ioman = FairRootManager::Instance();
54 cout <<
"-E- FairGeaneTrKalStt::Init: "
55 <<
"RootManager not instantised!" << endl;
74 ioman->Register(
"GeaneTrackIni",
"Geane",
fTrackParIni, kTRUE);
80 fHitArray = (TClonesArray*) ioman->GetObject(
"STTHit");
81 if (!
fHitArray) cout <<
"-W- FairGeaneTrKalStt::Init: No Hit array!" << endl;
83 fPointArray = (TClonesArray*) ioman->GetObject(
"STTPoint");
84 if (!
fPointArray) cout <<
"-W- FairGeaneTrKalStt::Init: No Point array!" << endl;
87 fTrackArray = (TClonesArray*) ioman->GetObject(
"STTTrack");
89 cout <<
"-E- FairGeaneTrKalStt::Init: No SttTrack array!" << endl;
93 fPro =
new FairGeanePro();
94 fUtil =
new FairGeaneUtil();
104 cout <<
"FairGeaneTrKalStt::FinishTask" <<
" total " <<
total <<
" total hits " <<
tothits << endl;
116 cout <<
"FairGeaneTrKalStt::Exec" <<
" total " <<
total <<
" total hits " <<
tothits << endl;
130 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++)
134 if(!pTrack)
continue;
164 Int_t hitcounter = pTrack->GetNofHits();
167 Int_t iHit2 = pTrack->GetHitIndex(0);
169 if(!currenthit2)
continue;
170 if(currenthit2->GetXint() == -999 || currenthit2->GetYint() == -999)
continue;
171 Int_t refindex2 = currenthit2->GetRefIndex();
183 TVector3 EndPosErr = TVector3(0,0,0);
184 TVector3 EndMom = TVector3(iPoint2->GetPXtot(), iPoint2->GetPYtot(), iPoint2->GetPZtot());
185 TVector3 EndMomErr = TVector3(0,0,0);
188 TDatabasePDG *fdbPDG= TDatabasePDG::Instance();
190 Double_t fCharge= fParticle->Charge();
193 Int_t size1 = clref1.GetEntriesFast();
194 FairTrackParP *fStart =
new (clref1[size1]) FairTrackParP(
StartPos,
StartMom,
StartPosErr,
StartMomErr, fCharge,
StartPos, TVector3(0.,1.,0.), TVector3(0.,0.,1.));
197 Int_t size = clref.GetEntriesFast();
198 FairTrackParP *fRes =
new(clref[size]) FairTrackParP();
201 Int_t size2 = clref2.GetEntriesFast();
202 FairTrackParP *fFinal =
new(clref2[size2]) FairTrackParP();
203 FairTrackParH *fFinalH =
new FairTrackParH(EndPos, EndMom, EndPosErr, EndMomErr, fCharge);
205 Int_t processedhit = 0;
206 Int_t backprocessedhit = 0;
208 FairTrackParP *fRunningRes =
new FairTrackParP();
210 for(Int_t iteration = 0; iteration < 3; iteration++)
216 FairTrackParP *fRunningStart =
new FairTrackParP(
StartPos,
StartMom,
StartPosErr,
StartMomErr, fCharge, TVector3(0.,0.,0.), TVector3(0.,1.,0.), TVector3(0.,0.,1.));
217 if(!fRunningStart)
continue;
218 fRunningRes->Reset();
222 Int_t donecounter = 0;
227 if(iteration > 0) start = backprocessedhit + 1;
228 for(
int i = start;
i < hitcounter;
i++)
236 if(rc_prochit == kFALSE) {
243 if(donecounter == 0) {
249 FairTrackParP *fRunningKal =
new FairTrackParP();
251 fRunningRes->GetCov(KD2);
252 fRunningKal->SetTrackPar(fRunningRes->GetV(), fRunningRes->GetW(),
253 fRunningRes->GetTV(), fRunningRes->GetTW(),
254 fRunningRes->GetQp(), KD2, fRunningRes->GetOrigin(),
255 fRunningRes->GetIVer(), fRunningRes->GetJVer(), fRunningRes->GetKVer(),
256 fRunningRes->GetSPU());
257 Int_t backcounter = 0;
258 backprocessedhit = 0;
260 for(
int i = (processedhit-1);
i >= 0;
i--)
265 if(rc_back == kFALSE) {
269 backprocessedhit =
i;
271 StartPos = TVector3(fRunningRes->GetX(), fRunningRes->GetY(), fRunningRes->GetZ());
272 StartMom = TVector3(fRunningRes->GetPx(), fRunningRes->GetPy(), fRunningRes->GetPz());
273 StartPosErr = TVector3(fRunningRes->GetDX(), fRunningRes->GetDY(), fRunningRes->GetDZ());
274 StartMomErr = TVector3(fRunningRes->GetDPx(), fRunningRes->GetDPy(), fRunningRes->GetDPz());
276 if(backcounter == 0) {
289 if(rc_vtx == kFALSE) {
298 Double_t PD[3], RD[15], H[3], CH, SPU, DJ[3], DK[3], PC[3], RC[15];
301 PC[0] = fFinalH->GetQp()/fFinalH->GetQ();
302 PC[1] = fFinalH->GetLambda();
303 PC[2] = fFinalH->GetPhi();
307 H[0] = 0; H[1] = 0; H[2] = 20;
309 if(fRunningRes->GetQ()!=0) CH = fRunningRes->GetQ()/
TMath::Abs(fRunningRes->GetQ());
312 DJ[0] = fRunningRes->GetJVer().X();
313 DJ[1] = fRunningRes->GetJVer().Y();
314 DJ[2] = fRunningRes->GetJVer().Z();
315 DK[0] = fRunningRes->GetKVer().X();
316 DK[1] = fRunningRes->GetKVer().Y();
317 DK[2] = fRunningRes->GetKVer().Z();
319 fUtil->FromSCToSD(PC, RC, H, CH, DJ, DK, IERR, SPU, PD, RD);
321 TVector3 positionsd =
fUtil->FromMARSToSDCoord(TVector3(fFinalH->GetX(), fFinalH->GetY(), fFinalH->GetZ()), fRunningRes->GetOrigin(), fRunningRes->GetIVer(), fRunningRes->GetJVer(), fRunningRes->GetKVer());
327 fFinal->SetTrackPar(v, w, PD[1], PD[2], CH*PD[0], RD, fRunningRes->GetOrigin(), fRunningRes->GetIVer(), fRunningRes->GetJVer(),
328 fRunningRes->GetKVer(),spu);
342 if(!fRunningStart)
return kFALSE;
343 Int_t iHit = pTrack->GetHitIndex(i);
345 if(!currenthit) { cout <<
"NON HIT" << endl;
return kFALSE;}
346 if(currenthit->GetXint() == -999 || currenthit->GetYint() == -999) { cout <<
"NON HIT INT" << endl;
return kFALSE; }
347 Int_t refindex = currenthit->GetRefIndex();
368 if(rc_pro == kFALSE) {
383 Bool_t rc_kal =
Kalman(currenthit, fRunningRes, fRunningStart);
385 if(rc_kal == kFALSE)
return kFALSE;
413 TVector3 v0 = TVector3(0., 0., 0.);
417 TVector3 center = TVector3(currenthit->GetX(), currenthit->GetY(), currenthit->GetZ());
418 TVector3 wiredir = currenthit->GetWireDirection();
420 TVector3 second = (TVector3)(center + wiredir);
421 TVector3 first = (TVector3)(center - wiredir);
423 fPro->SetWire(first, second);
424 if(fb ==
"FWD")
fPro->PropagateToVirtualPlaneAtPCA(2);
425 else if(fb ==
"BKW")
fPro->BackTrackToVirtualPlaneAtPCA(2);
428 rc =
fPro->Propagate(fRunningStart, fRunningRes,
PDGCode);
433 if(
fabs(fRunningRes->GetX()) > 50. ||
fabs(fRunningRes->GetY()) > 50. ||
fabs(fRunningRes->GetZ()) > 50) rc = kFALSE;
444 TMatrixT<double> extrap(5,1);
445 extrap[0][0] = fRunningRes->GetQp()/fRunningRes->GetQ();
446 extrap[1][0] = fRunningRes->GetTV();
447 extrap[2][0] = fRunningRes->GetTW();
448 extrap[3][0] = fRunningRes->GetV();
449 extrap[4][0] = fRunningRes->GetW();
453 TMatrixT<double> sigmaex(5,5);
454 Double_t SIGMAEX[15], SIGMAEX55[5][5];
455 fRunningRes->GetCov(SIGMAEX);
456 fUtil->FromVec15ToMat25(SIGMAEX, SIGMAEX55);
457 for(
int i = 0;
i < 5;
i++)
for(
int j = 0; j < 5; j++) sigmaex[
i][j] = SIGMAEX55[
i][j];
458 TMatrixT<double> weightex(5,5);
460 Double_t det1 = weightex.Determinant();
461 if(det1 != 0) weightex.Invert();
463 cout <<
"det1 = 0!!!!!" << endl;
469 TMatrixT<double> meas(5,1);
475 if(currenthit->GetWireDirection() == TVector3(0.,0.,1.)) meas[4][0] = 0.;
476 else if(currenthit->GetZint() != -999) meas[4][0] = currenthit->GetZint();
477 else meas[4][0] = 0.;
481 TMatrixT<double> weightmi(5,5);
482 for(
int i = 0;
i < 5;
i++)
for(
int j = 0; j < 5; j++) weightmi[
i][j] = 0.;
483 weightmi[3][3] = 1./(0.0150 * 0.0150);
484 if(meas[4][0] == 0) weightmi[4][4] = 1./(1.5 * 1.5);
493 TMatrixT<double> weightsum(5,5);
494 weightsum = weightex + weightmi;
496 TMatrixT<double> sigmakal(5,5);
497 sigmakal = weightsum;
498 Double_t det2 = sigmakal.Determinant();
499 if(det2 != 0) sigmakal.Invert();
501 cout <<
"det2 = 0!!!!!" << endl;
507 TMatrixT<double> wextrap(weightex,TMatrixT<double>::kMult,extrap);
509 TMatrixT<double> wmeas(weightmi,TMatrixT<double>::kMult,meas);
511 TMatrixT<double> sum(5,1);
517 sum = wextrap + wmeas;
527 TMatrixT<double>
kalman(sigmakal,TMatrixT<double>::kMult,sum);
531 Double_t SIGMAKAL[5][5], SIGMAKAL15[15];
532 for(
int i = 0;
i < 5;
i++)
for(
int j = 0; j < 5; j++) SIGMAKAL[
i][j] = sigmakal[
i][j];
533 fUtil->FromMat25ToVec15(SIGMAKAL, SIGMAKAL15);
535 fRunningStart->SetTrackPar(kalman[3][0], kalman[4][0],
536 kalman[1][0], kalman[2][0],
537 kalman[0][0] * fRunningRes->GetQ(), SIGMAKAL15, fRunningRes->GetOrigin(),
538 fRunningRes->GetIVer(), fRunningRes->GetJVer(), fRunningRes->GetKVer(),
539 fRunningRes->GetSPU());
568 TVector3 *vertex =
new TVector3(0.,0.,0.);
569 TVector3 *recovtx = fFitter->PCAToPoint(pTrack, vertex);
571 momeatvtx = fFitter->MomentumAtPoint(pTrack, recovtx);
577 Double_t d = pTrack->GetParamLast()->GetX();
625 if(fRunningRes->GetQp() == 0)
return kFALSE;
627 TVector3 v0 = TVector3(0., 0., 0.);
629 fPro->SetWire(v0,v0);
630 fPro->BackTrackToVertex();
632 TVector3 lastPos = TVector3(fRunningRes->GetX(),
634 fRunningRes->GetZ());
635 TVector3 lastMom = TVector3(fRunningRes->GetPx(),
636 fRunningRes->GetPy(),
637 fRunningRes->GetPz());
638 TVector3 lastPosErr = TVector3(fRunningRes->GetDX(),
639 fRunningRes->GetDY(),
640 fRunningRes->GetDZ());
641 TVector3 lastMomErr = TVector3(fRunningRes->GetDPx(),
642 fRunningRes->GetDPy(),
643 fRunningRes->GetDPz());
645 FairTrackParH *fKalH1 =
new FairTrackParH(lastPos, lastMom,
646 lastPosErr, lastMomErr,
647 fRunningRes->GetQ());
652 FairTrackParH *fKalH2 =
new FairTrackParH();
656 if(rc_vtx == kFALSE)
return kFALSE;
657 Double_t PC[3], RC[15], H[3], CH, DJ[3], DK[3], SPU, PD[3], RD[15];
659 PC[0] = fKalH2->GetQp()/fKalH2->GetQ(); PC[1] = fKalH2->GetLambda(); PC[2] = fKalH2->GetPhi();
661 H[0] = 0.; H[1] = 0.; H[2] = 20.;
663 DJ[0] = 0.; DJ[1] = 1.; DJ[2] = 0;
664 DK[0] = 0.; DK[1] = 0.; DK[2] = 1;
665 fUtil->FromSCToSD(PC,RC, H,CH, DJ, DK, IERR, SPU,PD,RD);
667 fRunningKal->SetTrackPar(fKalH2->GetX(), fKalH2->GetY(), fKalH2->GetZ(),
668 fKalH2->GetPx(), fKalH2->GetPy(), fKalH2->GetPz(),
670 TVector3(0.,0.,0.), TVector3(1.,0.,0.), TVector3(0.,1.,0.), TVector3(0.,0.,1.));
682 if(!fRunningRes)
return kFALSE;
686 TVector3 v0 = TVector3(0., 0., 0.);
688 fPro->SetWire(v0,v0);
690 fPro->BackTrackToVirtualPlaneAtPCA(1);
693 rc =
fPro->Propagate(fRunningRes, fRunningKal,
PDGCode);
Int_t notbackprocessedhit
virtual void Exec(Option_t *opt)
Bool_t ProcessHit(PndSttTrack *pTrack, Int_t k, FairTrackParP *fRunningStart, FairTrackParP *fRunningRes, TString fb)
TClonesArray * fTrackArray
virtual InitStatus Init()
Bool_t BackToVertex(FairTrackParP *fRunningRes, FairTrackParP *fRes)
TClonesArray * fTrackParFinal
Double_t GetIsochrone() const
TClonesArray * fTrackParGeane
friend F32vec4 fabs(const F32vec4 &a)
Bool_t RetrieveVertex(PndSttTrack *pTrack)
Bool_t BackToVertex2(FairTrackParP *fRunningRes, FairTrackParP *fRes)
Bool_t Propagation(PndSttHit *currenthit, FairTrackParP *fRunningStart, FairTrackParP *fRunningRes, TString fb)
TClonesArray * fPointArray
Bool_t Kalman(PndSttHit *currenthit, FairTrackParP *fRunningRes, FairTrackParP *fRunningStart)
TClonesArray * fTrackParIni