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