]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCAlign.cxx
secure code
[u/mrichter/AliRoot.git] / TPC / AliTPCAlign.cxx
CommitLineData
2574314d 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$Log$
68e43693 18Revision 1.3 2007/10/22 14:20:25 kowal2
19Hardwired "ideal" coordinates replaced with those from the DCDB.
20Corrected bug in SetDebug method
21
3e3d6422 22Revision 1.2 2007/10/03 09:27:50 marian
23Extra semicolon removed (Marian)
24
dd89d4d2 25Revision 1.1 2007/10/01 14:12:45 kowal2
26Class creating the aligmnent object fro the surveyor measurements.
27
2574314d 28*/
29
30//
31// Creates the TPC align object
32//
33
34#include "AliTPCAlign.h"
68e43693 35#include "AliSurveyPoint.h"
36#include "AliSurveyPoint.h"
2574314d 37//
38#include "TROOT.h"
39#include "Riostream.h"
40#include "TFile.h"
41#include "TMath.h"
42#include "TSystem.h"
43#include "AliSurveyObj.h"
68e43693 44#include "AliSurveyPoint.h"
2574314d 45#include "AliAlignObjParams.h"
46#include "AliCDBStorage.h"
47#include <TClonesArray.h>
48#include <TFile.h>
49#include "AliLog.h"
50#include "AliCDBManager.h"
51
dd89d4d2 52ClassImp(AliTPCAlign)
2574314d 53
54AliTPCAlign::AliTPCAlign() :
55 TObject(),
56 fFileLoc(0x0),
57 fFileGlob(0x0),
58 fTPCAlignObj(0x0),
59 fX(),
60 fA(),
61 fY(),
62 fDebug(0)
63{
64 //
65 // default constructor
66 //
67}
68//________________________________________________________________________
69AliTPCAlign::AliTPCAlign(Int_t reportloc, Int_t reportglob) :
70 TObject(),
71 fFileLoc(0x0),
72 fFileGlob(0x0),
73 fTPCAlignObj(0x0),
74 fX(6,1),
75 fA(24,6),
76 fY(24,1),
77 fDebug(0)
78{
79 //
80 // constructor - defines data files
81 //
82 fFileLoc = new Char_t[80];
83 fFileGlob = new Char_t[80];
84 Char_t path[50];
94e6c6f4 85 //sprintf(path,gSystem->Getenv("ALICE_ROOT"));
86 snprintf(path,50,gSystem->Getenv("ALICE_ROOT"));
2574314d 87 //
94e6c6f4 88 //sprintf(fFileLoc,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
89 snprintf(fFileLoc,100,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
90 //sprintf(fFileGlob,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
91 snprintf(fFileGlob,100,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
2574314d 92 //
93
94}
95//_________________________________________________________________________
96AliTPCAlign::AliTPCAlign(const AliTPCAlign &align) :
97 TObject(),
98 fFileLoc(0x0),
99 fFileGlob(0x0),
100 fTPCAlignObj(0x0),
101 fX(),
102 fA(),
103 fY(),
104 fDebug(0)
105{
106 //
107 // copy constructor - dummy
108 //
109 fDebug = align.fDebug;
110}
111//__________________________________________________________________________
112AliTPCAlign & AliTPCAlign::operator =(const AliTPCAlign & align)
113{
114 //
115 // assignment operator - dummy
116 //
117 fDebug=align.fDebug;
118 return (*this);
119}
120
121//__________________________________________________________________________
122AliTPCAlign::~AliTPCAlign(){
123 //
124 // destructor
125 //
126 if(fTPCAlignObj) delete fTPCAlignObj;
127}
128//__________________________________________________________________________
129Bool_t AliTPCAlign::LoadSurveyData(){
130 //
131 // for a time being it loads from the local file the surveyed point
132 // and has the ideal points hardwired. I am waiting until Ricardo
133 // completes his job
134 //
135
136 AliSurveyObj * s1 = new AliSurveyObj();
137 s1->FillFromLocalFile(fFileGlob);
138 //
139 Int_t numberPoints = 8;
140 //
141 TString pointNames[8] = {"T1Final_R04241","T1Final_R05241","T1Final_R06241",
142 "T1Final_R07241","T1Final_R08241","T1Final_R10241",
143 "T1Final_R11241","T1Final_R12241"};
144 //
145 Float_t surveyedPoints[8][3];
146 AliSurveyPoint *currPoint;
147 //
148 for(Int_t i=0;i<numberPoints;i++){
149 currPoint=0;
150 currPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNames[i]);
151 //
152 if(currPoint){
153 surveyedPoints[i][0]=currPoint->GetX();
154 surveyedPoints[i][1]=currPoint->GetY();
155 surveyedPoints[i][2]=currPoint->GetZ();
156 if(fDebug)
157 Printf(Form("INFO: Point \"%s\" coordinates read.", pointNames[i].Data()));
158 }
159 else {
160 if(fDebug){
161 Printf(Form("ERROR: Essential point missing: \"%s\"", pointNames[i].Data()));
162 return 1;
163 }
164 }
165 }
166 //
167 // Ideal points
168 //
169 Float_t idealPoints[8][3];
170 //
3e3d6422 171 AliSurveyObj * s2 = new AliSurveyObj();
172 s2->FillFromLocalFile(fFileLoc);
2574314d 173 //
3e3d6422 174 TString pointNamesL[8] ={"R04","R05","R06","R07","R08","R10","R11","R12"};
2574314d 175 //
3e3d6422 176 AliSurveyPoint *currPointL;
177 //
178 for(Int_t i=0;i<numberPoints;i++){
179 currPointL=0;
180 currPointL = (AliSurveyPoint *) s2->GetData()->FindObject(pointNamesL[i]);
181 if(currPointL){
182 idealPoints[i][0]=currPointL->GetY();
183 idealPoints[i][1]=currPointL->GetZ();
184 idealPoints[i][2]=currPointL->GetX();
185 if(fDebug)
186 Printf(Form("INFO: Point \"%s\" coordinates read.", pointNamesL[i].Data()));
187 }
188 else{
189 if(fDebug){
190 Printf(Form("ERROR: Essential point missing: \"%s\"", pointNamesL[i].Data()));
191 return 1; }
192 }
193 }
2574314d 194 //
195 // Create and fill matrices a & y
196 //
197 for(Int_t i = 0;i<numberPoints;i++){
198 for(Int_t j=0;j<3;j++){
199 fY(i*3+j,0)=surveyedPoints[i][j]-idealPoints[i][j];
200
201 }
202 }
203 fA.Zero();
204 //
205 //
206 // setting matrix a
207 //
208 for(Int_t i=0;i<numberPoints;i++){
209 fA(3*i,0)= -idealPoints[i][1];
210 fA(3*i,1)= idealPoints[i][2];
211 fA(3*i,3)=1.;
212 fA(3*i+1,0)= idealPoints[i][0];
213 fA(3*i+1,2)= -idealPoints[i][2];
214 fA(3*i+1,4)= 1.;
215 fA(3*i+2,1)= -idealPoints[i][0];
216 fA(3*i+2,2)= idealPoints[i][1];
217 fA(3*i+2,5)=1.;
218 }
219 //
220 delete s1;
221 //
222 return 0;
223}
224//_________________________________________________________________
225Double_t AliTPCAlign::ComputeTransform(){
226 //
227 // Here simple matrix operations for the linear least square
228 // The trigonometric function sin is approximated by the angle
229 // and the cos by "1", because angles are very small (Y-convention!)
230 // This secures the linearity of the problem
231 // This method returns a sum of squares of residuals
232 //
233 TMatrixD tt1(TMatrixD::kInverted,(TMatrixD(fA,TMatrixD::kTransposeMult,fA)));
234 fX=TMatrixD(tt1,TMatrixD::kMult,TMatrixD(fA,TMatrixD::kTransposeMult,fY));
235 //
236 TMatrixD Unit(24,24);
237 Unit.UnitMatrix();
238 TMatrixD xxt1(TMatrixD::kInverted,TMatrixD(fA,TMatrixD::kTransposeMult,fA));
239 TMatrixD t(fA,TMatrixD::kMult,TMatrixD(xxt1,TMatrixD::kMultTranspose,fA));
240 TMatrixD t2(Unit,TMatrixD::kMinus,t);
241 TMatrixD chi2(fY,TMatrixD::kTransposeMult,TMatrixD(t2,TMatrixD::kMult,fY));
242 //
243
244 return chi2(0,0);
245
246}
247//_______________________________________________________________________
248void AliTPCAlign::CreateAlignObj(){
249 //
250 // This method creates AliAlignObj and fills it with Euler angles
251 // and shifts. The units are degrees and cm.
252 //
253 fTPCAlignObj = new AliAlignObjParams();
254 fTPCAlignObj->SetSymName("ALIC_1/TPC_M_1");
255 fTPCAlignObj->SetVolUID(0);
256 Double_t raddeg = TMath::RadToDeg();
257 Double_t phi,theta,psi;
258 //
259 phi=fX(0,0)*raddeg;
260 theta=fX(1,0)*raddeg;
261 psi=fX(2,0)*raddeg;
262 //
263 Double_t dx,dy,dz;
264 dx=fX(3,0)*100.;
265 dy=fX(4,0)*100.;
266 dz=fX(5,0)*100.;
267 fTPCAlignObj->SetRotation(psi,theta,phi);
268 fTPCAlignObj->SetTranslation(dx,dy,dz);
269 fTPCAlignObj->Print("");
270}
271//______________________________________________________________________
272void AliTPCAlign::Run(){
273 //
274 // runs the full chain
275 //
276 SetDebug(0);
277 Bool_t flag = LoadSurveyData();
278 if(flag) {
279 cout<<"Missing points"<<endl;
280 return;
281 }
282 Double_t chi2 = ComputeTransform();
283 if(chi2>0.01) return;
284 CreateAlignObj();
285 StoreAlignObj();
286 //
287}
288//_________________________________________________________________________
289void AliTPCAlign::StoreAlignObj(){
290 //
291AliCDBManager* cdb = AliCDBManager::Instance();
162637e4 292 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
2574314d 293 //
294TClonesArray *array = new TClonesArray("AliAlignObjParams",1);
295//
296 Double_t shifts[3];
297 Double_t rots[3];
298 //
299 fTPCAlignObj->GetPars(shifts,rots);
300 new((*array)[0]) AliAlignObjParams(fTPCAlignObj->GetSymName(),0,shifts[0],
301 shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
302
303//
304// storing either in the OCDB or local file
305//
306 if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
307 // save on file
308 const char* filename = "TPCSurveyMisalignment.root";
309 Char_t fullname[80];
32a48cc1 310 //sprintf(fullname,"%s/TPC/%s",gSystem->Getenv("ALICE_ROOT"),filename);
311 snprintf(fullname,80,"%s/TPC/%s",gSystem->Getenv("ALICE_ROOT"),filename);
2574314d 312 TFile *f = new TFile(fullname,"RECREATE");
313 if(!f){
314 AliError("cannot open file for output\n");
315 return;
316 }
317 AliInfo(Form("Saving alignment objects to the file %s", filename));
318 f->cd();
319 f->WriteObject(array,"TPCAlignObjs","kSingleKey");
320 f->Close();
321 }else{
322 // save in CDB storage
323 AliCDBStorage* storage;
324 //
325 TString Storage = gSystem->Getenv("STORAGE");
326 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
327 AliError(Form(
328 "STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
329 return;
330 }
331 storage = cdb->GetStorage(Storage.Data());
332 if(!storage){
333 AliError(Form("Unable to open storage %s\n",Storage.Data()));
334 return;
335 }
336 //
337 AliCDBMetaData* md = new AliCDBMetaData();
338 md->SetResponsible("Marek Kowalski");
339 md->SetComment("Full misalignment of entire TPC from surveyors");
340 AliCDBId id("TPC/Align/Data",0,AliCDBRunRange::Infinity());
341 storage->Put(array,id,md);
342 }
343
344}