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"
29 #include "AliTPCcalibDB.h"
30 #include "AliTPCTransform.h"
31 #include "AliTPCParam.h"
32 #include "AliTPCRecoParam.h"
33 #include "AliGeomManager.h"
39 ClassImp(AliHLTTPCClusterTransformation) //ROOT macro for the implementation of ROOT specific class methods
41 AliHLTTPCClusterTransformation::AliHLTTPCClusterTransformation()
43 fOfflineTransform(NULL),
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 //delete fOfflineTransform;
64 int AliHLTTPCClusterTransformation::Init( double FieldBz, UInt_t TimeStamp )
68 //delete fOfflineTransform;
69 fOfflineTransform = 0;
72 AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
74 if(!pCalib ) return -1;
76 pCalib->SetExBField(FieldBz);
78 if(!AliGeomManager::GetGeometry()){
79 AliGeomManager::LoadGeometry();
82 if( !pCalib->GetTransform() ) return -2;
84 //fOfflineTransform = new AliTPCTransform (*pCalib->GetTransform());
85 fOfflineTransform = pCalib->GetTransform();
86 fOfflineTransform->SetCurrentRecoParam( AliTPCRecoParam::GetHLTParam() );
87 fOfflineTransform->SetCurrentTimeStamp( TimeStamp );
88 fOfflineTPCParam = pCalib->GetParameters();
89 if( !fOfflineTPCParam ) return -3;
91 fOfflineTPCParam->Update();
92 fOfflineTPCParam->ReadGeoMatrices();
105 void AliHLTTPCClusterTransformation::SetCurrentTimeStamp( UInt_t TimeStamp )
107 // Set the current time stamp
108 if( fOfflineTransform ) fOfflineTransform->SetCurrentTimeStamp( TimeStamp );
112 int AliHLTTPCClusterTransformation::Transform( int Slice, int Row, float Pad, float Time, float XYZ[] )
114 // Convert row, pad, time to X Y Z
116 Int_t sector=-99, thisrow=-99;
117 AliHLTTPCTransform::Slice2Sector( Slice, Row, sector, thisrow);
119 if( !fOfflineTransform ){
120 AliHLTTPCTransform::Raw2Local( XYZ, sector, thisrow, Pad, Time);
121 if(Slice>17) XYZ[1]= - XYZ[1];
125 Int_t iSector[1]= {sector};
126 Double_t x[3] = { thisrow, Pad, Time };
127 fOfflineTransform->Transform(x,iSector,0,1);
129 if( sector!= fLastSector ){
130 if( fOfflineTPCParam && sector<fOfflineTPCParam->GetNSector() ){
131 TGeoHMatrix *alignment = fOfflineTPCParam->GetClusterMatrix( sector );
133 const Double_t *tr = alignment->GetTranslation();
134 const Double_t *rot = alignment->GetRotationMatrix();
136 for( int i=0; i<3; i++ ) fAliT[i] = tr[i];
137 for( int i=0; i<9; i++ ) fAliR[i] = rot[i];
144 for( int i=0; i<9; i++ ) fAliR[i] = 0;
149 fLastSector = sector;
151 // alignment->LocalToMaster( x, y);
153 XYZ[0] = fAliT[0] + x[0]*fAliR[0] + x[1]*fAliR[1] + x[2]*fAliR[2];
154 XYZ[1] = fAliT[1] + x[0]*fAliR[3] + x[1]*fAliR[4] + x[2]*fAliR[5];
155 XYZ[2] = fAliT[2] + x[0]*fAliR[6] + x[1]*fAliR[7] + x[2]*fAliR[8];
160 int AliHLTTPCClusterTransformation::ReverseAlignment( float XYZ[], int slice, int padrow)
162 // reverse the alignment correction
163 Int_t sector=-99, thisrow=-99;
164 AliHLTTPCTransform::Slice2Sector( slice, padrow, sector, thisrow);
165 if( sector!= fLastSector ){
166 if( fOfflineTPCParam && sector<fOfflineTPCParam->GetNSector() ){
167 TGeoHMatrix *alignment = fOfflineTPCParam->GetClusterMatrix( sector );
169 const Double_t *tr = alignment->GetTranslation();
170 const Double_t *rot = alignment->GetRotationMatrix();
172 for( int i=0; i<3; i++ ) fAliT[i] = tr[i];
174 SetRotationMatrix(rot, true);
180 SetRotationMatrix(NULL, true);
182 fLastSector = sector;
185 // correct for alignment: translation
187 xyz[0] = XYZ[0] - fAliT[0];
188 xyz[1] = XYZ[1] - fAliT[1];
189 xyz[2] = XYZ[2] - fAliT[2];
191 // correct for alignment: rotation
192 XYZ[0]=xyz[0]*fAdjR[0] + xyz[1]*fAdjR[1] + xyz[2]*fAdjR[2];
193 XYZ[1]=xyz[0]*fAdjR[3] + xyz[1]*fAdjR[4] + xyz[2]*fAdjR[5];
194 XYZ[2]=xyz[0]*fAdjR[6] + xyz[1]*fAdjR[7] + xyz[2]*fAdjR[8];
199 void AliHLTTPCClusterTransformation::SetRotationMatrix(const Double_t *rot, bool bCalcAdjugate)
201 // set the rotation matrix and calculate the adjugate if requested
203 for( int i=0; i<9; i++ ) fAliR[i] = rot[i];
205 CalcAdjugateRotation();
209 for( int i=0; i<9; i++ ) {fAliR[i] = 0; fAdjR[i] = 0;}
218 bool AliHLTTPCClusterTransformation::CalcAdjugateRotation(bool bCheck)
220 // check rotation matrix and adjugate for consistency
221 fAdjR[0]= fAliR[4]*fAliR[8]-fAliR[5]*fAliR[7];
222 fAdjR[1]= fAliR[5]*fAliR[6]-fAliR[3]*fAliR[8];
223 fAdjR[2]= fAliR[3]*fAliR[7]-fAliR[4]*fAliR[6];
225 fAdjR[3]= fAliR[2]*fAliR[7]-fAliR[1]*fAliR[8];
226 fAdjR[4]= fAliR[0]*fAliR[8]-fAliR[2]*fAliR[6];
227 fAdjR[5]= fAliR[2]*fAliR[6]-fAliR[0]*fAliR[7];
229 fAdjR[6]= fAliR[1]*fAliR[5]-fAliR[2]*fAliR[4];
230 fAdjR[7]= fAliR[2]*fAliR[3]-fAliR[0]*fAliR[5];
231 fAdjR[8]= fAliR[0]*fAliR[4]-fAliR[1]*fAliR[3];
234 for (int r=0; r<3; r++) {
235 for (int c=0; c<3; c++) {
238 if (r==c) expected=1.;
239 for (int i=0; i<3; i++) {
240 a+=fAliR[3*r+i]*fAdjR[c+(3*i)];
242 if (TMath::Abs(a-expected)>0.00001) {
243 std::cout << "inconsistent adjugate at " << r << c << ": " << a << " " << expected << std::endl;
252 void AliHLTTPCClusterTransformation::Print(const char* /*option*/) const
255 ios::fmtflags coutflags=std::cout.flags(); // backup cout status flags
256 std::cout << "AliHLTTPCClusterTransformation for sector " << fLastSector << std::endl;
258 std::cout.setf(ios_base::showpos|ios_base::showpos|ios::right);
259 std::cout << " translation: " << std::endl;
261 for (r=0; r<3; r++) {
262 std::cout << setw(7) << fixed << setprecision(2);
263 cout << " " << fAliT[r] << std::endl;
265 std::cout << " rotation and adjugated rotation: " << std::endl;
266 for (r=0; r<3; r++) {
268 std::cout << setw(7) << fixed << setprecision(2);
269 for (c=0; c<3; c++) std::cout << " " << fAliR[3*r+c];
271 for (c=0; c<3; c++) std::cout << " " << fAdjR[3*r+c];
274 std::cout.flags(coutflags); // restore the original flags