ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

//-------------------------------------------------------------------------
//                         Class AliCluster
// This is the future base for managing the clusters in barrel detectors.
// It is fully interfaced with the ROOT geometrical modeller TGeo.
// Each cluster contains XYZ coordinates in the local tracking c.s. and
// the unique ID of the sensitive detector element which continas the
// cluster. The coordinates in global c.s. are computed using the interface
// to TGeo and will be not overwritten by the derived sub-detector cluster
// classes.
//
// cvetan.cheshkov@cern.ch & jouri.belikov@cern.ch    5/3/2007
//-------------------------------------------------------------------------

#include <TGeoManager.h>
#include <TGeoMatrix.h>
#include <TGeoPhysicalNode.h>
#include <TMath.h>

#include "AliCluster.h"
#include "AliLog.h"
#include "AliAlignObj.h"

ClassImp(AliCluster)

//______________________________________________________________________________
AliCluster::AliCluster():
  TObject(),
  fX(0),
  fY(0),
  fZ(0),
  fSigmaY2(0),
  fSigmaZ2(0),
  fSigmaYZ(0),
  fVolumeId(0),
  fIsMisaligned(kFALSE)
{
  // Default constructor
  fTracks[0]=fTracks[1]=fTracks[2]=-3141593; 
}

//______________________________________________________________________________
AliCluster::AliCluster(UShort_t volId,
			       const Float_t *hit,
			       Float_t x,
			       Float_t sigyz,
			       const Int_t *lab):
  TObject(),
  fX(x),
  fY(hit[0]),
  fZ(hit[1]),
  fSigmaY2(hit[2]),
  fSigmaZ2(hit[3]),
  fSigmaYZ(sigyz),
  fVolumeId(volId),
  fIsMisaligned(kFALSE)
{
  // Constructor
  if (lab) {
    fTracks[0] = lab[0];
    fTracks[1] = lab[1];
    fTracks[2] = lab[2];
  }
  else
    fTracks[0]=fTracks[1]=fTracks[2]=-3141593; 
}

//______________________________________________________________________________
AliCluster::AliCluster(UShort_t volId,
			       Float_t x, Float_t y, Float_t z,
			       Float_t sy2, Float_t sz2, Float_t syz,
			       const Int_t *lab):
  TObject(),
  fX(x),
  fY(y),
  fZ(z),
  fSigmaY2(sy2),
  fSigmaZ2(sz2),
  fSigmaYZ(syz),
  fVolumeId(volId),
  fIsMisaligned(kFALSE)
{
  // Constructor
  if (lab) {
    fTracks[0] = lab[0];
    fTracks[1] = lab[1];
    fTracks[2] = lab[2];
  }
  else
    fTracks[0]=fTracks[1]=fTracks[2]=-3141593; 
}

//______________________________________________________________________________
AliCluster::AliCluster(const AliCluster& cluster):
  TObject(cluster),
  fX(cluster.fX),
  fY(cluster.fY),
  fZ(cluster.fZ),
  fSigmaY2(cluster.fSigmaY2),
  fSigmaZ2(cluster.fSigmaZ2),
  fSigmaYZ(cluster.fSigmaYZ),
  fVolumeId(cluster.fVolumeId),
  fIsMisaligned(cluster.fIsMisaligned)
{
  // Copy constructor
  fTracks[0] = cluster.fTracks[0];
  fTracks[1] = cluster.fTracks[1];
  fTracks[2] = cluster.fTracks[2];
}

//______________________________________________________________________________
AliCluster & AliCluster::operator=(const AliCluster& cluster)
{
  // Assignment operator

  if(&cluster == this) return *this;

  fX = cluster.fX;
  fY = cluster.fY;
  fZ = cluster.fZ;
  fSigmaY2 = cluster.fSigmaY2;
  fSigmaZ2 = cluster.fSigmaZ2;
  fSigmaYZ = cluster.fSigmaYZ;
  fVolumeId = cluster.fVolumeId;
  fIsMisaligned = cluster.fIsMisaligned;

  fTracks[0] = cluster.fTracks[0];
  fTracks[1] = cluster.fTracks[1];
  fTracks[2] = cluster.fTracks[2];

  return *this;
}

