- Timestamp:
- May 17, 2021, 6:05:45 PM (4 years ago)
- Branches:
- master
- Children:
- 1c1c9c2, 33a6b3a, f8e61b2
- Parents:
- 4afb18d (diff), 4acf2fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Michele Selvaggi <michele.selvaggi@…> (05/17/21 18:05:45)
- git-committer:
- GitHub <noreply@…> (05/17/21 18:05:45)
- Location:
- external/TrackCovariance
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
external/TrackCovariance/ObsTrk.cc
r4afb18d r7dac4ea 14 14 ObsTrk::ObsTrk(TVector3 x, TVector3 p, Double_t Q, Double_t B, SolGridCov *GC) 15 15 { 16 SetB field(B);16 SetB(B); 17 17 fGC = GC; 18 18 fGenX = x; … … 56 56 ObsTrk::ObsTrk(Double_t *x, Double_t *p, Double_t Q, Double_t B, SolGridCov* GC) 57 57 { 58 SetB field(B);58 SetB(B); 59 59 fGC = GC; 60 60 fGenX.SetXYZ(x[0],x[1],x[2]); -
external/TrackCovariance/VertexFit.cc
r4afb18d r7dac4ea 18 18 fxCst.ResizeTo(3); 19 19 fCovCst.ResizeTo(3, 3); 20 fCovCstInv.ResizeTo(3, 3); 20 21 fXv.ResizeTo(3); 21 22 fcovXv.ResizeTo(3, 3); … … 31 32 fxCst.ResizeTo(3); 32 33 fCovCst.ResizeTo(3, 3); 34 fCovCstInv.ResizeTo(3, 3); 33 35 fXv.ResizeTo(3); 34 36 fcovXv.ResizeTo(3, 3); … … 38 40 TVectorD pr = *trkPar[i]; 39 41 fPar.push_back(new TVectorD(pr)); 42 fParNew.push_back(new TVectorD(pr)); 40 43 TMatrixDSym cv = *trkCov[i]; 41 44 fCov.push_back(new TMatrixDSym(cv)); 45 fCovNew.push_back(new TMatrixDSym(cv)); 42 46 } 43 47 fChi2List.ResizeTo(fNtr); … … 54 58 fxCst.ResizeTo(3); 55 59 fCovCst.ResizeTo(3, 3); 60 fCovCstInv.ResizeTo(3, 3); 56 61 fXv.ResizeTo(3); 57 62 fcovXv.ResizeTo(3, 3); … … 61 66 { 62 67 fPar.push_back(new TVectorD(track[i]->GetObsPar())); 68 fParNew.push_back(new TVectorD(track[i]->GetObsPar())); 63 69 fCov.push_back(new TMatrixDSym(track[i]->GetCov())); 70 fCovNew.push_back(new TMatrixDSym(track[i]->GetCov())); 64 71 } 65 72 } … … 73 80 { 74 81 if (fx0i[i]) { fx0i[i]->Clear(); delete fx0i[i]; } 75 if (fai[i]) { fai[i]->Clear(); delete fai[i]; } 76 if (fDi[i]) { fDi[i]->Clear(); delete fDi[i]; } 77 if (fWi[i]) { fWi[i]->Clear(); delete fWi[i]; } 82 if (fai[i]) { fai[i]->Clear(); delete fai[i]; } 83 if (fdi[i]) { fdi[i]->Clear(); delete fdi[i]; } 84 if (fAti[i]) { fAti[i]->Clear(); delete fAti[i]; } 85 if (fDi[i]) { fDi[i]->Clear(); delete fDi[i]; } 86 if (fWi[i]) { fWi[i]->Clear(); delete fWi[i]; } 78 87 if (fWinvi[i]){ fWinvi[i]->Clear(); delete fWinvi[i]; } 79 88 } … … 81 90 fx0i.clear(); 82 91 fai.clear(); 92 fdi.clear(); 93 fAti.clear(); 83 94 fDi.clear(); 84 95 fWi.clear(); … … 88 99 { 89 100 fxCst.Clear(); 90 fCovCst.Clear(); 101 fCovCst.Clear(); 102 fCovCstInv.Clear(); 91 103 fXv.Clear(); 92 104 fcovXv.Clear(); … … 95 107 for (Int_t i = 0; i < fNtr; i++) 96 108 { 97 fPar[i]->Clear(); delete fPar[i]; 98 fCov[i]->Clear(); delete fCov[i]; 109 fPar[i]->Clear(); delete fPar[i]; 110 fParNew[i]->Clear(); delete fParNew[i]; 111 fCov[i]->Clear(); delete fCov[i]; 112 fCovNew[i]->Clear(); delete fCovNew[i]; 99 113 } 100 114 fPar.clear(); 101 fCov.clear(); 115 fParNew.clear(); 116 fCov.clear(); 117 fCovNew.clear(); 102 118 // 103 119 ResetWrkArrays(); … … 424 440 // 425 441 // Get track parameters and their covariance 426 TVectorD par = *fPar [i];442 TVectorD par = *fParNew[i]; 427 443 TMatrixDSym Cov = *fCov[i]; 428 444 // … … 433 449 // 434 450 TMatrixD A = Fill_A(par, fs); // A = dx/da = derivatives wrt track parameters 451 TMatrixD At(TMatrixD::kTransposed, A); // A transposed 452 fAti.push_back(new TMatrixD(At)); // Store A' 453 TVectorD di = A * (par - *fPar[i]); // x-shift 454 fdi.push_back(new TVectorD(di)); // Store x-shift 435 455 TMatrixDSym Winv = Cov.Similarity(A); // W^-1 = A*C*A' 436 fWinvi.push_back(new TMatrixDSym(Winv)); 456 fWinvi.push_back(new TMatrixDSym(Winv)); // Store W^-1 matrix 437 457 // 438 458 TMatrixDSym W = RegInv(Winv); // W = (A*C*A')^-1 … … 456 476 { 457 477 //std::cout << "VertexFitter: just in" << std::endl; 458 if (fNtr < 2) 459 { 478 if (fNtr < 2 && !fVtxCst){ 460 479 std::cout << "VertexFit::VertexFitter - Method called with less than 2 tracks - Aborting " << std::endl; 461 480 std::exit(1); … … 469 488 Double_t Chi2 = 0; 470 489 TVectorD x0 = fXv; // If previous fit done 471 if (fRold < 0.0)for (Int_t i = 0; i < 3; i++)x0(i) = 1000.; // Set to arbitrary large value if not 490 if (fRold < 0.0) { 491 // External constraint 492 if (fVtxCst) fRold = TMath::Sqrt(fxCst(0) * fxCst(0) + fxCst(1) * fxCst(1)); 493 // No constraint 494 else for (Int_t i = 0; i < 3; i++)x0(i) = 1000.; // Set to arbitrary large value 495 } 472 496 // 473 497 // Starting vertex radius approximation … … 475 499 Double_t R = fRold; // Use previous fit if available 476 500 if (R < 0.0) R = StartRadius(); // Rough vertex estimate 501 //std::cout << "Start radius: " << R << std::endl; 477 502 // 478 503 // Iteration properties … … 529 554 H += Ds; 530 555 // update constant term 531 TVectorD xs = *fx0i[i]; 556 TVectorD xs = *fx0i[i] - *fdi[i]; 557 TVectorD xx0 = *fx0i[i]; 558 /* 559 std::cout << "Iter. " << Ntry << ", trk " << i << ", x= " 560 << xx0(0) << ", " << xx0(1) << ", " << xx0(2)<< 561 ", ph0= "<<par(1)<< std::endl; 562 */ 532 563 cterm += Ds * xs; 533 564 } // End loop on tracks 565 // Some additions in case of external constraints 566 if (fVtxCst) { 567 H += fCovCstInv; 568 cterm += fCovCstInv * fxCst; 569 DW1D += fCovCstInv; 570 } 534 571 // 535 572 // update vertex position … … 544 581 for (Int_t i = 0; i < fNtr; i++) 545 582 { 546 TVectorD lambda = (*fDi[i]) * (*fx0i[i] - x );583 TVectorD lambda = (*fDi[i]) * (*fx0i[i] - x - *fdi[i]); 547 584 TMatrixDSym Wm1 = *fWinvi[i]; 548 585 fChi2List(i) = Wm1.Similarity(lambda); … … 551 588 TVectorD b = (*fWi[i]) * (x - (*fx0i[i])); 552 589 for (Int_t j = 0; j < 3; j++)ffi[i] += a(j) * b(j) / fa2i[i]; 590 TVectorD newPar = *fPar[i] - ((*fCov[i]) * (*fAti[i])) * lambda; 591 fParNew[i] = new TVectorD(newPar); 553 592 } 593 // Add external constraint to Chi2 594 if (fVtxCst) Chi2 += fCovCstInv.Similarity(x - fxCst); 554 595 // 555 596 TVectorD dx = x - x0; … … 562 603 // Store result 563 604 // 564 fXv = x; 605 fXv = x; // Vertex position 565 606 fcovXv = covX; // Vertex covariance 566 607 fChi2 = Chi2; // Vertex fit Chi2 608 //std::cout << "Found vertex " << fXv(0) << ", " << fXv(1) << ", " << fXv(2) << std::endl; 567 609 } // end of iteration loop 568 610 // … … 603 645 void VertexFit::AddVtxConstraint(TVectorD xv, TMatrixDSym cov) // Add gaussian vertex constraint 604 646 { 605 std::cout << "VertexFit::AddVtxConstraint: Not implemented yet" << std::endl; 647 //std::cout << "VertexFit::AddVtxConstraint: Not implemented yet" << std::endl; 648 fVtxCst = kTRUE; // Vertex constraint flag 649 fxCst = xv; // Constraint value 650 fCovCst = cov; // Constraint covariance 651 fCovCstInv = cov; 652 fCovCstInv.Invert(); // Its inverse 653 // 654 // Set starting vertex as external constraint 655 fXv = fxCst; 656 fcovXv = fCovCst; 606 657 } 607 658 // … … 613 664 fPar.push_back(par); // add new track 614 665 fCov.push_back(Cov); 666 fParNew.push_back(par); // add new track 667 fCovNew.push_back(Cov); 615 668 // 616 669 // Reset previous vertex temp arrays … … 628 681 fPar.erase(fPar.begin() + iTrk); // Remove track 629 682 fCov.erase(fCov.begin() + iTrk); 683 fParNew.erase(fParNew.begin() + iTrk); // Remove track 684 fCovNew.erase(fCovNew.begin() + iTrk); 630 685 // 631 686 // Reset previous vertex temp arrays -
external/TrackCovariance/VertexFit.h
r4afb18d r7dac4ea 23 23 Int_t fNtr; // Number of tracks 24 24 std::vector<TVectorD*> fPar; // Input parameter array 25 std::vector<TMatrixDSym*> fCov;// Input parameter covariances 25 std::vector<TVectorD*> fParNew; // Updated parameter array 26 std::vector<TMatrixDSym*> fCov; // Input parameter covariances 27 std::vector<TMatrixDSym*> fCovNew; // Updated parameter covariances 26 28 // Constraints 27 29 Bool_t fVtxCst; // Vertex constraint flag 28 30 TVectorD fxCst; // Constraint value 29 TMatrixDSym fCovCst; // Constraint covariance 31 TMatrixDSym fCovCst; // Constraint 32 TMatrixDSym fCovCstInv; // Inverse of constraint covariance 30 33 // 31 34 // Results … … 39 42 // Work arrays 40 43 std::vector<Double_t> ffi; // Fit phases 41 std::vector<TVectorD*> fx0i; 44 std::vector<TVectorD*> fx0i; // Track expansion points 42 45 std::vector<TVectorD*> fai; // dx/dphi 46 std::vector<TVectorD*> fdi; // x-shift 43 47 std::vector<Double_t> fa2i; // a'Wa 48 std::vector<TMatrixD*> fAti; // A transposed 44 49 std::vector<TMatrixDSym*> fDi; // W-WBW 45 50 std::vector<TMatrixDSym*> fWi; // (ACA')^-1
Note:
See TracChangeset
for help on using the changeset viewer.