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 //-------------------------------------------------------------------------
17 // Class AliClusterTGeo
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 "AliClusterTGeo.h"
35 #include "AliAlignObj.h"
37 ClassImp(AliClusterTGeo)
39 //______________________________________________________________________________
40 AliClusterTGeo::AliClusterTGeo():
51 // Default constructor
52 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
55 //______________________________________________________________________________
56 AliClusterTGeo::AliClusterTGeo(UShort_t volId,
78 fTracks[0]=fTracks[1]=fTracks[2]=-3141593;
81 //______________________________________________________________________________
82 AliClusterTGeo::AliClusterTGeo(const AliClusterTGeo& cluster):
87 fSigmaY2(cluster.fSigmaY2),
88 fSigmaZ2(cluster.fSigmaZ2),
89 fSigmaYZ(cluster.fSigmaYZ),
90 fVolumeId(cluster.fVolumeId),
91 fIsMisaligned(cluster.fIsMisaligned)
94 fTracks[0] = cluster.fTracks[0];
95 fTracks[1] = cluster.fTracks[1];
96 fTracks[2] = cluster.fTracks[2];
99 //______________________________________________________________________________
100 AliClusterTGeo & AliClusterTGeo::operator=(const AliClusterTGeo& cluster)
102 // Assignment operator
104 if(&cluster == this) return *this;
109 fSigmaY2 = cluster.fSigmaY2;
110 fSigmaZ2 = cluster.fSigmaZ2;
111 fSigmaYZ = cluster.fSigmaYZ;
112 fVolumeId = cluster.fVolumeId;
113 fIsMisaligned = cluster.fIsMisaligned;
115 fTracks[0] = cluster.fTracks[0];
116 fTracks[1] = cluster.fTracks[1];
117 fTracks[2] = cluster.fTracks[2];
122 //______________________________________________________________________________
123 Bool_t AliClusterTGeo::GetGlobalXYZ(Float_t xyz[3]) const
125 // Get the global coordinates of the cluster
126 // All the needed information is taken only
129 xyz[0] = xyz[1] = xyz[2] = 0;
131 if (!gGeoManager || !gGeoManager->IsClosed()) {
132 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
136 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
137 if (!mt) return kFALSE;
138 Double_t txyz[3] = {fX, fY, fZ};
139 Double_t lxyz[3] = {0, 0, 0};
140 mt->LocalToMaster(txyz,lxyz);
142 TGeoHMatrix *ml = GetMatrix();
143 if (!ml) return kFALSE;
144 Double_t gxyz[3] = {0, 0, 0};
145 ml->LocalToMaster(lxyz,gxyz);
146 xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
150 //______________________________________________________________________________
151 Bool_t AliClusterTGeo::GetGlobalCov(Float_t cov[6]) const
153 // Get the global covariance matrix of the cluster coordinates
154 // All the needed information is taken only
156 for (Int_t i = 0; i < 6; i++) cov[i] = 0;
158 if (!gGeoManager || !gGeoManager->IsClosed()) {
159 AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
163 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
164 if (!mt) return kFALSE;
166 TGeoHMatrix *ml = GetMatrix();
167 if (!ml) return kFALSE;
170 Double_t tcov[9] = { 0, 0, 0, 0, fSigmaY2, fSigmaYZ, 0, fSigmaYZ, fSigmaZ2 };
172 m.Multiply(&mt->Inverse());
173 m.Multiply(&ml->Inverse());
176 Double_t *ncov = m.GetRotationMatrix();
177 cov[0] = ncov[0]; cov[1] = ncov[1]; cov[2] = ncov[2];
178 cov[3] = ncov[4]; cov[4] = ncov[5];
184 //______________________________________________________________________________
185 Bool_t AliClusterTGeo::GetXRefPlane(Float_t &xref) const
187 // Get the distance between the origin and the ref.plane.
188 // All the needed information is taken only
192 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
193 if (!mt) return kFALSE;
195 TGeoHMatrix *ml = GetMatrix();
196 if (!ml) return kFALSE;
201 xref = (m.Inverse()).GetTranslation()[0];
205 //______________________________________________________________________________
206 Bool_t AliClusterTGeo::Misalign()
209 // All the needed information is taken only
211 if (!gGeoManager || !gGeoManager->IsClosed()) {
212 AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
217 AliError("The cluster was already misaligned!");
221 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
222 if (!mt) return kFALSE;
224 TGeoHMatrix *ml = GetMatrix();
225 if (!ml) return kFALSE;
227 TGeoHMatrix *mlorig = GetMatrix(kTRUE);
228 if (!mlorig) return kFALSE;
230 TGeoHMatrix delta = *mt;
231 delta.MultiplyLeft(ml);
232 delta.MultiplyLeft(&(mlorig->Inverse()));
233 delta.MultiplyLeft(&(mt->Inverse()));
235 Double_t xyzorig[3] = {fX, fY, fZ};
236 Double_t xyz[3] = {0, 0, 0};
237 delta.LocalToMaster(xyzorig,xyz);
238 fX = xyz[0]; fY = xyz[1]; fZ = xyz[2];
239 fIsMisaligned = kTRUE;
243 //______________________________________________________________________________
244 TGeoHMatrix* AliClusterTGeo::GetMatrix(Bool_t original) const
246 // Get the matrix which transforms from the
247 // local TGeo alignable volume c.s. to the global one.
248 // In case the cluster was already misaligned, get the
249 // ideal matrix from TGeo. The option 'original'
250 // can be used to force the calculation of the ideal
252 if (!fIsMisaligned && (original == kFALSE)) {
253 TGeoPNEntry *pne = GetPNEntry();
254 if (!pne) return NULL;
256 TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
257 if (pnode) return pnode->GetMatrix();
259 const char* path = pne->GetTitle();
260 if (!gGeoManager->cd(path)) {
261 AliError(Form("Volume path %s not valid!",path));
264 return gGeoManager->GetCurrentMatrix();
267 const char* symname = AliAlignObj::SymName(fVolumeId);
268 if (!symname) return NULL;
270 static TGeoHMatrix m;
271 if (AliAlignObj::GetOrigGlobalMatrix(symname,m))
278 //______________________________________________________________________________
279 const TGeoHMatrix* AliClusterTGeo::GetTracking2LocalMatrix() const
281 // Get the matrix which is stored with the PN entries in TGeo.
282 // The matrix makes the transformation from the tracking c.s. to
284 TGeoPNEntry *pne = GetPNEntry();
285 if (!pne) return NULL;
287 const TGeoHMatrix *m = pne->GetMatrix();
289 AliError(Form("TGeoPNEntry (%s) contains no matrix !",pne->GetName()));
294 //______________________________________________________________________________
295 TGeoPNEntry* AliClusterTGeo::GetPNEntry() const
297 // Get a pointer to the physical node entry
298 // corresponding to the alignable volume to
299 // which the cluster belongs
301 if (!gGeoManager || !gGeoManager->IsClosed()) {
302 AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
306 const char* symname = AliAlignObj::SymName(fVolumeId);
307 if (!symname) return NULL;
309 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
311 AliError(Form("The symbolic volume name %s does not correspond to a physical entry!",