//______________________________________________________________________________
void AliCluster::Print(Option_t* /*option*/) const
{
  // Print cluster information.
  
  printf("AliCluster pos=(%.4f, %.4f, %.4f), s_y2=%f, s_z2=%f, s_yz=%f, vol=%hu\n",
         fX, fY, fZ, fSigmaY2, fSigmaZ2, fSigmaYZ, fVolumeId);
  Float_t g[3];
  if (GetGlobalXYZ(g))
    printf("    global_pos=(%.4f, %.4f, %.4f)\n", g[0], g[1], g[2]);

}

//______________________________________________________________________________
Bool_t AliCluster::GetGlobalXYZ(Float_t xyz[3]) const
{
  // Get the global coordinates of the cluster
  // All the needed information is taken only
  // from TGeo.

  xyz[0] = xyz[1] = xyz[2] = 0;

  if (!gGeoManager || !gGeoManager->IsClosed()) {
    AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
    return kFALSE;
  }

  const TGeoHMatrix *mt = GetTracking2LocalMatrix();
  if (!mt) return kFALSE;
  Double_t txyz[3] = {fX, fY, fZ};
  Double_t lxyz[3] = {0, 0, 0};
  mt->LocalToMaster(txyz,lxyz);

  TGeoHMatrix *ml = GetMatrix();
  if (!ml) return kFALSE;
  Double_t gxyz[3] = {0, 0, 0};
  ml->LocalToMaster(lxyz,gxyz);
  xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
  return kTRUE;
}

//______________________________________________________________________________
Bool_t AliCluster::GetGlobalCov(Float_t cov[6]) const
{
  // Get the global covariance matrix of the cluster coordinates
  // All the needed information is taken only
  // from TGeo.
  for (Int_t i = 0; i < 6; i++) cov[i] = 0;

  if (!gGeoManager || !gGeoManager->IsClosed()) {
    AliError("Can't get the global coordinates! gGeoManager doesn't exist or it is still opened!");
    return kFALSE;
  }

  const TGeoHMatrix *mt = GetTracking2LocalMatrix();
  if (!mt) return kFALSE;

  TGeoHMatrix *ml = GetMatrix();
  if (!ml) return kFALSE;

  TGeoHMatrix m;
  Double_t tcov[9] = { 0, 0, 0, 0, fSigmaY2, fSigmaYZ, 0, fSigmaYZ, fSigmaZ2 };
  m.SetRotation(tcov);
  m.Multiply(&mt->Inverse());
  m.Multiply(&ml->Inverse());
  m.MultiplyLeft(mt);
  m.MultiplyLeft(ml);
  Double_t *ncov = m.GetRotationMatrix();
  cov[0] = ncov[0]; cov[1] = ncov[1]; cov[2] = ncov[2];
  cov[3] = ncov[4]; cov[4] = ncov[5];
  cov[5] = ncov[8];

  return kTRUE;
}

//______________________________________________________________________________
Bool_t AliCluster::GetXRefPlane(Float_t &xref) const
{
  // Get the distance between the origin and the ref.plane.
  // All the needed information is taken only
  // from TGeo.
  xref = 0;

  const TGeoHMatrix *mt = GetTracking2LocalMatrix();
  if (!mt) return kFALSE;

  TGeoHMatrix *ml = GetMatrix();
  if (!ml) return kFALSE;

  TGeoHMatrix m = *mt;
  m.MultiplyLeft(ml);

  xref = -(m.Inverse()).GetTranslation()[0];
  return kTRUE;
}

//______________________________________________________________________________
Bool_t AliCluster::GetXAlphaRefPlane(Float_t &x, Float_t &alpha) const
{
  // Get the distance between the origin and the ref. plane together with
  // the rotation anlge of the ref. plane.
  // All the needed information is taken only
  // from TGeo.
  const TGeoHMatrix *mt = GetTracking2LocalMatrix();
  if (!mt) return kFALSE;

  const TGeoHMatrix *ml = GetMatrix();
  if (!ml) return kFALSE;

  TGeoHMatrix m(*ml);
  m.Multiply(mt);
  const Double_t txyz[3]={0.}; Double_t xyz[3]={0.};
  m.LocalToMaster(txyz,xyz);
    
  x=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
    
  Double_t a=TMath::ATan2(xyz[1],xyz[0]);
  if (a<0) a+=TMath::TwoPi();
  else if (a>=TMath::TwoPi()) a-=TMath::TwoPi();
  alpha=a;

  return kTRUE;
}

