Changeset bd33fce in git
- Timestamp:
- Mar 8, 2021, 9:52:15 AM (4 years ago)
- Branches:
- master
- Children:
- a10293e, b1cb322
- Parents:
- 2eaa9fd (diff), 91ef0b8 (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@…> (03/08/21 09:52:15)
- git-committer:
- GitHub <noreply@…> (03/08/21 09:52:15)
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/ExamplePVtxFit.C
r2eaa9fd rbd33fce 40 40 // 41 41 // Loop over all events 42 Int_t Nev = TMath::Min(Nevent, (Int_t) 42 Int_t Nev = TMath::Min(Nevent, (Int_t)numberOfEntries); 43 43 for (Int_t entry = 0; entry < Nev; ++entry) 44 44 { … … 61 61 GenParticle* gp = (GenParticle*)trk->Particle.GetObject(); 62 62 // 63 // Position of origin in m eters64 Double_t x = 1.0e-3 *gp->X;65 Double_t y = 1.0e-3 *gp->Y;66 Double_t z = 1.0e-3 *gp->Z;63 // Position of origin in mm 64 Double_t x = gp->X; 65 Double_t y = gp->Y; 66 Double_t z = gp->Z; 67 67 // 68 68 // group tracks originating from the primary vertex … … 78 78 Double_t oPar[5] = { obsD0, obsPhi, obsC, obsZ0, obsCtg }; 79 79 TVectorD obsPar(5, oPar); // Fill observed parameters 80 TVector3 xv(x, y, z);81 80 // 82 81 pr[Ntr] = new TVectorD(obsPar); 83 cv[Ntr] = new TMatrixDSym(TrkUtil::CovToMm(trk->CovarianceMatrix())); 82 //std::cout<<"Cov Matrix:"<<std::endl; 83 //trk->CovarianceMatrix().Print(); 84 cv[Ntr] = new TMatrixDSym(trk->CovarianceMatrix()); 84 85 Ntr++; 85 86 } 86 87 } // End loop on tracks 87 //std::cout << "Total of " << Ntr << " primary tracks out of " << NtrG << " tracks" << std::endl;88 88 } 89 89 // … … 118 118 // Show resulting histograms 119 119 // 120 TCanvas* Cnv = new TCanvas("Cnv", "Delphes generated track plots", 50, 50, 900, 500);120 TCanvas* Cnv = new TCanvas("Cnv", "Delphes primary vertex pulls", 50, 50, 900, 500); 121 121 Cnv->Divide(2, 2); 122 122 Cnv->cd(1); gPad->SetLogy(1); gStyle->SetOptFit(1111); -
external/TrackCovariance/VertexFit.cc
r2eaa9fd rbd33fce 15 15 fVtxCst = kFALSE; 16 16 fxCst.ResizeTo(3); 17 fCovCst.ResizeTo(3, 3);17 fCovCst.ResizeTo(3, 3); 18 18 fXv.ResizeTo(3); 19 fcovXv.ResizeTo(3, 3);19 fcovXv.ResizeTo(3, 3); 20 20 } 21 21 // Parameters and covariances … … 26 26 fVtxCst = kFALSE; 27 27 fxCst.ResizeTo(3); 28 fCovCst.ResizeTo(3, 3);28 fCovCst.ResizeTo(3, 3); 29 29 fXv.ResizeTo(3); 30 fcovXv.ResizeTo(3, 3);30 fcovXv.ResizeTo(3, 3); 31 31 // 32 32 fPar = trkPar; … … 35 35 // 36 36 ffi = new Double_t[Ntr]; // Fit phases 37 fx0i = new TVectorD * [Ntr]; // Track expansion points37 fx0i = new TVectorD * [Ntr]; // Track expansion points 38 38 for (Int_t i = 0; i < Ntr; i++) fx0i[i] = new TVectorD(3); 39 39 fai = new TVectorD * [Ntr]; // dx/dphi 40 40 for (Int_t i = 0; i < Ntr; i++) fai[i] = new TVectorD(3); 41 41 fa2i = new Double_t[Ntr]; // a'Wa 42 fDi = new TMatrixDSym *[Ntr]; // W-WBW42 fDi = new TMatrixDSym * [Ntr]; // W-WBW 43 43 for (Int_t i = 0; i < Ntr; i++) fDi[i] = new TMatrixDSym(3); 44 44 fWi = new TMatrixDSym * [Ntr]; // (ACA')^-1 … … 46 46 fWinvi = new TMatrixDSym * [Ntr]; // ACA' 47 47 for (Int_t i = 0; i < Ntr; i++) fWinvi[i] = new TMatrixDSym(3); 48 49 48 } 50 49 // ObsTrk list … … 55 54 fVtxCst = kFALSE; 56 55 fxCst.ResizeTo(3); 57 fCovCst.ResizeTo(3, 3);56 fCovCst.ResizeTo(3, 3); 58 57 fXv.ResizeTo(3); 59 fcovXv.ResizeTo(3, 3);60 // 61 fPar = new TVectorD *[Ntr];62 fCov = new TMatrixDSym *[Ntr];58 fcovXv.ResizeTo(3, 3); 59 // 60 fPar = new TVectorD * [Ntr]; 61 fCov = new TMatrixDSym * [Ntr]; 63 62 fChi2List.ResizeTo(Ntr); 64 63 for (Int_t i = 0; i < Ntr; i++) 65 64 { 66 65 fPar[i] = new TVectorD(track[i]->GetObsPar()); 67 //std::cout << "fPar = " << std::endl; fPar[i]->Print();68 66 fCov[i] = new TMatrixDSym(track[i]->GetCov()); 69 //std::cout << "fCov = " << std::endl; fCov[i]->Print();70 67 } 71 68 // … … 82 79 fWinvi = new TMatrixDSym * [Ntr]; // ACA' 83 80 for (Int_t i = 0; i < Ntr; i++) fWinvi[i] = new TMatrixDSym(3); 84 85 //std::cout << "VertexFit constructor executed" << std::endl;86 81 } 87 82 // … … 95 90 fChi2List.Clear(); 96 91 // 97 for (Int_t i = 0; i < fNtr; i++)92 for (Int_t i = 0; i < fNtr; i++) 98 93 { 99 94 fPar[i]->Clear(); … … 148 143 H(1, 1) = nn; 149 144 TVectorD c(2); 150 c(0) = 0; for (Int_t i = 0; i < 3; i++)c(0) += 145 c(0) = 0; for (Int_t i = 0; i < 3; i++)c(0) += n(i) * (y0(i) - x0(i)); 151 146 c(1) = 0; for (Int_t i = 0; i < 3; i++)c(1) += -k(i) * (y0(i) - x0(i)); 152 147 TVectorD smin = (H * c); … … 158 153 Double_t R2 = TMath::Sqrt(Y(0) * Y(0) + Y(1) * Y(1)); 159 154 // 160 return 0.5 *(R1+R2);155 return 0.5 * (R1 + R2); 161 156 } 162 157 Double_t VertexFit::FastRv(TVectorD p1, TVectorD p2) … … 170 165 TMatrixDSym H(2); 171 166 H(0, 0) = -TMath::Cos(p2(1)); 172 H(0, 1) = 167 H(0, 1) = TMath::Cos(p1(1)); 173 168 H(1, 0) = -TMath::Sin(p2(1)); 174 H(1, 1) = 169 H(1, 1) = TMath::Sin(p1(1)); 175 170 Double_t Det = TMath::Sin(p2(1) - p1(1)); 176 171 H *= 1.0 / Det; … … 208 203 } 209 204 210 TMatrixDSym VertexFit::RegInv3(TMatrixDSym &Smat0)205 TMatrixDSym VertexFit::RegInv3(TMatrixDSym& Smat0) 211 206 { 212 207 // … … 232 227 for (Int_t j = 0; j < 2; j++)Q(i, j) = RegMat(i, j); 233 228 } 234 Double_t Det = 1 - Q(0, 1) *Q(1, 0);229 Double_t Det = 1 - Q(0, 1) * Q(1, 0); 235 230 TMatrixDSym H(2); 236 231 H = Q; … … 241 236 p(1) = RegMat(1, 2); 242 237 Double_t pHp = H.Similarity(p); 243 Double_t h = pHp -Det;238 Double_t h = pHp - Det; 244 239 // 245 240 TMatrixDSym pp(2); pp.Rank1Update(p); 246 TMatrixDSym F = (h *H) - pp.Similarity(H);241 TMatrixDSym F = (h * H) - pp.Similarity(H); 247 242 F *= 1.0 / Det; 248 TVectorD b = H *p;243 TVectorD b = H * p; 249 244 TMatrixDSym InvReg(3); 250 245 for (Int_t i = 0; i < 2; i++) … … 263 258 else 264 259 { 265 std::cout << "RegInv3: found negative elements in diagonal. Return standard inversion." << std::endl; 266 return Smat.Invert(); 260 D.Zero(); 261 for (Int_t i = 0; i < N; i++) D(i, i) = 1.0 / TMath::Sqrt(TMath::Abs(Smat(i, i))); 262 TMatrixDSym RegMat = Smat.Similarity(D); 263 RegMat.Invert(); 264 return RegMat.Similarity(D); 267 265 } 268 266 } … … 273 271 { 274 272 // 275 // Derivative of track 3D position vector with respect to track parameters at constant phase 273 // Derivative of track 3D position vector with respect to track parameters at constant phase 276 274 // 277 275 // par = vector of track parameters … … 294 292 A(2, 0) = 0.0; 295 293 // phi0 296 A(0, 1) = -D *TMath::Cos(p0) + (TMath::Cos(phi + p0) - TMath::Cos(p0)) / (2 * C);297 A(1, 1) = -D *TMath::Sin(p0) + (TMath::Sin(phi + p0) - TMath::Sin(p0)) / (2 * C);294 A(0, 1) = -D * TMath::Cos(p0) + (TMath::Cos(phi + p0) - TMath::Cos(p0)) / (2 * C); 295 A(1, 1) = -D * TMath::Sin(p0) + (TMath::Sin(phi + p0) - TMath::Sin(p0)) / (2 * C); 298 296 A(2, 1) = 0.0; 299 297 // C 300 A(0, 2) = -(TMath::Sin(phi + p0) - TMath::Sin(p0)) / (2 * C *C);301 A(1, 2) = (TMath::Cos(phi + p0) - TMath::Cos(p0)) / (2 * C *C);302 A(2, 2) = -ct *phi / (2 * C*C);298 A(0, 2) = -(TMath::Sin(phi + p0) - TMath::Sin(p0)) / (2 * C * C); 299 A(1, 2) = (TMath::Cos(phi + p0) - TMath::Cos(p0)) / (2 * C * C); 300 A(2, 2) = -ct * phi / (2 * C * C); 303 301 // z0 304 302 A(0, 3) = 0.0; … … 353 351 Double_t ct = par(4); 354 352 // 355 x0(0) = -D * TMath::Sin(p0);356 x0(1) = D *TMath::Cos(p0);353 x0(0) = -D * TMath::Sin(p0); 354 x0(1) = D * TMath::Cos(p0); 357 355 x0(2) = z0; 358 356 // … … 378 376 x(0) = x0(0) + (TMath::Sin(phi + p0) - TMath::Sin(p0)) / (2 * C); 379 377 x(1) = x0(1) - (TMath::Cos(phi + p0) - TMath::Cos(p0)) / (2 * C); 380 x(2) = x0(2) + ct *phi / (2 * C);378 x(2) = x0(2) + ct * phi / (2 * C); 381 379 // 382 380 return x; … … 395 393 // 396 394 // Stored quantities 397 Double_t *fi = new Double_t[fNtr]; // Phases398 TVectorD **x0i = new TVectorD*[fNtr]; // Track expansion point399 TVectorD **ai = new TVectorD*[fNtr]; // dx/dphi400 Double_t *a2i = new Double_t[fNtr]; // a'Wa401 TMatrixDSym **Di = new TMatrixDSym*[fNtr]; // W-WBW402 TMatrixDSym **Wi = new TMatrixDSym*[fNtr]; // (ACA')^-1403 TMatrixDSym **Winvi = new TMatrixDSym*[fNtr]; // ACA'395 Double_t* fi = new Double_t[fNtr]; // Phases 396 TVectorD** x0i = new TVectorD * [fNtr]; // Track expansion point 397 TVectorD** ai = new TVectorD * [fNtr]; // dx/dphi 398 Double_t* a2i = new Double_t[fNtr]; // a'Wa 399 TMatrixDSym** Di = new TMatrixDSym * [fNtr]; // W-WBW 400 TMatrixDSym** Wi = new TMatrixDSym * [fNtr]; // (ACA')^-1 401 TMatrixDSym** Winvi = new TMatrixDSym * [fNtr]; // ACA' 404 402 // 405 403 // vertex radius approximation … … 415 413 // 416 414 // Find track pair with largest phi difference 417 Int_t isel =0; Int_t jsel=0; // selected track indices415 Int_t isel = 0; Int_t jsel = 0; // selected track indices 418 416 Double_t dphiMax = 0.0; // Max phi difference 419 for (Int_t i = 0; i < fNtr-1; i++) 417 418 for (Int_t i = 0; i < fNtr - 1; i++) 420 419 { 421 420 //ObsTrk* ti = tracks[i]; … … 423 422 Double_t phi1 = pari(1); 424 423 425 for (Int_t j = i +1; j < fNtr; j++)424 for (Int_t j = i + 1; j < fNtr; j++) 426 425 { 427 426 //ObsTrk* tj = tracks[j]; … … 438 437 } 439 438 // 440 //441 //ObsTrk* t1 = tracks[isel];442 439 TVectorD p1 = *fPar[isel]; 443 //ObsTrk* t2 = tracks[jsel];444 440 TVectorD p2 = *fPar[jsel]; 445 441 Double_t R = FastRv1(p1, p2); 446 if (R > 1.0) R = Rd; 447 R = 0.9*R + 0.1*Rd; 448 // 449 //std::cout << "VertexFinder: fast R = " << R << std::endl; 442 if (R > 1000.0) R = Rd; 443 R = 0.9 * R + 0.1 * Rd; 450 444 // 451 445 // Iteration properties … … 469 463 { 470 464 // Get track helix parameters and their covariance matrix 471 //ObsTrk *t = tracks[i];472 465 TVectorD par = *fPar[i]; 473 466 TMatrixDSym Cov = *fCov[i]; 467 474 468 Double_t fs; 475 469 if (Ntry <= 0) // Initialize all phases on first pass … … 477 471 Double_t D = par(0); 478 472 Double_t C = par(2); 479 Double_t arg = TMath::Max(1.0e-6, (R *R - D*D) / (1 + 2 * C*D));480 fs = 2 * TMath::ASin(C *TMath::Sqrt(arg));473 Double_t arg = TMath::Max(1.0e-6, (R * R - D * D) / (1 + 2 * C * D)); 474 fs = 2 * TMath::ASin(C * TMath::Sqrt(arg)); 481 475 fi[i] = fs; 482 476 } … … 484 478 // Starting values 485 479 // 486 fs = fi[i]; 480 fs = fi[i]; // Get phase 487 481 //std::cout << "VertexFinder: phase fs set" << std::endl; 488 482 TVectorD xs = Fill_x(par, fs); … … 507 501 // Build D matrix 508 502 TMatrixDSym B(3); 503 509 504 B.Rank1Update(a, 1.0); 510 505 B *= -1. / a2; 511 506 B.Similarity(W); 512 TMatrixDSym Ds = W +B; // D matrix507 TMatrixDSym Ds = W + B; // D matrix 513 508 Di[i] = new TMatrixDSym(Ds); // Store D matrix 514 509 //std::cout << "VertexFinder: matrix Di stored" << std::endl; … … 523 518 // update vertex position 524 519 TMatrixDSym H1 = RegInv3(H); 525 x = H1 *cterm;520 x = H1 * cterm; 526 521 //std::cout << "VertexFinder: x vertex set" << std::endl; 527 522 // Update vertex covariance … … 532 527 for (Int_t i = 0; i < fNtr; i++) 533 528 { 534 TVectorD lambda = (*Di[i]) *(*x0i[i] - x);529 TVectorD lambda = (*Di[i]) * (*x0i[i] - x); 535 530 TMatrixDSym Wm1 = *Winvi[i]; 536 531 fChi2List(i) = Wm1.Similarity(lambda); 537 532 Chi2 += fChi2List(i); 538 533 TVectorD a = *ai[i]; 539 TVectorD b = (*Wi[i]) *(x - *x0i[i]);540 for (Int_t j = 0; j < 3; j++)fi[i] += a(j) *b(j) / a2i[i];534 TVectorD b = (*Wi[i]) * (x - *x0i[i]); 535 for (Int_t j = 0; j < 3; j++)fi[i] += a(j) * b(j) / a2i[i]; 541 536 } 542 537 543 //std::cout << "VertexFinder: end chi2 calculation" << std::endl;544 538 // 545 539 TVectorD dx = x - x0;
Note:
See TracChangeset
for help on using the changeset viewer.