1 // $Id: AliHLTTPCClusterTransformation.cxx 41244 2010-05-14 08:13:35Z kkanaki $
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
8 //* for The ALICE HLT Project. *
10 //* Permission to use, copy, modify and distribute this software and its *
11 //* documentation strictly for non-commercial purposes is hereby granted *
12 //* without fee, provided that the above copyright notice appears in all *
13 //* copies and that both the copyright notice and this permission notice *
14 //* appear in the supporting documentation. The authors make no claims *
15 //* about the suitability of this software for any purpose. It is *
16 //* provided "as is" without express or implied warranty. *
17 //**************************************************************************
19 /** @file AliHLTTPCClusterTransformation.cxx
20 @author Kalliopi Kanaki, Sergey Gorbubnov
26 #include "AliHLTTPCClusterTransformation.h"
27 #include "AliHLTTPCTransform.h"
28 #include "AliHLTTPCFastTransform.h"
30 #include "AliTPCcalibDB.h"
31 #include "AliTPCTransform.h"
32 #include "AliTPCParam.h"
33 #include "AliTPCRecoParam.h"
34 #include "AliGeomManager.h"
40 ClassImp(AliHLTTPCClusterTransformation) //ROOT macro for the implementation of ROOT specific class methods
42 AliHLTTPCClusterTransformation::AliHLTTPCClusterTransformation()
44 fOfflineTPCParam( NULL ),
47 // see header file for class documentation
49 // refer to README to build package
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57 AliHLTTPCClusterTransformation::~AliHLTTPCClusterTransformation()
59 // see header file for class documentation
60 AliHLTTPCFastTransform::Terminate();
64 int AliHLTTPCClusterTransformation::Init( double FieldBz, UInt_t TimeStamp )
70 AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
72 if(!pCalib ) return -1;
74 pCalib->SetExBField(FieldBz);
76 if(!AliGeomManager::GetGeometry()){
77 AliGeomManager::LoadGeometry();
80 if( !pCalib->GetTransform() ) return -2;
82 fOfflineTPCParam = pCalib->GetParameters();
83 if( !fOfflineTPCParam ) return -3;
85 fOfflineTPCParam->Update();
86 fOfflineTPCParam->ReadGeoMatrices();
94 SetCurrentTimeStamp( TimeStamp );
99 void AliHLTTPCClusterTransformation::SetCurrentTimeStamp( UInt_t TimeStamp )
101 // Set the current time stamp
102 AliHLTTPCFastTransform::Instance()->SetCurrentTimeStamp( TimeStamp );
106 int AliHLTTPCClusterTransformation::Transform( int Slice, int Row, float Pad, float Time, float XYZ[] )
108 // Convert row, pad, time to X Y Z
110 Int_t sector=-99, thisrow=-99;
111 AliHLTTPCTransform::Slice2Sector( Slice, Row, sector, thisrow);
112 Double_t x[3] = {0,0,0};
113 AliHLTTPCFastTransform::Instance()->Transform(sector, thisrow, Pad, Time, x);
115 if( sector!= fLastSector ){
116 if( fOfflineTPCParam && sector<fOfflineTPCParam->GetNSector() ){
117 TGeoHMatrix *alignment = fOfflineTPCParam->GetClusterMatrix( sector );
119 const Double_t *tr = alignment->GetTranslation();
120 const Double_t *rot = alignment->GetRotationMatrix();
122 for( int i=0; i<3; i++ ) fAliT[i] = tr[i];
123 for( int i=0; i<9; i++ ) fAliR[i] = rot[i];
130 for( int i=0; i<9; i++ ) fAliR[i] = 0;
135 fLastSector = sector;
137 // alignment->LocalToMaster( x, y);
139 XYZ[0] = fAliT[0] + x[0]*fAliR[0] + x[1]*fAliR[1] + x[2]*fAliR[2];
140 XYZ[1] = fAliT[1] + x[0]*fAliR[3] + x[1]*fAliR[4] + x[2]*fAliR[5];
141 XYZ[2] = fAliT[2] + x[0]*fAliR[6] + x[1]*fAliR[7] + x[2]*fAliR[8];
146 int AliHLTTPCClusterTransformation::ReverseAlignment( float XYZ[], int slice, int padrow)
148 // reverse the alignment correction
149 Int_t sector=-99, thisrow=-99;
150 AliHLTTPCTransform::Slice2Sector( slice, padrow, sector, thisrow);
151 if( sector!= fLastSector ){
152 if( fOfflineTPCParam && sector<fOfflineTPCParam->GetNSector() ){
153 TGeoHMatrix *alignment = fOfflineTPCParam->GetClusterMatrix( sector );
155 const Double_t *tr = alignment->GetTranslation();
156 const Double_t *rot = alignment->GetRotationMatrix();
158 for( int i=0; i<3; i++ ) fAliT[i] = tr[i];
160 SetRotationMatrix(rot, true);
166 SetRotationMatrix(NULL, true);
168 fLastSector = sector;
171 // correct for alignment: translation
173 xyz[0] = XYZ[0] - fAliT[0];
174 xyz[1] = XYZ[1] - fAliT[1];
175 xyz[2] = XYZ[2] - fAliT[2];
177 // correct for alignment: rotation
178 XYZ[0]=xyz[0]*fAdjR[0] + xyz[1]*fAdjR[1] + xyz[2]*fAdjR[2];
179 XYZ[1]=xyz[0]*fAdjR[3] + xyz[1]*fAdjR[4] + xyz[2]*fAdjR[5];
180 XYZ[2]=xyz[0]*fAdjR[6] + xyz[1]*fAdjR[7] + xyz[2]*fAdjR[8];
185 void AliHLTTPCClusterTransformation::SetRotationMatrix(const Double_t *rot, bool bCalcAdjugate)
187 // set the rotation matrix and calculate the adjugate if requested
189 for( int i=0; i<9; i++ ) fAliR[i] = rot[i];
191 CalcAdjugateRotation();
195 for( int i=0; i<9; i++ ) {fAliR[i] = 0; fAdjR[i] = 0;}
204 bool AliHLTTPCClusterTransformation::CalcAdjugateRotation(bool bCheck)
206 // check rotation matrix and adjugate for consistency
207 fAdjR[0]= fAliR[4]*fAliR[8]-fAliR[5]*fAliR[7];
208 fAdjR[1]= fAliR[5]*fAliR[6]-fAliR[3]*fAliR[8];
209 fAdjR[2]= fAliR[3]*fAliR[7]-fAliR[4]*fAliR[6];
211 fAdjR[3]= fAliR[2]*fAliR[7]-fAliR[1]*fAliR[8];
212 fAdjR[4]= fAliR[0]*fAliR[8]-fAliR[2]*fAliR[6];
213 fAdjR[5]= fAliR[2]*fAliR[6]-fAliR[0]*fAliR[7];
215 fAdjR[6]= fAliR[1]*fAliR[5]-fAliR[2]*fAliR[4];
216 fAdjR[7]= fAliR[2]*fAliR[3]-fAliR[0]*fAliR[5];
217 fAdjR[8]= fAliR[0]*fAliR[4]-fAliR[1]*fAliR[3];
220 for (int r=0; r<3; r++) {
221 for (int c=0; c<3; c++) {
224 if (r==c) expected=1.;
225 for (int i=0; i<3; i++) {
226 a+=fAliR[3*r+i]*fAdjR[c+(3*i)];
228 if (TMath::Abs(a-expected)>0.00001) {
229 std::cout << "inconsistent adjugate at " << r << c << ": " << a << " " << expected << std::endl;
238 void AliHLTTPCClusterTransformation::Print(const char* /*option*/) const
241 ios::fmtflags coutflags=std::cout.flags(); // backup cout status flags
242 std::cout << "AliHLTTPCClusterTransformation for sector " << fLastSector << std::endl;
244 std::cout.setf(ios_base::showpos|ios_base::showpos|ios::right);
245 std::cout << " translation: " << std::endl;
247 for (r=0; r<3; r++) {
248 std::cout << setw(7) << fixed << setprecision(2);
249 cout << " " << fAliT[r] << std::endl;
251 std::cout << " rotation and adjugated rotation: " << std::endl;
252 for (r=0; r<3; r++) {
254 std::cout << setw(7) << fixed << setprecision(2);
255 for (c=0; c<3; c++) std::cout << " " << fAliR[3*r+c];
257 for (c=0; c<3; c++) std::cout << " " << fAdjR[3*r+c];
260 std::cout.flags(coutflags); // restore the original flags