]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAlignmentTracks.cxx
Corrected call to the static method AliBitPacking::UnpackWord
[u/mrichter/AliRoot.git] / STEER / AliAlignmentTracks.cxx
CommitLineData
98937d93 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//-----------------------------------------------------------------
17// Implementation of the alignment steering class
18// It provides an access to the track space points
19// written along the esd tracks. The class enables
20// the user to plug any track fitter (deriving from
21// AliTrackFitter class) and minimization fo the
22// track residual sums (deriving from the AliTrackResiduals).
23//-----------------------------------------------------------------
24
25#include <TChain.h>
bfbd5665 26#include <TFile.h>
98937d93 27
28#include "AliAlignmentTracks.h"
29#include "AliTrackPointArray.h"
30#include "AliAlignObjAngles.h"
31#include "AliTrackFitterRieman.h"
32#include "AliTrackResidualsChi2.h"
33#include "AliESD.h"
34#include "AliLog.h"
35
36ClassImp(AliAlignmentTracks)
37
38//______________________________________________________________________________
39AliAlignmentTracks::AliAlignmentTracks():
40 fESDChain(0),
41 fPointsFilename("AliTrackPoints.root"),
42 fPointsFile(0),
43 fPointsTree(0),
44 fLastIndex(0),
45 fArrayIndex(0),
46 fIsIndexBuilt(kFALSE),
46ae650f 47 fMisalignObjs(0),
98937d93 48 fTrackFitter(0),
49 fMinimizer(0)
50{
51 // Default constructor
52 InitIndex();
53 InitAlignObjs();
54}
55
56//______________________________________________________________________________
57AliAlignmentTracks::AliAlignmentTracks(TChain *esdchain):
58 fESDChain(esdchain),
59 fPointsFilename("AliTrackPoints.root"),
60 fPointsFile(0),
61 fPointsTree(0),
62 fLastIndex(0),
63 fArrayIndex(0),
64 fIsIndexBuilt(kFALSE),
46ae650f 65 fMisalignObjs(0),
98937d93 66 fTrackFitter(0),
67 fMinimizer(0)
68{
69 // Constructor in the case
70 // the user provides an already
71 // built TChain with ESD trees
72 InitIndex();
73 InitAlignObjs();
74}
75
76
77//______________________________________________________________________________
78AliAlignmentTracks::AliAlignmentTracks(const char *esdfilename, const char *esdtreename):
79 fPointsFilename("AliTrackPoints.root"),
80 fPointsFile(0),
81 fPointsTree(0),
82 fLastIndex(0),
83 fArrayIndex(0),
84 fIsIndexBuilt(kFALSE),
46ae650f 85 fMisalignObjs(0),
98937d93 86 fTrackFitter(0),
87 fMinimizer(0)
88{
89 // Constructor in the case
90 // the user provides a single ESD file
91 // or a directory containing ESD files
92 fESDChain = new TChain(esdtreename);
93 fESDChain->Add(esdfilename);
94
95 InitIndex();
96 InitAlignObjs();
97}
98
99//______________________________________________________________________________
100AliAlignmentTracks::AliAlignmentTracks(const AliAlignmentTracks &alignment):
101 TObject(alignment)
102{
103 // Copy constructor
104 // not implemented
105 AliWarning("Copy constructor not implemented!");
106}
107
108//______________________________________________________________________________
109AliAlignmentTracks& AliAlignmentTracks::operator= (const AliAlignmentTracks& alignment)
110{
111 // Asignment operator
112 // not implemented
113 if(this==&alignment) return *this;
114
115 AliWarning("Asignment operator not implemented!");
116
117 ((TObject *)this)->operator=(alignment);
118
119 return *this;
120}
121
122//______________________________________________________________________________
123AliAlignmentTracks::~AliAlignmentTracks()
124{
125 // Destructor
126 if (fESDChain) delete fESDChain;
127
128 DeleteIndex();
129 DeleteAlignObjs();
130
131 delete fTrackFitter;
132 delete fMinimizer;
133
134 if (fPointsFile) fPointsFile->Close();
135}
136
137//______________________________________________________________________________
138void AliAlignmentTracks::AddESD(TChain *esdchain)
139{
140 // Add a chain with ESD files
141 if (fESDChain)
142 fESDChain->Add(esdchain);
143 else
144 fESDChain = esdchain;
145}
146
147//______________________________________________________________________________
148void AliAlignmentTracks::AddESD(const char *esdfilename, const char *esdtreename)
149{
150 // Add a single file or
151 // a directory to the chain
152 // with the ESD files
153 if (fESDChain)
154 fESDChain->AddFile(esdfilename,TChain::kBigNumber,esdtreename);
155 else {
156 fESDChain = new TChain(esdtreename);
157 fESDChain->Add(esdfilename);
158 }
159}
160
161//______________________________________________________________________________
162void AliAlignmentTracks::ProcessESD()
163{
164 // Analyzes and filters ESD tracks
165 // Stores the selected track space points
166 // into the output file
167
168 if (!fESDChain) return;
169
170 AliESD *esd = 0;
171 fESDChain->SetBranchAddress("ESD",&esd);
172
173 // Open the output file
174 if (fPointsFilename.Data() == "") {
175 AliWarning("Incorrect output filename!");
176 return;
177 }
178
179 TFile *pointsFile = TFile::Open(fPointsFilename,"RECREATE");
180 if (!pointsFile || !pointsFile->IsOpen()) {
181 AliWarning(Form("Can't open %s !",fPointsFilename.Data()));
182 return;
183 }
184
185 TTree *pointsTree = new TTree("spTree", "Tree with track space point arrays");
15e85efa 186 const AliTrackPointArray *array = 0;
98937d93 187 pointsTree->Branch("SP","AliTrackPointArray", &array);
188
189 Int_t ievent = 0;
190 while (fESDChain->GetEntry(ievent++)) {
191 if (!esd) break;
192 Int_t ntracks = esd->GetNumberOfTracks();
193 for (Int_t itrack=0; itrack < ntracks; itrack++) {
194 AliESDtrack * track = esd->GetTrack(itrack);
195 if (!track) continue;
196
8e392455 197 // UInt_t status = AliESDtrack::kITSpid;
198// status|=AliESDtrack::kTPCpid;
199// status|=AliESDtrack::kTRDpid;
200// if ((track->GetStatus() & status) != status) continue;
98937d93 201
202 if (track->GetP() < 0.5) continue;
203
204 array = track->GetTrackPointArray();
205 pointsTree->Fill();
206 }
207 }
208
209 if (!pointsTree->Write()) {
210 AliWarning("Can't write the tree with track point arrays!");
211 return;
212 }
213
214 pointsFile->Close();
215}
216
217//______________________________________________________________________________
218void AliAlignmentTracks::ProcessESD(TSelector *selector)
219{
220 AliWarning(Form("ESD processing based on selector is not yet implemented (%p) !",selector));
221}
222
223//______________________________________________________________________________
224void AliAlignmentTracks::BuildIndex()
225{
226 // Build index of points tree entries
227 // Used for access based on the volume IDs
46ae650f 228 if (fIsIndexBuilt) return;
229
230 fIsIndexBuilt = kTRUE;
98937d93 231
33bebad6 232 // Dummy object is created in order
233 // to initialize the volume paths
234 AliAlignObjAngles alobj;
235
98937d93 236 TFile *fPointsFile = TFile::Open(fPointsFilename);
237 if (!fPointsFile || !fPointsFile->IsOpen()) {
238 AliWarning(Form("Can't open %s !",fPointsFilename.Data()));
239 return;
240 }
241
242 // AliTrackPointArray* array = new AliTrackPointArray;
243 AliTrackPointArray* array = 0;
46ae650f 244 fPointsTree = (TTree*) fPointsFile->Get("spTree");
245 if (!fPointsTree) {
98937d93 246 AliWarning("No pointsTree found!");
247 return;
248 }
46ae650f 249 fPointsTree->SetBranchAddress("SP", &array);
98937d93 250
46ae650f 251 Int_t nArrays = fPointsTree->GetEntries();
98937d93 252 for (Int_t iArray = 0; iArray < nArrays; iArray++)
253 {
46ae650f 254 fPointsTree->GetEvent(iArray);
98937d93 255 if (!array) continue;
256 for (Int_t ipoint = 0; ipoint < array->GetNPoints(); ipoint++) {
257 UShort_t volId = array->GetVolumeID()[ipoint];
33bebad6 258 // check if the volId is valid
6baf24ce 259 if (!AliAlignObj::GetVolPath(volId)) {
260 AliError(Form("The volume id %d has no default volume path !",
261 volId));
262 continue;
263 }
98937d93 264 Int_t modId;
265 Int_t layerId = AliAlignObj::VolUIDToLayer(volId,modId)
266 - AliAlignObj::kFirstLayer;
267 if (!fArrayIndex[layerId][modId]) {
268 //first entry for this volume
269 fArrayIndex[layerId][modId] = new TArrayI(1000);
270 }
271 else {
272 Int_t size = fArrayIndex[layerId][modId]->GetSize();
273 // If needed allocate new size
274 if (fLastIndex[layerId][modId] >= size)
275 fArrayIndex[layerId][modId]->Set(size + 1000);
276 }
277
278 // Check if the index is already filled
279 Bool_t fillIndex = kTRUE;
280 if (fLastIndex[layerId][modId] != 0) {
281 if ((*fArrayIndex[layerId][modId])[fLastIndex[layerId][modId]-1] == iArray)
282 fillIndex = kFALSE;
283 }
284 // Fill the index array and store last filled index
285 if (fillIndex) {
286 (*fArrayIndex[layerId][modId])[fLastIndex[layerId][modId]] = iArray;
287 fLastIndex[layerId][modId]++;
288 }
289 }
290 }
291
292}
293
98937d93 294//______________________________________________________________________________
295void AliAlignmentTracks::InitIndex()
296{
297 // Initialize the index arrays
298 Int_t nLayers = AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer;
299 fLastIndex = new Int_t*[nLayers];
300 fArrayIndex = new TArrayI**[nLayers];
301 for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) {
c041444f 302 fLastIndex[iLayer] = new Int_t[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)];
303 fArrayIndex[iLayer] = new TArrayI*[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)];
304 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) {
98937d93 305 fLastIndex[iLayer][iModule] = 0;
306 fArrayIndex[iLayer][iModule] = 0;
307 }
308 }
309}
310
311//______________________________________________________________________________
312void AliAlignmentTracks::ResetIndex()
313{
314 // Reset the value of the last filled index
315 // Do not realocate memory
46ae650f 316
317 fIsIndexBuilt = kFALSE;
318
319 for (Int_t iLayer = 0; iLayer < AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer; iLayer++) {
c041444f 320 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) {
98937d93 321 fLastIndex[iLayer][iModule] = 0;
322 }
323 }
324}
325
326//______________________________________________________________________________
327void AliAlignmentTracks::DeleteIndex()
328{
329 // Delete the index arrays
330 // Called by the destructor
331 for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) {
c041444f 332 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) {
98937d93 333 if (fArrayIndex[iLayer][iModule]) {
334 delete fArrayIndex[iLayer][iModule];
335 fArrayIndex[iLayer][iModule] = 0;
336 }
337 }
338 delete [] fLastIndex[iLayer];
339 delete [] fArrayIndex[iLayer];
340 }
341 delete [] fLastIndex;
342 delete [] fArrayIndex;
343}
344
345//______________________________________________________________________________
46ae650f 346Bool_t AliAlignmentTracks::ReadAlignObjs(const char *alignObjFileName, const char* arrayName)
98937d93 347{
348 // Read alignment object from a file
349 // To be replaced by a call to CDB
46ae650f 350 AliWarning(Form("Method not yet implemented (%s in %s) !",arrayName,alignObjFileName));
98937d93 351
352 return kFALSE;
353}
354
355//______________________________________________________________________________
356void AliAlignmentTracks::InitAlignObjs()
357{
358 // Initialize the alignment objects array
359 Int_t nLayers = AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer;
360 fAlignObjs = new AliAlignObj**[nLayers];
361 for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) {
c041444f 362 fAlignObjs[iLayer] = new AliAlignObj*[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)];
363 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) {
46ae650f 364 UShort_t volid = AliAlignObj::LayerToVolUID(iLayer+ AliAlignObj::kFirstLayer,iModule);
365 fAlignObjs[iLayer][iModule] = new AliAlignObjAngles("",volid,0,0,0,0,0,0);
366 }
98937d93 367 }
368}
369
370//______________________________________________________________________________
371void AliAlignmentTracks::ResetAlignObjs()
372{
373 // Reset the alignment objects array
374 for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) {
c041444f 375 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++)
98937d93 376 fAlignObjs[iLayer][iModule]->SetPars(0,0,0,0,0,0);
377 }
378}
379
380//______________________________________________________________________________
381void AliAlignmentTracks::DeleteAlignObjs()
382{
383 // Delete the alignment objects array
384 for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) {
c041444f 385 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++)
98937d93 386 if (fAlignObjs[iLayer][iModule])
387 delete fAlignObjs[iLayer][iModule];
388 delete [] fAlignObjs[iLayer];
389 }
390 delete [] fAlignObjs;
46ae650f 391 fAlignObjs = 0;
98937d93 392}
393
cc345ce3 394void AliAlignmentTracks::AlignDetector(AliAlignObj::ELayerID firstLayer,
395 AliAlignObj::ELayerID lastLayer,
396 AliAlignObj::ELayerID layerRangeMin,
397 AliAlignObj::ELayerID layerRangeMax,
398 Int_t iterations)
98937d93 399{
cc345ce3 400 // Align detector volumes within
401 // a given layer range
402 // (could be whole detector).
403 // Tracks are fitted only within
404 // the range defined by the user.
405 Int_t nModules = 0;
406 for (Int_t iLayer = firstLayer; iLayer < lastLayer; iLayer++)
c041444f 407 nModules += AliAlignObj::LayerSize(iLayer);
cc345ce3 408 TArrayI volIds(nModules);
409
410 Int_t modnum = 0;
411 for (Int_t iLayer = firstLayer; iLayer < lastLayer; iLayer++) {
c041444f 412 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer); iModule++) {
cc345ce3 413 UShort_t volId = AliAlignObj::LayerToVolUID(iLayer,iModule);
414 volIds.AddAt(volId,modnum);
415 modnum++;
416 }
417 }
418
98937d93 419 while (iterations > 0) {
cc345ce3 420 AlignVolumes(&volIds,0x0,layerRangeMin,layerRangeMax);
421 iterations--;
98937d93 422 }
423}
424
425//______________________________________________________________________________
426void AliAlignmentTracks::AlignLayer(AliAlignObj::ELayerID layer,
427 AliAlignObj::ELayerID layerRangeMin,
428 AliAlignObj::ELayerID layerRangeMax,
429 Int_t iterations)
430{
431 // Align detector volumes within
432 // a given layer.
433 // Tracks are fitted only within
434 // the range defined by the user.
c041444f 435 Int_t nModules = AliAlignObj::LayerSize(layer);
cc345ce3 436 TArrayI volIds(nModules);
437 for (Int_t iModule = 0; iModule < nModules; iModule++) {
438 UShort_t volId = AliAlignObj::LayerToVolUID(layer,iModule);
439 volIds.AddAt(volId,iModule);
440 }
441
98937d93 442 while (iterations > 0) {
cc345ce3 443 AlignVolumes(&volIds,0x0,layerRangeMin,layerRangeMax);
444 iterations--;
445 }
446}
447
448//______________________________________________________________________________
449void AliAlignmentTracks::AlignVolume(UShort_t volId, UShort_t volIdFit,
450 Int_t iterations)
451{
452 // Align single detector volume to
453 // another volume.
454 // Tracks are fitted only within
455 // the second volume.
456 TArrayI volIds(1);
457 volIds.AddAt(volId,0);
458 TArrayI volIdsFit(1);
459 volIdsFit.AddAt(volIdFit,0);
460
461 while (iterations > 0) {
462 AlignVolumes(&volIds,&volIdsFit);
98937d93 463 iterations--;
464 }
465}
466
467//______________________________________________________________________________
cc345ce3 468void AliAlignmentTracks::AlignVolumes(const TArrayI *volids, const TArrayI *volidsfit,
98937d93 469 AliAlignObj::ELayerID layerRangeMin,
46ae650f 470 AliAlignObj::ELayerID layerRangeMax,
471 Int_t iterations)
98937d93 472{
cc345ce3 473 // Align a set of detector volumes.
98937d93 474 // Tracks are fitted only within
46ae650f 475 // the range defined by the user
476 // (by layerRangeMin and layerRangeMax)
cc345ce3 477 // or within the set of volidsfit
46ae650f 478 // Repeat the procedure 'iterations' times
98937d93 479
cc345ce3 480 Int_t nVolIds = volids->GetSize();
481 if (nVolIds == 0) {
482 AliError("Volume IDs array is empty!");
483 return;
484 }
98937d93 485
cc345ce3 486 // Load only the tracks with at least one
487 // space point in the set of volume (volids)
98937d93 488 BuildIndex();
489 AliTrackPointArray **points;
46ae650f 490 // Start the iterations
491 while (iterations > 0) {
cc345ce3 492 Int_t nArrays = LoadPoints(volids, points);
46ae650f 493 if (nArrays == 0) return;
494
495 AliTrackResiduals *minimizer = CreateMinimizer();
496 minimizer->SetNTracks(nArrays);
cc345ce3 497 minimizer->InitAlignObj();
46ae650f 498 AliTrackFitter *fitter = CreateFitter();
499 for (Int_t iArray = 0; iArray < nArrays; iArray++) {
33bebad6 500 if (!points[iArray]) continue;
46ae650f 501 fitter->SetTrackPointArray(points[iArray], kFALSE);
33bebad6 502 if (fitter->Fit(volids,volidsfit,layerRangeMin,layerRangeMax) == kFALSE) continue;
46ae650f 503 AliTrackPointArray *pVolId,*pTrack;
504 fitter->GetTrackResiduals(pVolId,pTrack);
505 minimizer->AddTrackPointArrays(pVolId,pTrack);
506 }
507 minimizer->Minimize();
cc345ce3 508
509 // Update the alignment object(s)
510 for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) {
511 UShort_t volid = (*volids)[iVolId];
512 Int_t iModule;
513 AliAlignObj::ELayerID iLayer = AliAlignObj::VolUIDToLayer(volid,iModule);
514 AliAlignObj *alignObj = fAlignObjs[iLayer-AliAlignObj::kFirstLayer][iModule];
515 *alignObj *= *minimizer->GetAlignObj();
516 alignObj->Print("");
517 }
98937d93 518
46ae650f 519 UnloadPoints(nArrays, points);
520
521 iterations--;
98937d93 522 }
98937d93 523}
524
525//______________________________________________________________________________
cc345ce3 526Int_t AliAlignmentTracks::LoadPoints(const TArrayI *volids, AliTrackPointArray** &points)
98937d93 527{
528 // Load track point arrays with at least
cc345ce3 529 // one space point in a given set of detector
530 // volumes (array volids).
98937d93 531 // Use the already created tree index for
532 // fast access.
98937d93 533
46ae650f 534 if (!fPointsTree) {
cc345ce3 535 AliError("Tree with the space point arrays not initialized!");
98937d93 536 points = 0;
537 return 0;
538 }
539
cc345ce3 540 Int_t nVolIds = volids->GetSize();
541 if (nVolIds == 0) {
542 AliError("Volume IDs array is empty!");
543 points = 0;
544 return 0;
545 }
546
547 Int_t nArrays = 0;
548 for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) {
549 UShort_t volid = (*volids)[iVolId];
550 Int_t iModule;
551 AliAlignObj::ELayerID iLayer = AliAlignObj::VolUIDToLayer(volid,iModule);
552
553 // In case of empty index
554 if (fLastIndex[iLayer-AliAlignObj::kFirstLayer][iModule] == 0) {
555 AliWarning(Form("There are no space-points belonging to the volume which is to be aligned (Volume ID =%d)!",volid));
556 continue;
557 }
558 nArrays += fLastIndex[iLayer-AliAlignObj::kFirstLayer][iModule];
559 }
46ae650f 560
46ae650f 561 if (nArrays == 0) {
cc345ce3 562 AliError("There are no space-points belonging to all of the volumes which are to be aligned!");
98937d93 563 points = 0;
564 return 0;
565 }
566
98937d93 567 AliTrackPointArray* array = 0;
568 fPointsTree->SetBranchAddress("SP", &array);
569
cc345ce3 570 // Allocate the pointer to the space-point arrays
98937d93 571 points = new AliTrackPointArray*[nArrays];
5caa5567 572 for (Int_t i = 0; i < nArrays; i++) points[i] = 0x0;
cc345ce3 573
574 // Init the array used to flag already loaded tree entries
575 Bool_t *indexUsed = new Bool_t[fPointsTree->GetEntries()];
576 for (Int_t i = 0; i < fPointsTree->GetEntries(); i++)
577 indexUsed[i] = kFALSE;
578
579 // Start the loop over the volume ids
580 Int_t iArray = 0;
581 for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) {
582 UShort_t volid = (*volids)[iVolId];
583 Int_t iModule;
584 AliAlignObj::ELayerID iLayer = AliAlignObj::VolUIDToLayer(volid,iModule);
585
586 Int_t nArraysId = fLastIndex[iLayer-AliAlignObj::kFirstLayer][iModule];
587 TArrayI *index = fArrayIndex[iLayer-AliAlignObj::kFirstLayer][iModule];
588 AliTrackPoint p;
589
590 for (Int_t iArrayId = 0; iArrayId < nArraysId; iArrayId++) {
591
592 // Get tree entry
593 Int_t entry = (*index)[iArrayId];
594 if (indexUsed[entry] == kTRUE) continue;
595 fPointsTree->GetEvent(entry);
596 if (!array) {
597 AliWarning("Wrong space point array index!");
598 continue;
46ae650f 599 }
cc345ce3 600 indexUsed[entry] = kTRUE;
601
602 // Get the space-point array
603 Int_t nPoints = array->GetNPoints();
604 points[iArray] = new AliTrackPointArray(nPoints);
605 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
606 array->GetPoint(p,iPoint);
607 Int_t modnum;
608 AliAlignObj::ELayerID layer = AliAlignObj::VolUIDToLayer(p.GetVolumeID(),modnum);
33bebad6 609 // check if the layer id is valid
6baf24ce 610 if ((layer < AliAlignObj::kFirstLayer) ||
611 (layer >= AliAlignObj::kLastLayer)) {
612 AliError(Form("Layer index is invalid: %d (%d -> %d) !",
613 layer,AliAlignObj::kFirstLayer,AliAlignObj::kLastLayer-1));
614 continue;
615 }
616 if ((modnum >= AliAlignObj::LayerSize(layer)) ||
617 (modnum < 0)) {
618 AliError(Form("Module number inside layer %d is invalid: %d (0 -> %d)",
619 layer,modnum,AliAlignObj::LayerSize(layer)));
620 continue;
621 }
cc345ce3 622
623 // Misalignment is introduced here
624 // Switch it off in case of real
625 // alignment job!
626 if (fMisalignObjs) {
627 AliAlignObj *misalignObj = fMisalignObjs[layer-AliAlignObj::kFirstLayer][modnum];
628 if (misalignObj)
629 misalignObj->Transform(p);
630 }
631 // End of misalignment
46ae650f 632
cc345ce3 633 AliAlignObj *alignObj = fAlignObjs[layer-AliAlignObj::kFirstLayer][modnum];
634 alignObj->Transform(p);
635 points[iArray]->AddPoint(iPoint,&p);
636 }
637 iArray++;
98937d93 638 }
639 }
640
cc345ce3 641
642 delete [] indexUsed;
643
98937d93 644 return nArrays;
645}
646
647//______________________________________________________________________________
648void AliAlignmentTracks::UnloadPoints(Int_t n, AliTrackPointArray **points)
649{
650 // Unload track point arrays for a given
651 // detector volume
652 for (Int_t iArray = 0; iArray < n; iArray++)
653 delete points[iArray];
654 delete [] points;
655}
656
657//______________________________________________________________________________
658AliTrackFitter *AliAlignmentTracks::CreateFitter()
659{
660 // Check if the user has already supplied
661 // a track fitter object.
662 // If not, create a default one.
663 if (!fTrackFitter)
664 fTrackFitter = new AliTrackFitterRieman;
665
666 return fTrackFitter;
667}
668
669//______________________________________________________________________________
670AliTrackResiduals *AliAlignmentTracks::CreateMinimizer()
671{
672 // Check if the user has already supplied
673 // a track residuals minimizer object.
674 // If not, create a default one.
675 if (!fMinimizer)
676 fMinimizer = new AliTrackResidualsChi2;
677
678 return fMinimizer;
679}
46ae650f 680
681//______________________________________________________________________________
682Bool_t AliAlignmentTracks::Misalign(const char *misalignObjFileName, const char* arrayName)
683{
684 // The method reads from a file a set of AliAlignObj which are
685 // then used to apply misalignments directly on the track
686 // space-points. The method is supposed to be used only for
687 // fast development and debugging of the alignment algorithms.
688 // Be careful not to use it in the case of 'real' alignment
689 // scenario since it will bias the results.
690
691 // Initialize the misalignment objects array
692 Int_t nLayers = AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer;
693 fMisalignObjs = new AliAlignObj**[nLayers];
694 for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) {
c041444f 695 fMisalignObjs[iLayer] = new AliAlignObj*[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)];
696 for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++)
46ae650f 697 fMisalignObjs[iLayer][iModule] = 0x0;
698 }
699
700 // Open the misliagnment file and load the array with
701 // misalignment objects
702 TFile* inFile = TFile::Open(misalignObjFileName,"READ");
703 if (!inFile || !inFile->IsOpen()) {
704 AliError(Form("Could not open misalignment file %s !",misalignObjFileName));
705 return kFALSE;
706 }
707
708 TClonesArray* array = ((TClonesArray*) inFile->Get(arrayName));
709 if (!array) {
710 AliError(Form("Could not find misalignment array %s in the file %s !",arrayName,misalignObjFileName));
711 inFile->Close();
712 return kFALSE;
713 }
714 inFile->Close();
715
716 // Store the misalignment objects for further usage
717 Int_t nObjs = array->GetEntriesFast();
718 AliAlignObj::ELayerID layerId; // volume layer
719 Int_t modId; // volume ID inside the layer
720 for(Int_t i=0; i<nObjs; i++)
721 {
722 AliAlignObj* alObj = (AliAlignObj*)array->UncheckedAt(i);
723 alObj->GetVolUID(layerId,modId);
724 fMisalignObjs[layerId-AliAlignObj::kFirstLayer][modId] = alObj;
725 }
726 return kTRUE;
727}