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