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