]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSUClusterLines.cxx
optimized mat.budget estimator macro
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUClusterLines.cxx
CommitLineData
30da2335 1#include "AliITSUClusterLines.h"
2#include <TMath.h>
3
5e2539d9 4using std::cout;
5using std::endl;
6
30da2335 7ClassImp(AliITSUClusterLines);
8
9//////////////////////////////////////////////////////////////////////
10// This class is used by the AliITSUVertexer to compute and store //
11// information about vertex candidates. //
12// The cluster is seeded starting from two lines, then it is //
13// possible to attach other lines. Whenever a new line is attached //
14// the weight and coefficient matrices are computed. //
15// Origin puccio@to.infn.it Feb. 20 2014 //
16//////////////////////////////////////////////////////////////////////
17
18
19//____________________________________________________________________________________________________________
20AliITSUClusterLines::AliITSUClusterLines() : TObject(),
21 fA(),
22 fB(),
23 fLabels(),
24 fV() {
25 // Default Constructor
769bd110 26
27 for(Int_t i=0;i<9;++i) fW[i] = 0.;
30da2335 28}
29
30//____________________________________________________________________________________________________________
31AliITSUClusterLines::AliITSUClusterLines(UInt_t first, AliStrLine *line1, UInt_t second, AliStrLine *line2,Bool_t weight) : TObject(),
32 fA(),
33 fB(),
34 fLabels(),
35 fV() {
36 // Standard constructor
37 fLabels.push_back(first);
38 fLabels.push_back(second);
39 Double_t wmat1[9],wmat2[9],p1[3],p2[3],cd1[3],cd2[3],sq1[3]={1.,1.,1.},sq2[3]={1.,1.,1.};
40 line1->GetWMatrix(wmat1);
41 line2->GetWMatrix(wmat2);
42 for(Int_t i=0;i<9;++i) fW[i]=wmat1[i]+wmat2[i];
43 line1->GetP0(p1);
44 line2->GetP0(p2);
45 line1->GetCd(cd1);
46 line2->GetCd(cd2);
47 if(weight) {
48 line1->GetSigma2P0(sq1);
49 line2->GetSigma2P0(sq2);
50 }
51
52 Double_t det1=cd1[2]*cd1[2]*sq1[0]*sq1[1]+cd1[1]*cd1[1]*sq1[0]*sq1[2]+cd1[0]*cd1[0]*sq1[1]*sq1[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1[1]*sq1[0]*(-cd1[1]*p1[2]+cd1[2]*p1[1]))/det1;
67 fB[2]+=(cd2[0]*sq2[1]*(-cd2[0]*p2[2]+cd2[2]*p2[0])+cd2[1]*sq2[0]*(-cd2[1]*p2[2]+cd2[2]*p2[1]))/det2;
68
69 this->ComputeClusterCentroid();
70
71}
72
73//____________________________________________________________________________________________________________
74AliITSUClusterLines::~AliITSUClusterLines() {
75 // Destructor
76}
77
78//____________________________________________________________________________________________________________
79void AliITSUClusterLines::Add(UInt_t label, AliStrLine *line, Bool_t weight) {
80 // Add a line to the cluster. It changes the weight matrix of the cluster and its parameters
81 fLabels.push_back(label);
82 Double_t wmat[9],p[3],cd[3],sq[3]={1.,1.,1.};
83 line->GetWMatrix(wmat);
84 line->GetP0(p);
85 line->GetCd(cd);
86
87 for(Int_t i=0;i<9;++i) fW[i]+=wmat[i];
88 if(weight) line->GetSigma2P0(sq);
89
90 Double_t det=cd[2]*cd[2]*sq[0]*sq[1]+cd[1]*cd[1]*sq[0]*sq[2]+cd[0]*cd[0]*sq[1]*sq[2];
91 fA[0]+=(cd[2]*cd[2]*sq[1]+cd[1]*cd[1]*sq[2])/det;
92 fA[1]+=-cd[0]*cd[1]*sq[2]/det;
93 fA[2]+=-cd[0]*cd[2]*sq[1]/det;
94 fA[3]+=(cd[2]*cd[2]*sq[0]+cd[0]*cd[0]*sq[2])/det;
95 fA[4]+=-cd[1]*cd[2]*sq[0]/det;
96 fA[5]+=(cd[1]*cd[1]*sq[0]+cd[0]*cd[0]*sq[1])/det;
97
98 fB[0]+=(cd[1]*sq[2]*(-cd[1]*p[0]+cd[0]*p[1])+cd[2]*sq[1]*(-cd[2]*p[0]+cd[0]*p[2]))/det;
99 fB[1]+=(cd[0]*sq[2]*(-cd[0]*p[1]+cd[1]*p[0])+cd[2]*sq[0]*(-cd[2]*p[1]+cd[1]*p[2]))/det;
100 fB[2]+=(cd[0]*sq[1]*(-cd[0]*p[2]+cd[2]*p[0])+cd[1]*sq[0]*(-cd[1]*p[2]+cd[2]*p[1]))/det;
101
102 this->ComputeClusterCentroid();
103}
104
105//____________________________________________________________________________________________________________
106Int_t AliITSUClusterLines::Compare(const TObject* obj) const {
107 // Comparison criteria between two clusters
108 const AliITSUClusterLines *cl=(const AliITSUClusterLines*)obj;
109 if(fLabels.size()<cl->GetSize()) return 1;
110 if(fLabels.size()>cl->GetSize()) return -1;
111 return 0;
112}
113
114//____________________________________________________________________________________________________________
115void AliITSUClusterLines::ComputeClusterCentroid() {
116 // Calculation of the centroid
117 Double_t *a=fA;
118 Double_t *b=fB;
119 Double_t *v=fV;
120
121 Double_t det=a[0]*(a[3]*a[5]-a[4]*a[4])-a[1]*(a[1]*a[5]-a[4]*a[2])+a[2]*(a[1]*a[4]-a[2]*a[3]);
122
123 if(det==0) {
124 cout << "Could not invert weight matrix" << endl;
125 return;
126 }
127 v[0]=-(b[0]*(a[3]*a[5]-a[4]*a[4])-a[1]*(b[1]*a[5]-a[4]*b[2])+a[2]*(b[1]*a[4]-b[2]*a[3]))/det;
128 v[1]=-(a[0]*(b[1]*a[5]-b[2]*a[4])-b[0]*(a[1]*a[5]-a[4]*a[2])+a[2]*(a[1]*b[2]-a[2]*b[1]))/det;
129 v[2]=-(a[0]*(a[3]*b[2]-b[1]*a[4])-a[1]*(a[1]*b[2]-b[1]*a[2])+b[0]*(a[1]*a[4]-a[2]*a[3]))/det;
130}
131
132//____________________________________________________________________________________________________________
133void AliITSUClusterLines::GetCovMatrix(Float_t cov[6]) {
134 // Returns the covariance matrix (single precision)
135 Double_t *w=fW;
136 Double_t den=w[0]*(w[4]*w[8]-w[5]*w[7])-w[1]*(w[3]*w[8]-w[5]*w[6])+w[2]*(w[3]*w[7]-w[4]*w[6]);
137 if(den==0) {
138 cout << "Could not invert weight matrix" << endl;
139 return;
140 }
141 cov[0]=(w[4]*w[8]-w[5]*w[7])/den;
142 cov[1]=-(w[1]*w[8]-w[7]*w[2])/den;
143 cov[2]=(w[1]*w[5]-w[4]*w[2])/den;
144 cov[3]=(w[0]*w[8]-w[6]*w[2])/den;
145 cov[4]=-(w[0]*w[5]-w[3]*w[2])/den;
146 cov[5]=(w[0]*w[4]-w[1]*w[3])/den;
147}
148
149//____________________________________________________________________________________________________________
150void AliITSUClusterLines::GetCovMatrix(Double_t cov[6]) {
151 // Returns the covariance matrix (double precision)
152 Double_t *w=fW;
153 Double_t den=w[0]*(w[4]*w[8]-w[5]*w[7])-w[1]*(w[3]*w[8]-w[5]*w[6])+w[2]*(w[3]*w[7]-w[4]*w[6]);
154 if(den==0) {
155 cout << "Could not invert weight matrix" << endl;
156 return;
157 }
158 cov[0]=(w[4]*w[8]-w[5]*w[7])/den;
159 cov[1]=-(w[1]*w[8]-w[7]*w[2])/den;
160 cov[2]=(w[1]*w[5]-w[4]*w[2])/den;
161 cov[3]=(w[0]*w[8]-w[6]*w[2])/den;
162 cov[4]=-(w[0]*w[5]-w[3]*w[2])/den;
163 cov[5]=(w[0]*w[4]-w[1]*w[3])/den;
164
165}
166
167//____________________________________________________________________________________________________________
168Bool_t AliITSUClusterLines::IsEqual(const TObject* obj) const {
169 // Comparison criteria between two clusters
170 const AliITSUClusterLines *cl=(const AliITSUClusterLines*)obj;
171 if(fLabels.size()==cl->GetSize()) return kTRUE;
172 return kFALSE;
173}
174