1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-------------------------------------------------------------------------
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
26 // cvetan.cheshkov@cern.ch & jouri.belikov@cern.ch 5/3/2007
27 //-------------------------------------------------------------------------
29 #include <TGeoManager.h>
30 #include <TGeoMatrix.h>
31 #include <TGeoPhysicalNode.h>
33 #include "AliCluster.h"
35 #include "AliAlignObj.h"
39 //______________________________________________________________________________
40 AliCluster::AliCluster():
51 // Default constructor
52 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
55 //______________________________________________________________________________
56 AliCluster::AliCluster(UShort_t volId,
78 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
81 //______________________________________________________________________________
82 AliCluster::AliCluster(UShort_t volId,
83 Float_t x, Float_t y, Float_t z,
84 Float_t sy2, Float_t sz2, Float_t syz,
103 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
106 //______________________________________________________________________________
107 AliCluster::AliCluster(const AliCluster& cluster):
112 fSigmaY2(cluster.fSigmaY2),
113 fSigmaZ2(cluster.fSigmaZ2),
114 fSigmaYZ(cluster.fSigmaYZ),
115 fVolumeId(cluster.fVolumeId),
116 fIsMisaligned(cluster.fIsMisaligned)
119 fTracks[0] = cluster.fTracks[0];
120 fTracks[1] = cluster.fTracks[1];
121 fTracks[2] = cluster.fTracks[2];
124 //______________________________________________________________________________
125 AliCluster & AliCluster::operator=(const AliCluster& cluster)
127 // Assignment operator
129 if(&cluster == this) return *this;
134 fSigmaY2 = cluster.fSigmaY2;
135 fSigmaZ2 = cluster.fSigmaZ2;
136 fSigmaYZ = cluster.fSigmaYZ;
137 fVolumeId = cluster.fVolumeId;
138 fIsMisaligned = cluster.fIsMisaligned;
140 fTracks[0] = cluster.fTracks[0];
141 fTracks[1] = cluster.fTracks[1];
142 fTracks[2] = cluster.fTracks[2];
147 //______________________________________________________________________________
148 void AliCluster::Print(Option_t* /*option*/) const
150 // Print cluster information.
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);
156 printf(" global_pos=(%.4f, %.4f, %.4f)\n", g[0], g[1], g[2]);
160 //______________________________________________________________________________
161 Bool_t AliCluster::GetGlobalXYZ(Float_t xyz[3]) const
163 // Get the global coordinates of the cluster
164 // All the needed information is taken only
167 xyz[0] = xyz[1] = xyz[2] = 0;
169 if (!gGeoManager || !gGeoManager->IsClosed()) {
170 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
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);
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];
188 //______________________________________________________________________________
189 Bool_t AliCluster::GetGlobalCov(Float_t cov[6]) const
191 // Get the global covariance matrix of the cluster coordinates
192 // All the needed information is taken only
194 for (Int_t i = 0; i < 6; i++) cov[i] = 0;
196 if (!gGeoManager || !gGeoManager->IsClosed()) {
197 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
201 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
202 if (!mt) return kFALSE;
204 TGeoHMatrix *ml = GetMatrix();
205 if (!ml) return kFALSE;
208 Double_t tcov[9] = { 0, 0, 0, 0, fSigmaY2, fSigmaYZ, 0, fSigmaYZ, fSigmaZ2 };
210 m.Multiply(&mt->Inverse());
211 m.Multiply(&ml->Inverse());
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];
222 //______________________________________________________________________________
223 Bool_t AliCluster::GetXRefPlane(Float_t &xref) const
225 // Get the distance between the origin and the ref.plane.
226 // All the needed information is taken only
230 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
231 if (!mt) return kFALSE;
233 TGeoHMatrix *ml = GetMatrix();
234 if (!ml) return kFALSE;
239 xref = (m.Inverse()).GetTranslation()[0];
243 //______________________________________________________________________________
244 Bool_t AliCluster::Misalign()
247 // All the needed information is taken only
249 if (!gGeoManager || !gGeoManager->IsClosed()) {
250 AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
255 AliError("The cluster was already misaligned!");
259 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
260 if (!mt) return kFALSE;
262 TGeoHMatrix *ml = GetMatrix();
263 if (!ml) return kFALSE;
265 TGeoHMatrix *mlorig = GetMatrix(kTRUE);
266 if (!mlorig) return kFALSE;
268 TGeoHMatrix delta = *mt;
269 delta.MultiplyLeft(ml);
270 delta.MultiplyLeft(&(mlorig->Inverse()));
271 delta.MultiplyLeft(&(mt->Inverse()));
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;
281 //______________________________________________________________________________
282 TGeoHMatrix* AliCluster::GetMatrix(Bool_t original) const
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
290 if (!fIsMisaligned && (original == kFALSE)) {
291 return AliGeomManager::GetMatrix(fVolumeId);
294 return AliGeomManager::GetOrigGlobalMatrix(fVolumeId);
298 //______________________________________________________________________________
299 const TGeoHMatrix* AliCluster::GetTracking2LocalMatrix() const
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
304 return AliGeomManager::GetTracking2LocalMatrix(fVolumeId);