Changes in / [91ef0b8:363e269] in git
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/ExamplePVtxFit.C
r91ef0b8 r363e269 40 40 // 41 41 // Loop over all events 42 Int_t Nev = TMath::Min(Nevent, (Int_t) numberOfEntries);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 m64 Double_t x = gp->X;65 Double_t y = gp->Y;66 Double_t z = gp->Z;63 // Position of origin in meters 64 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; 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); 80 81 // 81 82 pr[Ntr] = new TVectorD(obsPar); 82 //std::cout<<"Cov Matrix:"<<std::endl; 83 //trk->CovarianceMatrix().Print(); 84 cv[Ntr] = new TMatrixDSym(trk->CovarianceMatrix()); 83 cv[Ntr] = new TMatrixDSym(TrkUtil::CovToMm(trk->CovarianceMatrix())); 85 84 Ntr++; 86 85 } 87 86 } // 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 primary vertex pulls", 50, 50, 900, 500);120 TCanvas* Cnv = new TCanvas("Cnv", "Delphes generated track plots", 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
r91ef0b8 r363e269 15 15 fVtxCst = kFALSE; 16 16 fxCst.ResizeTo(3); 17 fCovCst.ResizeTo(3, 17 fCovCst.ResizeTo(3,3); 18 18 fXv.ResizeTo(3); 19 fcovXv.ResizeTo(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, 28 fCovCst.ResizeTo(3,3); 29 29 fXv.ResizeTo(3); 30 fcovXv.ResizeTo(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 37 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 48 49 } 49 50 // ObsTrk list … … 54 55 fVtxCst = kFALSE; 55 56 fxCst.ResizeTo(3); 56 fCovCst.ResizeTo(3, 57 fCovCst.ResizeTo(3,3); 57 58 fXv.ResizeTo(3); 58 fcovXv.ResizeTo(3, 59 // 60 fPar = new TVectorD *[Ntr];61 fCov = new TMatrixDSym *[Ntr];59 fcovXv.ResizeTo(3,3); 60 // 61 fPar = new TVectorD*[Ntr]; 62 fCov = new TMatrixDSym*[Ntr]; 62 63 fChi2List.ResizeTo(Ntr); 63 64 for (Int_t i = 0; i < Ntr; i++) 64 65 { 65 66 fPar[i] = new TVectorD(track[i]->GetObsPar()); 67 //std::cout << "fPar = " << std::endl; fPar[i]->Print(); 66 68 fCov[i] = new TMatrixDSym(track[i]->GetCov()); 69 //std::cout << "fCov = " << std::endl; fCov[i]->Print(); 67 70 } 68 71 // … … 79 82 fWinvi = new TMatrixDSym * [Ntr]; // ACA' 80 83 for (Int_t i = 0; i < Ntr; i++) fWinvi[i] = new TMatrixDSym(3); 84 85 //std::cout << "VertexFit constructor executed" << std::endl; 81 86 } 82 87 // … … 90 95 fChi2List.Clear(); 91 96 // 92 for (Int_t i 97 for (Int_t i= 0; i < fNtr; i++) 93 98 { 94 99 fPar[i]->Clear(); … … 143 148 H(1, 1) = nn; 144 149 TVectorD c(2); 145 c(0) = 0; for (Int_t i = 0; i < 3; i++)c(0) += n(i) * (y0(i) - x0(i));150 c(0) = 0; for (Int_t i = 0; i < 3; i++)c(0) += n(i) * (y0(i) - x0(i)); 146 151 c(1) = 0; for (Int_t i = 0; i < 3; i++)c(1) += -k(i) * (y0(i) - x0(i)); 147 152 TVectorD smin = (H * c); … … 153 158 Double_t R2 = TMath::Sqrt(Y(0) * Y(0) + Y(1) * Y(1)); 154 159 // 155 return 0.5 * (R1 +R2);160 return 0.5*(R1+R2); 156 161 } 157 162 Double_t VertexFit::FastRv(TVectorD p1, TVectorD p2) … … 165 170 TMatrixDSym H(2); 166 171 H(0, 0) = -TMath::Cos(p2(1)); 167 H(0, 1) = TMath::Cos(p1(1));172 H(0, 1) = TMath::Cos(p1(1)); 168 173 H(1, 0) = -TMath::Sin(p2(1)); 169 H(1, 1) = TMath::Sin(p1(1));174 H(1, 1) = TMath::Sin(p1(1)); 170 175 Double_t Det = TMath::Sin(p2(1) - p1(1)); 171 176 H *= 1.0 / Det; … … 203 208 } 204 209 205 TMatrixDSym VertexFit::RegInv3(TMatrixDSym &Smat0)210 TMatrixDSym VertexFit::RegInv3(TMatrixDSym &Smat0) 206 211 { 207 212 // … … 227 232 for (Int_t j = 0; j < 2; j++)Q(i, j) = RegMat(i, j); 228 233 } 229 Double_t Det = 1 - Q(0, 1) *Q(1, 0);234 Double_t Det = 1 - Q(0, 1)*Q(1, 0); 230 235 TMatrixDSym H(2); 231 236 H = Q; … … 236 241 p(1) = RegMat(1, 2); 237 242 Double_t pHp = H.Similarity(p); 238 Double_t h = pHp -Det;243 Double_t h = pHp-Det; 239 244 // 240 245 TMatrixDSym pp(2); pp.Rank1Update(p); 241 TMatrixDSym F = (h *H) - pp.Similarity(H);246 TMatrixDSym F = (h*H) - pp.Similarity(H); 242 247 F *= 1.0 / Det; 243 TVectorD b = H *p;248 TVectorD b = H*p; 244 249 TMatrixDSym InvReg(3); 245 250 for (Int_t i = 0; i < 2; i++) … … 258 263 else 259 264 { 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); 265 std::cout << "RegInv3: found negative elements in diagonal. Return standard inversion." << std::endl; 266 return Smat.Invert(); 265 267 } 266 268 } … … 271 273 { 272 274 // 273 // Derivative of track 3D position vector with respect to track parameters at constant phase 275 // Derivative of track 3D position vector with respect to track parameters at constant phase 274 276 // 275 277 // par = vector of track parameters … … 292 294 A(2, 0) = 0.0; 293 295 // phi0 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);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); 296 298 A(2, 1) = 0.0; 297 299 // 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);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); 301 303 // z0 302 304 A(0, 3) = 0.0; … … 351 353 Double_t ct = par(4); 352 354 // 353 x0(0) = -D * 354 x0(1) = D *TMath::Cos(p0);355 x0(0) = -D *TMath::Sin(p0); 356 x0(1) = D*TMath::Cos(p0); 355 357 x0(2) = z0; 356 358 // … … 376 378 x(0) = x0(0) + (TMath::Sin(phi + p0) - TMath::Sin(p0)) / (2 * C); 377 379 x(1) = x0(1) - (TMath::Cos(phi + p0) - TMath::Cos(p0)) / (2 * C); 378 x(2) = x0(2) + ct *phi / (2 * C);380 x(2) = x0(2) + ct*phi / (2 * C); 379 381 // 380 382 return x; … … 393 395 // 394 396 // Stored quantities 395 Double_t *fi = new Double_t[fNtr]; // Phases396 TVectorD ** x0i = new TVectorD *[fNtr]; // Track expansion point397 TVectorD ** ai = new TVectorD *[fNtr]; // dx/dphi398 Double_t *a2i = new Double_t[fNtr]; // a'Wa399 TMatrixDSym ** Di = new TMatrixDSym *[fNtr]; // W-WBW400 TMatrixDSym ** Wi = new TMatrixDSym *[fNtr]; // (ACA')^-1401 TMatrixDSym ** Winvi = new TMatrixDSym *[fNtr]; // ACA'397 Double_t *fi = new Double_t[fNtr]; // Phases 398 TVectorD **x0i = new TVectorD*[fNtr]; // Track expansion point 399 TVectorD **ai = new TVectorD*[fNtr]; // dx/dphi 400 Double_t *a2i = new Double_t[fNtr]; // a'Wa 401 TMatrixDSym **Di = new TMatrixDSym*[fNtr]; // W-WBW 402 TMatrixDSym **Wi = new TMatrixDSym*[fNtr]; // (ACA')^-1 403 TMatrixDSym **Winvi = new TMatrixDSym*[fNtr]; // ACA' 402 404 // 403 405 // vertex radius approximation … … 413 415 // 414 416 // Find track pair with largest phi difference 415 Int_t isel = 0; Int_t jsel =0; // selected track indices417 Int_t isel=0; Int_t jsel=0; // selected track indices 416 418 Double_t dphiMax = 0.0; // Max phi difference 417 418 for (Int_t i = 0; i < fNtr - 1; i++) 419 for (Int_t i = 0; i < fNtr-1; i++) 419 420 { 420 421 //ObsTrk* ti = tracks[i]; … … 422 423 Double_t phi1 = pari(1); 423 424 424 for (Int_t j = i +1; j < fNtr; j++)425 for (Int_t j = i+1; j < fNtr; j++) 425 426 { 426 427 //ObsTrk* tj = tracks[j]; … … 437 438 } 438 439 // 440 // 441 //ObsTrk* t1 = tracks[isel]; 439 442 TVectorD p1 = *fPar[isel]; 443 //ObsTrk* t2 = tracks[jsel]; 440 444 TVectorD p2 = *fPar[jsel]; 441 445 Double_t R = FastRv1(p1, p2); 442 if (R > 1000.0) R = Rd; 443 R = 0.9 * R + 0.1 * Rd; 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; 444 450 // 445 451 // Iteration properties … … 463 469 { 464 470 // Get track helix parameters and their covariance matrix 471 //ObsTrk *t = tracks[i]; 465 472 TVectorD par = *fPar[i]; 466 473 TMatrixDSym Cov = *fCov[i]; 467 468 474 Double_t fs; 469 475 if (Ntry <= 0) // Initialize all phases on first pass … … 471 477 Double_t D = par(0); 472 478 Double_t C = par(2); 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));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)); 475 481 fi[i] = fs; 476 482 } … … 478 484 // Starting values 479 485 // 480 fs = fi[i]; // Get phase486 fs = fi[i]; // Get phase 481 487 //std::cout << "VertexFinder: phase fs set" << std::endl; 482 488 TVectorD xs = Fill_x(par, fs); … … 501 507 // Build D matrix 502 508 TMatrixDSym B(3); 503 504 509 B.Rank1Update(a, 1.0); 505 510 B *= -1. / a2; 506 511 B.Similarity(W); 507 TMatrixDSym Ds = W +B; // D matrix512 TMatrixDSym Ds = W+B; // D matrix 508 513 Di[i] = new TMatrixDSym(Ds); // Store D matrix 509 514 //std::cout << "VertexFinder: matrix Di stored" << std::endl; … … 518 523 // update vertex position 519 524 TMatrixDSym H1 = RegInv3(H); 520 x = H1 *cterm;525 x = H1*cterm; 521 526 //std::cout << "VertexFinder: x vertex set" << std::endl; 522 527 // Update vertex covariance … … 527 532 for (Int_t i = 0; i < fNtr; i++) 528 533 { 529 TVectorD lambda = (*Di[i]) *(*x0i[i] - x);534 TVectorD lambda = (*Di[i])*(*x0i[i] - x); 530 535 TMatrixDSym Wm1 = *Winvi[i]; 531 536 fChi2List(i) = Wm1.Similarity(lambda); 532 537 Chi2 += fChi2List(i); 533 538 TVectorD a = *ai[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];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]; 536 541 } 537 542 543 //std::cout << "VertexFinder: end chi2 calculation" << std::endl; 538 544 // 539 545 TVectorD dx = x - x0;
Note:
See TracChangeset
for help on using the changeset viewer.