]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliClusterTGeo.cxx
Bit added to indicate if this track was used to fit the primary vertex.
[u/mrichter/AliRoot.git] / STEER / AliClusterTGeo.cxx
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 //-------------------------------------------------------------------------
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
24 // classes.
25 //
26 // cvetan.cheshkov@cern.ch & jouri.belikov@cern.ch    5/3/2007
27 //-------------------------------------------------------------------------
28
29 #include <TGeoManager.h>
30 #include <TGeoMatrix.h>
31 #include <TGeoPhysicalNode.h>
32
33 #include "AliClusterTGeo.h"
34 #include "AliLog.h"
35 #include "AliAlignObj.h"
36
37 ClassImp(AliClusterTGeo)
38
39 //______________________________________________________________________________
40 AliClusterTGeo::AliClusterTGeo():
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
52   fTracks[0]=fTracks[1]=fTracks[2]=-3141593; 
53 }
54
55 //______________________________________________________________________________
56 AliClusterTGeo::AliClusterTGeo(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)
70 {
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 //______________________________________________________________________________
82 AliClusterTGeo::AliClusterTGeo(const AliClusterTGeo& cluster):
83   TObject(cluster),
84   fX(cluster.fX),
85   fY(cluster.fY),
86   fZ(cluster.fZ),
87   fSigmaY2(cluster.fSigmaY2),
88   fSigmaZ2(cluster.fSigmaZ2),
89   fSigmaYZ(cluster.fSigmaYZ),
90   fVolumeId(cluster.fVolumeId),
91   fIsMisaligned(cluster.fIsMisaligned)
92 {
93   // Copy constructor
94   fTracks[0] = cluster.fTracks[0];
95   fTracks[1] = cluster.fTracks[1];
96   fTracks[2] = cluster.fTracks[2];
97 }
98
99 //______________________________________________________________________________
100 AliClusterTGeo & AliClusterTGeo::operator=(const AliClusterTGeo& cluster)
101 {
102   // Assignment operator
103
104   if(&cluster == this) return *this;
105
106   fX = cluster.fX;
107   fY = cluster.fY;
108   fZ = cluster.fZ;
109   fSigmaY2 = cluster.fSigmaY2;
110   fSigmaZ2 = cluster.fSigmaZ2;
111   fSigmaYZ = cluster.fSigmaYZ;
112   fVolumeId = cluster.fVolumeId;
113   fIsMisaligned = cluster.fIsMisaligned;
114
115   fTracks[0] = cluster.fTracks[0];
116   fTracks[1] = cluster.fTracks[1];
117   fTracks[2] = cluster.fTracks[2];
118
119   return *this;
120 }
121
122 //______________________________________________________________________________
123 Bool_t AliClusterTGeo::GetGlobalXYZ(Float_t xyz[3]) const
124 {
125   // Get the global coordinates of the cluster
126   // All the needed information is taken only
127   // from TGeo.
128
129   xyz[0] = xyz[1] = xyz[2] = 0;
130
131   if (!gGeoManager || !gGeoManager->IsClosed()) {
132     AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
133     return kFALSE;
134   }
135
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);
141
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];
147   return kTRUE;
148 }
149
150 //______________________________________________________________________________
151 Bool_t AliClusterTGeo::GetGlobalCov(Float_t cov[6]) const
152 {
153   // Get the global covariance matrix of the cluster coordinates
154   // All the needed information is taken only
155   // from TGeo.
156   for (Int_t i = 0; i < 6; i++) cov[i] = 0;
157
158   if (!gGeoManager || !gGeoManager->IsClosed()) {
159     AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
160     return kFALSE;
161   }
162
163   const TGeoHMatrix *mt = GetTracking2LocalMatrix();
164   if (!mt) return kFALSE;
165
166   TGeoHMatrix *ml = GetMatrix();
167   if (!ml) return kFALSE;
168
169   TGeoHMatrix m;
170   Double_t tcov[9] = { 0, 0, 0, 0, fSigmaY2, fSigmaYZ, 0, fSigmaYZ, fSigmaZ2 };
171   m.SetRotation(tcov);
172   m.Multiply(&mt->Inverse());
173   m.Multiply(&ml->Inverse());
174   m.MultiplyLeft(mt);
175   m.MultiplyLeft(ml);
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];
179   cov[5] = ncov[8];
180
181   return kTRUE;
182 }
183
184 //______________________________________________________________________________
185 Bool_t AliClusterTGeo::GetXRefPlane(Float_t &xref) const
186 {
187   // Get the distance between the origin and the ref.plane.
188   // All the needed information is taken only
189   // from TGeo.
190   xref = 0;
191
192   const TGeoHMatrix *mt = GetTracking2LocalMatrix();
193   if (!mt) return kFALSE;
194
195   TGeoHMatrix *ml = GetMatrix();
196   if (!ml) return kFALSE;
197
198   TGeoHMatrix m = *mt;
199   m.MultiplyLeft(ml);
200
201   xref = (m.Inverse()).GetTranslation()[0];
202   return kTRUE;
203 }
204
205 //______________________________________________________________________________
206 Bool_t AliClusterTGeo::Misalign()
207 {
208   // ...
209   // All the needed information is taken only
210   // from TGeo.
211   if (!gGeoManager || !gGeoManager->IsClosed()) {
212     AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
213     return kFALSE;
214   }
215
216   if (fIsMisaligned) {
217     AliError("The cluster was already misaligned!");
218     return kFALSE;
219   }
220
221   const TGeoHMatrix *mt = GetTracking2LocalMatrix();
222   if (!mt) return kFALSE;
223
224   TGeoHMatrix *ml = GetMatrix();
225   if (!ml) return kFALSE;
226
227   TGeoHMatrix *mlorig = GetMatrix(kTRUE);
228   if (!mlorig) return kFALSE;
229
230   TGeoHMatrix delta = *mt;
231   delta.MultiplyLeft(ml);
232   delta.MultiplyLeft(&(mlorig->Inverse()));
233   delta.MultiplyLeft(&(mt->Inverse()));
234
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;
240   return kTRUE;
241 }
242
243 //______________________________________________________________________________
244 TGeoHMatrix* AliClusterTGeo::GetMatrix(Bool_t original) const
245 {
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
251   // matrix.
252   if (!fIsMisaligned && (original == kFALSE)) {
253     TGeoPNEntry *pne = GetPNEntry();
254     if (!pne) return NULL;
255
256     TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
257     if (pnode) return pnode->GetMatrix();
258
259     const char* path = pne->GetTitle();
260     if (!gGeoManager->cd(path)) {
261       AliError(Form("Volume path %s not valid!",path));
262       return NULL;
263     }
264     return gGeoManager->GetCurrentMatrix();
265   }
266   else {
267     const char* symname = AliAlignObj::SymName(fVolumeId);
268     if (!symname) return NULL;
269
270     static TGeoHMatrix m;
271     if (AliAlignObj::GetOrigGlobalMatrix(symname,m))
272       return &m;
273     else
274       return NULL;
275   }
276 }
277
278 //______________________________________________________________________________
279 const TGeoHMatrix* AliClusterTGeo::GetTracking2LocalMatrix() const
280 {
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
283   // global one.
284   TGeoPNEntry *pne = GetPNEntry();
285   if (!pne) return NULL;
286
287   const TGeoHMatrix *m = pne->GetMatrix();
288   if (!m)
289     AliError(Form("TGeoPNEntry (%s) contains no matrix !",pne->GetName()));
290
291   return m;
292 }
293
294 //______________________________________________________________________________
295 TGeoPNEntry* AliClusterTGeo::GetPNEntry() const
296 {
297   // Get a pointer to the physical node entry
298   // corresponding to the alignable volume to
299   // which the cluster belongs
300
301   if (!gGeoManager || !gGeoManager->IsClosed()) {
302     AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
303     return NULL;
304   }
305
306   const char* symname = AliAlignObj::SymName(fVolumeId);
307   if (!symname) return NULL;
308
309   TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
310   if (!pne)
311     AliError(Form("The symbolic volume name %s does not correspond to a physical entry!",
312                   symname));
313   return pne;
314 }