Fork me on GitHub

source: git/external/TrackCovariance/ObsTrk.cc@ 3fdfd04

Last change on this file since 3fdfd04 was a617744, checked in by michele <michele.selvaggi@…>, 4 years ago

adding latest TrackCovariance libraries (F. Bedeschi)

  • Property mode set to 100644
File size: 4.5 KB
Line 
1#include <TMath.h>
2#include <TVector3.h>
3#include <TMatrixD.h>
4#include <TMatrixDSym.h>
5#include <TDecompChol.h>
6#include <TRandom.h>
7#include <iostream>
8#include "SolGridCov.h"
9#include "ObsTrk.h"
10//
11// Constructors
12//
13// x(3) track origin, p(3) track momentum at origin, Q charge, B magnetic field in Tesla
14ObsTrk::ObsTrk(TVector3 x, TVector3 p, Double_t Q, Double_t B, SolGridCov *GC)
15{
16 SetBfield(B);
17 fGC = GC;
18 fGenX = x;
19 fGenP = p;
20 fGenQ = Q;
21 fB = B;
22 fGenPar.ResizeTo(5);
23 fGenParMm.ResizeTo(5);
24 fGenParACTS.ResizeTo(6);
25 fGenParILC.ResizeTo(5);
26 fObsPar.ResizeTo(5);
27 fObsParMm.ResizeTo(5);
28 fObsParACTS.ResizeTo(6);
29 fObsParILC.ResizeTo(5);
30 fCov.ResizeTo(5, 5);
31 fCovMm.ResizeTo(5, 5);
32 fCovACTS.ResizeTo(6, 6);
33 fCovILC.ResizeTo(5, 5);
34 fGenPar = XPtoPar(x,p,Q);
35 fGenParMm = ParToMm(fGenPar);
36 fGenParACTS = ParToACTS(fGenPar);
37 fGenParILC = ParToILC(fGenPar);
38 /*
39 cout << "ObsTrk::ObsTrk: fGenPar";
40 for (Int_t i = 0; i < 5; i++)cout << fGenPar(i) << ", ";
41 cout << endl;
42 */
43 fObsPar = GenToObsPar(fGenPar, fGC);
44 fObsParMm = ParToMm(fObsPar);
45 fObsParACTS = ParToACTS(fObsPar);
46 fObsParILC = ParToILC(fObsPar);
47 fObsX = ParToX(fObsPar);
48 fObsP = ParToP(fObsPar);
49 fObsQ = ParToQ(fObsPar);
50 fCovMm = CovToMm(fCov);
51 fCovACTS = CovToACTS(fObsPar, fCov);
52 fCovILC = CovToILC(fCov);
53}
54//
55// x[3] track origin, p[3] track momentum at origin, Q charge, B magnetic field in Tesla
56ObsTrk::ObsTrk(Double_t *x, Double_t *p, Double_t Q, Double_t B, SolGridCov* GC)
57{
58 SetBfield(B);
59 fGC = GC;
60 fGenX.SetXYZ(x[0],x[1],x[2]);
61 fGenP.SetXYZ(p[0],p[1],p[2]);
62 fGenQ = Q;
63 fB = B;
64 fGenPar.ResizeTo(5);
65 fGenParMm.ResizeTo(5);
66 fGenParACTS.ResizeTo(6);
67 fGenParILC.ResizeTo(5);
68 fObsPar.ResizeTo(5);
69 fObsParMm.ResizeTo(5);
70 fObsParACTS.ResizeTo(6);
71 fObsParILC.ResizeTo(5);
72 fCov.ResizeTo(5, 5);
73 fCovMm.ResizeTo(5, 5);
74 fCovACTS.ResizeTo(6, 6);
75 fCovILC.ResizeTo(5, 5);
76 fGenPar = XPtoPar(fGenX, fGenP, Q);
77 fGenParACTS = ParToACTS(fGenPar);
78 fGenParILC = ParToILC(fGenPar);
79 /*
80 cout << "ObsTrk::ObsTrk: fGenPar";
81 for (Int_t i = 0; i < 5; i++)cout << fGenPar(i) << ", ";
82 cout << endl;
83 */
84 fObsPar = GenToObsPar(fGenPar, fGC);
85 fObsParACTS = ParToACTS(fObsPar);
86 fObsParILC = ParToILC(fObsPar);
87 fObsX = ParToX(fObsPar);
88 fObsP = ParToP(fObsPar);
89 fObsQ = ParToQ(fObsPar);
90 fCovACTS = CovToACTS(fObsPar, fCov);
91 fCovILC = CovToILC(fCov);
92}
93//
94// Destructor
95ObsTrk::~ObsTrk()
96{
97 fGenX.Clear();
98 fGenP.Clear();
99 fGenPar.Clear();
100 fGenParMm.Clear();
101 fGenParACTS.Clear();
102 fGenParILC.Clear();
103 fObsX.Clear();
104 fObsP.Clear();
105 fObsPar.Clear();
106 fObsParMm.Clear();
107 fObsParACTS.Clear();
108 fObsParILC.Clear();
109 fCov.Clear();
110 fCovMm.Clear();
111 fCovACTS.Clear();
112 fCovILC.Clear();
113}
114//
115TVectorD ObsTrk::GenToObsPar(TVectorD gPar, SolGridCov *GC)
116{
117 TVector3 p = ParToP(gPar);
118 Double_t pt = p.Pt();
119 Double_t tanTh = 1.0 / TMath::Abs(gPar(4));
120 Double_t angd = TMath::ATan(tanTh)*180. / TMath::Pi();
121 //
122 // Check ranges
123 Double_t minPt = GC->GetMinPt ();
124 //if (pt < minPt) cout << "Warning ObsTrk::GenToObsPar: pt " << pt << " is below grid range of " << minPt << endl;
125 Double_t maxPt = GC->GetMaxPt();
126 //if (pt > maxPt) cout << "Warning ObsTrk::GenToObsPar: pt " << pt << " is above grid range of " << maxPt << endl;
127 Double_t minAn = GC->GetMinAng();
128 //if (angd < minAn) cout << "Warning ObsTrk::GenToObsPar: angle " << angd
129 // << " is below grid range of " << minAn << endl;
130 Double_t maxAn = GC->GetMaxAng();
131 //if (angd > maxAn) cout << "Warning ObsTrk::GenToObsPar: angle " << angd
132 // << " is above grid range of " << maxAn << endl;
133 //
134 TMatrixDSym Cov = GC->GetCov(pt, angd);
135 fCov = Cov;
136 //
137 // Now do Choleski decomposition and random number extraction, with appropriate stabilization
138 //
139 TMatrixDSym CvN = Cov;
140 TMatrixDSym DCv(5); DCv.Zero();
141 TMatrixDSym DCvInv(5); DCvInv.Zero();
142 for (Int_t id = 0; id < 5; id++)
143 {
144 Double_t dVal = TMath::Sqrt(Cov(id, id));
145 DCv (id, id) = dVal;
146 DCvInv(id, id) = 1.0 / dVal;
147 }
148 CvN.Similarity(DCvInv); // Normalize diagonal to 1
149 TDecompChol Chl(CvN);
150 Bool_t OK = Chl.Decompose(); // Choleski decomposition of normalized matrix
151 TMatrixD U = Chl.GetU(); // Get Upper triangular matrix
152 TMatrixD Ut(TMatrixD::kTransposed, U); // Transposed of U (lower triangular)
153 TVectorD r(5);
154 for (Int_t i = 0; i < 5; i++)r(i) = gRandom->Gaus(0.0, 1.0); // Array of normal random numbers
155 TVectorD oPar = gPar + DCv*(Ut*r); // Observed parameter vector
156 //
157 return oPar;
158}
Note: See TracBrowser for help on using the repository browser.