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>
34 #include "AliCluster.h"
36 #include "AliAlignObj.h"
40 //______________________________________________________________________________
41 AliCluster::AliCluster():
52 // Default constructor
53 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
56 //______________________________________________________________________________
57 AliCluster::AliCluster(UShort_t volId,
79 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
82 //______________________________________________________________________________
83 AliCluster::AliCluster(UShort_t volId,
84 Float_t x, Float_t y, Float_t z,
85 Float_t sy2, Float_t sz2, Float_t syz,
104 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
107 //______________________________________________________________________________
108 AliCluster::AliCluster(const AliCluster& cluster):
113 fSigmaY2(cluster.fSigmaY2),
114 fSigmaZ2(cluster.fSigmaZ2),
115 fSigmaYZ(cluster.fSigmaYZ),
116 fVolumeId(cluster.fVolumeId),
117 fIsMisaligned(cluster.fIsMisaligned)
120 fTracks[0] = cluster.fTracks[0];
121 fTracks[1] = cluster.fTracks[1];
122 fTracks[2] = cluster.fTracks[2];
125 //______________________________________________________________________________
126 AliCluster & AliCluster::operator=(const AliCluster& cluster)
128 // Assignment operator
130 if(&cluster == this) return *this;
135 fSigmaY2 = cluster.fSigmaY2;
136 fSigmaZ2 = cluster.fSigmaZ2;
137 fSigmaYZ = cluster.fSigmaYZ;
138 fVolumeId = cluster.fVolumeId;
139 fIsMisaligned = cluster.fIsMisaligned;
141 fTracks[0] = cluster.fTracks[0];
142 fTracks[1] = cluster.fTracks[1];
143 fTracks[2] = cluster.fTracks[2];
148 //______________________________________________________________________________
149 void AliCluster::Print(Option_t* /*option*/) const
151 // Print cluster information.
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);
157 printf(" global_pos=(%.4f, %.4f, %.4f)\n", g[0], g[1], g[2]);
161 //______________________________________________________________________________
162 Bool_t AliCluster::GetGlobalXYZ(Float_t xyz[3]) const
164 // Get the global coordinates of the cluster
165 // All the needed information is taken only
168 xyz[0] = xyz[1] = xyz[2] = 0;
170 if (!gGeoManager || !gGeoManager->IsClosed()) {
171 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
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);
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];
189 //______________________________________________________________________________
190 Bool_t AliCluster::GetGlobalCov(Float_t cov[6]) const
192 // Get the global covariance matrix of the cluster coordinates
193 // All the needed information is taken only
195 for (Int_t i = 0; i < 6; i++) cov[i] = 0;
197 if (!gGeoManager || !gGeoManager->IsClosed()) {
198 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
202 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
203 if (!mt) return kFALSE;
205 TGeoHMatrix *ml = GetMatrix();
206 if (!ml) return kFALSE;
209 Double_t tcov[9] = { 0, 0, 0, 0, fSigmaY2, fSigmaYZ, 0, fSigmaYZ, fSigmaZ2 };
211 m.Multiply(&mt->Inverse());
212 m.Multiply(&ml->Inverse());
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];
223 //______________________________________________________________________________
224 Bool_t AliCluster::GetXRefPlane(Float_t &xref) const
226 // Get the distance between the origin and the ref.plane.
227 // All the needed information is taken only
231 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
232 if (!mt) return kFALSE;
234 TGeoHMatrix *ml = GetMatrix();
235 if (!ml) return kFALSE;
240 xref = -(m.Inverse()).GetTranslation()[0];
244 //______________________________________________________________________________
245 Bool_t AliCluster::GetXAlphaRefPlane(Float_t &x, Float_t &alpha) const
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
251 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
252 if (!mt) return kFALSE;
254 const TGeoHMatrix *ml = GetMatrix();
255 if (!ml) return kFALSE;
259 const Double_t txyz[3]={0.}; Double_t xyz[3]={0.};
260 m.LocalToMaster(txyz,xyz);
262 x=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
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();
272 //______________________________________________________________________________
273 Bool_t AliCluster::Misalign()
276 // All the needed information is taken only
278 if (!gGeoManager || !gGeoManager->IsClosed()) {
279 AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
284 AliError("The cluster was already misaligned!");
288 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
289 if (!mt) return kFALSE;
291 TGeoHMatrix *ml = GetMatrix();
292 if (!ml) return kFALSE;
294 TGeoHMatrix *mlorig = GetMatrix(kTRUE);
295 if (!mlorig) return kFALSE;
297 TGeoHMatrix delta = *mt;
298 delta.MultiplyLeft(ml);
299 delta.MultiplyLeft(&(mlorig->Inverse()));
300 delta.MultiplyLeft(&(mt->Inverse()));
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;
310 //______________________________________________________________________________
311 TGeoHMatrix* AliCluster::GetMatrix(Bool_t original) const
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
319 if (!fIsMisaligned && (original == kFALSE)) {
320 return AliGeomManager::GetMatrix(fVolumeId);
323 return AliGeomManager::GetOrigGlobalMatrix(fVolumeId);
327 //______________________________________________________________________________
328 const TGeoHMatrix* AliCluster::GetTracking2LocalMatrix() const
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
333 return AliGeomManager::GetTracking2LocalMatrix(fVolumeId);