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 **************************************************************************/
18 Revision 1.2 2007/10/03 09:27:50 marian
19 Extra semicolon removed (Marian)
21 Revision 1.1 2007/10/01 14:12:45 kowal2
22 Class creating the aligmnent object fro the surveyor measurements.
27 // Creates the TPC align object
30 #include "AliTPCAlign.h"
33 #include "Riostream.h"
37 #include "AliSurveyObj.h"
38 #include "AliAlignObjParams.h"
39 #include "AliCDBStorage.h"
40 #include <TClonesArray.h>
43 #include "AliCDBManager.h"
47 AliTPCAlign::AliTPCAlign() :
58 // default constructor
61 //________________________________________________________________________
62 AliTPCAlign::AliTPCAlign(Int_t reportloc, Int_t reportglob) :
73 // constructor - defines data files
75 fFileLoc = new Char_t[80];
76 fFileGlob = new Char_t[80];
78 sprintf(path,gSystem->Getenv("ALICE_ROOT"));
80 sprintf(fFileLoc,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
81 sprintf(fFileGlob,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
85 //_________________________________________________________________________
86 AliTPCAlign::AliTPCAlign(const AliTPCAlign &align) :
97 // copy constructor - dummy
99 fDebug = align.fDebug;
101 //__________________________________________________________________________
102 AliTPCAlign & AliTPCAlign::operator =(const AliTPCAlign & align)
105 // assignment operator - dummy
111 //__________________________________________________________________________
112 AliTPCAlign::~AliTPCAlign(){
116 if(fTPCAlignObj) delete fTPCAlignObj;
118 //__________________________________________________________________________
119 Bool_t AliTPCAlign::LoadSurveyData(){
121 // for a time being it loads from the local file the surveyed point
122 // and has the ideal points hardwired. I am waiting until Ricardo
126 AliSurveyObj * s1 = new AliSurveyObj();
127 s1->FillFromLocalFile(fFileGlob);
129 Int_t numberPoints = 8;
131 TString pointNames[8] = {"T1Final_R04241","T1Final_R05241","T1Final_R06241",
132 "T1Final_R07241","T1Final_R08241","T1Final_R10241",
133 "T1Final_R11241","T1Final_R12241"};
135 Float_t surveyedPoints[8][3];
136 AliSurveyPoint *currPoint;
138 for(Int_t i=0;i<numberPoints;i++){
140 currPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNames[i]);
143 surveyedPoints[i][0]=currPoint->GetX();
144 surveyedPoints[i][1]=currPoint->GetY();
145 surveyedPoints[i][2]=currPoint->GetZ();
147 Printf(Form("INFO: Point \"%s\" coordinates read.", pointNames[i].Data()));
151 Printf(Form("ERROR: Essential point missing: \"%s\"", pointNames[i].Data()));
159 Float_t idealPoints[8][3];
161 AliSurveyObj * s2 = new AliSurveyObj();
162 s2->FillFromLocalFile(fFileLoc);
164 TString pointNamesL[8] ={"R04","R05","R06","R07","R08","R10","R11","R12"};
166 AliSurveyPoint *currPointL;
168 for(Int_t i=0;i<numberPoints;i++){
170 currPointL = (AliSurveyPoint *) s2->GetData()->FindObject(pointNamesL[i]);
172 idealPoints[i][0]=currPointL->GetY();
173 idealPoints[i][1]=currPointL->GetZ();
174 idealPoints[i][2]=currPointL->GetX();
176 Printf(Form("INFO: Point \"%s\" coordinates read.", pointNamesL[i].Data()));
180 Printf(Form("ERROR: Essential point missing: \"%s\"", pointNamesL[i].Data()));
185 // Create and fill matrices a & y
187 for(Int_t i = 0;i<numberPoints;i++){
188 for(Int_t j=0;j<3;j++){
189 fY(i*3+j,0)=surveyedPoints[i][j]-idealPoints[i][j];
198 for(Int_t i=0;i<numberPoints;i++){
199 fA(3*i,0)= -idealPoints[i][1];
200 fA(3*i,1)= idealPoints[i][2];
202 fA(3*i+1,0)= idealPoints[i][0];
203 fA(3*i+1,2)= -idealPoints[i][2];
205 fA(3*i+2,1)= -idealPoints[i][0];
206 fA(3*i+2,2)= idealPoints[i][1];
214 //_________________________________________________________________
215 Double_t AliTPCAlign::ComputeTransform(){
217 // Here simple matrix operations for the linear least square
218 // The trigonometric function sin is approximated by the angle
219 // and the cos by "1", because angles are very small (Y-convention!)
220 // This secures the linearity of the problem
221 // This method returns a sum of squares of residuals
223 TMatrixD tt1(TMatrixD::kInverted,(TMatrixD(fA,TMatrixD::kTransposeMult,fA)));
224 fX=TMatrixD(tt1,TMatrixD::kMult,TMatrixD(fA,TMatrixD::kTransposeMult,fY));
226 TMatrixD Unit(24,24);
228 TMatrixD xxt1(TMatrixD::kInverted,TMatrixD(fA,TMatrixD::kTransposeMult,fA));
229 TMatrixD t(fA,TMatrixD::kMult,TMatrixD(xxt1,TMatrixD::kMultTranspose,fA));
230 TMatrixD t2(Unit,TMatrixD::kMinus,t);
231 TMatrixD chi2(fY,TMatrixD::kTransposeMult,TMatrixD(t2,TMatrixD::kMult,fY));
237 //_______________________________________________________________________
238 void AliTPCAlign::CreateAlignObj(){
240 // This method creates AliAlignObj and fills it with Euler angles
241 // and shifts. The units are degrees and cm.
243 fTPCAlignObj = new AliAlignObjParams();
244 fTPCAlignObj->SetSymName("ALIC_1/TPC_M_1");
245 fTPCAlignObj->SetVolUID(0);
246 Double_t raddeg = TMath::RadToDeg();
247 Double_t phi,theta,psi;
250 theta=fX(1,0)*raddeg;
257 fTPCAlignObj->SetRotation(psi,theta,phi);
258 fTPCAlignObj->SetTranslation(dx,dy,dz);
259 fTPCAlignObj->Print("");
261 //______________________________________________________________________
262 void AliTPCAlign::Run(){
264 // runs the full chain
267 Bool_t flag = LoadSurveyData();
269 cout<<"Missing points"<<endl;
272 Double_t chi2 = ComputeTransform();
273 if(chi2>0.01) return;
278 //_________________________________________________________________________
279 void AliTPCAlign::StoreAlignObj(){
281 AliCDBManager* cdb = AliCDBManager::Instance();
282 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
284 TClonesArray *array = new TClonesArray("AliAlignObjParams",1);
289 fTPCAlignObj->GetPars(shifts,rots);
290 new((*array)[0]) AliAlignObjParams(fTPCAlignObj->GetSymName(),0,shifts[0],
291 shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
294 // storing either in the OCDB or local file
296 if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
298 const char* filename = "TPCSurveyMisalignment.root";
300 sprintf(fullname,"%s/TPC/%s",gSystem->Getenv("ALICE_ROOT"),filename);
301 TFile *f = new TFile(fullname,"RECREATE");
303 AliError("cannot open file for output\n");
306 AliInfo(Form("Saving alignment objects to the file %s", filename));
308 f->WriteObject(array,"TPCAlignObjs","kSingleKey");
311 // save in CDB storage
312 AliCDBStorage* storage;
314 TString Storage = gSystem->Getenv("STORAGE");
315 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
317 "STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
320 storage = cdb->GetStorage(Storage.Data());
322 AliError(Form("Unable to open storage %s\n",Storage.Data()));
326 AliCDBMetaData* md = new AliCDBMetaData();
327 md->SetResponsible("Marek Kowalski");
328 md->SetComment("Full misalignment of entire TPC from surveyors");
329 AliCDBId id("TPC/Align/Data",0,AliCDBRunRange::Infinity());
330 storage->Put(array,id,md);