//______________________________________________________________________________
Bool_t AliCluster::Misalign()
{
  // ...
  // All the needed information is taken only
  // from TGeo.
  if (!gGeoManager || !gGeoManager->IsClosed()) {
    AliError("Can't get the PN entry! gGeoManager doesn't exist or it is still opened!");
    return kFALSE;
  }

  if (fIsMisaligned) {
    AliError("The cluster was already misaligned!");
    return kFALSE;
  }

  const TGeoHMatrix *mt = GetTracking2LocalMatrix();
  if (!mt) return kFALSE;

  TGeoHMatrix *ml = GetMatrix();
  if (!ml) return kFALSE;

  TGeoHMatrix *mlorig = GetMatrix(kTRUE);
  if (!mlorig) return kFALSE;

  TGeoHMatrix delta = *mt;
  delta.MultiplyLeft(ml);
  delta.MultiplyLeft(&(mlorig->Inverse()));
  delta.MultiplyLeft(&(mt->Inverse()));

  Double_t xyzorig[3] = {fX, fY, fZ};
  Double_t xyz[3] = {0, 0, 0};
  delta.LocalToMaster(xyzorig,xyz);
  fX = xyz[0]; fY = xyz[1]; fZ = xyz[2];
  fIsMisaligned = kTRUE;
  return kTRUE;
}

//______________________________________________________________________________
TGeoHMatrix* AliCluster::GetMatrix(Bool_t original) const
{
  // Get the matrix which transforms from the
  // local TGeo alignable volume c.s. to the global one.
  // In case the cluster was already misaligned, get the
  // ideal matrix from TGeo. The option 'original'
  // can be used to force the calculation of the ideal
  // matrix.
  if (!fIsMisaligned && (original == kFALSE)) {
    return AliGeomManager::GetMatrix(fVolumeId);
  }
  else {
    return AliGeomManager::GetOrigGlobalMatrix(fVolumeId);
  }
}

