Processing SPD Mean Vertex only in PHYSICS runs.
[u/mrichter/AliRoot.git] / 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>
32
87594435 33#include "AliCluster.h"
75fb37cc 34#include "AliLog.h"
35#include "AliAlignObj.h"
87594435 36
37ClassImp(AliCluster)
75fb37cc 38
39//______________________________________________________________________________
40AliCluster::AliCluster():
41 TObject(),
42 fX(0),
43 fY(0),
44 fZ(0),
45 fSigmaY2(0),
46 fSigmaZ2(0),
47 fSigmaYZ(0),
48 fVolumeId(0),
49 fIsMisaligned(kFALSE)
50{
51 // Default constructor
87594435 52 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
87594435 53}
54
75fb37cc 55//______________________________________________________________________________
56AliCluster::AliCluster(UShort_t volId,
57 const Float_t *hit,
58 Float_t x,
59 Float_t sigyz,
60 const Int_t *lab):
61 TObject(),
62 fX(x),
63 fY(hit[0]),
64 fZ(hit[1]),
65 fSigmaY2(hit[2]),
66 fSigmaZ2(hit[3]),
67 fSigmaYZ(sigyz),
68 fVolumeId(volId),
69 fIsMisaligned(kFALSE)
968c248e 70{
75fb37cc 71 // Constructor
72 if (lab) {
73 fTracks[0] = lab[0];
74 fTracks[1] = lab[1];
75 fTracks[2] = lab[2];
76 }
77 else
78 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
79}
80
81//______________________________________________________________________________
82AliCluster::AliCluster(UShort_t volId,
83 Float_t x, Float_t y, Float_t z,
84 Float_t sy2, Float_t sz2, Float_t syz,
85 const Int_t *lab):
86 TObject(),
87 fX(x),
88 fY(y),
89 fZ(z),
90 fSigmaY2(sy2),
91 fSigmaZ2(sz2),
92 fSigmaYZ(syz),
93 fVolumeId(volId),
94 fIsMisaligned(kFALSE)
95{
96 // Constructor
97 if (lab) {
98 fTracks[0] = lab[0];
99 fTracks[1] = lab[1];
100 fTracks[2] = lab[2];
101 }
102 else
103 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
104}
105
106//______________________________________________________________________________
107AliCluster::AliCluster(const AliCluster& cluster):
108 TObject(cluster),
109 fX(cluster.fX),
110 fY(cluster.fY),
111 fZ(cluster.fZ),
112 fSigmaY2(cluster.fSigmaY2),
113 fSigmaZ2(cluster.fSigmaZ2),
114 fSigmaYZ(cluster.fSigmaYZ),
115 fVolumeId(cluster.fVolumeId),
116 fIsMisaligned(cluster.fIsMisaligned)
117{
118 // Copy constructor
119 fTracks[0] = cluster.fTracks[0];
120 fTracks[1] = cluster.fTracks[1];
121 fTracks[2] = cluster.fTracks[2];
122}
123
124//______________________________________________________________________________
125AliCluster & AliCluster::operator=(const AliCluster& cluster)
126{
127 // Assignment operator
128
129 if(&cluster == this) return *this;
130
131 fX = cluster.fX;
132 fY = cluster.fY;
133 fZ = cluster.fZ;
134 fSigmaY2 = cluster.fSigmaY2;
135 fSigmaZ2 = cluster.fSigmaZ2;
136 fSigmaYZ = cluster.fSigmaYZ;
137 fVolumeId = cluster.fVolumeId;
138 fIsMisaligned = cluster.fIsMisaligned;
139
140 fTracks[0] = cluster.fTracks[0];
141 fTracks[1] = cluster.fTracks[1];
142 fTracks[2] = cluster.fTracks[2];
143
144 return *this;
145}
146
147//______________________________________________________________________________
c47d9105 148void AliCluster::Print(Option_t* option) const
149{
150 // Print cluster information.
151
152 printf("AliCluster pos=(%.4f, %.4f, %.4f), s_y2=%f, s_z2=%f, s_yz=%f, vol=%hu\n",
153 fX, fY, fZ, fSigmaY2, fSigmaZ2, fSigmaYZ, fVolumeId);
154 Float_t g[3];
155 if (GetGlobalXYZ(g))
156 printf(" global_pos=(%.4f, %.4f, %.4f)\n", g[0], g[1], g[2]);
157
158}
159
160//______________________________________________________________________________
75fb37cc 161Bool_t AliCluster::GetGlobalXYZ(Float_t xyz[3]) const
162{
163 // Get the global coordinates of the cluster
164 // All the needed information is taken only
165 // from TGeo.
166
167 xyz[0] = xyz[1] = xyz[2] = 0;
168
169 if (!gGeoManager || !gGeoManager->IsClosed()) {
170 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
171 return kFALSE;
172 }
173
174 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
175 if (!mt) return kFALSE;
176 Double_t txyz[3] = {fX, fY, fZ};
177 Double_t lxyz[3] = {0, 0, 0};
178 mt->LocalToMaster(txyz,lxyz);
179
180 TGeoHMatrix *ml = GetMatrix();
181 if (!ml) return kFALSE;
182 Double_t gxyz[3] = {0, 0, 0};
183 ml->LocalToMaster(lxyz,gxyz);
184 xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
185 return kTRUE;
186}
187
188//______________________________________________________________________________
189Bool_t AliCluster::GetGlobalCov(Float_t cov[6]) const
190{
191 // Get the global covariance matrix of the cluster coordinates
192 // All the needed information is taken only
193 // from TGeo.
194 for (Int_t i = 0; i < 6; i++) cov[i] = 0;
195
196 if (!gGeoManager || !gGeoManager->IsClosed()) {
197 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
198 return kFALSE;
199 }
200
201 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
202 if (!mt) return kFALSE;
203
204 TGeoHMatrix *ml = GetMatrix();
205 if (!ml) return kFALSE;
206
207 TGeoHMatrix m;
208 Double_t tcov[9] = { 0, 0, 0, 0, fSigmaY2, fSigmaYZ, 0, fSigmaYZ, fSigmaZ2 };
209 m.SetRotation(tcov);
210 m.Multiply(&mt->Inverse());
211 m.Multiply(&ml->Inverse());
212 m.MultiplyLeft(mt);
213 m.MultiplyLeft(ml);
214 Double_t *ncov = m.GetRotationMatrix();
215 cov[0] = ncov[0]; cov[1] = ncov[1]; cov[2] = ncov[2];
216 cov[3] = ncov[4]; cov[4] = ncov[5];
217 cov[5] = ncov[8];
218
219 return kTRUE;
220}
221
222//______________________________________________________________________________
223Bool_t AliCluster::GetXRefPlane(Float_t &xref) const
224{
225 // Get the distance between the origin and the ref.plane.
226 // All the needed information is taken only
227 // from TGeo.
228 xref = 0;
229
230 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
231 if (!mt) return kFALSE;
232
233 TGeoHMatrix *ml = GetMatrix();
234 if (!ml) return kFALSE;
235
236 TGeoHMatrix m = *mt;
237 m.MultiplyLeft(ml);
238
239 xref = (m.Inverse()).GetTranslation()[0];
240 return kTRUE;
241}
242
243//______________________________________________________________________________
244Bool_t AliCluster::Misalign()
245{
246 // ...
247 // All the needed information is taken only
248 // from TGeo.
249 if (!gGeoManager || !gGeoManager->IsClosed()) {
250 AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
251 return kFALSE;
252 }
253
254 if (fIsMisaligned) {
255 AliError("The cluster was already misaligned!");
256 return kFALSE;
257 }
258
259 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
260 if (!mt) return kFALSE;
261
262 TGeoHMatrix *ml = GetMatrix();
263 if (!ml) return kFALSE;
264
265 TGeoHMatrix *mlorig = GetMatrix(kTRUE);
266 if (!mlorig) return kFALSE;
267
268 TGeoHMatrix delta = *mt;
269 delta.MultiplyLeft(ml);
270 delta.MultiplyLeft(&(mlorig->Inverse()));
271 delta.MultiplyLeft(&(mt->Inverse()));
272
273 Double_t xyzorig[3] = {fX, fY, fZ};
274 Double_t xyz[3] = {0, 0, 0};
275 delta.LocalToMaster(xyzorig,xyz);
276 fX = xyz[0]; fY = xyz[1]; fZ = xyz[2];
277 fIsMisaligned = kTRUE;
278 return kTRUE;
279}
280
281//______________________________________________________________________________
282TGeoHMatrix* AliCluster::GetMatrix(Bool_t original) const
283{
284 // Get the matrix which transforms from the
285 // local TGeo alignable volume c.s. to the global one.
286 // In case the cluster was already misaligned, get the
287 // ideal matrix from TGeo. The option 'original'
288 // can be used to force the calculation of the ideal
289 // matrix.
290 if (!fIsMisaligned && (original == kFALSE)) {
b63e594f 291 return AliGeomManager::GetMatrix(fVolumeId);
75fb37cc 292 }
293 else {
b63e594f 294 return AliGeomManager::GetOrigGlobalMatrix(fVolumeId);
75fb37cc 295 }
296}
297
298//______________________________________________________________________________
299const TGeoHMatrix* AliCluster::GetTracking2LocalMatrix() const
300{
301 // Get the matrix which is stored with the PN entries in TGeo.
302 // The matrix makes the transformation from the tracking c.s. to
559157f8 303 // the local one.
b63e594f 304 return AliGeomManager::GetTracking2LocalMatrix(fVolumeId);
75fb37cc 305}
306