]>
Commit | Line | Data |
---|---|---|
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 | ||
36 | ClassImp(AliAlignmentTracks) | |
37 | ||
38 | //______________________________________________________________________________ | |
39 | AliAlignmentTracks::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 | //______________________________________________________________________________ | |
57 | AliAlignmentTracks::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 | //______________________________________________________________________________ | |
78 | AliAlignmentTracks::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 | //______________________________________________________________________________ | |
100 | AliAlignmentTracks::AliAlignmentTracks(const AliAlignmentTracks &alignment): | |
101 | TObject(alignment) | |
102 | { | |
103 | // Copy constructor | |
104 | // not implemented | |
105 | AliWarning("Copy constructor not implemented!"); | |
106 | } | |
107 | ||
108 | //______________________________________________________________________________ | |
109 | AliAlignmentTracks& 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 | //______________________________________________________________________________ | |
123 | AliAlignmentTracks::~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 | //______________________________________________________________________________ | |
138 | void 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 | //______________________________________________________________________________ | |
148 | void 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 | //______________________________________________________________________________ | |
162 | void 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 | //______________________________________________________________________________ | |
218 | void AliAlignmentTracks::ProcessESD(TSelector *selector) | |
219 | { | |
220 | AliWarning(Form("ESD processing based on selector is not yet implemented (%p) !",selector)); | |
221 | } | |
222 | ||
223 | //______________________________________________________________________________ | |
224 | void 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 |
259 | if (!AliAlignObj::GetVolPath(volId)) continue; | |
98937d93 | 260 | Int_t modId; |
261 | Int_t layerId = AliAlignObj::VolUIDToLayer(volId,modId) | |
262 | - AliAlignObj::kFirstLayer; | |
263 | if (!fArrayIndex[layerId][modId]) { | |
264 | //first entry for this volume | |
265 | fArrayIndex[layerId][modId] = new TArrayI(1000); | |
266 | } | |
267 | else { | |
268 | Int_t size = fArrayIndex[layerId][modId]->GetSize(); | |
269 | // If needed allocate new size | |
270 | if (fLastIndex[layerId][modId] >= size) | |
271 | fArrayIndex[layerId][modId]->Set(size + 1000); | |
272 | } | |
273 | ||
274 | // Check if the index is already filled | |
275 | Bool_t fillIndex = kTRUE; | |
276 | if (fLastIndex[layerId][modId] != 0) { | |
277 | if ((*fArrayIndex[layerId][modId])[fLastIndex[layerId][modId]-1] == iArray) | |
278 | fillIndex = kFALSE; | |
279 | } | |
280 | // Fill the index array and store last filled index | |
281 | if (fillIndex) { | |
282 | (*fArrayIndex[layerId][modId])[fLastIndex[layerId][modId]] = iArray; | |
283 | fLastIndex[layerId][modId]++; | |
284 | } | |
285 | } | |
286 | } | |
287 | ||
288 | } | |
289 | ||
98937d93 | 290 | //______________________________________________________________________________ |
291 | void AliAlignmentTracks::InitIndex() | |
292 | { | |
293 | // Initialize the index arrays | |
294 | Int_t nLayers = AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer; | |
295 | fLastIndex = new Int_t*[nLayers]; | |
296 | fArrayIndex = new TArrayI**[nLayers]; | |
297 | for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) { | |
c041444f | 298 | fLastIndex[iLayer] = new Int_t[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)]; |
299 | fArrayIndex[iLayer] = new TArrayI*[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)]; | |
300 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) { | |
98937d93 | 301 | fLastIndex[iLayer][iModule] = 0; |
302 | fArrayIndex[iLayer][iModule] = 0; | |
303 | } | |
304 | } | |
305 | } | |
306 | ||
307 | //______________________________________________________________________________ | |
308 | void AliAlignmentTracks::ResetIndex() | |
309 | { | |
310 | // Reset the value of the last filled index | |
311 | // Do not realocate memory | |
46ae650f | 312 | |
313 | fIsIndexBuilt = kFALSE; | |
314 | ||
315 | for (Int_t iLayer = 0; iLayer < AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer; iLayer++) { | |
c041444f | 316 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) { |
98937d93 | 317 | fLastIndex[iLayer][iModule] = 0; |
318 | } | |
319 | } | |
320 | } | |
321 | ||
322 | //______________________________________________________________________________ | |
323 | void AliAlignmentTracks::DeleteIndex() | |
324 | { | |
325 | // Delete the index arrays | |
326 | // Called by the destructor | |
327 | for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) { | |
c041444f | 328 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) { |
98937d93 | 329 | if (fArrayIndex[iLayer][iModule]) { |
330 | delete fArrayIndex[iLayer][iModule]; | |
331 | fArrayIndex[iLayer][iModule] = 0; | |
332 | } | |
333 | } | |
334 | delete [] fLastIndex[iLayer]; | |
335 | delete [] fArrayIndex[iLayer]; | |
336 | } | |
337 | delete [] fLastIndex; | |
338 | delete [] fArrayIndex; | |
339 | } | |
340 | ||
341 | //______________________________________________________________________________ | |
46ae650f | 342 | Bool_t AliAlignmentTracks::ReadAlignObjs(const char *alignObjFileName, const char* arrayName) |
98937d93 | 343 | { |
344 | // Read alignment object from a file | |
345 | // To be replaced by a call to CDB | |
46ae650f | 346 | AliWarning(Form("Method not yet implemented (%s in %s) !",arrayName,alignObjFileName)); |
98937d93 | 347 | |
348 | return kFALSE; | |
349 | } | |
350 | ||
351 | //______________________________________________________________________________ | |
352 | void AliAlignmentTracks::InitAlignObjs() | |
353 | { | |
354 | // Initialize the alignment objects array | |
355 | Int_t nLayers = AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer; | |
356 | fAlignObjs = new AliAlignObj**[nLayers]; | |
357 | for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) { | |
c041444f | 358 | fAlignObjs[iLayer] = new AliAlignObj*[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)]; |
359 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) { | |
46ae650f | 360 | UShort_t volid = AliAlignObj::LayerToVolUID(iLayer+ AliAlignObj::kFirstLayer,iModule); |
361 | fAlignObjs[iLayer][iModule] = new AliAlignObjAngles("",volid,0,0,0,0,0,0); | |
362 | } | |
98937d93 | 363 | } |
364 | } | |
365 | ||
366 | //______________________________________________________________________________ | |
367 | void AliAlignmentTracks::ResetAlignObjs() | |
368 | { | |
369 | // Reset the alignment objects array | |
370 | for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) { | |
c041444f | 371 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) |
98937d93 | 372 | fAlignObjs[iLayer][iModule]->SetPars(0,0,0,0,0,0); |
373 | } | |
374 | } | |
375 | ||
376 | //______________________________________________________________________________ | |
377 | void AliAlignmentTracks::DeleteAlignObjs() | |
378 | { | |
379 | // Delete the alignment objects array | |
380 | for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) { | |
c041444f | 381 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) |
98937d93 | 382 | if (fAlignObjs[iLayer][iModule]) |
383 | delete fAlignObjs[iLayer][iModule]; | |
384 | delete [] fAlignObjs[iLayer]; | |
385 | } | |
386 | delete [] fAlignObjs; | |
46ae650f | 387 | fAlignObjs = 0; |
98937d93 | 388 | } |
389 | ||
cc345ce3 | 390 | void AliAlignmentTracks::AlignDetector(AliAlignObj::ELayerID firstLayer, |
391 | AliAlignObj::ELayerID lastLayer, | |
392 | AliAlignObj::ELayerID layerRangeMin, | |
393 | AliAlignObj::ELayerID layerRangeMax, | |
394 | Int_t iterations) | |
98937d93 | 395 | { |
cc345ce3 | 396 | // Align detector volumes within |
397 | // a given layer range | |
398 | // (could be whole detector). | |
399 | // Tracks are fitted only within | |
400 | // the range defined by the user. | |
401 | Int_t nModules = 0; | |
402 | for (Int_t iLayer = firstLayer; iLayer < lastLayer; iLayer++) | |
c041444f | 403 | nModules += AliAlignObj::LayerSize(iLayer); |
cc345ce3 | 404 | TArrayI volIds(nModules); |
405 | ||
406 | Int_t modnum = 0; | |
407 | for (Int_t iLayer = firstLayer; iLayer < lastLayer; iLayer++) { | |
c041444f | 408 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer); iModule++) { |
cc345ce3 | 409 | UShort_t volId = AliAlignObj::LayerToVolUID(iLayer,iModule); |
410 | volIds.AddAt(volId,modnum); | |
411 | modnum++; | |
412 | } | |
413 | } | |
414 | ||
98937d93 | 415 | while (iterations > 0) { |
cc345ce3 | 416 | AlignVolumes(&volIds,0x0,layerRangeMin,layerRangeMax); |
417 | iterations--; | |
98937d93 | 418 | } |
419 | } | |
420 | ||
421 | //______________________________________________________________________________ | |
422 | void AliAlignmentTracks::AlignLayer(AliAlignObj::ELayerID layer, | |
423 | AliAlignObj::ELayerID layerRangeMin, | |
424 | AliAlignObj::ELayerID layerRangeMax, | |
425 | Int_t iterations) | |
426 | { | |
427 | // Align detector volumes within | |
428 | // a given layer. | |
429 | // Tracks are fitted only within | |
430 | // the range defined by the user. | |
c041444f | 431 | Int_t nModules = AliAlignObj::LayerSize(layer); |
cc345ce3 | 432 | TArrayI volIds(nModules); |
433 | for (Int_t iModule = 0; iModule < nModules; iModule++) { | |
434 | UShort_t volId = AliAlignObj::LayerToVolUID(layer,iModule); | |
435 | volIds.AddAt(volId,iModule); | |
436 | } | |
437 | ||
98937d93 | 438 | while (iterations > 0) { |
cc345ce3 | 439 | AlignVolumes(&volIds,0x0,layerRangeMin,layerRangeMax); |
440 | iterations--; | |
441 | } | |
442 | } | |
443 | ||
444 | //______________________________________________________________________________ | |
445 | void AliAlignmentTracks::AlignVolume(UShort_t volId, UShort_t volIdFit, | |
446 | Int_t iterations) | |
447 | { | |
448 | // Align single detector volume to | |
449 | // another volume. | |
450 | // Tracks are fitted only within | |
451 | // the second volume. | |
452 | TArrayI volIds(1); | |
453 | volIds.AddAt(volId,0); | |
454 | TArrayI volIdsFit(1); | |
455 | volIdsFit.AddAt(volIdFit,0); | |
456 | ||
457 | while (iterations > 0) { | |
458 | AlignVolumes(&volIds,&volIdsFit); | |
98937d93 | 459 | iterations--; |
460 | } | |
461 | } | |
462 | ||
463 | //______________________________________________________________________________ | |
cc345ce3 | 464 | void AliAlignmentTracks::AlignVolumes(const TArrayI *volids, const TArrayI *volidsfit, |
98937d93 | 465 | AliAlignObj::ELayerID layerRangeMin, |
46ae650f | 466 | AliAlignObj::ELayerID layerRangeMax, |
467 | Int_t iterations) | |
98937d93 | 468 | { |
cc345ce3 | 469 | // Align a set of detector volumes. |
98937d93 | 470 | // Tracks are fitted only within |
46ae650f | 471 | // the range defined by the user |
472 | // (by layerRangeMin and layerRangeMax) | |
cc345ce3 | 473 | // or within the set of volidsfit |
46ae650f | 474 | // Repeat the procedure 'iterations' times |
98937d93 | 475 | |
cc345ce3 | 476 | Int_t nVolIds = volids->GetSize(); |
477 | if (nVolIds == 0) { | |
478 | AliError("Volume IDs array is empty!"); | |
479 | return; | |
480 | } | |
98937d93 | 481 | |
cc345ce3 | 482 | // Load only the tracks with at least one |
483 | // space point in the set of volume (volids) | |
98937d93 | 484 | BuildIndex(); |
485 | AliTrackPointArray **points; | |
46ae650f | 486 | // Start the iterations |
487 | while (iterations > 0) { | |
cc345ce3 | 488 | Int_t nArrays = LoadPoints(volids, points); |
46ae650f | 489 | if (nArrays == 0) return; |
490 | ||
491 | AliTrackResiduals *minimizer = CreateMinimizer(); | |
492 | minimizer->SetNTracks(nArrays); | |
cc345ce3 | 493 | minimizer->InitAlignObj(); |
46ae650f | 494 | AliTrackFitter *fitter = CreateFitter(); |
495 | for (Int_t iArray = 0; iArray < nArrays; iArray++) { | |
33bebad6 | 496 | if (!points[iArray]) continue; |
46ae650f | 497 | fitter->SetTrackPointArray(points[iArray], kFALSE); |
33bebad6 | 498 | if (fitter->Fit(volids,volidsfit,layerRangeMin,layerRangeMax) == kFALSE) continue; |
46ae650f | 499 | AliTrackPointArray *pVolId,*pTrack; |
500 | fitter->GetTrackResiduals(pVolId,pTrack); | |
501 | minimizer->AddTrackPointArrays(pVolId,pTrack); | |
502 | } | |
503 | minimizer->Minimize(); | |
cc345ce3 | 504 | |
505 | // Update the alignment object(s) | |
506 | for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) { | |
507 | UShort_t volid = (*volids)[iVolId]; | |
508 | Int_t iModule; | |
509 | AliAlignObj::ELayerID iLayer = AliAlignObj::VolUIDToLayer(volid,iModule); | |
510 | AliAlignObj *alignObj = fAlignObjs[iLayer-AliAlignObj::kFirstLayer][iModule]; | |
511 | *alignObj *= *minimizer->GetAlignObj(); | |
512 | alignObj->Print(""); | |
513 | } | |
98937d93 | 514 | |
46ae650f | 515 | UnloadPoints(nArrays, points); |
516 | ||
517 | iterations--; | |
98937d93 | 518 | } |
98937d93 | 519 | } |
520 | ||
521 | //______________________________________________________________________________ | |
cc345ce3 | 522 | Int_t AliAlignmentTracks::LoadPoints(const TArrayI *volids, AliTrackPointArray** &points) |
98937d93 | 523 | { |
524 | // Load track point arrays with at least | |
cc345ce3 | 525 | // one space point in a given set of detector |
526 | // volumes (array volids). | |
98937d93 | 527 | // Use the already created tree index for |
528 | // fast access. | |
98937d93 | 529 | |
46ae650f | 530 | if (!fPointsTree) { |
cc345ce3 | 531 | AliError("Tree with the space point arrays not initialized!"); |
98937d93 | 532 | points = 0; |
533 | return 0; | |
534 | } | |
535 | ||
cc345ce3 | 536 | Int_t nVolIds = volids->GetSize(); |
537 | if (nVolIds == 0) { | |
538 | AliError("Volume IDs array is empty!"); | |
539 | points = 0; | |
540 | return 0; | |
541 | } | |
542 | ||
543 | Int_t nArrays = 0; | |
544 | for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) { | |
545 | UShort_t volid = (*volids)[iVolId]; | |
546 | Int_t iModule; | |
547 | AliAlignObj::ELayerID iLayer = AliAlignObj::VolUIDToLayer(volid,iModule); | |
548 | ||
549 | // In case of empty index | |
550 | if (fLastIndex[iLayer-AliAlignObj::kFirstLayer][iModule] == 0) { | |
551 | AliWarning(Form("There are no space-points belonging to the volume which is to be aligned (Volume ID =%d)!",volid)); | |
552 | continue; | |
553 | } | |
554 | nArrays += fLastIndex[iLayer-AliAlignObj::kFirstLayer][iModule]; | |
555 | } | |
46ae650f | 556 | |
46ae650f | 557 | if (nArrays == 0) { |
cc345ce3 | 558 | AliError("There are no space-points belonging to all of the volumes which are to be aligned!"); |
98937d93 | 559 | points = 0; |
560 | return 0; | |
561 | } | |
562 | ||
98937d93 | 563 | AliTrackPointArray* array = 0; |
564 | fPointsTree->SetBranchAddress("SP", &array); | |
565 | ||
cc345ce3 | 566 | // Allocate the pointer to the space-point arrays |
98937d93 | 567 | points = new AliTrackPointArray*[nArrays]; |
5caa5567 | 568 | for (Int_t i = 0; i < nArrays; i++) points[i] = 0x0; |
cc345ce3 | 569 | |
570 | // Init the array used to flag already loaded tree entries | |
571 | Bool_t *indexUsed = new Bool_t[fPointsTree->GetEntries()]; | |
572 | for (Int_t i = 0; i < fPointsTree->GetEntries(); i++) | |
573 | indexUsed[i] = kFALSE; | |
574 | ||
575 | // Start the loop over the volume ids | |
576 | Int_t iArray = 0; | |
577 | for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) { | |
578 | UShort_t volid = (*volids)[iVolId]; | |
579 | Int_t iModule; | |
580 | AliAlignObj::ELayerID iLayer = AliAlignObj::VolUIDToLayer(volid,iModule); | |
581 | ||
582 | Int_t nArraysId = fLastIndex[iLayer-AliAlignObj::kFirstLayer][iModule]; | |
583 | TArrayI *index = fArrayIndex[iLayer-AliAlignObj::kFirstLayer][iModule]; | |
584 | AliTrackPoint p; | |
585 | ||
586 | for (Int_t iArrayId = 0; iArrayId < nArraysId; iArrayId++) { | |
587 | ||
588 | // Get tree entry | |
589 | Int_t entry = (*index)[iArrayId]; | |
590 | if (indexUsed[entry] == kTRUE) continue; | |
591 | fPointsTree->GetEvent(entry); | |
592 | if (!array) { | |
593 | AliWarning("Wrong space point array index!"); | |
594 | continue; | |
46ae650f | 595 | } |
cc345ce3 | 596 | indexUsed[entry] = kTRUE; |
597 | ||
598 | // Get the space-point array | |
599 | Int_t nPoints = array->GetNPoints(); | |
600 | points[iArray] = new AliTrackPointArray(nPoints); | |
601 | for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) { | |
602 | array->GetPoint(p,iPoint); | |
603 | Int_t modnum; | |
604 | AliAlignObj::ELayerID layer = AliAlignObj::VolUIDToLayer(p.GetVolumeID(),modnum); | |
33bebad6 | 605 | // check if the layer id is valid |
606 | if (layer == AliAlignObj::kInvalidLayer) continue; | |
cc345ce3 | 607 | |
608 | // Misalignment is introduced here | |
609 | // Switch it off in case of real | |
610 | // alignment job! | |
611 | if (fMisalignObjs) { | |
612 | AliAlignObj *misalignObj = fMisalignObjs[layer-AliAlignObj::kFirstLayer][modnum]; | |
613 | if (misalignObj) | |
614 | misalignObj->Transform(p); | |
615 | } | |
616 | // End of misalignment | |
46ae650f | 617 | |
cc345ce3 | 618 | AliAlignObj *alignObj = fAlignObjs[layer-AliAlignObj::kFirstLayer][modnum]; |
619 | alignObj->Transform(p); | |
620 | points[iArray]->AddPoint(iPoint,&p); | |
621 | } | |
622 | iArray++; | |
98937d93 | 623 | } |
624 | } | |
625 | ||
cc345ce3 | 626 | |
627 | delete [] indexUsed; | |
628 | ||
98937d93 | 629 | return nArrays; |
630 | } | |
631 | ||
632 | //______________________________________________________________________________ | |
633 | void AliAlignmentTracks::UnloadPoints(Int_t n, AliTrackPointArray **points) | |
634 | { | |
635 | // Unload track point arrays for a given | |
636 | // detector volume | |
637 | for (Int_t iArray = 0; iArray < n; iArray++) | |
638 | delete points[iArray]; | |
639 | delete [] points; | |
640 | } | |
641 | ||
642 | //______________________________________________________________________________ | |
643 | AliTrackFitter *AliAlignmentTracks::CreateFitter() | |
644 | { | |
645 | // Check if the user has already supplied | |
646 | // a track fitter object. | |
647 | // If not, create a default one. | |
648 | if (!fTrackFitter) | |
649 | fTrackFitter = new AliTrackFitterRieman; | |
650 | ||
651 | return fTrackFitter; | |
652 | } | |
653 | ||
654 | //______________________________________________________________________________ | |
655 | AliTrackResiduals *AliAlignmentTracks::CreateMinimizer() | |
656 | { | |
657 | // Check if the user has already supplied | |
658 | // a track residuals minimizer object. | |
659 | // If not, create a default one. | |
660 | if (!fMinimizer) | |
661 | fMinimizer = new AliTrackResidualsChi2; | |
662 | ||
663 | return fMinimizer; | |
664 | } | |
46ae650f | 665 | |
666 | //______________________________________________________________________________ | |
667 | Bool_t AliAlignmentTracks::Misalign(const char *misalignObjFileName, const char* arrayName) | |
668 | { | |
669 | // The method reads from a file a set of AliAlignObj which are | |
670 | // then used to apply misalignments directly on the track | |
671 | // space-points. The method is supposed to be used only for | |
672 | // fast development and debugging of the alignment algorithms. | |
673 | // Be careful not to use it in the case of 'real' alignment | |
674 | // scenario since it will bias the results. | |
675 | ||
676 | // Initialize the misalignment objects array | |
677 | Int_t nLayers = AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer; | |
678 | fMisalignObjs = new AliAlignObj**[nLayers]; | |
679 | for (Int_t iLayer = 0; iLayer < (AliAlignObj::kLastLayer - AliAlignObj::kFirstLayer); iLayer++) { | |
c041444f | 680 | fMisalignObjs[iLayer] = new AliAlignObj*[AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer)]; |
681 | for (Int_t iModule = 0; iModule < AliAlignObj::LayerSize(iLayer + AliAlignObj::kFirstLayer); iModule++) | |
46ae650f | 682 | fMisalignObjs[iLayer][iModule] = 0x0; |
683 | } | |
684 | ||
685 | // Open the misliagnment file and load the array with | |
686 | // misalignment objects | |
687 | TFile* inFile = TFile::Open(misalignObjFileName,"READ"); | |
688 | if (!inFile || !inFile->IsOpen()) { | |
689 | AliError(Form("Could not open misalignment file %s !",misalignObjFileName)); | |
690 | return kFALSE; | |
691 | } | |
692 | ||
693 | TClonesArray* array = ((TClonesArray*) inFile->Get(arrayName)); | |
694 | if (!array) { | |
695 | AliError(Form("Could not find misalignment array %s in the file %s !",arrayName,misalignObjFileName)); | |
696 | inFile->Close(); | |
697 | return kFALSE; | |
698 | } | |
699 | inFile->Close(); | |
700 | ||
701 | // Store the misalignment objects for further usage | |
702 | Int_t nObjs = array->GetEntriesFast(); | |
703 | AliAlignObj::ELayerID layerId; // volume layer | |
704 | Int_t modId; // volume ID inside the layer | |
705 | for(Int_t i=0; i<nObjs; i++) | |
706 | { | |
707 | AliAlignObj* alObj = (AliAlignObj*)array->UncheckedAt(i); | |
708 | alObj->GetVolUID(layerId,modId); | |
709 | fMisalignObjs[layerId-AliAlignObj::kFirstLayer][modId] = alObj; | |
710 | } | |
711 | return kTRUE; | |
712 | } |