]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEER/AliCluster.cxx
Merge branch 'master' into TPCdev
[u/mrichter/AliRoot.git] / STEER / STEER / AliCluster.cxx
CommitLineData
87594435 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//-------------------------------------------------------------------------
75fb37cc 17// Class AliCluster
18// This is the future base for managing the clusters in barrel detectors.
19// It is fully interfaced with the ROOT geometrical modeller TGeo.
20// Each cluster contains XYZ coordinates in the local tracking c.s. and
21// the unique ID of the sensitive detector element which continas the
22// cluster. The coordinates in global c.s. are computed using the interface
23// to TGeo and will be not overwritten by the derived sub-detector cluster
24// classes.
25//
26// cvetan.cheshkov@cern.ch & jouri.belikov@cern.ch 5/3/2007
87594435 27//-------------------------------------------------------------------------
28
75fb37cc 29#include <TGeoManager.h>
30#include <TGeoMatrix.h>
31#include <TGeoPhysicalNode.h>
494a045f 32#include <TMath.h>
75fb37cc 33
87594435 34#include "AliCluster.h"
75fb37cc 35#include "AliLog.h"
36#include "AliAlignObj.h"
87594435 37
38ClassImp(AliCluster)
75fb37cc 39
40//______________________________________________________________________________
41AliCluster::AliCluster():
42 TObject(),
43 fX(0),
44 fY(0),
45 fZ(0),
46 fSigmaY2(0),
47 fSigmaZ2(0),
48 fSigmaYZ(0),
49 fVolumeId(0),
50 fIsMisaligned(kFALSE)
51{
52 // Default constructor
87594435 53 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
87594435 54}
55
75fb37cc 56//______________________________________________________________________________
57AliCluster::AliCluster(UShort_t volId,
58 const Float_t *hit,
59 Float_t x,
60 Float_t sigyz,
61 const Int_t *lab):
62 TObject(),
63 fX(x),
64 fY(hit[0]),
65 fZ(hit[1]),
66 fSigmaY2(hit[2]),
67 fSigmaZ2(hit[3]),
68 fSigmaYZ(sigyz),
69 fVolumeId(volId),
70 fIsMisaligned(kFALSE)
968c248e 71{
75fb37cc 72 // Constructor
73 if (lab) {
74 fTracks[0] = lab[0];
75 fTracks[1] = lab[1];
76 fTracks[2] = lab[2];
77 }
78 else
79 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
80}
81
82//______________________________________________________________________________
83AliCluster::AliCluster(UShort_t volId,
84 Float_t x, Float_t y, Float_t z,
85 Float_t sy2, Float_t sz2, Float_t syz,
86 const Int_t *lab):
87 TObject(),
88 fX(x),
89 fY(y),
90 fZ(z),
91 fSigmaY2(sy2),
92 fSigmaZ2(sz2),
93 fSigmaYZ(syz),
94 fVolumeId(volId),
95 fIsMisaligned(kFALSE)
96{
97 // Constructor
98 if (lab) {
99 fTracks[0] = lab[0];
100 fTracks[1] = lab[1];
101 fTracks[2] = lab[2];
102 }
103 else
104 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
105}
106
107//______________________________________________________________________________
108AliCluster::AliCluster(const AliCluster& cluster):
109 TObject(cluster),
110 fX(cluster.fX),
111 fY(cluster.fY),
112 fZ(cluster.fZ),
113 fSigmaY2(cluster.fSigmaY2),
114 fSigmaZ2(cluster.fSigmaZ2),
115 fSigmaYZ(cluster.fSigmaYZ),
116 fVolumeId(cluster.fVolumeId),
117 fIsMisaligned(cluster.fIsMisaligned)
118{
119 // Copy constructor
120 fTracks[0] = cluster.fTracks[0];
121 fTracks[1] = cluster.fTracks[1];
122 fTracks[2] = cluster.fTracks[2];
123}
124
125//______________________________________________________________________________
126AliCluster & AliCluster::operator=(const AliCluster& cluster)
127{
128 // Assignment operator
129
130 if(&cluster == this) return *this;
131
132 fX = cluster.fX;
133 fY = cluster.fY;
134 fZ = cluster.fZ;
135 fSigmaY2 = cluster.fSigmaY2;
136 fSigmaZ2 = cluster.fSigmaZ2;
137 fSigmaYZ = cluster.fSigmaYZ;
138 fVolumeId = cluster.fVolumeId;
139 fIsMisaligned = cluster.fIsMisaligned;
140
141 fTracks[0] = cluster.fTracks[0];
142 fTracks[1] = cluster.fTracks[1];
143 fTracks[2] = cluster.fTracks[2];
144
145 return *this;
146}
147
c47d9105 148//______________________________________________________________________________
d999f2e6 149void AliCluster::Print(Option_t* /*option*/) const
c47d9105 150{
151 // Print cluster information.
152
153 printf("AliCluster pos=(%.4f, %.4f, %.4f), s_y2=%f, s_z2=%f, s_yz=%f, vol=%hu\n",
154 fX, fY, fZ, fSigmaY2, fSigmaZ2, fSigmaYZ, fVolumeId);
155 Float_t g[3];
156 if (GetGlobalXYZ(g))
157 printf(" global_pos=(%.4f, %.4f, %.4f)\n", g[0], g[1], g[2]);
158
159}
160
75fb37cc 161//______________________________________________________________________________
162Bool_t AliCluster::GetGlobalXYZ(Float_t xyz[3]) const
163{
164 // Get the global coordinates of the cluster
165 // All the needed information is taken only
166 // from TGeo.
167
168 xyz[0] = xyz[1] = xyz[2] = 0;
169
170 if (!gGeoManager || !gGeoManager->IsClosed()) {
171 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
172 return kFALSE;
173 }
174
175 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
176 if (!mt) return kFALSE;
177 Double_t txyz[3] = {fX, fY, fZ};
178 Double_t lxyz[3] = {0, 0, 0};
179 mt->LocalToMaster(txyz,lxyz);
180
181 TGeoHMatrix *ml = GetMatrix();
182 if (!ml) return kFALSE;
183 Double_t gxyz[3] = {0, 0, 0};
184 ml->LocalToMaster(lxyz,gxyz);
185 xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
186 return kTRUE;
187}
188
189//______________________________________________________________________________
190Bool_t AliCluster::GetGlobalCov(Float_t cov[6]) const
191{
192 // Get the global covariance matrix of the cluster coordinates
193 // All the needed information is taken only
194 // from TGeo.
195 for (Int_t i = 0; i < 6; i++) cov[i] = 0;
196
197 if (!gGeoManager || !gGeoManager->IsClosed()) {
198 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
199 return kFALSE;
200 }
201
202 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
203 if (!mt) return kFALSE;
204
205 TGeoHMatrix *ml = GetMatrix();
206 if (!ml) return kFALSE;
207
208 TGeoHMatrix m;
209 Double_t tcov[9] = { 0, 0, 0, 0, fSigmaY2, fSigmaYZ, 0, fSigmaYZ, fSigmaZ2 };
210 m.SetRotation(tcov);
211 m.Multiply(&mt->Inverse());
212 m.Multiply(&ml->Inverse());
213 m.MultiplyLeft(mt);
214 m.MultiplyLeft(ml);
215 Double_t *ncov = m.GetRotationMatrix();
216 cov[0] = ncov[0]; cov[1] = ncov[1]; cov[2] = ncov[2];
217 cov[3] = ncov[4]; cov[4] = ncov[5];
218 cov[5] = ncov[8];
219
220 return kTRUE;
221}
222
223//______________________________________________________________________________
224Bool_t AliCluster::GetXRefPlane(Float_t &xref) const
225{
226 // Get the distance between the origin and the ref.plane.
227 // All the needed information is taken only
228 // from TGeo.
229 xref = 0;
230
231 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
232 if (!mt) return kFALSE;
233
234 TGeoHMatrix *ml = GetMatrix();
235 if (!ml) return kFALSE;
236
237 TGeoHMatrix m = *mt;
238 m.MultiplyLeft(ml);
239
7105349f 240 xref = -(m.Inverse()).GetTranslation()[0];
75fb37cc 241 return kTRUE;
242}
243
494a045f 244//______________________________________________________________________________
245Bool_t AliCluster::GetXAlphaRefPlane(Float_t &x, Float_t &alpha) const
246{
247 // Get the distance between the origin and the ref. plane together with
248 // the rotation anlge of the ref. plane.
249 // All the needed information is taken only
250 // from TGeo.
251 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
252 if (!mt) return kFALSE;
253
254 const TGeoHMatrix *ml = GetMatrix();
255 if (!ml) return kFALSE;
256
257 TGeoHMatrix m(*ml);
258 m.Multiply(mt);
259 const Double_t txyz[3]={0.}; Double_t xyz[3]={0.};
260 m.LocalToMaster(txyz,xyz);
261
262 x=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
263
264 Double_t a=TMath::ATan2(xyz[1],xyz[0]);
265 if (a<0) a+=TMath::TwoPi();
266 else if (a>=TMath::TwoPi()) a-=TMath::TwoPi();
267 alpha=a;
268
269 return kTRUE;
270}
271
75fb37cc 272//______________________________________________________________________________
273Bool_t AliCluster::Misalign()
274{
275 // ...
276 // All the needed information is taken only
277 // from TGeo.
278 if (!gGeoManager || !gGeoManager->IsClosed()) {
279 AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
280 return kFALSE;
281 }
282
283 if (fIsMisaligned) {
284 AliError("The cluster was already misaligned!");
285 return kFALSE;
286 }
287
288 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
289 if (!mt) return kFALSE;
290
291 TGeoHMatrix *ml = GetMatrix();
292 if (!ml) return kFALSE;
293
294 TGeoHMatrix *mlorig = GetMatrix(kTRUE);
295 if (!mlorig) return kFALSE;
296
297 TGeoHMatrix delta = *mt;
298 delta.MultiplyLeft(ml);
299 delta.MultiplyLeft(&(mlorig->Inverse()));
300 delta.MultiplyLeft(&(mt->Inverse()));
301
302 Double_t xyzorig[3] = {fX, fY, fZ};
303 Double_t xyz[3] = {0, 0, 0};
304 delta.LocalToMaster(xyzorig,xyz);
305 fX = xyz[0]; fY = xyz[1]; fZ = xyz[2];
306 fIsMisaligned = kTRUE;
307 return kTRUE;
308}
309
310//______________________________________________________________________________
311TGeoHMatrix* AliCluster::GetMatrix(Bool_t original) const
312{
313 // Get the matrix which transforms from the
314 // local TGeo alignable volume c.s. to the global one.
315 // In case the cluster was already misaligned, get the
316 // ideal matrix from TGeo. The option 'original'
317 // can be used to force the calculation of the ideal
318 // matrix.
319 if (!fIsMisaligned && (original == kFALSE)) {
b63e594f 320 return AliGeomManager::GetMatrix(fVolumeId);
75fb37cc 321 }
322 else {
b63e594f 323 return AliGeomManager::GetOrigGlobalMatrix(fVolumeId);
75fb37cc 324 }
325}
326
327//______________________________________________________________________________
328const TGeoHMatrix* AliCluster::GetTracking2LocalMatrix() const
329{
330 // Get the matrix which is stored with the PN entries in TGeo.
331 // The matrix makes the transformation from the tracking c.s. to
559157f8 332 // the local one.
b63e594f 333 return AliGeomManager::GetTracking2LocalMatrix(fVolumeId);
75fb37cc 334}
335