//______________________________________________________________________________
const TGeoHMatrix* AliCluster::GetTracking2LocalMatrix() const
{
  // Get the matrix which is stored with the PN entries in TGeo.
  // The matrix makes the transformation from the tracking c.s. to
  // the local one.
  return AliGeomManager::GetTracking2LocalMatrix(fVolumeId);
}

 AliCluster.cxx:1
 AliCluster.cxx:2
 AliCluster.cxx:3
 AliCluster.cxx:4
 AliCluster.cxx:5
 AliCluster.cxx:6
 AliCluster.cxx:7
 AliCluster.cxx:8
 AliCluster.cxx:9
 AliCluster.cxx:10
 AliCluster.cxx:11
 AliCluster.cxx:12
 AliCluster.cxx:13
 AliCluster.cxx:14
 AliCluster.cxx:15
 AliCluster.cxx:16
 AliCluster.cxx:17
 AliCluster.cxx:18
 AliCluster.cxx:19
 AliCluster.cxx:20
 AliCluster.cxx:21
 AliCluster.cxx:22
 AliCluster.cxx:23
 AliCluster.cxx:24
 AliCluster.cxx:25
 AliCluster.cxx:26
 AliCluster.cxx:27
 AliCluster.cxx:28
 AliCluster.cxx:29
 AliCluster.cxx:30
 AliCluster.cxx:31
 AliCluster.cxx:32
 AliCluster.cxx:33
 AliCluster.cxx:34
 AliCluster.cxx:35
 AliCluster.cxx:36
 AliCluster.cxx:37
 AliCluster.cxx:38
 AliCluster.cxx:39
 AliCluster.cxx:40
 AliCluster.cxx:41
 AliCluster.cxx:42
 AliCluster.cxx:43
 AliCluster.cxx:44
 AliCluster.cxx:45
 AliCluster.cxx:46
 AliCluster.cxx:47
 AliCluster.cxx:48
 AliCluster.cxx:49
 AliCluster.cxx:50
 AliCluster.cxx:51
 AliCluster.cxx:52
 AliCluster.cxx:53
 AliCluster.cxx:54
 AliCluster.cxx:55
 AliCluster.cxx:56
 AliCluster.cxx:57
 AliCluster.cxx:58
 AliCluster.cxx:59
 AliCluster.cxx:60
 AliCluster.cxx:61
 AliCluster.cxx:62
 AliCluster.cxx:63
 AliCluster.cxx:64
 AliCluster.cxx:65
 AliCluster.cxx:66
 AliCluster.cxx:67
 AliCluster.cxx:68
 AliCluster.cxx:69
 AliCluster.cxx:70
 AliCluster.cxx:71
 AliCluster.cxx:72
 AliCluster.cxx:73
 AliCluster.cxx:74
 AliCluster.cxx:75
 AliCluster.cxx:76
 AliCluster.cxx:77
 AliCluster.cxx:78
 AliCluster.cxx:79
 AliCluster.cxx:80
 AliCluster.cxx:81
 AliCluster.cxx:82
 AliCluster.cxx:83
 AliCluster.cxx:84
 AliCluster.cxx:85
 AliCluster.cxx:86
 AliCluster.cxx:87
 AliCluster.cxx:88
 AliCluster.cxx:89
 AliCluster.cxx:90
 AliCluster.cxx:91
 AliCluster.cxx:92
 AliCluster.cxx:93
 AliCluster.cxx:94
 AliCluster.cxx:95
 AliCluster.cxx:96
 AliCluster.cxx:97
 AliCluster.cxx:98
 AliCluster.cxx:99
 AliCluster.cxx:100
 AliCluster.cxx:101
 AliCluster.cxx:102
 AliCluster.cxx:103
 AliCluster.cxx:104
 AliCluster.cxx:105
 AliCluster.cxx:106
 AliCluster.cxx:107
 AliCluster.cxx:108
 AliCluster.cxx:109
 AliCluster.cxx:110
 AliCluster.cxx:111
 AliCluster.cxx:112
 AliCluster.cxx:113
 AliCluster.cxx:114
 AliCluster.cxx:115
 AliCluster.cxx:116
 AliCluster.cxx:117
 AliCluster.cxx:118
 AliCluster.cxx:119
 AliCluster.cxx:120
 AliCluster.cxx:121
 AliCluster.cxx:122
 AliCluster.cxx:123
 AliCluster.cxx:124
 AliCluster.cxx:125
 AliCluster.cxx:126
 AliCluster.cxx:127
 AliCluster.cxx:128
 AliCluster.cxx:129
 AliCluster.cxx:130
 AliCluster.cxx:131
 AliCluster.cxx:132
 AliCluster.cxx:133
 AliCluster.cxx:134
 AliCluster.cxx:135
 AliCluster.cxx:136
 AliCluster.cxx:137
 AliCluster.cxx:138
 AliCluster.cxx:139
 AliCluster.cxx:140
 AliCluster.cxx:141
 AliCluster.cxx:142
 AliCluster.cxx:143
 AliCluster.cxx:144
 AliCluster.cxx:145
 AliCluster.cxx:146
 AliCluster.cxx:147
 AliCluster.cxx:148
 AliCluster.cxx:149
 AliCluster.cxx:150
 AliCluster.cxx:151
 AliCluster.cxx:152
 AliCluster.cxx:153
 AliCluster.cxx:154
 AliCluster.cxx:155
 AliCluster.cxx:156
 AliCluster.cxx:157
 AliCluster.cxx:158
 AliCluster.cxx:159
 AliCluster.cxx:160
 AliCluster.cxx:161
 AliCluster.cxx:162
 AliCluster.cxx:163
 AliCluster.cxx:164
 AliCluster.cxx:165
 AliCluster.cxx:166
 AliCluster.cxx:167
 AliCluster.cxx:168
 AliCluster.cxx:169
 AliCluster.cxx:170
 AliCluster.cxx:171
 AliCluster.cxx:172
 AliCluster.cxx:173
 AliCluster.cxx:174
 AliCluster.cxx:175
 AliCluster.cxx:176
 AliCluster.cxx:177
 AliCluster.cxx:178
 AliCluster.cxx:179
 AliCluster.cxx:180
 AliCluster.cxx:181
 AliCluster.cxx:182
 AliCluster.cxx:183
 AliCluster.cxx:184
 AliCluster.cxx:185
 AliCluster.cxx:186
 AliCluster.cxx:187
 AliCluster.cxx:188
 AliCluster.cxx:189
 AliCluster.cxx:190
 AliCluster.cxx:191
 AliCluster.cxx:192
 AliCluster.cxx:193
 AliCluster.cxx:194
 AliCluster.cxx:195
 AliCluster.cxx:196
 AliCluster.cxx:197
 AliCluster.cxx:198
 AliCluster.cxx:199
 AliCluster.cxx:200
 AliCluster.cxx:201
 AliCluster.cxx:202
 AliCluster.cxx:203
 AliCluster.cxx:204
 AliCluster.cxx:205
 AliCluster.cxx:206
 AliCluster.cxx:207
 AliCluster.cxx:208
 AliCluster.cxx:209
 AliCluster.cxx:210
 AliCluster.cxx:211
 AliCluster.cxx:212
 AliCluster.cxx:213
 AliCluster.cxx:214
 AliCluster.cxx:215
 AliCluster.cxx:216
 AliCluster.cxx:217
 AliCluster.cxx:218
 AliCluster.cxx:219
 AliCluster.cxx:220
 AliCluster.cxx:221
 AliCluster.cxx:222
 AliCluster.cxx:223
 AliCluster.cxx:224
 AliCluster.cxx:225
 AliCluster.cxx:226
 AliCluster.cxx:227
 AliCluster.cxx:228
 AliCluster.cxx:229
 AliCluster.cxx:230
 AliCluster.cxx:231
 AliCluster.cxx:232
 AliCluster.cxx:233
 AliCluster.cxx:234
 AliCluster.cxx:235
 AliCluster.cxx:236
 AliCluster.cxx:237
 AliCluster.cxx:238
 AliCluster.cxx:239
 AliCluster.cxx:240
 AliCluster.cxx:241
 AliCluster.cxx:242
 AliCluster.cxx:243
 AliCluster.cxx:244
 AliCluster.cxx:245
 AliCluster.cxx:246
 AliCluster.cxx:247
 AliCluster.cxx:248
 AliCluster.cxx:249
 AliCluster.cxx:250
 AliCluster.cxx:251
 AliCluster.cxx:252
 AliCluster.cxx:253
 AliCluster.cxx:254
 AliCluster.cxx:255
 AliCluster.cxx:256
 AliCluster.cxx:257
 AliCluster.cxx:258
 AliCluster.cxx:259
 AliCluster.cxx:260
 AliCluster.cxx:261
 AliCluster.cxx:262
 AliCluster.cxx:263
 AliCluster.cxx:264
 AliCluster.cxx:265
 AliCluster.cxx:266
 AliCluster.cxx:267
 AliCluster.cxx:268
 AliCluster.cxx:269
 AliCluster.cxx:270
 AliCluster.cxx:271
 AliCluster.cxx:272
 AliCluster.cxx:273
 AliCluster.cxx:274
 AliCluster.cxx:275
 AliCluster.cxx:276
 AliCluster.cxx:277
 AliCluster.cxx:278
 AliCluster.cxx:279
 AliCluster.cxx:280
 AliCluster.cxx:281
 AliCluster.cxx:282
 AliCluster.cxx:283
 AliCluster.cxx:284
 AliCluster.cxx:285
 AliCluster.cxx:286
 AliCluster.cxx:287
 AliCluster.cxx:288
 AliCluster.cxx:289
 AliCluster.cxx:290
 AliCluster.cxx:291
 AliCluster.cxx:292
 AliCluster.cxx:293
 AliCluster.cxx:294
 AliCluster.cxx:295
 AliCluster.cxx:296
 AliCluster.cxx:297
 AliCluster.cxx:298
 AliCluster.cxx:299
 AliCluster.cxx:300
 AliCluster.cxx:301
 AliCluster.cxx:302
 AliCluster.cxx:303
 AliCluster.cxx:304
 AliCluster.cxx:305
 AliCluster.cxx:306
 AliCluster.cxx:307
 AliCluster.cxx:308
 AliCluster.cxx:309
 AliCluster.cxx:310
 AliCluster.cxx:311
 AliCluster.cxx:312
 AliCluster.cxx:313
 AliCluster.cxx:314
 AliCluster.cxx:315
 AliCluster.cxx:316
 AliCluster.cxx:317
 AliCluster.cxx:318
 AliCluster.cxx:319
 AliCluster.cxx:320
 AliCluster.cxx:321
 AliCluster.cxx:322
 AliCluster.cxx:323
 AliCluster.cxx:324
 AliCluster.cxx:325
 AliCluster.cxx:326
 AliCluster.cxx:327
 AliCluster.cxx:328
 AliCluster.cxx:329
 AliCluster.cxx:330
 AliCluster.cxx:331
 AliCluster.cxx:332
 AliCluster.cxx:333
 AliCluster.cxx:334
 AliCluster.cxx:335