]>
Commit | Line | Data |
---|---|---|
8775e4e8 | 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 | /* $Id$ */ | |
d15124a9 | 17 | /////////////////////////////////////////////////////////////////////////////// |
18 | // // | |
19 | // An AliTRDalignment object contains the alignment data (3 shifts and 3 // | |
20 | // tilts) for all the alignable volumes of the TRD, i.e. for 18 supermodules // | |
21 | // and 540 chambers. The class provides simple tools for reading and writing // | |
22 | // these data in different formats, and for generating fake data that can be // | |
23 | // used to simulate misalignment. // | |
24 | // The six alignment variables have the following meaning: // | |
25 | // shift in rphi // | |
26 | // shift in z // | |
27 | // shift in r // | |
28 | // tilt around rphi // | |
29 | // tilt around z // | |
30 | // tilt around r // | |
31 | // The shifts are in cm and the tilts are in degrees. // | |
32 | // The currently supported formats are: // | |
33 | // - ascii // | |
34 | // - root file containing a TClonesArray of alignment objects // | |
35 | // - offline conditions database // | |
36 | // - OCDB-like root file // | |
37 | // - geometry file (like misaligned_geometry.root) // | |
38 | // // | |
69219822 | 39 | // Some examples of usage (in an aliroot session): // |
40 | // AliTRDalignment a,b,c,d,e; // | |
41 | // double xsm[]={0,0,0,-70,0,0}; // | |
42 | // double xch[]={0,0,-50,0,0,0}; // | |
43 | // a.SetSm(4,xsm); // | |
44 | // a.SetCh(120,xch); // | |
45 | // a.WriteAscii("kuku.dat"); // | |
46 | // TGeoManager::Import("geometry.root"); a.WriteRoot("kuku.root"); // | |
47 | // TGeoManager::Import("geometry.root"); a.WriteDB("kukudb.root",0,0); // | |
48 | // TGeoManager::Import("geometry.root"); // | |
162637e4 | 49 | // a.WriteDB("local://$ALICE_ROOT/OCDB", "TRD/Align/Data", 0,0); // |
69219822 | 50 | // TGeoManager::Import("geometry.root"); a.WriteGeo("kukugeometry.root"); // |
51 | // // | |
52 | // b.ReadAscii("kuku.dat"); // | |
53 | // TGeoManager::Import("geometry.root"); c.ReadRoot("kuku.root"); // | |
54 | // TGeoManager::Import("geometry.root"); d.ReadDB("kukudb.root"); // | |
55 | // TGeoManager::Import("kukugeometry.root"); e.ReadCurrentGeo(); // | |
56 | // // | |
57 | // e.PrintSm(4); // | |
58 | // e.PrintCh(120); // | |
59 | // a.PrintRMS(); // | |
60 | // b.PrintRMS(); // | |
61 | // e.PrintRMS(); // | |
62 | // // | |
63 | // // | |
d15124a9 | 64 | // D.Miskowiec, November 2006 // |
65 | // // | |
66 | /////////////////////////////////////////////////////////////////////////////// | |
67 | ||
68 | #include <iostream> | |
8775e4e8 | 69 | #include <fstream> |
8775e4e8 | 70 | |
71 | #include "TMath.h" | |
72 | #include "TFile.h" | |
73 | #include "TGeoManager.h" | |
74 | #include "TGeoPhysicalNode.h" | |
75 | #include "TClonesArray.h" | |
d15124a9 | 76 | #include "TString.h" |
77 | #include "TFitter.h" | |
78 | #include "TMinuit.h" | |
8775e4e8 | 79 | |
80 | #include "AliLog.h" | |
81 | #include "AliAlignObj.h" | |
90dbf5fb | 82 | #include "AliAlignObjParams.h" |
8775e4e8 | 83 | #include "AliCDBManager.h" |
84 | #include "AliCDBStorage.h" | |
85 | #include "AliCDBMetaData.h" | |
86 | #include "AliCDBEntry.h" | |
afba1460 | 87 | #include "AliSurveyObj.h" |
88 | #include "AliSurveyPoint.h" | |
8775e4e8 | 89 | |
90 | #include "AliTRDalignment.h" | |
91 | ||
69219822 | 92 | void trdAlignmentFcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *x, Int_t iflag); |
d15124a9 | 93 | |
8775e4e8 | 94 | ClassImp(AliTRDalignment) |
95 | ||
96 | //_____________________________________________________________________________ | |
97 | AliTRDalignment::AliTRDalignment() | |
98 | :TObject() | |
d15124a9 | 99 | ,fComment() |
8775e4e8 | 100 | ,fRan(0) |
101 | { | |
102 | // | |
103 | // constructor | |
104 | // | |
105 | ||
106 | SetZero(); | |
107 | ||
d15124a9 | 108 | for (int i=0; i<18; i++) for (int j=0; j<2; j++) for (int k=0; k<2; k++) for (int l=0; l<2; l++) { |
109 | fSurveyX[i][j][k][l] = 0.0; | |
110 | fSurveyY[i][j][k][l] = 0.0; | |
111 | fSurveyZ[i][j][k][l] = 0.0; | |
afba1460 | 112 | fSurveyEX[i][j][k][l] = 0.0; |
113 | fSurveyEY[i][j][k][l] = 0.0; | |
114 | fSurveyEZ[i][j][k][l] = 0.0; | |
d15124a9 | 115 | } |
116 | ||
117 | // Initialize the nominal positions of the survey points | |
118 | // in the local frame of supermodule (where y is the long side, | |
119 | // z corresponds to the radius in lab, and x to the phi in lab). | |
120 | // Four survey marks are on each z-side of the supermodule. | |
121 | // A B | |
122 | // ----o-----------o---- x | | |
123 | // \ / | | |
124 | // \ / | | |
125 | // \ / | | |
126 | // \ / | | |
127 | // ---o-----o--- --------------> | |
128 | // C D y | |
129 | // | |
130 | // For the purpose of this explanation lets define the origin such that | |
131 | // the supermodule occupies 0 < x < 77.9 cm. Then the coordinates (x,y) | |
132 | // are (in cm) | |
133 | // A (76.2,-30.25) | |
134 | // B (76.2,+30.25) | |
135 | // C ( 2.2,-22.5 ) | |
136 | // D ( 2.2,+22.5 ) | |
137 | // | |
138 | ||
139 | double x[2] = {22.5,30.25}; // lab phi, or tracking-y | |
140 | double y[2] = {353.0, -353.0}; // lab z; inc. 2 cm survey target offset | |
141 | double z[2] = {-(77.9/2.0-2.0),77.9/2.0-1.5}; // lab r, or better tracking-x | |
142 | ||
143 | for (int j=0; j<2; j++) for (int k=0; k<2; k++) for (int l=0; l<2; l++) { | |
9ef36ec3 | 144 | fSurveyX0[j][k][l] = -TMath::Power(-1,l) * x[k]; |
d15124a9 | 145 | fSurveyY0[j][k][l] = y[j]; |
146 | fSurveyZ0[j][k][l] = z[k]; | |
147 | } | |
148 | ||
2f9bdd85 | 149 | for (int i=0; i<1000; i++) { |
150 | fIbuffer[i] = 0; | |
151 | fDbuffer[i] = 0.0; | |
152 | } | |
153 | ||
8775e4e8 | 154 | } |
155 | ||
156 | //_____________________________________________________________________________ | |
157 | AliTRDalignment::AliTRDalignment(const AliTRDalignment& source) | |
158 | :TObject(source) | |
d15124a9 | 159 | ,fComment(source.fComment) |
160 | ,fRan(source.fRan) | |
8775e4e8 | 161 | { |
162 | // | |
163 | // copy constructor | |
164 | // | |
165 | ||
d15124a9 | 166 | for (int i=0; i<18; i++) SetSm(i,source.fSm[i]); |
167 | for (int i=0; i<540; i++) SetCh(i,source.fCh[i]); | |
168 | for (int i=0; i<18; i++) for (int j=0; j<2; j++) for (int k=0; k<2; k++) for (int l=0; l<2; l++) { | |
169 | fSurveyX[i][j][k][l] = source.fSurveyX[i][j][k][l]; | |
170 | fSurveyY[i][j][k][l] = source.fSurveyY[i][j][k][l]; | |
171 | fSurveyZ[i][j][k][l] = source.fSurveyZ[i][j][k][l]; | |
afba1460 | 172 | fSurveyEX[i][j][k][l] = source.fSurveyEX[i][j][k][l]; |
173 | fSurveyEY[i][j][k][l] = source.fSurveyEY[i][j][k][l]; | |
174 | fSurveyEZ[i][j][k][l] = source.fSurveyEZ[i][j][k][l]; | |
8775e4e8 | 175 | } |
d15124a9 | 176 | for (int j=0; j<2; j++) for (int k=0; k<2; k++) for (int l=0; l<2; l++) { |
177 | fSurveyX0[j][k][l] = source.fSurveyX0[j][k][l]; | |
178 | fSurveyY0[j][k][l] = source.fSurveyY0[j][k][l]; | |
179 | fSurveyZ0[j][k][l] = source.fSurveyZ0[j][k][l]; | |
8775e4e8 | 180 | } |
a987273c | 181 | for (int i=0; i<1000; i++) { |
182 | fIbuffer[i] = 0; | |
183 | fDbuffer[i] = 0.0; | |
184 | } | |
8775e4e8 | 185 | |
186 | } | |
187 | ||
188 | //_____________________________________________________________________________ | |
189 | AliTRDalignment& AliTRDalignment::operator=(const AliTRDalignment &source) | |
190 | { | |
191 | // | |
192 | // assignment operator | |
193 | // | |
194 | ||
195 | if (this != &source) { | |
196 | for (int i = 0; i < 18; i++) SetSm(i,source.fSm[i]); | |
197 | for (int i = 0; i < 540; i++) SetCh(i,source.fCh[i]); | |
d15124a9 | 198 | for (int i=0; i<18; i++) for (int j=0; j<2; j++) for (int k=0; k<2; k++) for (int l=0; l<2; l++) { |
199 | fSurveyX[i][j][k][l] = source.fSurveyX[i][j][k][l]; | |
200 | fSurveyY[i][j][k][l] = source.fSurveyY[i][j][k][l]; | |
201 | fSurveyZ[i][j][k][l] = source.fSurveyZ[i][j][k][l]; | |
afba1460 | 202 | fSurveyEX[i][j][k][l] = source.fSurveyEX[i][j][k][l]; |
203 | fSurveyEY[i][j][k][l] = source.fSurveyEY[i][j][k][l]; | |
204 | fSurveyEZ[i][j][k][l] = source.fSurveyEZ[i][j][k][l]; | |
d15124a9 | 205 | } |
206 | for (int j=0; j<2; j++) for (int k=0; k<2; k++) for (int l=0; l<2; l++) { | |
207 | fSurveyX0[j][k][l] = source.fSurveyX0[j][k][l]; | |
208 | fSurveyY0[j][k][l] = source.fSurveyY0[j][k][l]; | |
209 | fSurveyZ0[j][k][l] = source.fSurveyZ0[j][k][l]; | |
210 | } | |
211 | fComment = source.fComment; | |
8775e4e8 | 212 | } |
213 | ||
214 | return *this; | |
215 | ||
216 | } | |
217 | ||
d15124a9 | 218 | //_____________________________________________________________________________ |
219 | AliTRDalignment& AliTRDalignment::operator*=(double fac) | |
220 | { | |
221 | // | |
222 | // multiplication operator | |
223 | // | |
224 | ||
225 | for (int i = 0; i < 18; i++) for (int j = 0; j < 6; j++) this->fSm[i][j] *= fac; | |
226 | for (int i = 0; i < 540; i++) for (int j = 0; j < 6; j++) this->fCh[i][j] *= fac; | |
227 | ||
228 | return *this; | |
229 | ||
230 | } | |
231 | ||
8775e4e8 | 232 | //_____________________________________________________________________________ |
233 | AliTRDalignment& AliTRDalignment::operator+=(const AliTRDalignment &source) | |
234 | { | |
235 | // | |
236 | // addition operator | |
237 | // | |
238 | ||
d15124a9 | 239 | for (int i = 0; i < 18; i++) for (int j = 0; j < 6; j++) this->fSm[i][j] += source.fSm[i][j]; |
240 | for (int i = 0; i < 540; i++) for (int j = 0; j < 6; j++) this->fCh[i][j] += source.fCh[i][j]; | |
8775e4e8 | 241 | |
242 | return *this; | |
243 | ||
244 | } | |
245 | ||
246 | //_____________________________________________________________________________ | |
247 | AliTRDalignment& AliTRDalignment::operator-=(const AliTRDalignment &source) | |
248 | { | |
249 | // | |
250 | // subtraction operator | |
251 | // | |
252 | ||
d15124a9 | 253 | for (int i = 0; i < 18; i++) for (int j = 0; j < 6; j++) fSm[i][j] -= source.fSm[i][j]; |
254 | for (int i = 0; i < 540; i++) for (int j = 0; j < 6; j++) fCh[i][j] -= source.fCh[i][j]; | |
8775e4e8 | 255 | |
256 | return *this; | |
257 | ||
258 | } | |
259 | ||
260 | //_____________________________________________________________________________ | |
261 | Bool_t AliTRDalignment::operator==(const AliTRDalignment &source) const | |
262 | { | |
263 | // | |
264 | // comparison operator | |
265 | // | |
266 | ||
267 | Bool_t areEqual = 1; | |
268 | ||
d15124a9 | 269 | for (int i = 0; i < 18; i++) for (int j = 0; j < 6; j++) areEqual &= (fSm[i][j] == source.fSm[i][j]); |
270 | for (int i = 0; i < 540; i++) for (int j = 0; j < 6; j++) areEqual &= (fCh[i][j] == source.fCh[i][j]); | |
8775e4e8 | 271 | |
272 | return areEqual; | |
273 | ||
274 | } | |
275 | ||
276 | //_____________________________________________________________________________ | |
277 | void AliTRDalignment::SetSmZero() | |
278 | { | |
279 | // | |
280 | // reset to zero supermodule data | |
281 | // | |
282 | ||
283 | memset(&fSm[0][0],0,sizeof(fSm)); | |
284 | ||
285 | } | |
286 | ||
287 | //_____________________________________________________________________________ | |
288 | void AliTRDalignment::SetChZero() | |
289 | { | |
290 | // | |
291 | // reset to zero chamber data | |
292 | // | |
293 | ||
294 | memset(&fCh[0][0],0,sizeof(fCh)); | |
295 | ||
296 | } | |
297 | ||
298 | //_____________________________________________________________________________ | |
d15124a9 | 299 | void AliTRDalignment::SetSmRandom(double a[6]) |
8775e4e8 | 300 | { |
301 | // | |
302 | // generate random gaussian supermodule data with sigmas a | |
303 | // | |
304 | ||
305 | double x[6]; | |
3415c35c | 306 | double xmax[6]={999, 0.6, 999, 999, 999, 999}; |
8775e4e8 | 307 | |
d15124a9 | 308 | for (int i = 0; i < 18; i++) { |
3415c35c | 309 | for (int j = 0; j < 6; j++) { |
310 | do {x[j] = fRan.Gaus(0,a[j]);} while (TMath::Abs(x[j]) > xmax[j]); | |
311 | } | |
8775e4e8 | 312 | SetSm(i,x); |
313 | //PrintSm(i); | |
314 | } | |
315 | ||
316 | } | |
317 | ||
318 | //_____________________________________________________________________________ | |
d15124a9 | 319 | void AliTRDalignment::SetChRandom(double a[6]) |
8775e4e8 | 320 | { |
321 | // | |
322 | // generate random gaussian chamber data with sigmas a | |
323 | // | |
324 | ||
325 | double x[6]; | |
326 | ||
d15124a9 | 327 | for (int i = 0; i < 540; i++) { |
8775e4e8 | 328 | fRan.Rannor(x[0],x[1]); |
329 | fRan.Rannor(x[2],x[3]); | |
330 | fRan.Rannor(x[4],x[5]); | |
d15124a9 | 331 | for (int j = 0; j < 6; j++) x[j] *= a[j]; |
8775e4e8 | 332 | SetCh(i,x); |
333 | //PrintCh(i); | |
334 | } | |
335 | ||
336 | } | |
337 | ||
338 | //_____________________________________________________________________________ | |
339 | void AliTRDalignment::SetSmFull() | |
340 | { | |
341 | // | |
342 | // generate random gaussian supermodule data similar to the misalignment | |
343 | // expected from the mechanical precision | |
344 | // | |
345 | ||
d15124a9 | 346 | double a[6]; |
8775e4e8 | 347 | |
348 | a[0] = 0.3; // phi | |
349 | a[1] = 0.3; // z | |
350 | a[2] = 0.3; // r | |
351 | a[3] = 0.4/1000.0 / TMath::Pi()*180.0; // phi | |
352 | a[4] = 2.0/1000.0 / TMath::Pi()*180.0; // z | |
353 | a[5] = 0.4/1000.0 / TMath::Pi()*180.0; // r | |
354 | ||
355 | SetSmRandom(a); | |
356 | ||
357 | } | |
358 | ||
359 | //_____________________________________________________________________________ | |
360 | void AliTRDalignment::SetChFull() | |
361 | { | |
362 | // | |
363 | // generate random gaussian chamber data similar to the misalignment | |
364 | // expected from the mechanical precision | |
365 | // | |
366 | ||
d15124a9 | 367 | double a[6]; |
8775e4e8 | 368 | |
369 | a[0] = 0.1; // phi | |
370 | a[1] = 0.1; // z | |
371 | a[2] = 0.1; // r | |
372 | a[3] = 1.0/1000.0 / TMath::Pi()*180.0; // phi | |
373 | a[4] = 1.0/1000.0 / TMath::Pi()*180.0; // z | |
374 | a[5] = 0.7/1000.0 / TMath::Pi()*180.0; // r | |
375 | ||
376 | SetChRandom(a); | |
377 | ||
378 | } | |
379 | ||
380 | //_____________________________________________________________________________ | |
381 | void AliTRDalignment::SetSmResidual() | |
382 | { | |
383 | // | |
384 | // generate random gaussian supermodule data similar to the misalignment | |
385 | // remaining after full calibration | |
386 | // I assume that it will be negligible | |
387 | // | |
388 | ||
389 | SetSmZero(); | |
390 | ||
391 | } | |
392 | ||
393 | //_____________________________________________________________________________ | |
394 | void AliTRDalignment::SetChResidual() | |
395 | { | |
396 | // | |
397 | // generate random gaussian chamber data similar to the misalignment | |
398 | // remaining after full calibration | |
399 | // | |
400 | ||
d15124a9 | 401 | double a[6]; |
8775e4e8 | 402 | |
403 | a[0] = 0.002; // phi | |
404 | a[1] = 0.003; // z | |
405 | a[2] = 0.007; // r | |
406 | a[3] = 0.3/1000.0 / TMath::Pi()*180.0; // phi | |
407 | a[4] = 0.3/1000.0 / TMath::Pi()*180.0; // z | |
408 | a[5] = 0.1/1000.0 / TMath::Pi()*180.0; // r | |
409 | ||
410 | SetChRandom(a); | |
411 | ||
412 | } | |
413 | ||
414 | //_____________________________________________________________________________ | |
5626950c | 415 | void AliTRDalignment::PrintSm(int i, FILE * const fp) const |
8775e4e8 | 416 | { |
417 | // | |
418 | // print the supermodule data | |
419 | // | |
420 | ||
421 | fprintf(fp,"%4d %11.4f %11.4f %11.4f %11.5f %11.5f %11.5f %6d %s\n" | |
422 | ,i,fSm[i][0],fSm[i][1],fSm[i][2],fSm[i][3],fSm[i][4],fSm[i][5] | |
423 | ,0,GetSmName(i)); | |
424 | ||
425 | } | |
426 | ||
427 | //_____________________________________________________________________________ | |
5626950c | 428 | void AliTRDalignment::PrintCh(int i, FILE * const fp) const |
8775e4e8 | 429 | { |
430 | // | |
431 | // print the chamber data | |
432 | // | |
433 | ||
434 | fprintf(fp,"%4d %11.4f %11.4f %11.4f %11.5f %11.5f %11.5f %6d %s\n" | |
435 | ,i,fCh[i][0],fCh[i][1],fCh[i][2],fCh[i][3],fCh[i][4],fCh[i][5] | |
436 | ,GetVoi(i),GetChName(i)); | |
437 | ||
438 | } | |
439 | ||
440 | //_____________________________________________________________________________ | |
5626950c | 441 | void AliTRDalignment::ReadAscii(const char * const filename) |
8775e4e8 | 442 | { |
443 | // | |
444 | // read the alignment data from ascii file | |
445 | // | |
446 | ||
447 | double x[6]; // alignment data | |
448 | int volid; // volume id | |
449 | std::string syna; // symbolic name | |
450 | int j; // dummy index | |
451 | ||
452 | fstream fi(filename,fstream::in); | |
453 | if (!fi) { | |
d15124a9 | 454 | AliError(Form("cannot open input file %s",filename)); |
455 | return; | |
8775e4e8 | 456 | } |
457 | ||
458 | // supermodules | |
459 | ||
460 | for (int i = 0; i < 18; i++) { | |
461 | fi>>j>>x[0]>>x[1]>>x[2]>>x[3]>>x[4]>>x[5]>>volid>>syna; | |
d15124a9 | 462 | if (j != i) AliError(Form("sm %d expected, %d found",i,j)); |
463 | if (volid != 0) AliError(Form("sm %d volume id %d expected, %d found",i,0,volid)); | |
8775e4e8 | 464 | std::string symnam = GetSmName(i); |
d15124a9 | 465 | if (syna != symnam) AliError(Form("sm %d name %s expected, %s found",i,symnam.data(),syna.data())); |
8775e4e8 | 466 | SetSm(i,x); |
467 | } | |
468 | ||
469 | // chambers | |
470 | ||
471 | for (int i = 0; i < 540; i++) { | |
472 | fi>>j>>x[0]>>x[1]>>x[2]>>x[3]>>x[4]>>x[5]>>volid>>syna; | |
d15124a9 | 473 | if (j != i) AliError(Form("ch %d expected, %d found",i,j)); |
474 | if (volid != GetVoi(i)) AliError(Form("ch %d volume id %d expected, %d found",i,GetVoi(i),volid)); | |
8775e4e8 | 475 | std::string symnam = GetChName(i); |
d15124a9 | 476 | if (syna != symnam) AliError(Form("ch %d name %s expected, %s found",i,symnam.data(),syna.data())); |
8775e4e8 | 477 | SetCh(i,x); |
478 | } | |
479 | ||
480 | fi.close(); | |
481 | ||
482 | } | |
483 | ||
484 | //_____________________________________________________________________________ | |
69219822 | 485 | void AliTRDalignment::ReadCurrentGeo() |
8775e4e8 | 486 | { |
487 | // | |
69219822 | 488 | // use currently loaded geometry to determine misalignment by comparing |
489 | // original and misaligned matrix of the last node | |
490 | // Now, original, does not mean "ideal". It is the matrix before the alignment. | |
491 | // So, if alignment was applied more than once, the numbers extracted will | |
492 | // represent just the last alignment. -- check this! | |
8775e4e8 | 493 | // |
494 | ||
9c485614 | 495 | TGeoPNEntry *pne; |
8775e4e8 | 496 | TGeoHMatrix *ideSm[18]; // ideal |
8775e4e8 | 497 | TGeoHMatrix *misSm[18]; // misaligned |
b1e8dacb | 498 | for (int i = 0; i < 18; i++) if ((pne = gGeoManager->GetAlignableEntry(GetSmName(i)))) { |
8775e4e8 | 499 | |
69219822 | 500 | // read misaligned and original matrices |
8775e4e8 | 501 | |
8775e4e8 | 502 | TGeoPhysicalNode *node = pne->GetPhysicalNode(); |
69219822 | 503 | if (!node) AliError(Form("physical node entry %s has no physical node",GetSmName(i))); |
504 | if (!node) continue; | |
8775e4e8 | 505 | misSm[i] = new TGeoHMatrix(*node->GetNode(node->GetLevel())->GetMatrix()); |
506 | ideSm[i] = new TGeoHMatrix(*node->GetOriginalMatrix()); | |
8775e4e8 | 507 | |
69219822 | 508 | // calculate the local misalignment matrices as inverse misaligned times ideal |
8775e4e8 | 509 | |
8775e4e8 | 510 | TGeoHMatrix mat(ideSm[i]->Inverse()); |
511 | mat.Multiply(misSm[i]); | |
512 | double *tra = mat.GetTranslation(); | |
513 | double *rot = mat.GetRotationMatrix(); | |
514 | double pars[6]; | |
515 | pars[0] = tra[0]; | |
516 | pars[1] = tra[1]; | |
517 | pars[2] = tra[2]; | |
d15124a9 | 518 | if (TMath::Abs(rot[0])<1e-7 || TMath::Abs(rot[8])<1e-7) AliError("Failed to extract roll-pitch-yall angles!"); |
8775e4e8 | 519 | double raddeg = TMath::RadToDeg(); |
520 | pars[3] = raddeg * TMath::ATan2(-rot[5],rot[8]); | |
521 | pars[4] = raddeg * TMath::ASin(rot[2]); | |
522 | pars[5] = raddeg * TMath::ATan2(-rot[1],rot[0]); | |
523 | SetSm(i,pars); | |
69219822 | 524 | |
525 | // cleanup | |
526 | ||
527 | delete ideSm[i]; | |
528 | delete misSm[i]; | |
8775e4e8 | 529 | } |
530 | ||
69219822 | 531 | TGeoHMatrix *ideCh[540]; // ideal |
532 | TGeoHMatrix *misCh[540]; // misaligned | |
b1e8dacb | 533 | for (int i = 0; i < 540; i++) if ((pne = gGeoManager->GetAlignableEntry(GetChName(i)))) { |
69219822 | 534 | |
535 | // read misaligned and original matrices | |
536 | ||
69219822 | 537 | TGeoPhysicalNode *node = pne->GetPhysicalNode(); |
538 | if (!node) AliError(Form("physical node entry %s has no physical node",GetChName(i))); | |
539 | if (!node) continue; | |
540 | misCh[i] = new TGeoHMatrix(*node->GetNode(node->GetLevel())->GetMatrix()); | |
541 | ideCh[i] = new TGeoHMatrix(*node->GetOriginalMatrix()); | |
542 | ||
543 | // calculate the local misalignment matrices as inverse misaligned times ideal | |
544 | ||
8775e4e8 | 545 | TGeoHMatrix mat(ideCh[i]->Inverse()); |
546 | mat.Multiply(misCh[i]); | |
547 | double *tra = mat.GetTranslation(); | |
548 | double *rot = mat.GetRotationMatrix(); | |
549 | double pars[6]; | |
550 | pars[0] = tra[0]; | |
551 | pars[1] = tra[1]; | |
552 | pars[2] = tra[2]; | |
553 | if(TMath::Abs(rot[0])<1e-7 || TMath::Abs(rot[8])<1e-7) { | |
554 | AliError("Failed to extract roll-pitch-yall angles!"); | |
555 | return; | |
556 | } | |
557 | double raddeg = TMath::RadToDeg(); | |
558 | pars[3] = raddeg * TMath::ATan2(-rot[5],rot[8]); | |
559 | pars[4] = raddeg * TMath::ASin(rot[2]); | |
560 | pars[5] = raddeg * TMath::ATan2(-rot[1],rot[0]); | |
561 | SetCh(i,pars); | |
69219822 | 562 | |
563 | // cleanup | |
564 | delete ideCh[i]; | |
565 | delete misCh[i]; | |
8775e4e8 | 566 | } |
567 | ||
69219822 | 568 | return; |
569 | ||
570 | } | |
571 | ||
572 | //_____________________________________________________________________________ | |
5626950c | 573 | void AliTRDalignment::ReadRoot(const char * const filename) |
69219822 | 574 | { |
575 | // | |
576 | // read the alignment data from root file | |
577 | // | |
578 | ||
579 | TFile fi(filename,"READ"); | |
580 | ||
581 | if (fi.IsOpen()) { | |
582 | TClonesArray *ar = (TClonesArray*) fi.Get("TRDAlignObjs"); | |
583 | ArToNumbers(ar); | |
584 | fi.Close(); | |
585 | } | |
586 | else AliError(Form("cannot open input file %s",filename)); | |
8775e4e8 | 587 | |
588 | return; | |
589 | ||
590 | } | |
591 | ||
69219822 | 592 | //_____________________________________________________________________________ |
5626950c | 593 | void AliTRDalignment::ReadDB(const char * const filename) |
69219822 | 594 | { |
595 | // | |
596 | // read the alignment data from database file | |
597 | // | |
598 | ||
599 | TFile fi(filename,"READ"); | |
600 | ||
601 | if (fi.IsOpen()) { | |
602 | AliCDBEntry *e = (AliCDBEntry *) fi.Get("AliCDBEntry"); | |
603 | e->PrintMetaData(); | |
604 | fComment.SetString(e->GetMetaData()->GetComment()); | |
605 | TClonesArray *ar = (TClonesArray *) e->GetObject(); | |
606 | ArToNumbers(ar); | |
607 | fi.Close(); | |
608 | } | |
609 | else AliError(Form("cannot open input file %s",filename)); | |
610 | ||
611 | return; | |
612 | ||
613 | } | |
614 | ||
615 | //_____________________________________________________________________________ | |
5626950c | 616 | void AliTRDalignment::ReadDB(const char * const db, const char * const path, |
617 | int run, int version, int subversion) | |
69219822 | 618 | { |
619 | // | |
620 | // read the alignment data from database | |
621 | // | |
622 | ||
623 | AliCDBManager *cdb = AliCDBManager::Instance(); | |
624 | AliCDBStorage *storLoc = cdb->GetStorage(db); | |
625 | AliCDBEntry *e = storLoc->Get(path,run,version,subversion); | |
626 | if (e) { | |
627 | e->PrintMetaData(); | |
628 | fComment.SetString(e->GetMetaData()->GetComment()); | |
629 | TClonesArray *ar = (TClonesArray *) e->GetObject(); | |
630 | ArToNumbers(ar); | |
631 | } | |
632 | } | |
633 | ||
afba1460 | 634 | //_____________________________________________________________________________ |
635 | Bool_t AliTRDalignment::DecodeSurveyPointName(TString pna, Int_t &sm, Int_t &iz, | |
636 | Int_t &ir, Int_t &iphi) { | |
637 | // decode the survey point name and extract the sm, z, r and phi indices | |
638 | ||
639 | if (pna(0,6)!="TRD_sm") { | |
640 | AliError(Form("unexpected point name: %s",pna.Data())); | |
641 | return kFALSE; | |
642 | } | |
643 | sm = atoi(pna(6,2).Data()); // supermodule number | |
644 | iz = -1; | |
645 | if (pna(8) == 'a') iz=0; // anticlockwise, positive z | |
646 | if (pna(8) == 'c') iz=1; // clockwise, negative z | |
647 | ir = -1; | |
648 | if (pna(9) == 'l') ir=0; // low radius | |
649 | if (pna(9) == 'h') ir=1; // high radius | |
3415c35c | 650 | iphi = -1; |
651 | if (pna(10) == '0') iphi = 0; // low phi within supermodule | |
652 | if (pna(10) == '1') iphi = 1; // high phi within supermodule | |
afba1460 | 653 | if (sm>=0 && sm<18 && iz>=0 && iz<2 && ir>=0 && ir<2 && iphi>=0 && iphi<2) return kTRUE; |
654 | AliError(Form("cannot decode point name: %s",pna.Data())); | |
655 | return kFALSE; | |
656 | } | |
3415c35c | 657 | |
8775e4e8 | 658 | //_____________________________________________________________________________ |
5626950c | 659 | void AliTRDalignment::ReadSurveyReport(const char * const filename) |
8775e4e8 | 660 | { |
d15124a9 | 661 | // |
662 | // Read survey report and store the numbers in fSurveyX, fSurveyY, fSurveyZ, | |
663 | // and fSurveyE. Store the survey info in the fComment. | |
664 | // Each supermodule has 8 survey points. The point names look like | |
665 | // TRD_sm08ah0 and have the following meaning. | |
666 | // | |
667 | // sm00..17 mean supermodule 0 through 17, following the phi. | |
668 | // Supermodule 00 is between phi=0 and phi=20 degrees. | |
669 | // | |
670 | // a or c denotes the anticlockwise and clockwise end of the supermodule | |
671 | // in z. Clockwise end is where z is negative and where the muon arm sits. | |
672 | // | |
673 | // l or h denote low radius and high radius holes | |
674 | // | |
675 | // 0 or 1 denote the hole at smaller and at larger phi, respectively. | |
676 | // | |
8775e4e8 | 677 | |
d15124a9 | 678 | // read the survey file |
679 | ||
680 | fstream in(filename,fstream::in); | |
681 | if (!in) { | |
682 | AliError(Form("cannot open input file %s",filename)); | |
683 | return; | |
684 | } | |
685 | ||
686 | // loop through the lines of the file until the beginning of data | |
687 | ||
688 | TString title,date,subdetector,url,version,observations,system,units; | |
689 | while (1) { | |
690 | char pee=in.peek(); | |
691 | if (pee==EOF) break; | |
692 | TString line; | |
693 | line.ReadLine(in); | |
694 | if (line.Contains("Title:")) title.ReadLine(in); | |
695 | if (line.Contains("Date:")) date.ReadLine(in); | |
696 | if (line.Contains("Subdetector:")) subdetector.ReadLine(in); | |
697 | if (line.Contains("URL:")) url.ReadLine(in); | |
698 | if (line.Contains("Version:")) version.ReadLine(in); | |
699 | if (line.Contains("Observations:")) observations.ReadLine(in); | |
700 | if (line.Contains("System:")) system.ReadLine(in); | |
701 | if (line.Contains("Units:")) units.ReadLine(in); | |
702 | if (line.Contains("Data:")) break; | |
703 | } | |
704 | ||
705 | // check what we found so far (watch out, they have \r at the end) | |
706 | ||
707 | std::cout<<"title .........."<<title<<std::endl; | |
708 | std::cout<<"date ..........."<<date<<std::endl; | |
709 | std::cout<<"subdetector ...."<<subdetector<<std::endl; | |
710 | std::cout<<"url ............"<<url<<std::endl; | |
711 | std::cout<<"version ........"<<version<<std::endl; | |
712 | std::cout<<"observations ..."<<observations<<std::endl; | |
713 | std::cout<<"system ........."<<system<<std::endl; | |
714 | std::cout<<"units .........."<<units<<std::endl; | |
715 | ||
716 | if (!subdetector.Contains("TRD")) { | |
717 | AliWarning(Form("Not a TRD survey file, subdetector = %s",subdetector.Data())); | |
718 | return; | |
719 | } | |
720 | double tocm = 0; // we want to have it in cm | |
721 | if (units.Contains("mm")) tocm = 0.1; | |
722 | else if (units.Contains("cm")) tocm = 1.0; | |
723 | else if (units.Contains("m")) tocm = 100.0; | |
724 | else if (units.Contains("pc")) tocm = 3.24078e-15; | |
725 | else { | |
726 | AliError(Form("unexpected units: %s",units.Data())); | |
727 | return; | |
728 | } | |
729 | if (!system.Contains("ALICEPH")) { | |
730 | AliError(Form("wrong system: %s, should be ALICEPH",system.Data())); | |
731 | return; | |
8775e4e8 | 732 | } |
733 | ||
d15124a9 | 734 | // scan the rest of the file which should contain list of surveyed points |
735 | // for every point, decode the point name and store the numbers in the right | |
736 | // place in the arrays fSurveyX etc. | |
737 | ||
738 | while (1) { | |
739 | TString pna; // point name | |
afba1460 | 740 | char type, target; |
d15124a9 | 741 | double x,y,z,precision; |
afba1460 | 742 | |
743 | in >> pna >> x >> y >> z >> type >> target >> precision; | |
d15124a9 | 744 | if (in.fail()) break; |
afba1460 | 745 | Int_t i,j,k,l; |
746 | if (DecodeSurveyPointName(pna,i,j,k,l)) { | |
d15124a9 | 747 | fSurveyX[i][j][k][l] = tocm*x; |
748 | fSurveyY[i][j][k][l] = tocm*y; | |
749 | fSurveyZ[i][j][k][l] = tocm*z; | |
afba1460 | 750 | fSurveyEX[i][j][k][l] = precision/10; // "precision" is supposed to be in mm |
751 | fSurveyEY[i][j][k][l] = precision/10; // "precision" is supposed to be in mm | |
752 | fSurveyEZ[i][j][k][l] = precision/10; // "precision" is supposed to be in mm | |
753 | // if, at some point, separate precision numbers for x,y,z show up in the | |
754 | // survey reports the function will fail here | |
3415c35c | 755 | printf("decoded %s %02d %d %d %d %8.2f %8.2f %8.2f %6.2f %6.2f %6.2f\n", |
756 | pna.Data(), i, j, k, l, | |
757 | fSurveyX[i][j][k][l], fSurveyY[i][j][k][l], fSurveyZ[i][j][k][l], | |
758 | fSurveyEX[i][j][k][l], fSurveyEY[i][j][k][l], fSurveyEZ[i][j][k][l]); | |
d15124a9 | 759 | } else AliError(Form("cannot decode point name: %s",pna.Data())); |
760 | } | |
761 | in.close(); | |
762 | TString info = "Survey "+title+" "+date+" "+url+" "+version+" "+observations; | |
763 | info.ReplaceAll("\r",""); | |
764 | fComment.SetString(info.Data()); | |
3415c35c | 765 | |
d15124a9 | 766 | } |
767 | ||
afba1460 | 768 | //_____________________________________________________________________________ |
5626950c | 769 | void AliTRDalignment::ReadSurveyReport(const AliSurveyObj * const so) |
afba1460 | 770 | { |
771 | // | |
772 | // Read survey report and store the numbers in fSurveyX, fSurveyY, fSurveyZ, | |
773 | // and fSurveyE. Store the survey info in the fComment. | |
774 | // Each supermodule has 8 survey points. The point names look like | |
775 | // TRD_sm08ah0 and have the following meaning. | |
776 | // | |
777 | // sm00..17 mean supermodule 0 through 17, following the phi. | |
778 | // Supermodule 00 is between phi=0 and phi=20 degrees. | |
779 | // | |
780 | // a or c denotes the anticlockwise and clockwise end of the supermodule | |
781 | // in z. Clockwise end is where z is negative and where the muon arm sits. | |
782 | // | |
783 | // l or h denote low radius and high radius holes | |
784 | // | |
785 | // 0 or 1 denote the hole at smaller and at larger phi, respectively. | |
786 | // | |
787 | ||
788 | // read and process the data from the survey object | |
789 | ||
790 | Int_t size = so->GetEntries(); | |
791 | printf("-> %d\n", size); | |
792 | ||
793 | TString title = so->GetReportTitle(); | |
794 | TString date = so->GetReportDate(); | |
795 | TString subdetector = so->GetDetector(); | |
796 | TString url = so->GetURL(); | |
797 | TString report = so->GetReportNumber(); | |
798 | TString version = so->GetReportVersion(); | |
799 | TString observations = so->GetObservations(); | |
800 | TString system = so->GetCoordSys(); | |
801 | TString units = so->GetUnits(); | |
802 | ||
803 | // check what we found so far (watch out, they have \r at the end) | |
804 | ||
805 | std::cout<<"title .........."<<title<<std::endl; | |
806 | std::cout<<"date ..........."<<date<<std::endl; | |
807 | std::cout<<"subdetector ...."<<subdetector<<std::endl; | |
808 | std::cout<<"url ............"<<url<<std::endl; | |
809 | std::cout<<"version ........"<<version<<std::endl; | |
810 | std::cout<<"observations ..."<<observations<<std::endl; | |
811 | std::cout<<"system ........."<<system<<std::endl; | |
812 | std::cout<<"units .........."<<units<<std::endl; | |
813 | ||
814 | if (!subdetector.Contains("TRD")) { | |
815 | AliWarning(Form("Not a TRD survey file, subdetector = %s",subdetector.Data())); | |
816 | return; | |
817 | } | |
818 | double tocm = 0; // we want to have it in cm | |
819 | if (units.Contains("mm")) tocm = 0.1; | |
820 | else if (units.Contains("cm")) tocm = 1.0; | |
821 | else if (units.Contains("m")) tocm = 100.0; | |
822 | else if (units.Contains("pc")) tocm = 3.24078e-15; | |
823 | else { | |
824 | AliError(Form("unexpected units: %s",units.Data())); | |
825 | return; | |
826 | } | |
827 | if (!system.Contains("ALICEPH")) { | |
828 | AliError(Form("wrong system: %s, should be ALICEPH",system.Data())); | |
829 | return; | |
830 | } | |
831 | ||
832 | // for every survey point, decode the point name and store the numbers in | |
833 | // the right place in the arrays fSurveyX etc. | |
834 | ||
835 | TObjArray *points = so->GetData(); | |
7bce990c | 836 | for (int ip = 0; ip<points->GetEntries(); ++ip) { |
837 | AliSurveyPoint *po = (AliSurveyPoint *) points->At(ip); | |
afba1460 | 838 | TString pna = po->GetPointName(); |
839 | Int_t i,j,k,l; | |
840 | if (DecodeSurveyPointName(pna,i,j,k,l)) { | |
841 | fSurveyX[i][j][k][l] = tocm*po->GetX(); | |
842 | fSurveyY[i][j][k][l] = tocm*po->GetY(); | |
843 | fSurveyZ[i][j][k][l] = tocm*po->GetZ(); | |
844 | fSurveyEX[i][j][k][l] = po->GetPrecisionX()/10; // "precision" is supposed to be in mm | |
845 | fSurveyEY[i][j][k][l] = po->GetPrecisionY()/10; | |
846 | fSurveyEZ[i][j][k][l] = po->GetPrecisionZ()/10; | |
3415c35c | 847 | printf("decoded %s %02d %d %d %d %8.2f %8.2f %8.2f %6.2f %6.2f %6.2f\n", |
848 | pna.Data(), i, j, k, l, | |
849 | fSurveyX[i][j][k][l], fSurveyY[i][j][k][l], fSurveyZ[i][j][k][l], | |
850 | fSurveyEX[i][j][k][l], fSurveyEY[i][j][k][l], fSurveyEZ[i][j][k][l]); | |
afba1460 | 851 | } else AliError(Form("cannot decode point name: %s",pna.Data())); |
852 | } | |
853 | ||
854 | TString info = "Survey "+title+" "+date+" "+url+" "+report+" "+version+" "+observations; | |
855 | info.ReplaceAll("\r",""); | |
856 | fComment.SetString(info.Data()); | |
857 | } | |
858 | ||
d15124a9 | 859 | //_____________________________________________________________________________ |
5626950c | 860 | double AliTRDalignment::SurveyChi2(int i, const double * const a) { |
d15124a9 | 861 | |
862 | // | |
863 | // Compare the survey results to the ideal positions of the survey marks | |
864 | // in the local frame of supermodule. When transforming, use the alignment | |
865 | // parameters a[6]. Return chi-squared. | |
866 | // | |
867 | ||
69219822 | 868 | if (!IsGeoLoaded()) return 0; |
d15124a9 | 869 | printf("Survey of supermodule %d\n",i); |
90dbf5fb | 870 | AliAlignObjParams al(GetSmName(i),0,a[0],a[1],a[2],a[3],a[4],a[5],0); |
fef4997a | 871 | |
d15124a9 | 872 | TGeoPNEntry *pne = gGeoManager->GetAlignableEntry(GetSmName(i)); |
873 | if (!pne) AliError(Form("no such physical node entry: %s",GetSmName(i))); | |
874 | TGeoPhysicalNode *node = pne->GetPhysicalNode(); | |
fef4997a | 875 | if (!node) { |
876 | AliWarning(Form("physical node entry %s has no physical node; making a new one",GetSmName(i))); | |
877 | node = gGeoManager->MakeAlignablePN(pne); | |
878 | } | |
d15124a9 | 879 | |
880 | // al.ApplyToGeometry(); | |
881 | // node = pne->GetPhysicalNode(); // changed in the meantime | |
882 | // TGeoHMatrix *ma = node->GetMatrix(); | |
883 | ||
884 | // a less destructive method (it does not modify geometry), gives the same result: | |
885 | ||
886 | TGeoHMatrix *ma = new TGeoHMatrix(); | |
887 | al.GetLocalMatrix(*ma); | |
888 | ma->MultiplyLeft(node->GetMatrix()); // global trafo, modified by a[] | |
889 | ||
890 | double chi2=0; | |
891 | printf(" sm z r phi x (lab phi) y (lab z) z (lab r) all in cm\n"); | |
892 | for (int j=0; j<2; j++) for (int k=0; k<2; k++) for (int l=0; l<2; l++) { | |
afba1460 | 893 | if (fSurveyEX[i][j][k][l] == 0.0 |
894 | && fSurveyEY[i][j][k][l] == 0.0 | |
895 | && fSurveyEZ[i][j][k][l] == 0.0) continue; // no data for this survey point | |
d15124a9 | 896 | double master[3] = {fSurveyX[i][j][k][l],fSurveyY[i][j][k][l],fSurveyZ[i][j][k][l]}; |
897 | double local[3]; | |
898 | ma->MasterToLocal(master,local); | |
899 | double dx = local[0]-fSurveyX0[j][k][l]; | |
900 | double dy = local[1]-fSurveyY0[j][k][l]; | |
901 | double dz = local[2]-fSurveyZ0[j][k][l]; | |
afba1460 | 902 | chi2 += dx*dx/fSurveyEX[i][j][k][l]/fSurveyEX[i][j][k][l]; |
903 | chi2 += dy*dy/fSurveyEY[i][j][k][l]/fSurveyEY[i][j][k][l]; | |
904 | chi2 += dz*dz/fSurveyEZ[i][j][k][l]/fSurveyEZ[i][j][k][l]; | |
d15124a9 | 905 | printf("local survey %3d %3d %3d %3d %12.3f %12.3f %12.3f\n",i,j,k,l,local[0],local[1],local[2]); |
906 | printf("local ideal %12.3f %12.3f %12.3f\n",fSurveyX0[j][k][l], | |
907 | fSurveyY0[j][k][l],fSurveyZ0[j][k][l]); | |
908 | printf("difference %12.3f %12.3f %12.3f\n",dx,dy,dz); | |
909 | } | |
910 | printf("chi2 = %.2f\n",chi2); | |
911 | return chi2; | |
912 | } | |
913 | ||
914 | //_____________________________________________________________________________ | |
69219822 | 915 | void trdAlignmentFcn(int &npar, double *g, double &f, double *par, int iflag) { |
d15124a9 | 916 | |
917 | // | |
918 | // Standard function as needed by Minuit-like minimization procedures. | |
919 | // For the set of parameters par calculates and returns chi-squared. | |
920 | // | |
921 | ||
922 | // smuggle a C++ object into a C function | |
923 | AliTRDalignment *alignment = (AliTRDalignment*) gMinuit->GetObjectFit(); | |
924 | ||
925 | f = alignment->SurveyChi2(par); | |
4f57cad7 | 926 | if (iflag==3) {} |
927 | if (npar) {} | |
928 | if (g) {} // no warnings about unused stuff... | |
d15124a9 | 929 | |
930 | } | |
931 | ||
932 | //_____________________________________________________________________________ | |
5626950c | 933 | void AliTRDalignment::SurveyToAlignment(int i, const char * const flag) { |
d15124a9 | 934 | |
935 | // | |
936 | // Find the supermodule alignment parameters needed to make the survey | |
937 | // results coincide with the ideal positions of the survey marks. | |
938 | // The string flag should look like "101000"; the six characters corresponds | |
939 | // to the six alignment parameters and 0/1 mean that the parameter should | |
940 | // be fixed/released in the fit. | |
941 | ||
942 | if (strlen(flag)!=6) { | |
943 | AliError(Form("unexpected flag: %s",flag)); | |
944 | return; | |
945 | } | |
946 | ||
947 | printf("Finding alignment matrix for supermodule %d\n",i); | |
948 | fIbuffer[0] = i; // store the sm number in the buffer so minuit can see it | |
949 | ||
950 | TFitter fitter(100); | |
951 | gMinuit->SetObjectFit(this); | |
69219822 | 952 | fitter.SetFCN(trdAlignmentFcn); |
d15124a9 | 953 | fitter.SetParameter(0,"dx",0,0.5,0,0); |
954 | fitter.SetParameter(1,"dy",0,0.5,0,0); | |
955 | fitter.SetParameter(2,"dz",0,0.5,0,0); | |
956 | fitter.SetParameter(3,"rx",0,0.1,0,0); | |
957 | fitter.SetParameter(4,"ry",0,0.1,0,0); | |
958 | fitter.SetParameter(5,"rz",0,0.1,0,0); | |
959 | ||
960 | for (int j=0; j<6; j++) if (flag[j]=='0') fitter.FixParameter(j); | |
961 | ||
962 | double arglist[100]; | |
963 | arglist[0] = 2; | |
964 | fitter.ExecuteCommand("SET PRINT", arglist, 1); | |
965 | fitter.ExecuteCommand("SET ERR", arglist, 1); | |
966 | arglist[0]=50; | |
967 | //fitter.ExecuteCommand("SIMPLEX", arglist, 1); | |
968 | fitter.ExecuteCommand("MINIMIZE", arglist, 1); | |
969 | fitter.ExecuteCommand("CALL 3", arglist,0); | |
970 | double a[6]; | |
971 | for (int j=0; j<6; j++) a[j] = fitter.GetParameter(j); | |
972 | SetSm(i,a); | |
973 | for (int j=0; j<6; j++) printf("%10.3f ",fitter.GetParameter(j)); | |
974 | printf("\n"); | |
975 | for (int j=0; j<6; j++) printf("%10.3f ",fitter.GetParError(j)); | |
976 | printf("\n"); | |
8775e4e8 | 977 | |
978 | } | |
979 | ||
980 | //_____________________________________________________________________________ | |
5626950c | 981 | void AliTRDalignment::ReadAny(const char * const filename) |
8775e4e8 | 982 | { |
983 | // | |
984 | // read the alignment data from any kind of file | |
985 | // | |
986 | ||
987 | TString fist(filename); | |
d15124a9 | 988 | if (fist.EndsWith(".txt")) ReadAscii(filename); |
989 | if (fist.EndsWith(".dat")) ReadAscii(filename); | |
8775e4e8 | 990 | if (fist.EndsWith(".root")) { |
d15124a9 | 991 | if (fist.Contains("Run")) ReadDB(filename); |
992 | else ReadRoot(filename); | |
8775e4e8 | 993 | } |
994 | ||
995 | } | |
996 | ||
997 | //_____________________________________________________________________________ | |
5626950c | 998 | void AliTRDalignment::WriteAscii(const char * const filename) const |
8775e4e8 | 999 | { |
1000 | // | |
1001 | // store the alignment data on ascii file | |
1002 | // | |
1003 | ||
1004 | FILE *fp = fopen(filename, "w"); | |
1005 | if (!fp) { | |
1006 | AliError(Form("cannot open output file %s",filename)); | |
1007 | return; | |
1008 | } | |
1009 | ||
1010 | PrintSm(fp); | |
1011 | PrintCh(fp); | |
1012 | ||
1013 | fclose(fp); | |
1014 | ||
1015 | } | |
1016 | ||
1017 | //_____________________________________________________________________________ | |
5626950c | 1018 | void AliTRDalignment::WriteRoot(const char * const filename) |
8775e4e8 | 1019 | { |
1020 | // | |
1021 | // store the alignment data on root file | |
1022 | // | |
1023 | ||
90dbf5fb | 1024 | TClonesArray *ar = new TClonesArray("AliAlignObjParams",10000); |
8775e4e8 | 1025 | NumbersToAr(ar); |
1026 | TFile fo(filename,"RECREATE"); | |
1027 | if (fo.IsOpen()) { | |
1028 | fo.cd(); | |
1029 | fo.WriteObject(ar,"TRDAlignObjs","kSingleKey"); | |
1030 | fo.Close(); | |
1031 | } | |
d15124a9 | 1032 | else AliError(Form("cannot open output file %s",filename)); |
8775e4e8 | 1033 | |
1034 | delete ar; | |
1035 | ||
1036 | } | |
1037 | ||
1038 | //_____________________________________________________________________________ | |
c238ac9a | 1039 | void AliTRDalignment::WriteDB(const char * const filename, int run0, int run1, int ver, int subver) |
8775e4e8 | 1040 | { |
1041 | // | |
1042 | // dumping on a DB-like file | |
1043 | // | |
1044 | ||
90dbf5fb | 1045 | TClonesArray *ar = new TClonesArray("AliAlignObjParams",10000); |
8775e4e8 | 1046 | NumbersToAr(ar); |
a6e0ebfe | 1047 | const Char_t *path = "TRD/Align/Data"; |
8775e4e8 | 1048 | AliCDBId id(path,run0,run1); |
1049 | AliCDBMetaData *md = new AliCDBMetaData(); | |
1050 | md->SetResponsible("Dariusz Miskowiec"); | |
d15124a9 | 1051 | md->SetComment(fComment.GetString().Data()); |
c238ac9a | 1052 | AliCDBEntry *e = new AliCDBEntry(ar, id, md); |
1053 | e->SetVersion(ver); | |
1054 | e->SetSubVersion(subver); | |
8775e4e8 | 1055 | TFile fi(filename,"RECREATE"); |
1056 | if (fi.IsOpen()) { | |
1057 | e->Write(); | |
1058 | fi.Close(); | |
1059 | } | |
d15124a9 | 1060 | else AliError(Form("cannot open input file %s",filename)); |
8775e4e8 | 1061 | |
1062 | delete e; | |
1063 | delete md; | |
1064 | delete ar; | |
1065 | ||
1066 | return; | |
1067 | ||
1068 | } | |
1069 | ||
1070 | //_____________________________________________________________________________ | |
5626950c | 1071 | void AliTRDalignment::WriteDB(char * const db, const char * const path, int run0, int run1) |
8775e4e8 | 1072 | { |
1073 | // | |
1074 | // store the alignment data in database | |
1075 | // | |
1076 | ||
90dbf5fb | 1077 | TClonesArray *ar = new TClonesArray("AliAlignObjParams",10000); |
8775e4e8 | 1078 | NumbersToAr(ar); |
1079 | AliCDBManager *cdb = AliCDBManager::Instance(); | |
1080 | AliCDBStorage *storLoc = cdb->GetStorage(db); | |
1081 | AliCDBMetaData *md = new AliCDBMetaData(); | |
1082 | md->SetResponsible("Dariusz Miskowiec"); | |
d15124a9 | 1083 | md->SetComment(fComment.GetString().Data()); |
8775e4e8 | 1084 | AliCDBId id(path,run0,run1); |
1085 | storLoc->Put(ar,id,md); | |
1086 | md->Delete(); | |
1087 | delete ar; | |
1088 | ||
1089 | } | |
1090 | ||
1091 | //_____________________________________________________________________________ | |
1092 | void AliTRDalignment::WriteGeo(char *filename) | |
1093 | { | |
1094 | // | |
69219822 | 1095 | // apply misalignment to current geometry and store the |
8775e4e8 | 1096 | // resulting geometry on a root file |
1097 | // | |
1098 | ||
90dbf5fb | 1099 | TClonesArray *ar = new TClonesArray("AliAlignObjParams",10000); |
8775e4e8 | 1100 | NumbersToAr(ar); |
8775e4e8 | 1101 | delete ar; |
1102 | gGeoManager->Export(filename); | |
1103 | ||
1104 | } | |
1105 | ||
1106 | //_____________________________________________________________________________ | |
d15124a9 | 1107 | double AliTRDalignment::GetSmRMS(int xyz) const |
8775e4e8 | 1108 | { |
1109 | // | |
1110 | // rms fSm[][xyz] | |
1111 | // | |
1112 | ||
d15124a9 | 1113 | double s1 = 0.0; |
1114 | double s2 = 0.0; | |
8775e4e8 | 1115 | for (int i = 0; i < 18; i++) { |
1116 | s1 += fSm[i][xyz]; | |
1117 | s2 += fSm[i][xyz]*fSm[i][xyz]; | |
1118 | } | |
d15124a9 | 1119 | double rms2 = s2/18.0 - s1*s1/18.0/18.0; |
8775e4e8 | 1120 | |
1121 | return rms2>0 ? sqrt(rms2) : 0.0; | |
1122 | ||
1123 | } | |
1124 | ||
1125 | //_____________________________________________________________________________ | |
d15124a9 | 1126 | double AliTRDalignment::GetChRMS(int xyz) const |
8775e4e8 | 1127 | { |
1128 | // | |
1129 | // rms fCh[][xyz] | |
1130 | // | |
1131 | ||
d15124a9 | 1132 | double s1 =0.0; |
1133 | double s2 =0.0; | |
8775e4e8 | 1134 | for (int i = 0; i < 540; i++) { |
1135 | s1 += fCh[i][xyz]; | |
1136 | s2 += fCh[i][xyz]*fCh[i][xyz]; | |
1137 | } | |
d15124a9 | 1138 | double rms2 = s2/540.0 - s1*s1/540.0/540.0; |
8775e4e8 | 1139 | |
1140 | return rms2>0 ? sqrt(rms2) : 0.0; | |
1141 | ||
1142 | } | |
1143 | ||
1144 | //_____________________________________________________________________________ | |
1145 | void AliTRDalignment::PrintSmRMS() const | |
1146 | { | |
1147 | // | |
1148 | // dump rms of fSm | |
1149 | // | |
1150 | ||
1151 | printf(" %11.4f %11.4f %11.4f %11.5f %11.5f %11.5f supermodule rms\n" | |
1152 | ,GetSmRMS(0),GetSmRMS(1),GetSmRMS(2),GetSmRMS(3),GetSmRMS(4),GetSmRMS(5)); | |
1153 | ||
1154 | } | |
1155 | ||
1156 | //_____________________________________________________________________________ | |
1157 | void AliTRDalignment::PrintChRMS() const | |
1158 | { | |
1159 | // | |
1160 | // dump rms of fCh | |
1161 | // | |
1162 | ||
1163 | printf(" %11.4f %11.4f %11.4f %11.5f %11.5f %11.5f chamber rms\n" | |
1164 | ,GetChRMS(0),GetChRMS(1),GetChRMS(2),GetChRMS(3),GetChRMS(4),GetChRMS(5)); | |
1165 | ||
1166 | } | |
1167 | ||
1168 | //_____________________________________________________________________________ | |
5626950c | 1169 | void AliTRDalignment::ArToNumbers(TClonesArray * const ar) |
8775e4e8 | 1170 | { |
1171 | // | |
69219822 | 1172 | // for each of the alignment objects in array ar extract the six local |
1173 | // alignment parameters; recognize by name to which supermodule or chamber | |
1174 | // the alignment object pertains; set the respective fSm or fCh | |
8775e4e8 | 1175 | // |
1176 | ||
69219822 | 1177 | ar->Sort(); |
1178 | if (!IsGeoLoaded()) return; | |
1179 | for (int i = 0; i < ar->GetEntries(); i++) { | |
8775e4e8 | 1180 | AliAlignObj *aao = (AliAlignObj *) ar->At(i); |
69219822 | 1181 | aao->ApplyToGeometry(); |
8775e4e8 | 1182 | } |
69219822 | 1183 | SetZero(); |
1184 | ReadCurrentGeo(); | |
8775e4e8 | 1185 | |
1186 | } | |
1187 | ||
1188 | //_____________________________________________________________________________ | |
5626950c | 1189 | void AliTRDalignment::NumbersToAr(TClonesArray * const ar) |
8775e4e8 | 1190 | { |
1191 | // | |
1192 | // build array of AliAlignObj objects based on fSm and fCh data | |
69219822 | 1193 | // at the same time, apply misalignment to the currently loaded geometry |
1194 | // it is important to apply misalignment of supermodules before creating | |
1195 | // alignment objects for chambers | |
8775e4e8 | 1196 | // |
1197 | ||
69219822 | 1198 | if (!IsGeoLoaded()) return; |
8775e4e8 | 1199 | TClonesArray &alobj = *ar; |
1200 | int nobj = 0; | |
1201 | for (int i = 0; i < 18; i++) { | |
90dbf5fb | 1202 | new(alobj[nobj]) AliAlignObjParams(GetSmName(i) |
8775e4e8 | 1203 | ,0 |
1204 | ,fSm[i][0],fSm[i][1],fSm[i][2] | |
1205 | ,fSm[i][3],fSm[i][4],fSm[i][5] | |
1206 | ,0); | |
69219822 | 1207 | ((AliAlignObj *) alobj[nobj])->ApplyToGeometry(); |
8775e4e8 | 1208 | nobj++; |
1209 | } | |
1210 | ||
1211 | for (int i = 0; i < 540; i++) { | |
9c485614 | 1212 | if (gGeoManager->GetAlignableEntry(GetChName(i))) { |
1213 | new(alobj[nobj]) AliAlignObjParams(GetChName(i) | |
1214 | ,GetVoi(i) | |
1215 | ,fCh[i][0],fCh[i][1],fCh[i][2] | |
1216 | ,fCh[i][3],fCh[i][4],fCh[i][5] | |
1217 | ,0); | |
1218 | ((AliAlignObj *) alobj[nobj])->ApplyToGeometry(); | |
1219 | nobj++; | |
1220 | } | |
8775e4e8 | 1221 | } |
69219822 | 1222 | AliInfo("current geometry modified"); |
8775e4e8 | 1223 | |
1224 | } | |
1225 | ||
1226 | //_____________________________________________________________________________ | |
69219822 | 1227 | int AliTRDalignment::IsGeoLoaded() |
8775e4e8 | 1228 | { |
1229 | // | |
69219822 | 1230 | // check whether a geometry is loaded |
1231 | // issue a warning if geometry is not ideal | |
8775e4e8 | 1232 | // |
1233 | ||
69219822 | 1234 | if (gGeoManager) { |
1235 | if (gGeoManager->GetListOfPhysicalNodes()->GetEntries()) AliWarning("current geometry is not ideal"); | |
1236 | return 1; | |
1237 | } else { | |
1238 | AliError("first load geometry by calling TGeoManager::Import(filename)"); | |
1239 | return 0; | |
8775e4e8 | 1240 | } |
1241 | ||
8775e4e8 | 1242 | } |
69219822 | 1243 | |
1244 | //_____________________________________________________________________________ |