New class for realignment with AliAlignmentTracks (A. Rossi)
[u/mrichter/AliRoot.git] / ITS / AliITSRealignTracks.cxx
CommitLineData
40053737 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#include <TArray.h>
18#include <TFile.h>
19#include <TStopwatch.h>
20#include <TArray.h>
21#include <TNtuple.h>
22#include <TClonesArray.h>
23#include <TMath.h>
24#include <TGeoManager.h>
25#include <TSystem.h>
26#include <TGeoMatrix.h>
27#include "AliITSRealignTracks.h"
28#include "AliAlignmentTracks.h"
29#include "AliAlignObjParams.h"
30#include "AliGeomManager.h"
31#include "AliTrackFitter.h"
32#include "AliTrackFitterKalman.h"
33#include "AliTrackFitterRieman.h"
34#include "AliTrackResidualsFast.h"
35#include "AliTrackResidualsChi2.h"
36#include "AliTrackResidualsLinear.h"
37#include "AliLog.h"
38
39
40ClassImp(AliITSRealignTracks)
41
42const Int_t referSect=2;
43
44
45AliITSRealignTracks::AliITSRealignTracks(TString minimizer,Int_t fit,Bool_t covUsed,TString fileintro,TString geometryfile,TString misalignmentFile,TString startingfile):
46 AliAlignmentTracks(),
47 fSurveyObjs(0),
48 fgeomfilename(),
49 fmintracks(),
50 fCovIsUsed(covUsed),
51 fUpdateCov(kFALSE)
52{
53
54 // minimizer="fast"->AliTrackResidualFast minimizer
55 // "minuit"->AliTrackResidualChi2 minimizer
56 // "minuitnorot"->AliTrackResidualChi2 minimizer without rotations degrees of freedom
57 // "linear"->AliTrackResidualLinear minimizer
58 //fit=0-> Riemann Fitter, fit=1->Kalman
59 //fileintro=file into which the Tree with the space points is stored
60 //geometryfile=file containing the geometry
61
62
63 SetPointsFilename(fileintro.Data());
64 SetGeomFilename(geometryfile);
65 InitAlignObjs();
66 if(!InitSurveyObjs(kFALSE))AliWarning("Unable to set Survey AlignObjs!");
67
68 if(startingfile=="")printf("Starting from default geometry \n");
69 else ReadAlignObjs(startingfile.Data(),"ITSAlignObjs");
70
71 if(misalignmentFile=="")printf("NO FAKE MISALIGNMENT INTRODUCED \n");
72 else {
73 Bool_t misal=Misalign(misalignmentFile,"ITSAlignObjs");
74 if(!misal)AliWarning("Incorrect fake misalignment filename!");;
75 }
76
77 if(!gGeoManager) AliGeomManager::LoadGeometry(fgeomfilename.Data());
78 if(covUsed)SetCovIsUsed(kTRUE);
79 if(!SelectFitter(fit))AliWarning("Incorrect fitter assignment!");
80 if(!SelectMinimizer(minimizer))AliWarning("Incorrect minimizer assignment!");
81
82 fmintracks=1;
83 BuildIndex();
84
85}
86
87AliITSRealignTracks::AliITSRealignTracks(const AliITSRealignTracks &realignTracks):
88 AliAlignmentTracks(),
89 fSurveyObjs(new AliAlignObj**(*realignTracks.fSurveyObjs)),
90 fgeomfilename(realignTracks.fgeomfilename),
91 fmintracks(realignTracks.fmintracks),
92 fCovIsUsed(realignTracks.fCovIsUsed),
93 fUpdateCov(realignTracks.fUpdateCov)
94{//Copy Constructor
95 AliWarning("Can't copy AliAlignmentTracks Data member!");
96}
97
98AliITSRealignTracks& AliITSRealignTracks::operator=(const AliITSRealignTracks &obj){
99 ////////////////////////
100 // Assignment operator
101 ////////////////////////
102 this->~AliITSRealignTracks();
103 new(this) AliITSRealignTracks(obj);
104 return *this;
105}
106
107AliITSRealignTracks::~AliITSRealignTracks(){
108 //destructor
109
110 if(fSurveyObjs) DeleteSurveyObjs();
111 //delete [] fSurveyObjs;
112
113}
114
115
116//_____________________________
117Bool_t AliITSRealignTracks::SelectFitter(Int_t fit,Int_t minTrackPoint){
118
119 if(fit==1){
120 AliTrackFitterKalman *fitter= new AliTrackFitterKalman();
121 fitter->SetMinNPoints(minTrackPoint);
122 SetTrackFitter(fitter);
123 }
124
125 else if(fit==0){
126 AliTrackFitterRieman *fitter=new AliTrackFitterRieman();
127 fitter=new AliTrackFitterRieman();
128 fitter->SetMinNPoints(minTrackPoint);
129 SetTrackFitter(fitter);
130 }
131 else return kFALSE;
132
133 return kTRUE;
134}
135
136
137Bool_t AliITSRealignTracks::SelectMinimizer(TString minimizer,Int_t minpoints,const Bool_t *coord){
138 AliTrackResiduals *res;
139 if(minimizer=="minuit"){
140 res = new AliTrackResidualsChi2();
141 if(coord){
142 for(Int_t j=0;j<6;j++){
143 if(coord[j])res->FixParameter(j);
144 }
145 }
146 }
147 else if(minimizer=="minuitnorot"){
148 res = new AliTrackResidualsChi2();
149 res->FixParameter(3);
150 res->FixParameter(4);
151 res->FixParameter(5);
152 }
153
154 else if(minimizer=="fast"){
155 res = new AliTrackResidualsFast();
156 if(coord){
157 for(Int_t j=0;j<6;j++){
158 if(coord[j])res->FixParameter(j);
159 }
160 }
161 }
162 else if(minimizer=="linear"){
163 res = new AliTrackResidualsLinear();
164 }
165
166 else {
167 printf("Trying to set a non existing minimizer! \n");
168 return kFALSE;
169 }
170
171 res->SetMinNPoints(minpoints);
172 SetMinimizer(res);
173
174 return kTRUE;
175}
176
177
178void AliITSRealignTracks::RealignITSVolIndependent(Int_t iter1,Int_t iterations,Int_t minNtracks,Int_t layer,Int_t minTrackPoint){
179
180
181 //iter1=#iterations inside AliAlignmentTracks::AliAlignVolumesITS method
182 //iterations=#iterations on the all procedure
183 //layer=0->all ITS, otherways the usual notation is considered (1=SPD1,2=SPD2,3=SDD1,4=SDD2,5=SSD1,6=SSD2)
184 //minNtracks=minimun number of tracks passing through a module in order to try to realign the module itsself
185 // if minNtracks<0, minimun number of tracks is |minNtracks|*minNumPoint[layer]/fact (see the code below): this allows a different
186 // choice of the number of tracks required on different layers and to vary these numbers once tuned the relative proportions.
187 //minTrackPoint=minimun number of "good" points required to a track (THE POINT ON THE MODULE THAT IS GOING TO BE REALIGNED
188 //IS NEVER CONSIDERED->max number can be required is 11 for cosmics tracks) for the track being considered in the minimization
189
190
191 fTrackFitter->SetMinNPoints(minTrackPoint);
192 TArrayI volIDs2(2200);
193 volIDs2.Reset(0);
194 TArrayI volIDs(1);
195 TString command;
196 TArrayI volIDsFit;
197
198 Int_t iLayer,iLayerToAlign;
199
200 Int_t minNumPoint[6]={100,100,100,100,50,50};
201 Double_t fact=10;
202 Int_t j=0;
203
204 Int_t size=0;
205 Int_t layerNum,modNum,lastVolid=0;
206 TNtuple *ntVolumeAlign=new TNtuple("ntVolumeAlign","NTuple with volume tried to be realigned","layerNum:modNum:volumeIDnum");
207
208 TStopwatch *timer=new TStopwatch();
209 timer->Start();
210 BuildIndex();
211 j=0;
212 UShort_t volid;
213
214 for(Int_t iter=0;iter<iterations;iter++){
215
216 //Starting Independent Modules Realignment
217 for(iLayerToAlign=(Int_t)AliGeomManager::kSPD1;iLayerToAlign<=(Int_t)AliGeomManager::kSSD2;iLayerToAlign++){
218 if(layer!=0&&iLayerToAlign!=layer)continue;
219 j=0;
220 size=0;
221 for(Int_t k=(Int_t)AliGeomManager::kSPD1;k<=(Int_t)AliGeomManager::kSSD2;k++){
222 size+=AliGeomManager::LayerSize(k);
223 printf("size: %d \n",size);
224 }
225
226 for (Int_t iModule=0;iModule<AliGeomManager::LayerSize(iLayerToAlign);iModule++){
227 j=0;
228 if(minNtracks<0){
229 if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNumPoint[iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer]*(-1*minNtracks/fact))continue; }
230 else if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNtracks)continue;
231
232 UShort_t volidAl = AliGeomManager::LayerToVolUID(iLayerToAlign,iModule);
233
234 volIDsFit.Reset(0);
235 volIDsFit.Set(size-1);
236 for (iLayer=AliGeomManager::kSPD1;iLayer<AliGeomManager::kTPC1;iLayer++){
237 for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
238 volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
239 if(AliGeomManager::LayerToVolUID(iLayer,iModule2)==volidAl)continue;
240 volIDsFit.AddAt(volid,j);
241 j++;
242 }
243 }
244 volIDs.AddAt((Int_t)volidAl,0);
245 if(iter==iterations-1){
246 volIDs2.AddAt(volidAl,lastVolid);
247 lastVolid++;
248 }
249 volIDs2.AddAt(volidAl,lastVolid);
250 AlignVolumesITS(&volIDs,&volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iter1);
251 }
252 }
253
254
255 if((iter+1)%5==0||iter==0||iter==1||iter==2||iter==3||iter==iterations-1){
256 command="RealignObj";
257 command+=(iter+1);
258 command.Append(".root");
259 WriteRealignObjArray(command.Data(),AliGeomManager::kSPD1,AliGeomManager::kSSD2);
260 }
261 }
262
263
264 if(j==0){printf("j=0 \n");return;}
265 for(Int_t k=0;k<volIDs2.GetSize();k++){
266 if(volIDs2.At(k)==0)break;
267 layerNum=AliGeomManager::VolUIDToLayer(volIDs2.At(k),modNum);
268 ntVolumeAlign->Fill(layerNum,modNum,volIDs2.At(k));
269 }
270 printf("End of selecting modules cycle: %d modules selected \n",j);
271 TFile *f=new TFile("RealignVolNt.root","RECREATE");
272 f->cd();
273 ntVolumeAlign->Write();
274 f->Close();
275
276 timer->Stop();
277 timer->Print();
278 return;
279}
280
281
282void AliITSRealignTracks::RealignITStracks(TString minimizer,Int_t fit=0,Int_t iter1=1,Int_t iterations=5,Int_t minNtracks=-10,Int_t layer=0,Int_t minTrackPoint=6,Bool_t covUsed=kFALSE,TString misalignmentFile="",TString startingfile="",Int_t doGlobal=1)
283{
284
285 // minimizer="fast"->AliTrackResidualFast minimizer
286 // "minuit"->AliTrackResidualChi2 minimizer
287 // "minuitnorot"->AliTrackResidualChi2 minimizer without rotations degrees of freedom
288 // "linear"->AliTrackResidualLinear minimizer
289 //fit=0-> Riemann Fitter, fit=1->Kalman
290 //iter1=#iterations inside AliAlignmentTracks::AliAlignVolumesITS method
291 //iterations=#iterations on the all procedure
292 //layer=0->all ITS, otherways the usual notation is considered (1=SPD1,2=SPD2,3=SDD1,4=SDD2,5=SSD1,6=SSD2)
293 //minNtracks=minimun number of tracks passing through a module in order to try to realign the module itsself
294 // if minNtracks<0, minimun number of tracks is |minNtracks|*minNumPoint[layer]/fact (see the code below): this allows a different
295 // choice of the number of tracks required on different layers and to vary these numbers once tuned the relative proportions.
296 //minTrackPoint=minimun number of "good" points required to a track (THE POINT ON THE MODULE THAT IS GOING TO BE REALIGNED
297 // IS NEVER CONSIDERED->max number that can be required is 11 for cosmics tracks) for the track being considered in the minimization
298 //doGlobal : do global realignment, 0=no, 1= yes, 2=only global
299
300
301 TArrayI volIDs2(2200);
302 volIDs2.Reset(0);
303 TArrayI volIDs(1);
304 TString command;
305 TArrayI volIDsFit;
306
307 Int_t iLayer,iLayerToAlign;
308
309 Int_t minNumPoint[6]={100,100,100,100,50,50};
310 Double_t fact=10;
311 Int_t count=0;
312
313 Int_t size=0;
314 Int_t layerNum,modNum,lastVolid=0;
315 TNtuple *ntVolumeAlign=new TNtuple("ntVolumeAlign","NTuple with volume tried to be realigned","layerNum:modNum:volumeIDnum");
316
317
318 if(!SelectFitter(fit))AliWarning("Incorrect fitter assignment!");
319 if(!SelectMinimizer(minimizer))AliWarning("Incorrect minimizer assignment!");
320 if(misalignmentFile=="")printf("NO FAKE MISALIGNMENT INTRODUCED \n");
321 else {
322 Bool_t misal=Misalign(misalignmentFile,"ITSAlignObjs");
323 if(!misal)return;
324 }
325
326
327 TStopwatch *timer=new TStopwatch();
328 timer->Start();
329 BuildIndex();
330 count=0;
331 UShort_t volid;
332
333 if(startingfile=="")printf("Starting from default geometry \n");
334 else {
335 printf("Starting from AlignObjs file: %s",startingfile.Data());
336 ReadAlignObjs(startingfile.Data(),"ITSAlignObjs");
337 }
338
339 for(Int_t iter=0;iter<iterations;iter++){
340 if(covUsed)SetCovIsUsed(kTRUE);
341
342
343 //START HIERARCHY REALIGNMENT
344
345 if(layer==0&&(doGlobal==1||doGlobal==2)){
346 for(Int_t siter=0;siter<5;siter++){
347 fTrackFitter->SetMinNPoints(2);
348 SetCovUpdate(kFALSE);
349 AlignSPDHalfBarrelToSectorRef(referSect,3);
350 // AlignSPDBarrel(1);
351 // if(siter==0)SetCovUpdate(kFALSE);
352 // AlignSPDHalfBarrel(0,3);
353 // SetCovUpdate(kTRUE);
354 AlignSPDHalfBarrelToHalfBarrel(1,3);
355 // AlignSPDHalfBarrelToSectorRef(referSect,3);
356 for(Int_t sector=0;sector<10;sector++){
357 SetMinNtracks(100);
358 if(sector==referSect)continue;
359 AlignSPDSectorWithSectors(sector,1);
360 }
361
362
363 for(Int_t lay=1;lay<=6;lay++){
364 if(!AlignLayerToSector(lay,referSect,3))AlignLayerToSPDHalfBarrel(lay,0,3);
365 }
366 AlignSPDHalfBarrel(0,3);
367
368 Int_t layers[6]={2,2,1,0,0,0};
369 fTrackFitter->SetMinNPoints(4);
370 AlignLayersToLayers(layers,1);
371
372 fTrackFitter->SetMinNPoints(6);
373 layers[2]=2;
374 layers[3]=1;//{2,2,2,1,0,0};
375 AlignLayersToLayers(layers,1);
376
377 fTrackFitter->SetMinNPoints(6);
378 layers[3]=2;
379 layers[4]=1;//{2,2,2,2,1,0};
380 AlignLayersToLayers(layers,1);
381
382 fTrackFitter->SetMinNPoints(6);
383 layers[4]=2;
384 layers[5]=1;//{2,2,2,2,2,1};
385 AlignLayersToLayers(layers,1);
386
387
388 for(Int_t sector=0;sector<10;sector++){
389 AlignSPDSectorToOuterLayers(sector,1);
390 }
391 WriteRealignObjArray("AfterGlobal.root",AliGeomManager::kSPD1,AliGeomManager::kSSD2);
392 }
393 }
394
395 if(doGlobal==2)return;
396
397 if(covUsed)SetCovUpdate(kTRUE);
398 SetMinNtracks(1);
399
400
401 // STARTS INDEPENDENT MOULES REALIGNMENT
402
403 fTrackFitter->SetMinNPoints(minTrackPoint);
404 for(iLayerToAlign=(Int_t)AliGeomManager::kSPD1;iLayerToAlign<=(Int_t)AliGeomManager::kSSD2;iLayerToAlign++){
405 if(layer!=0&&iLayerToAlign!=layer)continue;
406 count=0;
407 size=0;
408 for(Int_t k=(Int_t)AliGeomManager::kSPD1;k<=(Int_t)AliGeomManager::kSSD2;k++){
409 size+=AliGeomManager::LayerSize(k);
410 printf("size: %d \n",size);
411 }
412
413 for (Int_t iModule=0;iModule<AliGeomManager::LayerSize(iLayerToAlign);iModule++){
414 count=0;
415 if(minNtracks<0){
416 if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNumPoint[iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer]*(-1*minNtracks/fact))continue;
417 }
418 else if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNtracks)continue;
419
420 UShort_t volidAl = AliGeomManager::LayerToVolUID(iLayerToAlign,iModule);
421
422 volIDsFit.Reset(0);
423 volIDsFit.Set(size-1);
424 for (iLayer=(Int_t)AliGeomManager::kSPD1;iLayer<(Int_t)AliGeomManager::kTPC1;iLayer++){
425 for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
426
427
428 volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
429
430 if(AliGeomManager::LayerToVolUID(iLayer,iModule2)==volidAl)continue;
431 volIDsFit.AddAt(volid,count);
432 count++;
433 }
434 }
435
436 volIDs.AddAt((Int_t)volidAl,0);
437 if(iter==iterations-1){
438 volIDs2.AddAt(volidAl,lastVolid);
439 lastVolid++;
440 }
441 volIDs2.AddAt(volidAl,lastVolid);
442 AlignVolumesITS(&volIDs,&volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iter1);
443 }
444 }
445
446 if((iter+1)%2==0||(iter+1)%5==0||iter==0||iter==1||iter==2||iter==3||iter==iterations-1){
447 command="RealignObj";
448 command+=(iter+1);
449 command.Append(".root");
450 WriteRealignObjArray(command.Data(),AliGeomManager::kSPD1,AliGeomManager::kSSD2);
451 }
452
453 }
454
455 if(count==0){printf("count=0 \n");return;}
456 for(Int_t k=0;k<volIDs2.GetSize();k++){
457 if(volIDs2.At(k)==0)break;
458 layerNum=AliGeomManager::VolUIDToLayer(volIDs2.At(k),modNum);
459 ntVolumeAlign->Fill(layerNum,modNum,volIDs2.At(k));
460 }
461 printf("End of selecting modules cycle: %d modules selected \n",count);
462 TFile *f=new TFile("RealignVolNt.root","RECREATE");
463 f->cd();
464 ntVolumeAlign->Write();
465 f->Close();
466
467 timer->Stop();
468 timer->Print();
469 return;
470
471}
472
473
474//______________________________________________________________________________
475void AliITSRealignTracks::InitAlignObjs()
476{
477 // Initialize the alignment objects array
478 TMatrixDSym c(6);
479 Double_t cov[21];
480 for(Int_t i=0;i<21;i++)cov[i]=0.;
481 for(Int_t i=0;i<3;i++)cov[i*(i+1)/2+i]=0.05*0.05;//Set Default Error to 500 micron for Translations
482 for(Int_t i=3;i<6;i++)cov[i*(i+1)/2+i]=0.001*0.001*180*180/3.14/3.14;//and 1 mrad for rotations (global ref. sysytem->~40 micron for SPD1,~450 micron for SSD2)
483
484 Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
485 fAlignObjs = new AliAlignObj**[nLayers];
486 for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
487 fAlignObjs[iLayer] = new AliAlignObj*[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
488 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
489 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer+ AliGeomManager::kFirstLayer,iModule);
490 fAlignObjs[iLayer][iModule] = new AliAlignObjParams(AliGeomManager::SymName(volid),volid,0,0,0,0,0,0,kTRUE);
491 fAlignObjs[iLayer][iModule]->SetCorrMatrix(cov);
492 fAlignObjs[iLayer][iModule]->SetUniqueID(0);
493 }
494 }
495}
496
497//______________________________________________________________________________
498Bool_t AliITSRealignTracks::InitSurveyObjs(Bool_t infinite,Double_t factor,Bool_t fromfile,TString filename,TString arrayName){
499
500 if(filename!=""){
501 //Initialize from file
502 if(gSystem->AccessPathName(filename.Data(),kFileExists)){
503 printf("Wrong Survey AlignObjs File Name \n");
504 return kFALSE;
505 }
506
507 TFile *surveyObj=TFile::Open(filename.Data());
508 if (!surveyObj || !surveyObj->IsOpen()) {
509 AliError(Form("Could not open SurveyObjs file: file %s !",filename.Data()));
510 return kFALSE;
511 }
512 printf("Getting TClonesArray \n");
513 TClonesArray *clnarray=(TClonesArray*)surveyObj->Get(arrayName);
514 Int_t size=clnarray->GetSize();
515 UShort_t volid;
516 for(Int_t ivol=0;ivol<size;ivol++){
517 AliAlignObjParams *a=(AliAlignObjParams*)clnarray->At(ivol);
518 volid=a->GetVolUID();
519 Int_t iModule;
520 AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer(volid,iModule);
521 printf("Updating volume: %d ,layer: %d module: %d \n",volid,iLayer,iModule);
522 *fSurveyObjs[iLayer-AliGeomManager::kFirstLayer][iModule] *= *a;
523 }
524
525 delete clnarray;
526 surveyObj->Close();
527 return kTRUE;
528 }
529
530 // Initialize the alignment objects array with default values
531 Double_t v=1.*factor;
532 if(infinite)v*=100000.;
533 TMatrixDSym c(6);
534 Double_t cov[21];
535 for(Int_t i=0;i<21;i++)cov[i]=0.;
536 for(Int_t i=0;i<3;i++)cov[i*(i+1)/2+i]=0.1*0.1*v;//Set Default Error to 1 mm for Translation
537 for(Int_t i=3;i<6;i++)cov[i*(i+1)/2+i]=0.01*0.01*180.*180./3.14/3.14*v;//and 10 mrad (~0.5 degrees)for rotations (global ref. sysytem)
538 Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
539 fSurveyObjs = new AliAlignObj**[nLayers];
540 for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
541 fSurveyObjs[iLayer] = new AliAlignObj*[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
542 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
543 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer+ AliGeomManager::kFirstLayer,iModule);
544 if(!fromfile){
545 fSurveyObjs[iLayer][iModule] = new AliAlignObjParams(AliGeomManager::SymName(volid),volid,0,0,0,0,0,0,kTRUE);
546 fSurveyObjs[iLayer][iModule]->SetCorrMatrix(cov);
547 fSurveyObjs[iLayer][iModule]->SetUniqueID(0);
548 }
549 }
550 }
551 return kTRUE;
552}
553
554
555//______________________________________________________________________________
556void AliITSRealignTracks::ResetAlignObjs()
557{
558 // Reset the alignment objects array
559 for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
560 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++)
561 fAlignObjs[iLayer][iModule]->SetPars(0,0,0,0,0,0);
562 }
563}
564
565//______________________________________________-
566void AliITSRealignTracks::DeleteSurveyObjs()
567{
568 // Delete the alignment objects array
569 for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
570 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++)
571 if (fSurveyObjs[iLayer][iModule])
572 delete fSurveyObjs[iLayer][iModule];
573 delete [] fSurveyObjs[iLayer];
574 }
575 delete [] fSurveyObjs;
576 fSurveyObjs = 0;
577}
578
579
580//______________________________________________________________________________
581Bool_t AliITSRealignTracks::ReadAlignObjs(const char *alignObjFileName, const char* arrayName){
582
583 // Read alignment object from a file: update the alignobj already present with the one in the file
584 // To be replaced by a call to CDB
585
586 if(gSystem->AccessPathName(alignObjFileName,kFileExists)){
587 printf("Wrong AlignObjs File Name \n");
588 return kFALSE;
589 }
590
591 TFile *fRealign=TFile::Open(alignObjFileName);
592 if (!fRealign || !fRealign->IsOpen()) {
593 AliError(Form("Could not open Align Obj File file %s !",alignObjFileName));
594 return kFALSE;
595 }
596 printf("Getting TClonesArray \n");
597 TClonesArray *clnarray=(TClonesArray*)fRealign->Get(arrayName);
598 Int_t size=clnarray->GetSize();
599 UShort_t volid;
600
601 for(Int_t ivol=0;ivol<size;ivol++){
602 AliAlignObjParams *a=(AliAlignObjParams*)clnarray->At(ivol);
603 volid=a->GetVolUID();
604 Int_t iModule;
605 AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer(volid,iModule);
606 if(iLayer<AliGeomManager::kFirstLayer||iLayer>AliGeomManager::kSSD2)continue;
607 printf("Updating volume: %d ,layer: %d module: %d \n",volid,iLayer,iModule);
608 *fAlignObjs[iLayer-AliGeomManager::kFirstLayer][iModule] *= *a;
609 }
610
611 delete clnarray;
612 fRealign->Close();
613 return kTRUE;
614}
615
616//_________________________________________
617Bool_t AliITSRealignTracks::FirstAlignmentLayers(Bool_t *layers,Int_t minNtracks,Int_t iterations,TArrayI *volidsSet){
618
619 //Align all modules in the set of layers independently according to a sequence based on the number of tracks passing through a given module
620
621 BuildIndex();
622
623 UShort_t voluid;
624 Int_t **lastIndex;
625 Int_t laymax = 0;
626 Int_t modmax = 0;
627 Int_t maxntr=0,nMod=0;
628 Int_t size=0;
629 for(Int_t i=0;i<6;i++){
630 if(layers[i]==1)size+=AliGeomManager::LayerSize(i+AliGeomManager::kFirstLayer);
631 }
632 TArrayI *volFit3;
633 TArrayI *volFit=new TArrayI(size);
634 TArrayI *volFit2=new TArrayI(size-1);
635 TArrayI *sequence=new TArrayI(size);
636 TArrayI *volIn=new TArrayI(1);
637
638 // Initialize the index arrays
639 Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
640 lastIndex = new Int_t*[nLayers];
641 for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
642 lastIndex[iLayer] = new Int_t[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
643 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
644 lastIndex[iLayer][iModule] = fLastIndex[iLayer][iModule];
645 if(layers[iLayer]==1){
646 volFit->AddAt(AliGeomManager::LayerToVolUID(iLayer+AliGeomManager::kFirstLayer,iModule),maxntr);
647 maxntr++;
648 }
649 }
650 }
651 Int_t found=0;
652
653 while (maxntr>minNtracks){
654 maxntr=minNtracks;
655 for (Int_t iLayer = 0; iLayer <= (AliGeomManager::kSSD2 - AliGeomManager::kFirstLayer); iLayer++) {
656 if(layers[iLayer]==0)continue;
657 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
658 if(lastIndex[iLayer][iModule]>maxntr){
659 maxntr=lastIndex[iLayer][iModule];
660 laymax=iLayer;
661 modmax=iModule;
662 }
663 }
664 }
665 if(maxntr>minNtracks){
666 voluid=AliGeomManager::LayerToVolUID(laymax+AliGeomManager::kFirstLayer,modmax);
667 sequence->AddAt(voluid,nMod);
668 lastIndex[laymax][modmax]=0;
669 nMod++;
670 }
671 }
672
673 Int_t ilayer,imod;
674 for(Int_t iter=0;iter<iterations;iter++){
675 for(Int_t k=0;k<nMod;k++){
676 voluid=sequence->At(k);
677 ilayer=AliGeomManager::VolUIDToLayer(voluid,imod);
678 volIn->AddAt(voluid,0);
679 found=0;
680 for(Int_t j=0;j<volFit->GetSize();j++){
681 if(volFit->At(j)!=volIn->At(0))volFit2->AddAt(volFit->At(j),j-found);
682 else found=1;
683 }
684
685 if(volidsSet){
686 volFit3=IntersectVolArray(volidsSet,volFit2);
687 }
688 else volFit3=volFit2;
689 AlignVolumesITS(volIn,volFit3,AliGeomManager::kSPD1,AliGeomManager::kSDD1,2);
690 }
691 }
692 return kTRUE;
693}
694
695//__________________________________________
696Bool_t AliITSRealignTracks::FirstAlignmentSPD(Int_t minNtracks,Int_t iterations,TArrayI *volidsSet){
697
698 BuildIndex();
699
700 UShort_t voluid;
701 Int_t **lastIndex;
702 Int_t laymax = 0;
703 Int_t modmax = 0;
704 Int_t maxntr=0,nMod=0;
705 TArrayI *volFit=new TArrayI(AliGeomManager::LayerSize(1)+AliGeomManager::LayerSize(2));
706 TArrayI *volFit2=new TArrayI(AliGeomManager::LayerSize(1)+AliGeomManager::LayerSize(2)-1);
707 TArrayI *sequence=new TArrayI(AliGeomManager::LayerSize(1)+AliGeomManager::LayerSize(2));
708 TArrayI *volIn=new TArrayI(1);
709
710 // Initialize the index arrays
711 Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
712 lastIndex = new Int_t*[nLayers];
713 for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
714 lastIndex[iLayer] = new Int_t[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
715 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
716 lastIndex[iLayer][iModule] = fLastIndex[iLayer][iModule];
717 if(iLayer+AliGeomManager::kFirstLayer<=AliGeomManager::kSPD2){
718 volFit->AddAt(AliGeomManager::LayerToVolUID(iLayer+AliGeomManager::kFirstLayer,iModule),maxntr);
719 maxntr++;
720 }
721 }
722 }
723 Int_t found=0;
724
725 while (maxntr>minNtracks){
726 maxntr=minNtracks;
727 for (Int_t iLayer = 0; iLayer <= (AliGeomManager::kSPD2 - AliGeomManager::kFirstLayer); iLayer++) {
728 for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
729 if(lastIndex[iLayer][iModule]>maxntr){
730 laymax=iLayer;
731 modmax=iModule;
732 maxntr=lastIndex[iLayer][iModule];
733 }
734 }
735 }
736 if(maxntr>minNtracks){
737 voluid=AliGeomManager::LayerToVolUID(laymax+AliGeomManager::kFirstLayer,modmax);
738 sequence->AddAt(voluid,nMod);
739 lastIndex[laymax][modmax]=0;
740 nMod++;
741 volIn->AddAt(voluid,0);
742 }
743 }
744
745 TArrayI *volFit3;
746 Int_t ilayer,imod;
747 for(Int_t iter=0;iter<iterations;iter++){
748 for(Int_t k=0;k<nMod;k++){
749 voluid=sequence->At(k);
750 ilayer=AliGeomManager::VolUIDToLayer(voluid,imod);
751 volIn->AddAt(voluid,0);
752 found=0;
753 for(Int_t j=0;j<volFit->GetSize();j++){
754 if(volFit->At(j)!=volIn->At(0))volFit2->AddAt(volFit->At(j),j-found);
755 else found=1;
756 }
757
758 if(volidsSet){
759 volFit3=IntersectVolArray(volidsSet,volFit2);
760 }
761 else volFit3=volFit2;
762
763 AlignVolumesITS(volIn,volFit3,AliGeomManager::kSPD1,AliGeomManager::kSDD1,2);
764 }
765 }
766 return kTRUE;
767}
768
769
770//__________________________________
771Bool_t AliITSRealignTracks::SPDmodulesAlignToSSD(Int_t minNtracks,Int_t iterations){
772
773 Int_t volSSD[6]={0,0,0,0,1,1};
774 TArrayI *volOuter=GetLayersVolUID(volSSD);
775 TArrayI *voluid=new TArrayI(1);
776 for(Int_t iter=0;iter<iterations;iter++){
777 //SPD1
778 for(Int_t imod=0;imod<AliGeomManager::LayerSize(AliGeomManager::kSPD1);imod++){ if(GetLastIndex(AliGeomManager::kSPD1-AliGeomManager::kFirstLayer,imod)<minNtracks){
779 printf("Not enough tracks for module: lay %d mod %d \n",1,imod );
780 continue;
781 }
782 voluid->AddAt(AliGeomManager::LayerToVolUID(AliGeomManager::kSPD1,imod),0);
783 AlignVolumesITS(voluid,volOuter,AliGeomManager::kSSD1,AliGeomManager::kSSD2,2);
784 }
785 //SPD2
786 for(Int_t imod=0;imod<AliGeomManager::LayerSize(AliGeomManager::kSPD2);imod++){
787 if(GetLastIndex(AliGeomManager::kSPD2-AliGeomManager::kFirstLayer,imod)<minNtracks){
788 printf("Not enough tracks for module: lay %d mod %d \n",2,imod );
789 continue;
790 }
791 voluid->AddAt(AliGeomManager::LayerToVolUID(AliGeomManager::kSPD2,imod),0);
792 AlignVolumesITS(voluid,volOuter,AliGeomManager::kSSD1,AliGeomManager::kSSD2,2);
793 }
794 }
795 return kTRUE;
796}
797
798//______________________________________________________________________________
799Bool_t AliITSRealignTracks::AlignVolumesITS(const TArrayI *volids, const TArrayI *volidsfit,
800 AliGeomManager::ELayerID layerRangeMin,
801 AliGeomManager::ELayerID layerRangeMax,
802 Int_t iterations){
803
804 // Align a set of detector volumes.
805 // Tracks are fitted only within
806 // the range defined by the user
807 // (by layerRangeMin and layerRangeMax)
808 // or within the set of volidsfit
809 // Repeat the procedure 'iterations' times
810
811 Int_t nVolIds = volids->GetSize();
812 if (nVolIds == 0) {
813 AliError("Volume IDs array is empty!");
814 return kFALSE;
815 }
816
817 Double_t surveycov[21],transl[3],rot[3];
818
819 // Load only the tracks with at least one
820 // space point in the set of volume (volids)
821 BuildIndex();
822 AliTrackPointArray **points;
823 Bool_t failed=kFALSE;
824 // Start the iterations
825 while (iterations > 0) {
826 Int_t nArrays = LoadPoints(volids, points);
827 if (nArrays < fmintracks) {
828 failed=kTRUE;
829 printf("Not enough tracks to try minimization \n");
830 UnloadPoints(nArrays, points);
831 break;
832 }
833
834 AliTrackResiduals *minimizer = CreateMinimizer();
835 minimizer->SetNTracks(nArrays);
836 minimizer->InitAlignObj();
837 AliTrackFitter *fitter = CreateFitter();
838 for (Int_t iArray = 0; iArray < nArrays; iArray++) {
839 if (!points[iArray]) continue;
840 fitter->SetTrackPointArray(points[iArray], kTRUE);
841 if (fitter->Fit(volids,volidsfit,layerRangeMin,layerRangeMax) == kFALSE) continue;
842 AliTrackPointArray *pVolId,*pTrack;
843 fitter->GetTrackResiduals(pVolId,pTrack);
844 minimizer->AddTrackPointArrays(pVolId,pTrack);
845 }
846 if(minimizer->GetNFilledTracks()<=fmintracks){
847 printf("No good tracks found: could not find parameter for volume %d (and following in volids)\n",volids->At(0));
848 UnloadPoints(nArrays, points);
849 failed=kTRUE;
850 break;
851 }
852 failed=(!minimizer->Minimize());
853
854 // Update the alignment object(s)
855 if (fDoUpdate) for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) {
856 UShort_t volid = (*volids)[iVolId];
857 Int_t iModule;
858 AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer(volid,iModule);
859
860 AliAlignObj *alignObj = fAlignObjs[iLayer-AliGeomManager::kFirstLayer][iModule];
861 AliAlignObj *alignObjSurv = fSurveyObjs[iLayer-AliGeomManager::kFirstLayer][iModule];
862
863 if(!failed){
864 if(fUpdateCov)*alignObj *= *minimizer->GetAlignObj();
865 else{
866 TMatrixDSym covmatrx(6);
867 alignObj->GetCovMatrix(covmatrx);
868 *alignObj *= *minimizer->GetAlignObj();
869 alignObj->SetCorrMatrix(covmatrx);
870 alignObj->SetUniqueID(1);
871 }
872 alignObjSurv->GetCovMatrix(surveycov);
873 alignObj->GetPars(transl,rot);
874
875 if(TMath::Sqrt(TMath::Abs(surveycov[0]))*2<TMath::Abs(transl[0])||TMath::Sqrt(TMath::Abs(surveycov[2]))*2<TMath::Abs(transl[1])||TMath::Sqrt(TMath::Abs(surveycov[5]))*2<TMath::Abs(transl[2])||TMath::Sqrt(TMath::Abs(surveycov[9]))*2<TMath::Abs(rot[0])||TMath::Sqrt(TMath::Abs(surveycov[14]))*2<TMath::Abs(rot[1])||TMath::Sqrt(TMath::Abs(surveycov[20]))*2<TMath::Abs(rot[2])){
876 printf("Results for module %d out of Survey: reinitializing it from survey \n",volid);
877 // *alignObj = *alignObjSurv;
878 alignObj->SetPars(0.,0.,0.,0.,0.,0.);
879 alignObj->SetUniqueID(0);
880 if(fUpdateCov)alignObj->SetCorrMatrix(surveycov);
881 if(iterations==1){
882 failed=kTRUE;
883 UnloadPoints(nArrays, points);
884 break;
885 }
886 }
887 }
888 else {
889 printf("Minimization failed: cannot update AlignObj for volume: %d \n",volid);
890 UnloadPoints(nArrays, points);
891 break;
892 }
893 if(iterations==1)alignObj->Print("");
894 }
895
896 UnloadPoints(nArrays, points);
897 iterations--;
898 }
899 return (!failed);
900}
901
902
903
904//______________________________________________
905Bool_t AliITSRealignTracks::AlignSPDBarrel(Int_t iterations){
906
907 Int_t size=0,size2=0;
908 Int_t layers[6]={1,1,0,0,0,0};
909 for(Int_t k=1;k<=2;k++){
910 size+=AliGeomManager::LayerSize(k);
911 }
912 for(Int_t k=3;k<=6;k++){
913 size2+=AliGeomManager::LayerSize(k);
914 printf("size: %d \n",size2);
915 }
916
917 printf("Aligning SPDBarrel: nmodules: %d \n",size);
918 printf("Fitting modules: %d \n",size2);
919
920 TArrayI *volIDs=GetLayersVolUID(layers);
921 layers[0]=0;
922 layers[1]=0;
923 layers[2]=1;
924 layers[3]=1;
925 layers[4]=1;
926 layers[5]=1;
927 TArrayI *volIDsFit=GetLayersVolUID(layers);
928
929 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSDD1,AliGeomManager::kTPC1,iterations);
930
931 return kTRUE;
932}
933
934//______________________
935Bool_t AliITSRealignTracks::AlignSPDHalfBarrel(Int_t method,Int_t iterations){
936
937 Int_t size=0,size2=0;
938 Int_t layers[6]={0,0,1,1,1,1};
939 Int_t sectorsUp[10]={1,1,1,1,1,0,0,0,0,0};
940 Int_t sectorsDown[10]={0,0,0,0,0,1,1,1,1,1};
941
942 TString updownstr;
943 if(method==0)updownstr="UpNoDown";
944 else if (method==1)updownstr="DownNoUp";
945 else if (method==10)updownstr="UpWithDown";
946 else if (method==11)updownstr="DownWithUp";
947 else {
948 AliWarning("Wrong AlignSPDHalfBarrel method selected ");
949 return kFALSE;
950 }
951
952 for(Int_t i=1;i<=2;i++){
953 size+=AliGeomManager::LayerSize(i);
954 }
955
956 for(Int_t i=3;i<=6;i++){
957 size2+=AliGeomManager::LayerSize(i);
958 }
959
960 size=size/2;
961 if(method==10||method==11)size2+=size;
962
963 printf("Aligning SPDHalfBarrel %s: nmodules: %d \n",updownstr.Data(),size);
964 printf("Fitting modules: %d \n",size2);
965 TArrayI *volIDsFit2;
966 TArrayI *volids = NULL;
967 TArrayI *volIDsFit=GetLayersVolUID(layers);
968 if(method==0||method==10)volids=GetSPDSectorsVolids(sectorsUp);
969 if(method==1||method==11)volids=GetSPDSectorsVolids(sectorsDown);
970
971 if(method==10)volIDsFit2=JoinVolArrays(GetSPDSectorsVolids(sectorsDown),volIDsFit);
972 else if(method==11)volIDsFit2=JoinVolArrays(GetSPDSectorsVolids(sectorsUp),volIDsFit);
973 else volIDsFit2=volIDsFit;
974
975 AlignVolumesITS(volids,volIDsFit2,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
976
977 return kTRUE;
978}
979
980
981//______________________________________________________
982Bool_t AliITSRealignTracks::AlignLayer(Int_t layer,Int_t iterations){
983
984 Int_t size=0,size2=0;
985 Int_t layers[6]={0,0,0,0,0,0};
986 layers[layer-1]=1;
987 TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
988 for(Int_t k=1;k<=6;k++){
989 if(k!=layer)size2+=AliGeomManager::LayerSize(k);
990 }
991 size=AliGeomManager::LayerSize(layer);
992
993 printf("Aligning layer %s, nmodules %d ,fitted modules %d \n",layerstr[layer-1].Data(),size,size2);
994
995
996 TArrayI *volIDs=GetLayersVolUID(layers);
997 layers[0]=1;
998 layers[1]=1;
999 layers[2]=1;
1000 layers[3]=1;
1001 layers[4]=1;
1002 layers[5]=1;
1003 layers[layer]=0;
1004 TArrayI *volIDsFit=GetLayersVolUID(layers);
1005
1006 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSDD1,AliGeomManager::kSSD2,iterations);
1007
1008 return kTRUE;
1009}
1010
1011//___________________________________________
1012
1013Bool_t AliITSRealignTracks::AlignLayersToLayers(Int_t *layer,Int_t iterations){
1014
1015 UShort_t volid;
1016 Int_t size=0,size2=0,j=0,k=0;
1017 Int_t iLayer;
1018 TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
1019 TString command="",str;
1020 for(Int_t i=1;i<=6;i++){
1021 if(layer[i-1]==1||layer[i-1]==3){
1022 size+=AliGeomManager::LayerSize(i);
1023 command.Append(" ");
1024 command.Append(layerstr[i-1]);
1025 }
1026 if(layer[i-1]==2||layer[i-1]==3){
1027 size2+=AliGeomManager::LayerSize(i);
1028 str.Append(" ");
1029 str.Append(layerstr[i-1]);
1030 }
1031 }
1032
1033 printf("Aligning layers %s To layers %s, nmodules %d ,fitted modules %d \n",command.Data(),str.Data(),size,size2);
1034
1035
1036 TArrayI volIDs(size);
1037 TArrayI volIDsFit(size2);
1038
1039 for (iLayer=(Int_t)AliGeomManager::kSPD1;iLayer<(Int_t)AliGeomManager::kTPC1;iLayer++){
1040 if(layer[iLayer-AliGeomManager::kFirstLayer]==0)continue;
1041 if(layer[iLayer-AliGeomManager::kFirstLayer]==1){
1042 for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
1043 volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
1044 volIDs.AddAt(volid,j);
1045 j++;
1046 }
1047 }
1048 else if(layer[iLayer-AliGeomManager::kFirstLayer]==2){
1049 for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
1050 volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
1051 volIDsFit.AddAt(volid,k);
1052 k++;
1053 }
1054 }
1055 else if(layer[iLayer-AliGeomManager::kFirstLayer]==3){
1056 for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
1057 volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
1058 volIDs.AddAt(volid,j);
1059 j++;
1060 volIDsFit.AddAt(volid,k);
1061 k++;
1062 }
1063 }
1064 }
1065
1066 AlignVolumesITS(&volIDs,&volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
1067
1068 return kTRUE;
1069}
1070
1071//______________________________________________
1072
1073Bool_t AliITSRealignTracks::AlignSPDSectorToOuterLayers(Int_t sector,Int_t iterations){
1074
1075
1076 Int_t layers[6]={0,0,1,1,1,1};
1077 Bool_t spd=kFALSE;
1078 Int_t sectorsIN[10]={0,0,0,0,0,0,0,0,0,0};
1079 Int_t sectorsFit[10]={1,1,1,1,1,1,1,1,1,1};
1080
1081 if(sector<0){
1082 sector=-sector;
1083 spd=kTRUE;
1084 }
1085 sectorsIN[sector]=1;
1086 sectorsFit[sector]=0;
1087 TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1088 TArrayI *volIDsFit;
1089 if(spd){
1090 volIDsFit=JoinVolArrays(GetSPDSectorsVolids(sectorsFit),GetLayersVolUID(layers));
1091 }
1092 else volIDsFit=GetLayersVolUID(layers);
1093
1094 printf("Aligning SPD sector %d: nmodules: %d \n",sector,volIDs->GetSize());
1095 printf("Fitting modules: %d \n",volIDsFit->GetSize());
1096
1097 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1098
1099 return kTRUE;
1100}
1101
1102//______________________________________________
1103Bool_t AliITSRealignTracks::AlignSPDSectorWithSectors(Int_t sector,Int_t iterations){
1104
1105
1106 Int_t sectorsIN[10]={0,0,0,0,0,0,0,0,0,0};
1107 Int_t sectorsFit[10]={1,1,1,1,1,1,1,1,1,1};
1108
1109 sectorsIN[sector]=1;
1110 sectorsFit[sector]=0;
1111 TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1112 TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);;
1113
1114 printf("Aligning SPD sector %d: nmodules: %d \n",sector,volIDs->GetSize());
1115 printf("Fitting modules: %d \n",volIDsFit->GetSize());
1116
1117
1118 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSDD1,iterations);
1119
1120 return kTRUE;
1121}
1122
1123
1124
1125//___________________________________________________
1126Bool_t AliITSRealignTracks::AlignSPDSectorsWithSectors(Int_t *sectorsIN,Int_t *sectorsFit,Int_t iterations){
1127
1128 TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1129 TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);;
1130
1131 printf("Aligning SPD sectors: modules: %d \n",volIDs->GetSize());
1132 printf("Fitting modules: %d \n",volIDsFit->GetSize());
1133
1134 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSDD1,iterations);
1135
1136 return kTRUE;
1137}
1138
1139
1140//___________________________________________
1141
1142Bool_t AliITSRealignTracks::AlignLayerToSPDHalfBarrel(Int_t layer,Int_t updown,Int_t iterations){
1143
1144
1145 Int_t sectorsDown[10]={0,0,0,0,0,1,1,1,1,1};
1146 Int_t sectorsUp[10]={1,1,1,1,1,0,0,0,0,0};
1147 TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
1148 TArrayI *volIDsFit;
1149 Int_t layers[6]={0,0,0,0,0,0};
1150 layers[layer]=1;
1151 Int_t size=AliGeomManager::LayerSize(layer);
1152 TArrayI *volIDs=GetLayersVolUID(layers);
1153
1154 if(updown==0){
1155 volIDsFit=GetSPDSectorsVolids(sectorsUp);
1156 printf("Aligning layer %s, nmodules %d ,to half barrel Up \n",layerstr[layer-1].Data(),size);
1157 }
1158 else if(updown==1){
1159 volIDsFit=GetSPDSectorsVolids(sectorsDown);
1160 printf("Aligning layer %s, nmodules %d ,to half barrel Down \n",layerstr[layer-1].Data(),size);
1161 }
1162 else {
1163 printf("Wrong Half Barrel selection! \n");
1164 return kFALSE;
1165 }
1166
1167 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
1168
1169 return kTRUE;
1170}
1171
1172//___________________________________________
1173
1174Bool_t AliITSRealignTracks::AlignLayerToSector(Int_t layer,Int_t sector,Int_t iterations){
1175
1176 if(sector>9){
1177 printf("Wrong Sector selection! \n");
1178 return kFALSE;
1179 }
1180 Int_t sectors[10]={0,0,0,0,0,0,0,0,0,0};
1181 sectors[sector]=1;
1182 TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
1183 TArrayI *volIDsFit;
1184 Int_t layers[6]={0,0,0,0,0,0};
1185 layers[layer]=1;
1186 TArrayI *volIDs=GetLayersVolUID(layers);
1187 Int_t size=AliGeomManager::LayerSize(layer);
1188
1189
1190 volIDsFit=GetSPDSectorsVolids(sectors);
1191 printf("Aligning layer %s, nmodules %d ,to half barrel Up \n",layerstr[layer-1].Data(),size);
1192
1193 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
1194
1195 return kTRUE;
1196}
1197
1198//_______________________________________________
1199
1200Bool_t AliITSRealignTracks::AlignSPDHalfBarrelToHalfBarrel(Int_t updown,Int_t iterations){
1201
1202
1203 Int_t sectorsDown[10]={0,0,0,0,0,1,1,1,1,1};
1204 Int_t sectorsUp[10]={1,1,1,1,1,0,0,0,0,0};
1205
1206 TArrayI *volIDsUp=GetSPDSectorsVolids(sectorsUp);
1207 TArrayI *volIDsDown=GetSPDSectorsVolids(sectorsDown);
1208
1209 if(updown==0){
1210 printf("Aligning SPD HalfBarrel up to half Barrel down : nmodules: %d \n",volIDsUp->GetSize());
1211 printf("Fitting modules: %d \n",volIDsDown->GetSize());
1212 AlignVolumesITS(volIDsUp,volIDsDown,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1213 }
1214 else if(updown==1){
1215 printf("Aligning SPD HalfBarrel down to half Barrel Up : nmodules: %d \n",volIDsDown->GetSize());
1216 printf("Fitting modules: %d \n",volIDsUp->GetSize());
1217 AlignVolumesITS(volIDsDown,volIDsUp,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1218 }
1219 else {
1220 printf("Wrong Half Barrel selection! \n");
1221 return kFALSE;
1222 }
1223
1224 return kTRUE;
1225}
1226
1227
1228//_______________________
1229Bool_t AliITSRealignTracks::AlignSPDHalfBarrelToSectorRef(Int_t sector,Int_t iterations){
1230
1231 Int_t sectorsIN[10]={0,0,0,0,0,1,1,1,1,1};
1232 Int_t sectorsFit[10]={0,0,0,0,0,0,0,0,0,0};
1233
1234 sectorsFit[sector]=1;
1235
1236 TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1237 TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);
1238
1239 printf("Aligning SPD HalfBarrel to sector 0 %d: nmodules: %d \n",sector,volIDs->GetSize());
1240 printf("Fitting modules: %d \n",volIDsFit->GetSize());
1241
1242
1243 AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1244
1245
1246 return kTRUE;
1247}
1248//_________________________________________
1249Bool_t AliITSRealignTracks::AlignSPD1SectorRef(Int_t sector,Int_t iterations){
1250
1251 Int_t sectorsIN[10]={0,0,0,0,0,0,0,0,0,0};
1252 Int_t sectorsFit[10]={1,1,1,1,1,1,1,1,1,1};
1253 sectorsIN[sector]=1;
1254 sectorsFit[sector]=0;
1255 TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1256 TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);
1257 Int_t size=volIDs->GetSize();
1258 Int_t size2=volIDsFit->GetSize();
1259 UShort_t volID;
1260 Int_t k=0;
1261
1262 TArrayI *volIDsSPD1=new TArrayI(size-8);
1263 TArrayI *volIDsFit2=new TArrayI(size2+8);
1264
1265 for(Int_t j=0;j<size;j++){
1266 volID=volIDs->At(j);
1267 if(AliGeomManager::VolUIDToLayer(volID)==AliGeomManager::kSPD1){
1268 volIDsSPD1->AddAt(volID,size2+k);
1269 k++;
1270 }
1271 else volIDsFit2->AddAt(volID,j-k);
1272 }
1273
1274
1275 for(Int_t j=0;j<size2;j++){
1276 volID=volIDsFit->At(j);
1277 volIDsFit2->AddAt(volID,size-k+j);
1278 }
1279
1280 printf("Aligning SPD Sector %d: nmodules: %d \n",sector,volIDsSPD1->GetSize());
1281 printf("Fitting modules: %d \n",volIDsFit2->GetSize());
1282
1283 AlignVolumesITS(volIDsSPD1,volIDsFit2,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1284
1285 return kTRUE;
1286}
1287
1288//_____________________________________________
1289
1290AliAlignObjParams* AliITSRealignTracks::MediateAlignObj(TArrayI *volIDs,Int_t lastVolid){
1291 UShort_t volid;
1292
1293 TGeoHMatrix hm;
1294 Double_t *rot,*transl;
1295 Double_t rotSum[9],translSum[3]={0.,0.,0.};
1296 for(Int_t k=0;k<8;k++)rotSum[k]=0.;
1297
1298
1299 for(Int_t ivol=0;ivol<lastVolid;ivol++){
1300 volid=volIDs->At(ivol);
1301
1302 GetAlignObj(volIDs->At(ivol))->GetMatrix(hm);
1303
1304 rot=hm.GetRotationMatrix();
1305 transl=hm.GetTranslation();
1306
1307 for(Int_t j=0;j<9;j++)rotSum[j]+=rot[j];
1308 for(Int_t jt=0;jt<3;jt++)translSum[jt]+=transl[jt];
1309 }
1310 if(lastVolid!=0){
1311 for(Int_t j=0;j<9;j++)rotSum[j]=rotSum[j]/lastVolid;
1312 for(Int_t jt=0;jt<3;jt++)translSum[jt]=translSum[jt]/lastVolid;
1313 }
1314 else printf("Try to mediate results for zero modules \n");
1315
1316 hm.SetRotation(rotSum);
1317 hm.SetTranslation(translSum);
1318
1319
1320
1321 AliAlignObjParams *alignObj=new AliAlignObjParams("average", 0,hm, kTRUE);
1322 return alignObj;
1323
1324}
1325
1326//________________________________________________
1327TArrayI* AliITSRealignTracks::GetSPDSectorsVolids(Int_t *sectors)
1328{
1329 //
1330 // This method gets the volID Array for the chosen sectors.
1331 // You have to pass an array with a 1 for each selected sector.
1332 // i.e. sectors[10] = {1,1,0,0,0,0,0,0,1,0} -> Sector 0, 1, 9 selected.
1333 //
1334
1335 Int_t nSect=0;
1336 Int_t iModule=0;
1337
1338
1339 for(Int_t co=0;co<10;co++){ //counts the number of sectors chosen
1340 if(sectors[co]==1) nSect++;
1341 }
1342
1343 if(nSect<1){ //if no sector chosen -> exit
1344 Printf("Error! No Sector/s Selected!");
1345 return 0x0;
1346 }
1347
1348 TArrayI *volIDs = new TArrayI(nSect*24);
1349
1350 if(sectors[0]==1){ //--->cSect = 0 <---
1351 volIDs->AddAt(2048,iModule); iModule++;
1352 volIDs->AddAt(2049,iModule); iModule++;
1353 volIDs->AddAt(2050,iModule); iModule++;
1354 volIDs->AddAt(2051,iModule); iModule++;
1355 volIDs->AddAt(2052,iModule); iModule++;
1356 volIDs->AddAt(2053,iModule); iModule++;
1357 volIDs->AddAt(2054,iModule); iModule++;
1358 volIDs->AddAt(2055,iModule); iModule++;
1359 volIDs->AddAt(4096,iModule); iModule++;
1360 volIDs->AddAt(4097,iModule); iModule++;
1361 volIDs->AddAt(4098,iModule); iModule++;
1362 volIDs->AddAt(4099,iModule); iModule++;
1363 volIDs->AddAt(4100,iModule); iModule++;
1364 volIDs->AddAt(4101,iModule); iModule++;
1365 volIDs->AddAt(4102,iModule); iModule++;
1366 volIDs->AddAt(4103,iModule); iModule++;
1367 volIDs->AddAt(4104,iModule); iModule++;
1368 volIDs->AddAt(4105,iModule); iModule++;
1369 volIDs->AddAt(4106,iModule); iModule++;
1370 volIDs->AddAt(4107,iModule); iModule++;
1371 volIDs->AddAt(4108,iModule); iModule++;
1372 volIDs->AddAt(4109,iModule); iModule++;
1373 volIDs->AddAt(4110,iModule); iModule++;
1374 volIDs->AddAt(4111,iModule); iModule++;
1375 }
1376 if(sectors[1]==1){ //--->cSect = 1 <//---
1377 volIDs->AddAt(2056,iModule); iModule++;
1378 volIDs->AddAt(2057,iModule); iModule++;
1379 volIDs->AddAt(2058,iModule); iModule++;
1380 volIDs->AddAt(2059,iModule); iModule++;
1381 volIDs->AddAt(2060,iModule); iModule++;
1382 volIDs->AddAt(2061,iModule); iModule++;
1383 volIDs->AddAt(2062,iModule); iModule++;
1384 volIDs->AddAt(2063,iModule); iModule++;
1385 volIDs->AddAt(4112,iModule); iModule++;
1386 volIDs->AddAt(4113,iModule); iModule++;
1387 volIDs->AddAt(4114,iModule); iModule++;
1388 volIDs->AddAt(4115,iModule); iModule++;
1389 volIDs->AddAt(4116,iModule); iModule++;
1390 volIDs->AddAt(4117,iModule); iModule++;
1391 volIDs->AddAt(4118,iModule); iModule++;
1392 volIDs->AddAt(4119,iModule); iModule++;
1393 volIDs->AddAt(4120,iModule); iModule++;
1394 volIDs->AddAt(4121,iModule); iModule++;
1395 volIDs->AddAt(4122,iModule); iModule++;
1396 volIDs->AddAt(4123,iModule); iModule++;
1397 volIDs->AddAt(4124,iModule); iModule++;
1398 volIDs->AddAt(4125,iModule); iModule++;
1399 volIDs->AddAt(4126,iModule); iModule++;
1400 volIDs->AddAt(4127,iModule); iModule++;
1401 }
1402 if(sectors[2]==1){//--->cSect = 2 <//---
1403 volIDs->AddAt(2064,iModule); iModule++;
1404 volIDs->AddAt(2065,iModule); iModule++;
1405 volIDs->AddAt(2066,iModule); iModule++;
1406 volIDs->AddAt(2067,iModule); iModule++;
1407 volIDs->AddAt(2068,iModule); iModule++;
1408 volIDs->AddAt(2069,iModule); iModule++;
1409 volIDs->AddAt(2070,iModule); iModule++;
1410 volIDs->AddAt(2071,iModule); iModule++;
1411 volIDs->AddAt(4128,iModule); iModule++;
1412 volIDs->AddAt(4129,iModule); iModule++;
1413 volIDs->AddAt(4130,iModule); iModule++;
1414 volIDs->AddAt(4131,iModule); iModule++;
1415 volIDs->AddAt(4132,iModule); iModule++;
1416 volIDs->AddAt(4133,iModule); iModule++;
1417 volIDs->AddAt(4134,iModule); iModule++;
1418 volIDs->AddAt(4135,iModule); iModule++;
1419 volIDs->AddAt(4136,iModule); iModule++;
1420 volIDs->AddAt(4137,iModule); iModule++;
1421 volIDs->AddAt(4138,iModule); iModule++;
1422 volIDs->AddAt(4139,iModule); iModule++;
1423 volIDs->AddAt(4140,iModule); iModule++;
1424 volIDs->AddAt(4141,iModule); iModule++;
1425 volIDs->AddAt(4142,iModule); iModule++;
1426 volIDs->AddAt(4143,iModule); iModule++;
1427 }
1428 if(sectors[3]==1){//--->cSect = 3 <//---
1429 volIDs->AddAt(2072,iModule); iModule++;
1430 volIDs->AddAt(2073,iModule); iModule++;
1431 volIDs->AddAt(2074,iModule); iModule++;
1432 volIDs->AddAt(2075,iModule); iModule++;
1433 volIDs->AddAt(2076,iModule); iModule++;
1434 volIDs->AddAt(2077,iModule); iModule++;
1435 volIDs->AddAt(2078,iModule); iModule++;
1436 volIDs->AddAt(2079,iModule); iModule++;
1437 volIDs->AddAt(4144,iModule); iModule++;
1438 volIDs->AddAt(4145,iModule); iModule++;
1439 volIDs->AddAt(4146,iModule); iModule++;
1440 volIDs->AddAt(4147,iModule); iModule++;
1441 volIDs->AddAt(4148,iModule); iModule++;
1442 volIDs->AddAt(4149,iModule); iModule++;
1443 volIDs->AddAt(4150,iModule); iModule++;
1444 volIDs->AddAt(4151,iModule); iModule++;
1445 volIDs->AddAt(4152,iModule); iModule++;
1446 volIDs->AddAt(4153,iModule); iModule++;
1447 volIDs->AddAt(4154,iModule); iModule++;
1448 volIDs->AddAt(4155,iModule); iModule++;
1449 volIDs->AddAt(4156,iModule); iModule++;
1450 volIDs->AddAt(4157,iModule); iModule++;
1451 volIDs->AddAt(4158,iModule); iModule++;
1452 volIDs->AddAt(4159,iModule); iModule++;
1453 }
1454 if(sectors[4]==1){//--->cSect = 4 <//---
1455 volIDs->AddAt(2080,iModule); iModule++;
1456 volIDs->AddAt(2081,iModule); iModule++;
1457 volIDs->AddAt(2082,iModule); iModule++;
1458 volIDs->AddAt(2083,iModule); iModule++;
1459 volIDs->AddAt(2084,iModule); iModule++;
1460 volIDs->AddAt(2085,iModule); iModule++;
1461 volIDs->AddAt(2086,iModule); iModule++;
1462 volIDs->AddAt(2087,iModule); iModule++;
1463 volIDs->AddAt(4160,iModule); iModule++;
1464 volIDs->AddAt(4161,iModule); iModule++;
1465 volIDs->AddAt(4162,iModule); iModule++;
1466 volIDs->AddAt(4163,iModule); iModule++;
1467 volIDs->AddAt(4164,iModule); iModule++;
1468 volIDs->AddAt(4165,iModule); iModule++;
1469 volIDs->AddAt(4166,iModule); iModule++;
1470 volIDs->AddAt(4167,iModule); iModule++;
1471 volIDs->AddAt(4168,iModule); iModule++;
1472 volIDs->AddAt(4169,iModule); iModule++;
1473 volIDs->AddAt(4170,iModule); iModule++;
1474 volIDs->AddAt(4171,iModule); iModule++;
1475 volIDs->AddAt(4172,iModule); iModule++;
1476 volIDs->AddAt(4173,iModule); iModule++;
1477 volIDs->AddAt(4174,iModule); iModule++;
1478 volIDs->AddAt(4175,iModule); iModule++;
1479 }
1480 if(sectors[5]==1){//--->cSect = 5 <//---
1481 volIDs->AddAt(2088,iModule); iModule++;
1482 volIDs->AddAt(2089,iModule); iModule++;
1483 volIDs->AddAt(2090,iModule); iModule++;
1484 volIDs->AddAt(2091,iModule); iModule++;
1485 volIDs->AddAt(2092,iModule); iModule++;
1486 volIDs->AddAt(2093,iModule); iModule++;
1487 volIDs->AddAt(2094,iModule); iModule++;
1488 volIDs->AddAt(2095,iModule); iModule++;
1489 volIDs->AddAt(4176,iModule); iModule++;
1490 volIDs->AddAt(4177,iModule); iModule++;
1491 volIDs->AddAt(4178,iModule); iModule++;
1492 volIDs->AddAt(4179,iModule); iModule++;
1493 volIDs->AddAt(4180,iModule); iModule++;
1494 volIDs->AddAt(4181,iModule); iModule++;
1495 volIDs->AddAt(4182,iModule); iModule++;
1496 volIDs->AddAt(4183,iModule); iModule++;
1497 volIDs->AddAt(4184,iModule); iModule++;
1498 volIDs->AddAt(4185,iModule); iModule++;
1499 volIDs->AddAt(4186,iModule); iModule++;
1500 volIDs->AddAt(4187,iModule); iModule++;
1501 volIDs->AddAt(4188,iModule); iModule++;
1502 volIDs->AddAt(4189,iModule); iModule++;
1503 volIDs->AddAt(4190,iModule); iModule++;
1504 volIDs->AddAt(4191,iModule); iModule++;
1505 }
1506 if(sectors[6]==1){//--->cSect = 6 <//---
1507 volIDs->AddAt(2096,iModule); iModule++;
1508 volIDs->AddAt(2097,iModule); iModule++;
1509 volIDs->AddAt(2098,iModule); iModule++;
1510 volIDs->AddAt(2099,iModule); iModule++;
1511 volIDs->AddAt(2100,iModule); iModule++;
1512 volIDs->AddAt(2101,iModule); iModule++;
1513 volIDs->AddAt(2102,iModule); iModule++;
1514 volIDs->AddAt(2103,iModule); iModule++;
1515 volIDs->AddAt(4192,iModule); iModule++;
1516 volIDs->AddAt(4193,iModule); iModule++;
1517 volIDs->AddAt(4194,iModule); iModule++;
1518 volIDs->AddAt(4195,iModule); iModule++;
1519 volIDs->AddAt(4196,iModule); iModule++;
1520 volIDs->AddAt(4197,iModule); iModule++;
1521 volIDs->AddAt(4198,iModule); iModule++;
1522 volIDs->AddAt(4199,iModule); iModule++;
1523 volIDs->AddAt(4200,iModule); iModule++;
1524 volIDs->AddAt(4201,iModule); iModule++;
1525 volIDs->AddAt(4202,iModule); iModule++;
1526 volIDs->AddAt(4203,iModule); iModule++;
1527 volIDs->AddAt(4204,iModule); iModule++;
1528 volIDs->AddAt(4205,iModule); iModule++;
1529 volIDs->AddAt(4206,iModule); iModule++;
1530 volIDs->AddAt(4207,iModule); iModule++;
1531 }
1532 if(sectors[7]==1){ //--->cSect = 7 <//---
1533 volIDs->AddAt(2104,iModule); iModule++;
1534 volIDs->AddAt(2105,iModule); iModule++;
1535 volIDs->AddAt(2106,iModule); iModule++;
1536 volIDs->AddAt(2107,iModule); iModule++;
1537 volIDs->AddAt(2108,iModule); iModule++;
1538 volIDs->AddAt(2109,iModule); iModule++;
1539 volIDs->AddAt(2110,iModule); iModule++;
1540 volIDs->AddAt(2111,iModule); iModule++;
1541 volIDs->AddAt(4208,iModule); iModule++;
1542 volIDs->AddAt(4209,iModule); iModule++;
1543 volIDs->AddAt(4210,iModule); iModule++;
1544 volIDs->AddAt(4211,iModule); iModule++;
1545 volIDs->AddAt(4212,iModule); iModule++;
1546 volIDs->AddAt(4213,iModule); iModule++;
1547 volIDs->AddAt(4214,iModule); iModule++;
1548 volIDs->AddAt(4215,iModule); iModule++;
1549 volIDs->AddAt(4216,iModule); iModule++;
1550 volIDs->AddAt(4217,iModule); iModule++;
1551 volIDs->AddAt(4218,iModule); iModule++;
1552 volIDs->AddAt(4219,iModule); iModule++;
1553 volIDs->AddAt(4220,iModule); iModule++;
1554 volIDs->AddAt(4221,iModule); iModule++;
1555 volIDs->AddAt(4222,iModule); iModule++;
1556 volIDs->AddAt(4223,iModule); iModule++;
1557 }
1558 if(sectors[8]==1){//--->cSect = 8 <//---
1559 volIDs->AddAt(2112,iModule); iModule++;
1560 volIDs->AddAt(2113,iModule); iModule++;
1561 volIDs->AddAt(2114,iModule); iModule++;
1562 volIDs->AddAt(2115,iModule); iModule++;
1563 volIDs->AddAt(2116,iModule); iModule++;
1564 volIDs->AddAt(2117,iModule); iModule++;
1565 volIDs->AddAt(2118,iModule); iModule++;
1566 volIDs->AddAt(2119,iModule); iModule++;
1567 volIDs->AddAt(4224,iModule); iModule++;
1568 volIDs->AddAt(4225,iModule); iModule++;
1569 volIDs->AddAt(4226,iModule); iModule++;
1570 volIDs->AddAt(4227,iModule); iModule++;
1571 volIDs->AddAt(4228,iModule); iModule++;
1572 volIDs->AddAt(4229,iModule); iModule++;
1573 volIDs->AddAt(4230,iModule); iModule++;
1574 volIDs->AddAt(4231,iModule); iModule++;
1575 volIDs->AddAt(4232,iModule); iModule++;
1576 volIDs->AddAt(4233,iModule); iModule++;
1577 volIDs->AddAt(4234,iModule); iModule++;
1578 volIDs->AddAt(4235,iModule); iModule++;
1579 volIDs->AddAt(4236,iModule); iModule++;
1580 volIDs->AddAt(4237,iModule); iModule++;
1581 volIDs->AddAt(4238,iModule); iModule++;
1582 volIDs->AddAt(4239,iModule); iModule++;
1583 }
1584 if(sectors[9]==1){//--->cSect = 9 <//---
1585 volIDs->AddAt(2120,iModule); iModule++;
1586 volIDs->AddAt(2121,iModule); iModule++;
1587 volIDs->AddAt(2122,iModule); iModule++;
1588 volIDs->AddAt(2123,iModule); iModule++;
1589 volIDs->AddAt(2124,iModule); iModule++;
1590 volIDs->AddAt(2125,iModule); iModule++;
1591 volIDs->AddAt(2126,iModule); iModule++;
1592 volIDs->AddAt(2127,iModule); iModule++;
1593 volIDs->AddAt(4240,iModule); iModule++;
1594 volIDs->AddAt(4241,iModule); iModule++;
1595 volIDs->AddAt(4242,iModule); iModule++;
1596 volIDs->AddAt(4243,iModule); iModule++;
1597 volIDs->AddAt(4244,iModule); iModule++;
1598 volIDs->AddAt(4245,iModule); iModule++;
1599 volIDs->AddAt(4246,iModule); iModule++;
1600 volIDs->AddAt(4247,iModule); iModule++;
1601 volIDs->AddAt(4248,iModule); iModule++;
1602 volIDs->AddAt(4249,iModule); iModule++;
1603 volIDs->AddAt(4250,iModule); iModule++;
1604 volIDs->AddAt(4251,iModule); iModule++;
1605 volIDs->AddAt(4252,iModule); iModule++;
1606 volIDs->AddAt(4253,iModule); iModule++;
1607 volIDs->AddAt(4254,iModule); iModule++;
1608 volIDs->AddAt(4255,iModule); iModule++;
1609 }
1610
1611 return volIDs;
1612}
1613
1614//___________________________________
1615TArrayI* AliITSRealignTracks::GetLayersVolUID(Int_t *layer){
1616
1617 TArrayI *out=new TArrayI(2198);
1618 Int_t last=0;
1619 UShort_t voluid;
1620 for(Int_t i=0;i<6;i++){
1621 if(layer[i]==1){
1622 for(Int_t mod=0;mod<AliGeomManager::LayerSize(i+AliGeomManager::kFirstLayer);mod++){
1623 voluid=AliGeomManager::LayerToVolUID(i+AliGeomManager::kFirstLayer,mod);
1624 out->AddAt(voluid,last);
1625 // printf("voluid %d at position %d \n",out->At(last),last);
1626 last++;
1627 }
1628 }
1629 }
1630 out->Set(last);
1631 return out;
1632}
1633
1634//_________________
1635TArrayI* AliITSRealignTracks::SelectLayerInVolids(const TArrayI *volidsIN,AliGeomManager::ELayerID layer){
1636
1637 Int_t size=volidsIN->GetSize();
1638 Int_t count=0;
1639 for(Int_t j=0;j<size;j++){
1640 if(AliGeomManager::VolUIDToLayer(volidsIN->At(j))==layer)count++;
1641 }
1642 TArrayI *volidsOUT=new TArrayI(count);
1643 count=0;
1644 for(Int_t j=0;j<size;j++){
1645 if(AliGeomManager::VolUIDToLayer(volidsIN->At(j))==layer){
1646 volidsOUT->AddAt(volidsIN->At(j),count);
1647 count++;
1648 }
1649 }
1650 return volidsOUT;
1651}
1652
1653//______________________________________________
1654
1655TArrayI* AliITSRealignTracks::IntersectVolArray(const TArrayI *vol1,const TArrayI *vol2){
1656
1657 Int_t size1=vol1->GetSize();
1658 Int_t size2=vol2->GetSize();
1659 Int_t last=0,volid;
1660 Bool_t found;
1661 TArrayI *volidOut=new TArrayI(size1+size2);
1662
1663 for(Int_t k=0;k<size1;k++){
1664 found=kFALSE;
1665 volid=vol1->At(k);
1666 for(Int_t j=0;j<size2;j++){
1667 if(vol2->At(j)==volid)found=kTRUE;
1668 }
1669 if(found){
1670 volidOut->AddAt(volid,last);
1671 last++;
1672 }
1673 }
1674 volidOut->Set(last);
1675 return volidOut;
1676}
1677//_________________________________________
1678
1679TArrayI* AliITSRealignTracks::JoinVolArrays(const TArrayI *vol1,const TArrayI *vol2){
1680 //!BE CAREFUL: If an index is repeated in vol1 or vol2 will be repeated also in the final array
1681
1682 Int_t size1=vol1->GetSize();
1683 Int_t size2=vol2->GetSize();
1684 Int_t count=0;
1685 UShort_t volid;
1686 Bool_t found;
1687 TArrayI *volidOut=new TArrayI(size1+size2);
1688
1689 for(Int_t k=0;k<size1;k++){
1690 volid=vol1->At(k);
1691 volidOut->AddAt(volid,k);
1692 }
1693
1694 for(Int_t k=0;k<size1;k++){
1695 found=kFALSE;
1696 volid=vol1->At(k);
1697 for(Int_t j=0;j<size2;j++){
1698 if(vol2->At(j)==volid)found=kTRUE;
1699 }
1700 if(!found){
1701 volidOut->AddAt(volid,size1+count);
1702 count++;
1703 }
1704 }
1705 volidOut->Set(size1+count);
1706 return volidOut;
1707}
1708
1709//______________________________________
1710
1711TArrayI* AliITSRealignTracks::ExcludeVolidsFromVolidsArray(const TArrayI *volidsToExclude,const TArrayI *volStart){
1712
1713 Int_t size1=volidsToExclude->GetSize();
1714 Int_t size2=volStart->GetSize();
1715 Int_t last=0;
1716 UShort_t volid;
1717 Bool_t found;
1718 TArrayI *volidOut=new TArrayI(size2);
1719
1720 for(Int_t k=0;k<size2;k++){
1721 found=kFALSE;
1722 volid=volStart->At(k);
1723 for(Int_t j=0;j<size1;j++){
1724 if(volidsToExclude->At(j)==volid){
1725 found=kTRUE;
1726 break;
1727 }
1728 }
1729 if(!found){
1730 volidOut->AddAt(volid,last);
1731 last++;
1732 }
1733 }
1734 volidOut->Set(last);
1735 return volidOut;
1736}
1737
1738
1739//________________________________________
1740
1741TArrayI* AliITSRealignTracks::GetLayerVolumes(Int_t *layer){
1742
1743 TArrayI *out=new TArrayI(2198);
1744 Int_t last=0;
1745 UShort_t voluid;
1746 for(Int_t i=0;i<6;i++){
1747 if(layer[i]==1){
1748 for(Int_t mod=0;mod<AliGeomManager::LayerSize(i+AliGeomManager::kFirstLayer);mod++){
1749 voluid=AliGeomManager::LayerToVolUID(i+AliGeomManager::kFirstLayer,mod);
1750 out->AddAt(voluid,last);
1751 // printf("voluid %d at position %d \n",out->At(last),last);
1752 last++;
1753 }
1754 }
1755 }
1756 out->Set(last);
1757 return out;
1758}