Line data Source code
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 : //Class to perform the realignment if the Inner Tracking System
18 : //with an iterative approach based on track to cluster residuals
19 : // minimization. A chi2 function of the residuals is minimized with
20 : //respect to alignment parameters. The class allows both single module
21 : //realignment and set of modules realignment. Tracks are fitted with
22 : //AliTrackFitter* fitters. AliTrackFitterKalman is more suited for
23 : //straight line (e.g. cosmic in the absence of magnetic field) but can't
24 : //work with helixes. AliTrackFitterRieman is suited for helixes.
25 : //The minimization is performed by AliTrackResiduals* classes: default
26 : //one is AliTrackResidualsFast (analytic minimization by inversion).
27 : //For numerical minimization using MINUIT, use AliTrackResidualChi2.
28 : //Methods are present to defined both the set of modules where the tracks
29 : //are fittef and the set of modules which are to be realigned
30 : //The main method is AlignVolumesITS
31 : //
32 : //Class by: A. Rossi, andrea,rossi@ts.infn.it
33 :
34 : #include <TFile.h>
35 : #include <TStopwatch.h>
36 : #include <TNtuple.h>
37 : #include <TClonesArray.h>
38 : #include <TMath.h>
39 : #include <TGraph.h>
40 : #include <TCanvas.h>
41 : #include <TH1F.h>
42 : #include "AliITSRealignTracks.h"
43 : #include "AliAlignObjParams.h"
44 : #include "AliAlignObj.h"
45 : #include "AliGeomManager.h"
46 : #include "AliTrackFitter.h"
47 : #include "AliTrackFitterKalman.h"
48 : #include "AliTrackFitterRieman.h"
49 : #include "AliTrackResidualsFast.h"
50 : #include "AliTrackResidualsChi2.h"
51 : #include "AliTrackResidualsLinear.h"
52 :
53 : #include "AliLog.h"
54 : #include <TSystem.h>
55 : #include <TGeoManager.h>
56 :
57 : class AliAlignmentTracks;
58 : class TGeoMatrix;
59 : class TArray;
60 :
61 :
62 : /* $Id$ */
63 :
64 :
65 116 : ClassImp(AliITSRealignTracks)
66 :
67 : const Int_t kreferSect=2;
68 :
69 :
70 : AliITSRealignTracks::AliITSRealignTracks(TString minimizer,Int_t fit,Bool_t covUsed,TString fileintro,TString geometryfile,TString misalignmentFile,TString startingfile):
71 0 : AliAlignmentTracks(),
72 0 : fSurveyObjs(0),
73 0 : fgeomfilename(),
74 0 : fmintracks(),
75 0 : fUpdateCov(kFALSE),
76 0 : fVarySigmaY(kFALSE),
77 0 : fCorrModules(0),
78 0 : fLimitCorr(0),
79 0 : fsigmaY(),
80 0 : fDraw(kFALSE),
81 0 : fAlignDrawObjs(0),
82 0 : fCanvPar(0),
83 0 : fCanvGr(0),
84 0 : fgrIterMeanX(0),
85 0 : fgrIterRMSX(0),
86 0 : fgrIterMeanY(0),
87 0 : fgrIterRMSY(0),
88 0 : fgrIterMeanZ(0),
89 0 : fgrIterRMSZ(0),
90 0 : fgrIterMeanPsi(0),
91 0 : fgrIterRMSPsi(0),
92 0 : fgrIterMeanTheta(0),
93 0 : fgrIterRMSTheta(0),
94 0 : fgrIterMeanPhi(0),
95 0 : fgrIterRMSPhi(0)
96 0 : {
97 :
98 : // minimizer="fast"->AliTrackResidualFast minimizer
99 : // "minuit"->AliTrackResidualChi2 minimizer
100 : // "minuitnorot"->AliTrackResidualChi2 minimizer without rotations degrees of freedom
101 : // "linear"->AliTrackResidualLinear minimizer
102 : //fit=0-> Riemann Fitter, fit=1->Kalman
103 : //fileintro=file into which the Tree with the space points is stored
104 : //geometryfile=file containing the geometry
105 :
106 :
107 0 : SetPointsFilename(fileintro.Data());
108 0 : SetGeomFilename(geometryfile);
109 0 : InitAlignObjs();
110 0 : if(!InitSurveyObjs(kFALSE))AliWarning("Unable to set Survey AlignObjs!");
111 :
112 0 : if(startingfile=="")printf("Starting from default geometry \n");
113 0 : else ReadAlignObjs(startingfile.Data(),"ITSAlignObjs");
114 :
115 0 : if(misalignmentFile=="")printf("NO FAKE MISALIGNMENT INTRODUCED \n");
116 : else {
117 0 : Bool_t misal=Misalign(misalignmentFile,"ITSAlignObjs");
118 0 : if(!misal)AliWarning("Incorrect fake misalignment filename!");;
119 : }
120 :
121 0 : if(!gGeoManager) AliGeomManager::LoadGeometry(fgeomfilename.Data());
122 0 : if(covUsed)SetCovIsUsed(kTRUE);
123 0 : if(!SelectFitter(fit))AliWarning("Incorrect fitter assignment!");
124 0 : if(!SelectMinimizer(minimizer))AliWarning("Incorrect minimizer assignment!");
125 0 : fsigmaY=1.;
126 0 : fmintracks=1;
127 0 : BuildIndex();
128 :
129 0 : }
130 :
131 : AliITSRealignTracks::AliITSRealignTracks(const AliITSRealignTracks &realignTracks):
132 0 : AliAlignmentTracks(),
133 0 : fSurveyObjs(new AliAlignObj**(*realignTracks.fSurveyObjs)),
134 0 : fgeomfilename(realignTracks.fgeomfilename),
135 0 : fmintracks(realignTracks.fmintracks),
136 0 : fUpdateCov(realignTracks.fUpdateCov),
137 0 : fVarySigmaY(realignTracks.fVarySigmaY),
138 0 : fCorrModules(new Double_t *(*realignTracks.fCorrModules)),
139 0 : fLimitCorr(realignTracks.fLimitCorr),
140 0 : fsigmaY(realignTracks.fsigmaY),
141 0 : fDraw(kFALSE),
142 0 : fAlignDrawObjs(realignTracks.fAlignDrawObjs),
143 0 : fCanvPar(realignTracks.fCanvPar),
144 0 : fCanvGr(realignTracks.fCanvGr),
145 0 : fgrIterMeanX(realignTracks.fgrIterMeanX),
146 0 : fgrIterRMSX(realignTracks.fgrIterRMSX),
147 0 : fgrIterMeanY(realignTracks.fgrIterMeanY),
148 0 : fgrIterRMSY(realignTracks.fgrIterRMSY),
149 0 : fgrIterMeanZ(realignTracks.fgrIterMeanZ),
150 0 : fgrIterRMSZ(realignTracks.fgrIterRMSZ),
151 0 : fgrIterMeanPsi(realignTracks.fgrIterMeanPsi),
152 0 : fgrIterRMSPsi(realignTracks.fgrIterRMSPsi),
153 0 : fgrIterMeanTheta(realignTracks.fgrIterMeanTheta),
154 0 : fgrIterRMSTheta(realignTracks.fgrIterRMSTheta),
155 0 : fgrIterMeanPhi(realignTracks.fgrIterMeanPhi),
156 0 : fgrIterRMSPhi(realignTracks.fgrIterRMSPhi)
157 :
158 0 : {//Copy Constructor
159 0 : AliWarning("Can't copy AliAlignmentTracks Data member!");
160 0 : }
161 :
162 : AliITSRealignTracks& AliITSRealignTracks::operator=(const AliITSRealignTracks &obj){
163 : ////////////////////////
164 : // Assignment operator
165 : ////////////////////////
166 0 : this->~AliITSRealignTracks();
167 0 : new(this) AliITSRealignTracks(obj);
168 0 : return *this;
169 0 : }
170 :
171 0 : AliITSRealignTracks::~AliITSRealignTracks(){
172 : //destructor
173 :
174 0 : if(fSurveyObjs) DeleteSurveyObjs();
175 0 : if(fAlignDrawObjs) DeleteDrawHists();
176 : //delete [] fSurveyObjs;
177 :
178 0 : }
179 :
180 :
181 : //_____________________________
182 : Bool_t AliITSRealignTracks::SelectFitter(Int_t fit,Int_t minTrackPoint){
183 : //Method to select the fitter: 0 for AliTrackFitterRieman (use this for helixes)
184 : // 1 for AliTrackFitterKalman
185 : //minTrackPoint defines the minimum number of points (not rejected by the fit itself)
186 : //a track should have to fit it
187 :
188 0 : if(fit==1){
189 0 : AliTrackFitterKalman *fitter= new AliTrackFitterKalman();
190 0 : fitter->SetMinNPoints(minTrackPoint);
191 0 : SetTrackFitter(fitter);
192 0 : }
193 :
194 0 : else if(fit==0){
195 0 : AliTrackFitterRieman *fitter=new AliTrackFitterRieman();
196 0 : fitter->SetMinNPoints(minTrackPoint);
197 0 : SetTrackFitter(fitter);
198 : }
199 0 : else return kFALSE;
200 :
201 0 : return kTRUE;
202 0 : }
203 :
204 :
205 : Bool_t AliITSRealignTracks::SelectMinimizer(TString minimizer,Int_t minpoints,const Bool_t *coord){
206 : //Method to select the minimizer: "minuit" for AliTrackFitterChi2 (numerical minimization by MINUIT)
207 : // "fast" for AliTrackResidualsFast
208 : // "linear" for AliTrackResidualsLinear
209 : // "minuitnorot" for AliTrackFitterChi2 by
210 : // coord[6] allows to fix the degrees of freedom in the minimization (e.g. look only for tranlsations,
211 : // or only for rotations). The coord are: dTx,dTy,dTz,dPsi,dTheta,dPhi where "d" stands for
212 : // "differential" and "T" for translation. If coord[i] is set to kTRUE then the i coord is fixed
213 : // When a coordinate is fixed the value returnd for it is 0
214 : // minnpoints fix the minimum number of residuals to perform the minimization: it's not safe
215 : // to align a module with a small number of track passing through it since the results could be
216 : // not reliable. For single modules the number of residuals and the number of tracks passing
217 : // through it and accepted bu the fit procedure coincide. This is not the case for sets of modules,
218 : // since a given track can pass through two or more modules in the set (e.g a cosmic track can give
219 : // two cluster on a layer)
220 :
221 : AliTrackResiduals *res;
222 0 : if(minimizer=="minuit"){
223 0 : res = new AliTrackResidualsChi2();
224 0 : if(coord){
225 0 : for(Int_t j=0;j<6;j++){
226 0 : if(coord[j])res->FixParameter(j);
227 : }
228 0 : }
229 : }
230 0 : else if(minimizer=="minuitnorot"){
231 0 : res = new AliTrackResidualsChi2();
232 0 : res->FixParameter(3);
233 0 : res->FixParameter(4);
234 0 : res->FixParameter(5);
235 0 : }
236 :
237 0 : else if(minimizer=="fast"){
238 0 : res = new AliTrackResidualsFast();
239 0 : if(coord){
240 0 : for(Int_t j=0;j<6;j++){
241 0 : if(coord[j])res->FixParameter(j);
242 : }
243 0 : }
244 : }
245 0 : else if(minimizer=="linear"){
246 0 : res = new AliTrackResidualsLinear();
247 : }
248 :
249 : else {
250 0 : printf("Trying to set a non existing minimizer! \n");
251 0 : return kFALSE;
252 : }
253 :
254 0 : res->SetMinNPoints(minpoints);
255 0 : SetMinimizer(res);
256 :
257 0 : return kTRUE;
258 0 : }
259 :
260 : //____________________________________
261 : void AliITSRealignTracks::SetVarySigmaY(Bool_t varysigmay,Double_t sigmaYfixed){
262 : //SigmaY is the value of the error along the track direction assigned
263 : //to the AliTrackPoint constructed from the extrapolation of the fit of a track
264 : //to the module one is realigning. This error simulate the uncertainty on the
265 : //position of the cluster in space due to the misalingment of the module (i.e.
266 : //you don't the real position and orientation of the plane of the desired extrapolation
267 : //but you rely on the fit and consider the point to lie along the track)
268 :
269 :
270 0 : fVarySigmaY=varysigmay;
271 0 : if(!varysigmay){
272 0 : if(sigmaYfixed>0.)fsigmaY=sigmaYfixed;
273 : else {
274 0 : printf("Negative assignment to sigmaY! set it to default value (1 cm) \n");
275 0 : fsigmaY=1.;
276 : }
277 : }
278 0 : }
279 :
280 : //_______________________________________
281 : void AliITSRealignTracks::RealignITSVolIndependent(Int_t iter1,Int_t iterations,Int_t minNtracks,Int_t layer,Int_t minTrackPoint){
282 :
283 :
284 : //iter1=#iterations inside AliAlignmentTracks::AliAlignVolumesITS method
285 : //iterations=#iterations on the all procedure
286 : //layer=0->all ITS, otherways the usual notation is considered (1=SPD1,2=SPD2,3=SDD1,4=SDD2,5=SSD1,6=SSD2)
287 : //minNtracks=minimun number of tracks passing through a module in order to try to realign the module itsself
288 : // if minNtracks<0, minimun number of tracks is |minNtracks|*minNumPoint[layer]/fact (see the code below): this allows a different
289 : // choice of the number of tracks required on different layers and to vary these numbers once tuned the relative proportions.
290 : //minTrackPoint=minimun number of "good" points required to a track (THE POINT ON THE MODULE THAT IS GOING TO BE REALIGNED
291 : //IS NEVER CONSIDERED->max number can be required is 11 for cosmics tracks) for the track being considered in the minimization
292 :
293 :
294 0 : fTrackFitter->SetMinNPoints(minTrackPoint);
295 0 : TArrayI volIDs2(2200);
296 0 : volIDs2.Reset(0);
297 0 : TArrayI volIDs(1);
298 0 : TString command;
299 0 : TArrayI volIDsFit;
300 :
301 : Int_t iLayer,iLayerToAlign;
302 :
303 0 : Int_t minNumPoint[6]={100,100,100,100,50,50};
304 : Double_t fact=10;
305 : Int_t j=0;
306 :
307 : Int_t size=0;
308 0 : Int_t layerNum,modNum,lastVolid=0;
309 0 : TNtuple *ntVolumeAlign=new TNtuple("ntVolumeAlign","NTuple with volume tried to be realigned","layerNum:modNum:volumeIDnum");
310 :
311 0 : TStopwatch *timer=new TStopwatch();
312 0 : timer->Start();
313 0 : BuildIndex();
314 : j=0;
315 : UShort_t volid;
316 :
317 0 : for(Int_t iter=0;iter<iterations;iter++){
318 :
319 : //Starting Independent Modules Realignment
320 0 : for(iLayerToAlign=(Int_t)AliGeomManager::kSPD1;iLayerToAlign<=(Int_t)AliGeomManager::kSSD2;iLayerToAlign++){
321 0 : if(layer!=0&&iLayerToAlign!=layer)continue;
322 : j=0;
323 : size=0;
324 0 : for(Int_t k=(Int_t)AliGeomManager::kSPD1;k<=(Int_t)AliGeomManager::kSSD2;k++){
325 0 : size+=AliGeomManager::LayerSize(k);
326 0 : printf("size: %d \n",size);
327 : }
328 :
329 0 : for (Int_t iModule=0;iModule<AliGeomManager::LayerSize(iLayerToAlign);iModule++){
330 : j=0;
331 0 : if(minNtracks<0){
332 0 : if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNumPoint[iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer]*(-1*minNtracks/fact))continue; }
333 0 : else if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNtracks)continue;
334 :
335 0 : UShort_t volidAl = AliGeomManager::LayerToVolUID(iLayerToAlign,iModule);
336 :
337 0 : volIDsFit.Reset(0);
338 0 : volIDsFit.Set(size-1);
339 0 : for (iLayer=AliGeomManager::kSPD1;iLayer<AliGeomManager::kTPC1;iLayer++){
340 0 : for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
341 0 : volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
342 0 : if(AliGeomManager::LayerToVolUID(iLayer,iModule2)==volidAl)continue;
343 0 : volIDsFit.AddAt(volid,j);
344 0 : j++;
345 0 : }
346 : }
347 0 : volIDs.AddAt((Int_t)volidAl,0);
348 0 : if(iter==iterations-1){
349 0 : volIDs2.AddAt(volidAl,lastVolid);
350 0 : lastVolid++;
351 0 : }
352 0 : volIDs2.AddAt(volidAl,lastVolid);
353 0 : AlignVolumesITS(&volIDs,&volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iter1);
354 0 : }
355 0 : }
356 :
357 :
358 0 : if((iter+1)%5==0||iter==0||iter==1||iter==2||iter==3||iter==iterations-1){
359 0 : command="RealignObj";
360 0 : command+=(iter+1);
361 0 : command.Append(".root");
362 0 : WriteRealignObjArray(command.Data(),AliGeomManager::kSPD1,AliGeomManager::kSSD2);
363 0 : }
364 : }
365 :
366 :
367 0 : if(j==0){printf("j=0 \n");return;}
368 0 : for(Int_t k=0;k<volIDs2.GetSize();k++){
369 0 : if(volIDs2.At(k)==0)break;
370 0 : layerNum=AliGeomManager::VolUIDToLayer(volIDs2.At(k),modNum);
371 0 : ntVolumeAlign->Fill(layerNum,modNum,volIDs2.At(k));
372 : }
373 0 : printf("End of selecting modules cycle: %d modules selected \n",j);
374 0 : TFile *f=new TFile("RealignVolNt.root","RECREATE");
375 0 : f->cd();
376 0 : ntVolumeAlign->Write();
377 0 : f->Close();
378 :
379 0 : timer->Stop();
380 0 : timer->Print();
381 : return;
382 0 : }
383 :
384 :
385 : void 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)
386 : {
387 :
388 : // minimizer="fast"->AliTrackResidualFast minimizer
389 : // "minuit"->AliTrackResidualChi2 minimizer
390 : // "minuitnorot"->AliTrackResidualChi2 minimizer without rotations degrees of freedom
391 : // "linear"->AliTrackResidualLinear minimizer
392 : //fit=0-> Riemann Fitter, fit=1->Kalman
393 : //iter1=#iterations inside AliAlignmentTracks::AliAlignVolumesITS method
394 : //iterations=#iterations on the all procedure
395 : //layer=0->all ITS, otherways the usual notation is considered (1=SPD1,2=SPD2,3=SDD1,4=SDD2,5=SSD1,6=SSD2)
396 : //minNtracks=minimun number of tracks passing through a module in order to try to realign the module itsself
397 : // if minNtracks<0, minimun number of tracks is |minNtracks|*minNumPoint[layer]/fact (see the code below): this allows a different
398 : // choice of the number of tracks required on different layers and to vary these numbers once tuned the relative proportions.
399 : //minTrackPoint=minimun number of "good" points required to a track (THE POINT ON THE MODULE THAT IS GOING TO BE REALIGNED
400 : // IS NEVER CONSIDERED->max number that can be required is 11 for cosmics tracks) for the track being considered in the minimization
401 : //doGlobal : do global realignment, 0=no, 1= yes, 2=only global
402 :
403 :
404 0 : TArrayI volIDs2(2200);
405 0 : volIDs2.Reset(0);
406 0 : TArrayI volIDs(1);
407 0 : TString command;
408 0 : TArrayI volIDsFit;
409 :
410 : Int_t iLayer,iLayerToAlign;
411 :
412 0 : Int_t minNumPoint[6]={100,100,100,100,50,50};
413 : Double_t fact=10;
414 : Int_t count=0;
415 :
416 : Int_t size=0;
417 0 : Int_t layerNum,modNum,lastVolid=0;
418 0 : TNtuple *ntVolumeAlign=new TNtuple("ntVolumeAlign","NTuple with volume tried to be realigned","layerNum:modNum:volumeIDnum");
419 :
420 :
421 0 : if(!SelectFitter(fit))AliWarning("Incorrect fitter assignment!");
422 0 : if(!SelectMinimizer(minimizer))AliWarning("Incorrect minimizer assignment!");
423 0 : if(misalignmentFile=="")printf("NO FAKE MISALIGNMENT INTRODUCED \n");
424 : else {
425 0 : Bool_t misal=Misalign(misalignmentFile,"ITSAlignObjs");
426 0 : if(!misal)return;
427 0 : }
428 :
429 :
430 0 : TStopwatch *timer=new TStopwatch();
431 0 : timer->Start();
432 0 : BuildIndex();
433 : count=0;
434 : UShort_t volid;
435 :
436 0 : if(startingfile=="")printf("Starting from default geometry \n");
437 : else {
438 0 : printf("Starting from AlignObjs file: %s",startingfile.Data());
439 0 : ReadAlignObjs(startingfile.Data(),"ITSAlignObjs");
440 : }
441 :
442 0 : for(Int_t iter=0;iter<iterations;iter++){
443 0 : if(covUsed)SetCovIsUsed(kTRUE);
444 :
445 :
446 : //START HIERARCHY REALIGNMENT
447 :
448 0 : if(layer==0&&(doGlobal==1||doGlobal==2)){
449 0 : for(Int_t siter=0;siter<5;siter++){
450 0 : fTrackFitter->SetMinNPoints(2);
451 0 : SetCovUpdate(kFALSE);
452 0 : AlignSPDHalfBarrelToSectorRef(kreferSect,3);
453 : // AlignSPDBarrel(1);
454 : // if(siter==0)SetCovUpdate(kFALSE);
455 : // AlignSPDHalfBarrel(0,3);
456 : // SetCovUpdate(kTRUE);
457 0 : AlignSPDHalfBarrelToHalfBarrel(1,3);
458 : // AlignSPDHalfBarrelToSectorRef(kreferSect,3);
459 0 : for(Int_t sector=0;sector<10;sector++){
460 0 : SetMinNtracks(100);
461 0 : if(sector==kreferSect)continue;
462 0 : AlignSPDSectorWithSectors(sector,1);
463 : }
464 :
465 :
466 0 : for(Int_t lay=1;lay<=6;lay++){
467 0 : if(!AlignLayerToSector(lay,kreferSect,3))AlignLayerToSPDHalfBarrel(lay,0,3);
468 : }
469 0 : AlignSPDHalfBarrel(0,3);
470 :
471 0 : Int_t layers[6]={2,2,1,0,0,0};
472 0 : fTrackFitter->SetMinNPoints(4);
473 0 : AlignLayersToLayers(layers,1);
474 :
475 0 : fTrackFitter->SetMinNPoints(6);
476 0 : layers[2]=2;
477 0 : layers[3]=1;//{2,2,2,1,0,0};
478 0 : AlignLayersToLayers(layers,1);
479 :
480 0 : fTrackFitter->SetMinNPoints(6);
481 0 : layers[3]=2;
482 0 : layers[4]=1;//{2,2,2,2,1,0};
483 0 : AlignLayersToLayers(layers,1);
484 :
485 0 : fTrackFitter->SetMinNPoints(6);
486 0 : layers[4]=2;
487 0 : layers[5]=1;//{2,2,2,2,2,1};
488 0 : AlignLayersToLayers(layers,1);
489 :
490 :
491 0 : for(Int_t sector=0;sector<10;sector++){
492 0 : AlignSPDSectorToOuterLayers(sector,1);
493 : }
494 0 : WriteRealignObjArray("AfterGlobal.root",AliGeomManager::kSPD1,AliGeomManager::kSSD2);
495 0 : }
496 0 : }
497 :
498 0 : if(doGlobal==2)return;
499 :
500 0 : if(covUsed)SetCovUpdate(kTRUE);
501 0 : SetMinNtracks(1);
502 :
503 :
504 : // STARTS INDEPENDENT MOULES REALIGNMENT
505 :
506 0 : fTrackFitter->SetMinNPoints(minTrackPoint);
507 0 : for(iLayerToAlign=(Int_t)AliGeomManager::kSPD1;iLayerToAlign<=(Int_t)AliGeomManager::kSSD2;iLayerToAlign++){
508 0 : if(layer!=0&&iLayerToAlign!=layer)continue;
509 : count=0;
510 : size=0;
511 0 : for(Int_t k=(Int_t)AliGeomManager::kSPD1;k<=(Int_t)AliGeomManager::kSSD2;k++){
512 0 : size+=AliGeomManager::LayerSize(k);
513 0 : printf("size: %d \n",size);
514 : }
515 :
516 0 : for (Int_t iModule=0;iModule<AliGeomManager::LayerSize(iLayerToAlign);iModule++){
517 : count=0;
518 0 : if(minNtracks<0){
519 0 : if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNumPoint[iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer]*(-1*minNtracks/fact))continue;
520 : }
521 0 : else if(GetLastIndex(iLayerToAlign-(Int_t)AliGeomManager::kFirstLayer,iModule)<minNtracks)continue;
522 :
523 0 : UShort_t volidAl = AliGeomManager::LayerToVolUID(iLayerToAlign,iModule);
524 :
525 0 : volIDsFit.Reset(0);
526 0 : volIDsFit.Set(size-1);
527 0 : for (iLayer=(Int_t)AliGeomManager::kSPD1;iLayer<(Int_t)AliGeomManager::kTPC1;iLayer++){
528 0 : for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
529 :
530 :
531 0 : volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
532 :
533 0 : if(AliGeomManager::LayerToVolUID(iLayer,iModule2)==volidAl)continue;
534 0 : volIDsFit.AddAt(volid,count);
535 0 : count++;
536 0 : }
537 : }
538 :
539 0 : volIDs.AddAt((Int_t)volidAl,0);
540 0 : if(iter==iterations-1){
541 0 : volIDs2.AddAt(volidAl,lastVolid);
542 0 : lastVolid++;
543 0 : }
544 0 : volIDs2.AddAt(volidAl,lastVolid);
545 0 : AlignVolumesITS(&volIDs,&volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iter1);
546 0 : }
547 0 : }
548 :
549 0 : if((iter+1)%2==0||(iter+1)%5==0||iter==0||iter==1||iter==2||iter==3||iter==iterations-1){
550 0 : command="RealignObj";
551 0 : command+=(iter+1);
552 0 : command.Append(".root");
553 0 : WriteRealignObjArray(command.Data(),AliGeomManager::kSPD1,AliGeomManager::kSSD2);
554 0 : }
555 :
556 : }
557 :
558 0 : if(count==0){printf("count=0 \n");return;}
559 0 : for(Int_t k=0;k<volIDs2.GetSize();k++){
560 0 : if(volIDs2.At(k)==0)break;
561 0 : layerNum=AliGeomManager::VolUIDToLayer(volIDs2.At(k),modNum);
562 0 : ntVolumeAlign->Fill(layerNum,modNum,volIDs2.At(k));
563 : }
564 0 : printf("End of selecting modules cycle: %d modules selected \n",count);
565 0 : TFile *f=new TFile("RealignVolNt.root","RECREATE");
566 0 : f->cd();
567 0 : ntVolumeAlign->Write();
568 0 : f->Close();
569 :
570 0 : timer->Stop();
571 0 : timer->Print();
572 : return;
573 :
574 0 : }
575 :
576 :
577 : //______________________________________________________________________________
578 : void AliITSRealignTracks::InitAlignObjs()
579 : {
580 : // Initialize the alignment objects array
581 0 : TMatrixDSym c(6);
582 0 : Double_t cov[21];
583 0 : for(Int_t i=0;i<21;i++)cov[i]=0.;
584 0 : 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
585 0 : 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)
586 :
587 : Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
588 0 : fAlignObjs = new AliAlignObj**[nLayers];
589 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
590 0 : fAlignObjs[iLayer] = new AliAlignObj*[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
591 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
592 0 : UShort_t volid = AliGeomManager::LayerToVolUID(iLayer+ AliGeomManager::kFirstLayer,iModule);
593 0 : fAlignObjs[iLayer][iModule] = new AliAlignObjParams(AliGeomManager::SymName(volid),volid,0,0,0,0,0,0,kTRUE);
594 0 : fAlignObjs[iLayer][iModule]->SetCorrMatrix(cov);
595 0 : fAlignObjs[iLayer][iModule]->SetUniqueID(0);
596 : }
597 : }
598 0 : }
599 :
600 : //______________________________________________________________________________
601 : void AliITSRealignTracks::ResetCorrModules(){
602 : // Initialize and reset to 0 the array with the information on correlation
603 0 : if(!fCorrModules){
604 : Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
605 0 : fCorrModules = new Double_t*[nLayers];
606 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
607 0 : fCorrModules[iLayer] = new Double_t[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
608 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
609 0 : fCorrModules[iLayer][iModule]=0.;
610 : }
611 : }
612 0 : }
613 : else{
614 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
615 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
616 0 : fCorrModules[iLayer][iModule]=0.;
617 : }
618 : }
619 : }
620 0 : }
621 :
622 : //______________________________________________________________________________
623 : Bool_t AliITSRealignTracks::InitSurveyObjs(Bool_t infinite,Double_t factor,TString filename,TString arrayName){
624 : //Initialize the Survey Objects. There is the possibility to set them equal to external objects
625 : // stored in file filename. Otherwuse they are set equal to 0 and with default values for the variances
626 : //infinite: set the cov matrix to extremly large values, so that the results of a minimization
627 : // are never rejected by the comparison with the survey
628 : //factor: multiplication factor for the variances of the cov. matrix of the survey obj.
629 :
630 0 : if(fSurveyObjs)DeleteSurveyObjs();
631 : Bool_t fromfile=kFALSE;
632 : TFile *surveyObj;
633 : TClonesArray *clnarray;
634 0 : if(!filename.IsNull()){
635 : //Initialize from file
636 0 : if(gSystem->AccessPathName(filename.Data(),kFileExists)){
637 0 : printf("Wrong Survey AlignObjs File Name \n");
638 0 : return kFALSE;
639 : }
640 0 : if(arrayName.IsNull()){
641 0 : printf("Null Survey Object Name! \n");
642 0 : return kFALSE;
643 : }
644 :
645 : fromfile=kTRUE;
646 0 : }
647 :
648 : // Initialize the alignment objects array with default values
649 : Double_t v=1.*factor;
650 0 : if(infinite)v*=100000.;
651 0 : TMatrixDSym c(6);
652 0 : Double_t cov[21];
653 0 : for(Int_t i=0;i<21;i++)cov[i]=0.;
654 0 : 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
655 0 : for(Int_t i=3;i<6;i++)cov[i*(i+1)/2+i]=0.03*0.03*180.*180./3.14/3.14*v;//and 30 mrad (~1.7 degrees)for rotations (global ref. sysytem)
656 :
657 : Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
658 0 : fSurveyObjs = new AliAlignObj**[nLayers];
659 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
660 0 : fSurveyObjs[iLayer] = new AliAlignObj*[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
661 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
662 0 : fSurveyObjs[iLayer][iModule] = 0x0;
663 : }
664 : }
665 :
666 0 : if(fromfile){
667 0 : surveyObj=TFile::Open(filename.Data());
668 0 : if (!surveyObj || !surveyObj->IsOpen()) {
669 0 : AliError(Form("Could not open SurveyObjs file: %s !",filename.Data()));
670 0 : return kFALSE;
671 : }
672 0 : printf("Getting TClonesArray \n");
673 0 : clnarray=(TClonesArray*)surveyObj->Get(arrayName);
674 0 : Int_t size=clnarray->GetSize();
675 : UShort_t volid;
676 0 : for(Int_t ivol=0;ivol<size;ivol++){
677 0 : AliAlignObjParams *a=(AliAlignObjParams*)clnarray->At(ivol);
678 0 : volid=a->GetVolUID();
679 0 : Int_t iModule;
680 0 : AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer(volid,iModule);
681 0 : if(iLayer<=0)continue;
682 0 : if(a->GetUniqueID()==0)continue;
683 0 : printf("Updating survey for volume: %d ,layer: %d module: %d from file\n",volid,iLayer,iModule);
684 0 : fSurveyObjs[iLayer-AliGeomManager::kFirstLayer][iModule] = new AliAlignObjParams(*a);
685 0 : fSurveyObjs[iLayer-AliGeomManager::kFirstLayer][iModule]->SetUniqueID(a->GetUniqueID());
686 0 : fSurveyObjs[iLayer-AliGeomManager::kFirstLayer][iModule]->Print("");
687 0 : }
688 0 : delete clnarray;
689 0 : surveyObj->Close();
690 0 : }
691 :
692 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
693 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
694 0 : UShort_t volid = AliGeomManager::LayerToVolUID(iLayer+ AliGeomManager::kFirstLayer,iModule);
695 0 : if(!fSurveyObjs[iLayer][iModule]){
696 0 : printf("Updating survey for volume: %d ,layer: %d module: %d with default values \n",volid,iLayer,iModule);
697 0 : fSurveyObjs[iLayer][iModule] = new AliAlignObjParams(AliGeomManager::SymName(volid),volid,0,0,0,0,0,0,kTRUE);
698 0 : fSurveyObjs[iLayer][iModule]->SetCorrMatrix(cov);
699 0 : fSurveyObjs[iLayer][iModule]->SetUniqueID(0);
700 : }
701 :
702 : }
703 : }
704 :
705 :
706 0 : return kTRUE;
707 0 : }
708 :
709 :
710 : //______________________________________________________________________________
711 : Int_t AliITSRealignTracks::CheckWithSurvey(Double_t factor,const TArrayI *volids){
712 :
713 : // Check the parameters of the alignment objects in volids (or of all objects if volids is null)
714 : // are into the boundaries set by the cov. matrix of the survey objs
715 : // Returns the number of objects out of boudaries
716 : AliAlignObj *alignObj;
717 : Int_t outofsurv=0;
718 : UShort_t volid;
719 0 : Double_t surveycov[21],transl[3],rot[3],survtransl[3],survrot[3];
720 0 : if(volids==0x0){
721 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
722 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++){
723 0 : volid=AliGeomManager::LayerToVolUIDSafe(iLayer+AliGeomManager::kFirstLayer,iModule);
724 0 : alignObj=GetAlignObj(volid);
725 0 : alignObj->GetPars(transl,rot);
726 0 : fSurveyObjs[iLayer][iModule]->GetCovMatrix(surveycov);
727 0 : fSurveyObjs[iLayer][iModule]->GetPars(survtransl,survrot);
728 0 : if(TMath::Sqrt(TMath::Abs(surveycov[0]))*factor<TMath::Abs(transl[0]-survtransl[0])||TMath::Sqrt(TMath::Abs(surveycov[2]))*factor<TMath::Abs(transl[1]-survtransl[1])||TMath::Sqrt(TMath::Abs(surveycov[5]))*factor<TMath::Abs(transl[2]-survtransl[2])||TMath::Sqrt(TMath::Abs(surveycov[9]))*factor<TMath::Abs(rot[0]-survrot[0])||TMath::Sqrt(TMath::Abs(surveycov[14]))*factor<TMath::Abs(rot[1]-survrot[1])||TMath::Sqrt(TMath::Abs(surveycov[20]))*factor<TMath::Abs(rot[2]-survrot[2])){
729 0 : printf("Results for module %d out of Survey: reinitializing it from survey \n",volid);
730 : // *alignObj = *alignObjSurv;
731 0 : alignObj->SetPars(survtransl[0],survtransl[1],survtransl[2],survrot[0],survrot[1],survrot[2]);
732 0 : alignObj->SetUniqueID(0);
733 0 : if(fUpdateCov)alignObj->SetCorrMatrix(surveycov);
734 0 : outofsurv++;
735 0 : }
736 : }
737 : }
738 0 : }
739 : else{
740 : Int_t iLayer;
741 0 : Int_t iModule;
742 0 : for(Int_t j=0;j<volids->GetSize();j++){
743 0 : volid=volids->At(j);
744 0 : alignObj=GetAlignObj(volid);
745 0 : alignObj->GetPars(transl,rot);
746 0 : iLayer=(Int_t)AliGeomManager::VolUIDToLayerSafe(volid,iModule)-(Int_t)AliGeomManager::kFirstLayer;
747 0 : fSurveyObjs[iLayer][iModule]->GetCovMatrix(surveycov);
748 0 : fSurveyObjs[iLayer][iModule]->GetPars(survtransl,survrot);
749 0 : if(TMath::Sqrt(TMath::Abs(surveycov[0]))*factor<TMath::Abs(transl[0]-survtransl[0])||TMath::Sqrt(TMath::Abs(surveycov[2]))*factor<TMath::Abs(transl[1]-survtransl[1])||TMath::Sqrt(TMath::Abs(surveycov[5]))*factor<TMath::Abs(transl[2]-survtransl[2])||TMath::Sqrt(TMath::Abs(surveycov[9]))*factor<TMath::Abs(rot[0]-survrot[0])||TMath::Sqrt(TMath::Abs(surveycov[14]))*factor<TMath::Abs(rot[1]-survrot[1])||TMath::Sqrt(TMath::Abs(surveycov[20]))*factor<TMath::Abs(rot[2]-survrot[2])){
750 0 : printf("Results for module %d out of Survey: reinitializing it from survey \n",volid);
751 : // *alignObj = *alignObjSurv;
752 0 : alignObj->SetPars(survtransl[0],survtransl[1],survtransl[2],survrot[0],survrot[1],survrot[2]);
753 0 : alignObj->SetUniqueID(0);
754 0 : if(fUpdateCov)alignObj->SetCorrMatrix(surveycov);
755 0 : outofsurv++;
756 0 : }
757 : }
758 0 : }
759 0 : return outofsurv;
760 0 : }
761 :
762 : //___________________________________________________________________
763 :
764 : void AliITSRealignTracks::ResetAlignObjs(Bool_t all,TArrayI *volids)
765 : {
766 : // Reset the alignment objects in volids or all if all=kTRUE
767 0 : if(all){
768 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
769 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++)
770 0 : fAlignObjs[iLayer][iModule]->SetPars(0,0,0,0,0,0);
771 : }
772 0 : }
773 : else{
774 : Int_t layer;
775 0 : Int_t mod;
776 0 : for(Int_t j=0;j<volids->GetSize();j++){
777 0 : layer=(Int_t)AliGeomManager::VolUIDToLayer(volids->At(j),mod)-(Int_t)AliGeomManager::kFirstLayer;
778 0 : fAlignObjs[layer][mod]->SetPars(0,0,0,0,0,0);
779 : }
780 0 : }
781 0 : }
782 :
783 : //______________________________________________-
784 : void AliITSRealignTracks::DeleteSurveyObjs()
785 : {//destructor for the survey objs. array
786 :
787 0 : if(!fSurveyObjs)return;
788 : // Delete the alignment objects array
789 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
790 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++){
791 0 : if (fSurveyObjs[iLayer][iModule]) delete fSurveyObjs[iLayer][iModule];
792 : }
793 :
794 0 : if(fSurveyObjs[iLayer])delete [] fSurveyObjs[iLayer];
795 : }
796 :
797 0 : delete [] fSurveyObjs;
798 0 : fSurveyObjs = 0;
799 0 : }
800 :
801 :
802 : //______________________________________________________________________________
803 : Bool_t AliITSRealignTracks::ReadAlignObjs(const char *alignObjFileName, const char* arrayName){
804 :
805 : // Read alignment object from a file: update the alignobj already present with the one in the file
806 : // To be replaced by a call to CDB
807 :
808 0 : if(gSystem->AccessPathName(alignObjFileName,kFileExists)){
809 0 : printf("Wrong AlignObjs File Name \n");
810 0 : return kFALSE;
811 : }
812 :
813 0 : TFile *fRealign=TFile::Open(alignObjFileName);
814 0 : if (!fRealign || !fRealign->IsOpen()) {
815 0 : AliError(Form("Could not open Align Obj File file %s !",alignObjFileName));
816 0 : return kFALSE;
817 : }
818 0 : printf("Getting TClonesArray \n");
819 0 : TClonesArray *clnarray=(TClonesArray*)fRealign->Get(arrayName);
820 0 : Int_t size=clnarray->GetSize();
821 : UShort_t volid;
822 :
823 0 : for(Int_t ivol=0;ivol<size;ivol++){
824 0 : AliAlignObjParams *a=(AliAlignObjParams*)clnarray->At(ivol);
825 0 : volid=a->GetVolUID();
826 0 : Int_t iModule;
827 0 : AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer(volid,iModule);
828 0 : if(iLayer<AliGeomManager::kFirstLayer||iLayer>AliGeomManager::kSSD2)continue;
829 0 : printf("Updating volume: %d ,layer: %d module: %d \n",volid,iLayer,iModule);
830 0 : *fAlignObjs[iLayer-AliGeomManager::kFirstLayer][iModule] *= *a;
831 0 : }
832 :
833 0 : delete clnarray;
834 0 : fRealign->Close();
835 : return kTRUE;
836 0 : }
837 :
838 : //_________________________________________
839 : Bool_t AliITSRealignTracks::FirstAlignmentLayers(const Bool_t *layers,Int_t minNtracks,Int_t iterations,Bool_t fitall,const TArrayI *volidsSet){
840 :
841 : //Align all modules in the set of layers independently according to a sequence based on the number of tracks passing through a given module
842 :
843 0 : BuildIndex();
844 0 : TString name="DrawFirstAlignment_Layers";
845 : UShort_t voluid;
846 : Int_t **lastIndex;
847 : Int_t laymax = 0;
848 : Int_t modmax = 0;
849 : Int_t maxntr=0,nMod=0,modAligned=0,size=0;
850 0 : for(Int_t i=0;i<6;i++){
851 0 : if(layers[i]==1){
852 0 : size+=AliGeomManager::LayerSize(i+AliGeomManager::kFirstLayer);
853 0 : name+=i+1;
854 : }
855 : }
856 :
857 0 : TArrayI *volFit=new TArrayI(size);
858 0 : TArrayI *volFit2=new TArrayI(size-1);
859 0 : TArrayI *sequence=new TArrayI(size);
860 0 : TArrayI *volIn=new TArrayI(1);
861 :
862 : // Initialize the index arrays
863 : Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
864 0 : lastIndex = new Int_t*[nLayers];
865 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
866 0 : lastIndex[iLayer] = new Int_t[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
867 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
868 0 : lastIndex[iLayer][iModule] = fLastIndex[iLayer][iModule];
869 0 : if(iLayer<=(AliGeomManager::kSSD2-AliGeomManager::kFirstLayer)&&layers[iLayer]==1){
870 0 : volFit->AddAt(AliGeomManager::LayerToVolUID(iLayer+AliGeomManager::kFirstLayer,iModule),maxntr);
871 0 : maxntr++;
872 0 : }
873 : }
874 : }
875 : Int_t found=0;
876 0 : maxntr=minNtracks+1;
877 0 : while (maxntr>minNtracks){
878 : maxntr=minNtracks;
879 0 : for (Int_t iLayer = 0; iLayer <= (AliGeomManager::kSSD2 - AliGeomManager::kFirstLayer); iLayer++) {
880 0 : if(layers[iLayer]==0)continue;
881 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
882 0 : if(lastIndex[iLayer][iModule]>maxntr){
883 : maxntr=lastIndex[iLayer][iModule];
884 : laymax=iLayer;
885 : modmax=iModule;
886 0 : }
887 : }
888 0 : }
889 0 : if(maxntr>minNtracks){
890 0 : voluid=AliGeomManager::LayerToVolUID(laymax+AliGeomManager::kFirstLayer,modmax);
891 0 : sequence->AddAt(voluid,nMod);
892 0 : lastIndex[laymax][modmax]=0;
893 0 : nMod++;
894 0 : }
895 : }
896 :
897 0 : sequence->Set(nMod);
898 :
899 : // Int_t imod;
900 0 : for(Int_t iter=0;iter<iterations;iter++){
901 0 : if(iter>0&&fDraw)UpdateDraw(sequence,iter,iter);
902 : modAligned=0;
903 0 : for(Int_t k=0;k<nMod;k++){
904 : TArrayI *volFit3;
905 0 : voluid=sequence->At(k);
906 : // ilayer=AliGeomManager::VolUIDToLayer(voluid,imod);
907 0 : volIn->AddAt(voluid,0);
908 : found=0;
909 0 : if(!fitall){
910 0 : for(Int_t j=0;j<nMod;j++){
911 0 : if(j==k){
912 : found=1;
913 0 : continue;
914 : }
915 0 : else volFit2->AddAt(sequence->At(j),j-found);
916 : }
917 0 : volFit2->Set(nMod-1);
918 : }
919 : else{
920 0 : for(Int_t j=0;j<volFit->GetSize();j++){
921 0 : if(volFit->At(j)!=volIn->At(0))volFit2->AddAt(volFit->At(j),j-found);
922 : else found=1;
923 : }
924 : }
925 :
926 0 : if(volidsSet){
927 0 : volFit3=IntersectVolArray(volidsSet,volFit2);
928 0 : }
929 0 : else volFit3=new TArrayI(*volFit2);
930 :
931 :
932 0 : if(AlignVolumesITS(volIn,volFit3,AliGeomManager::kSPD1,AliGeomManager::kTPC1,2))modAligned++;
933 0 : delete volFit3;
934 :
935 : }
936 : }
937 0 : Int_t noutofsurv=CheckWithSurvey(2.,sequence);
938 0 : printf("%d modules into the sequence \n %d modules re-aligned \n %d modules moved far away from survey (-> reset) \n",nMod,modAligned,noutofsurv);
939 0 : name.Append("_iter");
940 0 : name+=iterations;
941 0 : name.Append(".root");
942 0 : if(fDraw)WriteHists(name.Data());
943 0 : delete volFit;
944 0 : delete volFit2;
945 0 : delete sequence;
946 0 : for(Int_t m=0;m<nLayers;m++){
947 0 : delete [] lastIndex[m];
948 : }
949 0 : delete [] lastIndex;
950 : return kTRUE;
951 :
952 0 : }
953 :
954 : //__________________________________________
955 : Bool_t AliITSRealignTracks::FirstAlignmentSPD(Int_t minNtracks,Int_t iterations,Bool_t fitall,const TArrayI *volidsSet){
956 :
957 : //OBSOLETE METHOD: perform a stand-alone realignment of the SPD modules
958 : // based on a sequence constructed accordingly to the number of tracks
959 : // passing through each module
960 :
961 0 : BuildIndex();
962 :
963 : UShort_t voluid;
964 : Int_t **lastIndex;
965 : Int_t laymax = 0;
966 : Int_t modmax = 0;
967 : Int_t maxntr=0,nMod=0,modAligned=0;
968 0 : TArrayI *volFit=new TArrayI(AliGeomManager::LayerSize(1)+AliGeomManager::LayerSize(2));
969 0 : TArrayI *volFit2=new TArrayI(AliGeomManager::LayerSize(1)+AliGeomManager::LayerSize(2)-1);
970 0 : TArrayI *sequence=new TArrayI(AliGeomManager::LayerSize(1)+AliGeomManager::LayerSize(2));
971 0 : TArrayI *volIn=new TArrayI(1);
972 :
973 : // Initialize the index arrays
974 : Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
975 0 : lastIndex = new Int_t*[nLayers];
976 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
977 0 : lastIndex[iLayer] = new Int_t[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
978 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
979 0 : lastIndex[iLayer][iModule] = fLastIndex[iLayer][iModule];
980 0 : if(iLayer+AliGeomManager::kFirstLayer<=AliGeomManager::kSPD2){
981 0 : volFit->AddAt(AliGeomManager::LayerToVolUID(iLayer+AliGeomManager::kFirstLayer,iModule),maxntr);
982 0 : maxntr++;
983 0 : }
984 : }
985 : }
986 : Int_t found=0;
987 0 : maxntr=minNtracks+1;
988 0 : while (maxntr>minNtracks){
989 : maxntr=minNtracks;
990 0 : for (Int_t iLayer = 0; iLayer <= (AliGeomManager::kSPD2 - AliGeomManager::kFirstLayer); iLayer++) {
991 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
992 0 : if(lastIndex[iLayer][iModule]>maxntr){
993 : laymax=iLayer;
994 : modmax=iModule;
995 : maxntr=lastIndex[iLayer][iModule];
996 0 : }
997 : }
998 : }
999 0 : if(maxntr>minNtracks){
1000 0 : voluid=AliGeomManager::LayerToVolUID(laymax+AliGeomManager::kFirstLayer,modmax);
1001 0 : sequence->AddAt(voluid,nMod);
1002 0 : lastIndex[laymax][modmax]=0;
1003 0 : nMod++;
1004 0 : volIn->AddAt(voluid,0);
1005 0 : }
1006 : }
1007 0 : sequence->Set(nMod);
1008 :
1009 0 : for(Int_t iter=0;iter<iterations;iter++){
1010 : modAligned=0;
1011 0 : for(Int_t k=0;k<nMod;k++){
1012 : TArrayI *volFit3;
1013 0 : voluid=sequence->At(k);
1014 : // ilayer=AliGeomManager::VolUIDToLayer(voluid,imod);
1015 0 : volIn->AddAt(voluid,0);
1016 : found=0;
1017 0 : if(!fitall){
1018 0 : for(Int_t j=0;j<nMod;j++){
1019 0 : if(j==k){
1020 : found=1;
1021 0 : continue;
1022 : }
1023 0 : else volFit2->AddAt(sequence->At(j),j-found);
1024 0 : }
1025 0 : volFit2->Set(nMod-1);
1026 0 : }
1027 : else{
1028 0 : for(Int_t j=0;j<volFit->GetSize();j++){
1029 0 : if(volFit->At(j)!=volIn->At(0))volFit2->AddAt(volFit->At(j),j-found);
1030 : else found=1;
1031 : }
1032 : }
1033 :
1034 0 : if(volidsSet){
1035 0 : volFit3=IntersectVolArray(volidsSet,volFit2);
1036 0 : }
1037 0 : else volFit3=new TArrayI(*volFit2);
1038 :
1039 :
1040 0 : if(AlignVolumesITS(volIn,volFit3,AliGeomManager::kSPD1,AliGeomManager::kSDD1,2))modAligned++;
1041 0 : delete volFit3;
1042 : // if(volidsSet)delete volFit3;
1043 : }
1044 : }
1045 0 : Int_t noutofsurv=CheckWithSurvey(2.,sequence);
1046 0 : printf("%d modules into the sequence \n %d modules re-aligned \n %d modules moved far away from survey (-> reset) \n",nMod,modAligned,noutofsurv);
1047 0 : delete volFit;
1048 0 : delete volFit2;
1049 0 : delete sequence;
1050 0 : for(Int_t m=0;m<nLayers;m++){
1051 0 : delete [] lastIndex[m];
1052 : }
1053 0 : delete [] lastIndex;
1054 :
1055 0 : return kTRUE;
1056 0 : }
1057 :
1058 :
1059 : //__________________________________
1060 : Bool_t AliITSRealignTracks::SPDmodulesAlignToSSD(Int_t minNtracks,Int_t iterations){
1061 : //Align each SPD module with at least minNtracks passing through it with respect to SSD
1062 : //The selection based on the minimum number of tracks is a fast one:
1063 : // the number considere here doesn't coincide with the tracks effectively used then in the
1064 : // minimization, it's just the total number of tracks in the sample passing through the module
1065 : // The procedure is iterated "iterations" times
1066 0 : Int_t volSSD[6]={0,0,0,0,1,1};
1067 0 : TArrayI *volOuter=GetLayersVolUID(volSSD);
1068 0 : TArrayI *voluid=new TArrayI(1);
1069 0 : for(Int_t iter=0;iter<iterations;iter++){
1070 : //SPD1
1071 0 : for(Int_t imod=0;imod<AliGeomManager::LayerSize(AliGeomManager::kSPD1);imod++){ if(GetLastIndex(AliGeomManager::kSPD1-AliGeomManager::kFirstLayer,imod)<minNtracks){
1072 0 : printf("Not enough tracks for module: lay %d mod %d \n",1,imod );
1073 0 : continue;
1074 : }
1075 0 : voluid->AddAt(AliGeomManager::LayerToVolUID(AliGeomManager::kSPD1,imod),0);
1076 0 : AlignVolumesITS(voluid,volOuter,AliGeomManager::kSSD1,AliGeomManager::kSSD2,2);
1077 0 : }
1078 : //SPD2
1079 0 : for(Int_t imod=0;imod<AliGeomManager::LayerSize(AliGeomManager::kSPD2);imod++){
1080 0 : if(GetLastIndex(AliGeomManager::kSPD2-AliGeomManager::kFirstLayer,imod)<minNtracks){
1081 0 : printf("Not enough tracks for module: lay %d mod %d \n",2,imod );
1082 0 : continue;
1083 : }
1084 0 : voluid->AddAt(AliGeomManager::LayerToVolUID(AliGeomManager::kSPD2,imod),0);
1085 0 : AlignVolumesITS(voluid,volOuter,AliGeomManager::kSSD1,AliGeomManager::kSSD2,2);
1086 0 : }
1087 : }
1088 0 : return kTRUE;
1089 0 : }
1090 :
1091 : //______________________________________________________________________________
1092 : Bool_t AliITSRealignTracks::AlignVolumesITS(const TArrayI *volids, const TArrayI *volidsfit,
1093 : AliGeomManager::ELayerID layerRangeMin,
1094 : AliGeomManager::ELayerID layerRangeMax,
1095 : Int_t iterations){
1096 :
1097 : // Align a set of detector volumes.
1098 : // Tracks are fitted only within
1099 : // the range defined by the user
1100 : // (by layerRangeMin and layerRangeMax)
1101 : // or within the set of volidsfit
1102 : // Repeat the procedure 'iterations' times
1103 :
1104 0 : Int_t nVolIds = volids->GetSize();
1105 0 : if (nVolIds == 0) {
1106 0 : AliError("Volume IDs array is empty!");
1107 0 : return kFALSE;
1108 : }
1109 : Bool_t correlated=kFALSE;
1110 0 : Double_t surveycov[21],transl[3],rot[3],survtransl[3],survrot[3];
1111 : Double_t frac;
1112 :
1113 0 : TGeoHMatrix hM;
1114 0 : Double_t smearing,rotorig[9],normplanevect[3]={0.,0.,0.},normplanevect2[3]={0.,0.,0.};
1115 : Double_t *deltarot;
1116 0 : TMatrixDSym covmatrx(6);
1117 : AliAlignObj *modAlign;
1118 :
1119 : // Load only the tracks with at least one
1120 : // space point in the set of volume (volids)
1121 0 : BuildIndex();
1122 0 : AliTrackPointArray **points;
1123 : Bool_t failed=kFALSE;
1124 0 : Int_t pointsdim=0,skipped=0;
1125 : // Start the iterations
1126 0 : while (iterations > 0){
1127 0 : normplanevect2[0]=0.;
1128 0 : normplanevect2[1]=0.;
1129 0 : normplanevect2[2]=0.;
1130 0 : if(fLimitCorr>0.){
1131 0 : ResetCorrModules();
1132 : skipped=0;
1133 0 : }
1134 0 : Int_t nArrays = LoadPoints(volids, points,pointsdim);
1135 :
1136 0 : if (nArrays < fmintracks||nArrays<=0){
1137 : failed=kTRUE;
1138 0 : printf("Not enough tracks to try minimization: volUID %d and following in volids \n", volids->At(0));
1139 0 : UnloadPoints(pointsdim, points);
1140 0 : break;
1141 : }
1142 0 : frac=1./(Double_t)nArrays;
1143 0 : AliTrackResiduals *minimizer = CreateMinimizer();
1144 0 : minimizer->SetNTracks(nArrays);
1145 0 : minimizer->InitAlignObj();
1146 0 : AliTrackFitter *fitter = CreateFitter();
1147 :
1148 : //Here prepare to set the plane for GetPCArot
1149 : // if(volids->GetSize()==1){//TEMPORARY: to be improved
1150 0 : AliGeomManager::GetOrigRotation(volids->At(0),rotorig);
1151 0 : if((Int_t)AliGeomManager::VolUIDToLayer(volids->At(0))==1){//TEMPORARY: to be improved
1152 0 : normplanevect[0]=-rotorig[1];
1153 0 : normplanevect[1]=-rotorig[4];
1154 0 : normplanevect[2]=0.;
1155 0 : }
1156 : else{
1157 0 : normplanevect[0]=rotorig[1];
1158 0 : normplanevect[1]=rotorig[4];
1159 0 : normplanevect[2]=0.;
1160 : }
1161 :
1162 : // phiglob=TMath::ATan2(normplanevect[1],normplanevect[0]);
1163 :
1164 0 : modAlign=GetAlignObj(volids->At(0));
1165 0 : modAlign->GetMatrix(hM);
1166 0 : deltarot=hM.GetRotationMatrix();
1167 0 : for(Int_t j=0;j<3;j++){
1168 0 : for(Int_t i=0;i<3;i++){
1169 0 : normplanevect2[j]+=deltarot[j*3+i]*normplanevect[i];
1170 : }
1171 : // printf("Here the difference: norm1[%d]=%f norm2[%d]=%f \n",j,normplanevect[j],j,normplanevect2[j]);
1172 : }
1173 :
1174 0 : if(fVarySigmaY){
1175 0 : if(modAlign->GetUniqueID()==0)smearing=fsigmaY;
1176 : else{
1177 0 : modAlign->GetCovMatrix(covmatrx);
1178 0 : smearing=5.*5.*(covmatrx(0,0)+covmatrx(1,1)+covmatrx(2,2)+10.*10.*covmatrx(3,3)+10.*10.*covmatrx(4,4)+10.*10.*covmatrx(5,5))/6.;
1179 : //This is a sort of average: the trace with the variances of the angles
1180 : //weighted with 10 cm divided per 6 and the result multiplied per 25
1181 : // (the sqrt would be 5 times a sort of "mean sigma" )
1182 : //
1183 : }
1184 : }
1185 0 : else smearing=fsigmaY;
1186 0 : printf("This is the sigmaY value: %f \n",smearing);
1187 : // the plane will be set into the loop on tracks
1188 :
1189 :
1190 0 : for (Int_t iArray = 0; iArray < nArrays; iArray++) {
1191 0 : if (!points[iArray]) continue;
1192 0 : points[iArray]->Sort(kTRUE);
1193 0 : fitter->SetTrackPointArray(points[iArray], kFALSE);
1194 : // printf("Here normplane vect: %f \n",normplanevect2[1]); //TO BE REPLACED BY fitter->SetNormPlaneVect(normplanevect2);
1195 0 : if (fitter->Fit(volids,volidsfit,layerRangeMin,layerRangeMax) == kFALSE) continue;
1196 :
1197 0 : if(fLimitCorr>0.){
1198 : correlated=kFALSE;
1199 0 : AliTrackPoint p;
1200 0 : Int_t layer,module;
1201 0 : TArrayI *volparray=new TArrayI(points[iArray]->GetNPoints());
1202 0 : for(Int_t point=0;point<points[iArray]->GetNPoints();point++){
1203 0 : points[iArray]->GetPoint(p,point);
1204 0 : volparray->AddAt(p.GetVolumeID(),point);
1205 : }
1206 0 : TArrayI *volpArray=ExcludeVolidsFromVolidsArray(volids,volparray);
1207 0 : for(Int_t point=0;point<volpArray->GetSize();point++){
1208 0 : layer=(Int_t)AliGeomManager::VolUIDToLayerSafe(volpArray->At(point),module);
1209 0 : if(fCorrModules[layer-AliGeomManager::kFirstLayer][module]>fLimitCorr){
1210 : correlated=kTRUE;
1211 : // printf("volid %d, iarray = %d : skipping %d for Volume: %d \n",volids->At(0),iArray,skipped,volpArray->At(point));
1212 0 : skipped++;
1213 0 : break;
1214 : }
1215 : }
1216 0 : if(!correlated){
1217 0 : for(Int_t point=0;point<volpArray->GetSize();point++){
1218 0 : layer=(Int_t)AliGeomManager::VolUIDToLayerSafe(volpArray->At(point),module);
1219 : //printf("Number of common tracks: %d \n",fCorrModules[layer-AliGeomManager::kFirstLayer][module]);
1220 0 : fCorrModules[layer-AliGeomManager::kFirstLayer][module]+=frac;
1221 : }
1222 0 : delete volparray;
1223 0 : delete volpArray;
1224 : }
1225 : else {
1226 0 : delete volparray;
1227 0 : delete volpArray;
1228 0 : continue;
1229 : }
1230 0 : }
1231 :
1232 0 : AliTrackPointArray *pVolId,*pTrack;
1233 0 : fitter->GetTrackResiduals(pVolId,pTrack);
1234 0 : minimizer->AddTrackPointArrays(pVolId,pTrack);
1235 0 : }
1236 :
1237 0 : printf("Number of tracks considered: %d \n",nArrays);
1238 0 : frac=(Double_t)skipped/(Double_t)nArrays;
1239 0 : printf("Number of tracks skipped cause of correlation: %d (fraction: %f )\n",skipped,frac);
1240 :
1241 0 : Int_t ntracks=minimizer->GetNFilledTracks();
1242 0 : frac=(Double_t)ntracks/(Double_t)nArrays;
1243 0 : printf("Number of tracks into the minimizer: %d (fraction: %f )\n",ntracks,frac);
1244 0 : if(ntracks<=fmintracks){
1245 0 : printf("Not enough good tracks found: could not find parameter for volume %d (and following in volids)\n",volids->At(0));
1246 0 : UnloadPoints(pointsdim, points);
1247 : failed=kTRUE;
1248 0 : break;
1249 : }
1250 :
1251 0 : failed=(!minimizer->Minimize());
1252 :
1253 : // Update the alignment object(s)
1254 0 : if (fDoUpdate) for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) {
1255 0 : UShort_t volid = (*volids)[iVolId];
1256 0 : if(!failed){
1257 0 : Int_t iModule;
1258 0 : AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer(volid,iModule);
1259 0 : AliAlignObj *alignObj = fAlignObjs[iLayer-AliGeomManager::kFirstLayer][iModule];
1260 :
1261 : //Check the last minimization is not too large
1262 0 : minimizer->GetAlignObj()->GetPars(transl,rot);
1263 0 : fSurveyObjs[iLayer-AliGeomManager::kFirstLayer][iModule]->GetCovMatrix(surveycov);
1264 0 : fSurveyObjs[iLayer-AliGeomManager::kFirstLayer][iModule]->GetPars(survtransl,survrot);
1265 0 : if(TMath::Sqrt(TMath::Abs(surveycov[0]))*2<TMath::Abs(transl[0]-survtransl[0])||TMath::Sqrt(TMath::Abs(surveycov[2]))*2<TMath::Abs(transl[1]-survtransl[1])||TMath::Sqrt(TMath::Abs(surveycov[5]))*2<TMath::Abs(transl[2]-survtransl[2])||TMath::Sqrt(TMath::Abs(surveycov[9]))*2<TMath::Abs(rot[0]-survrot[0])||TMath::Sqrt(TMath::Abs(surveycov[14]))*2<TMath::Abs(rot[1]-survrot[1])||TMath::Sqrt(TMath::Abs(surveycov[20]))*2<TMath::Abs(rot[2]-survrot[2])){
1266 0 : printf("Results for module %d too large: can't update them \n",volid);
1267 0 : alignObj->SetUniqueID(2);
1268 0 : if(iterations==1){
1269 : failed=kTRUE;
1270 0 : }
1271 : }
1272 : else{
1273 0 : if(fUpdateCov){
1274 0 : *alignObj *= *minimizer->GetAlignObj();
1275 0 : alignObj->SetUniqueID(1);
1276 : }
1277 : else{
1278 0 : alignObj->GetCovMatrix(covmatrx);
1279 0 : *alignObj *= *minimizer->GetAlignObj();
1280 0 : alignObj->SetCorrMatrix(covmatrx);
1281 0 : alignObj->SetUniqueID(1);
1282 : }
1283 :
1284 : /*alignObj->GetPars(transl,rot);
1285 :
1286 : if(TMath::Sqrt(TMath::Abs(surveycov[0]))*20<TMath::Abs(transl[0])||TMath::Sqrt(TMath::Abs(surveycov[2]))*20<TMath::Abs(transl[1])||TMath::Sqrt(TMath::Abs(surveycov[5]))*20<TMath::Abs(transl[2])||TMath::Sqrt(TMath::Abs(surveycov[9]))*20<TMath::Abs(rot[0])||TMath::Sqrt(TMath::Abs(surveycov[14]))*20<TMath::Abs(rot[1])||TMath::Sqrt(TMath::Abs(surveycov[20]))*20<TMath::Abs(rot[2])){
1287 : printf("Results for module %d out of Survey: reinitializing it from survey \n",volid);
1288 : // *alignObj = *alignObjSurv;
1289 : alignObj->SetPars(0.,0.,0.,0.,0.,0.);
1290 : alignObj->SetUniqueID(0);
1291 : if(fUpdateCov)alignObj->SetCorrMatrix(surveycov);
1292 : if(iterations==1){
1293 : failed=kTRUE;
1294 : }
1295 : }*/
1296 : }
1297 0 : if(iterations==1)alignObj->Print("");
1298 0 : }
1299 : else {
1300 0 : printf("Minimization failed: cannot update AlignObj for volume: %d \n",volid);
1301 : }
1302 0 : }
1303 0 : UnloadPoints(pointsdim,points);
1304 0 : if(failed)break;
1305 0 : minimizer->InitAlignObj();
1306 0 : iterations--;
1307 0 : }
1308 :
1309 0 : printf("\n \n");
1310 :
1311 0 : return (!failed);
1312 0 : }
1313 :
1314 :
1315 :
1316 : //______________________________________________
1317 : Bool_t AliITSRealignTracks::AlignSPDBarrel(Int_t iterations){
1318 : //Align the SPD barrel "iterations" times
1319 :
1320 : Int_t size=0,size2=0;
1321 0 : Int_t layers[6]={1,1,0,0,0,0};
1322 0 : for(Int_t k=1;k<=2;k++){
1323 0 : size+=AliGeomManager::LayerSize(k);
1324 : }
1325 0 : for(Int_t k=3;k<=6;k++){
1326 0 : size2+=AliGeomManager::LayerSize(k);
1327 0 : printf("size: %d \n",size2);
1328 : }
1329 :
1330 0 : printf("Aligning SPDBarrel: nmodules: %d \n",size);
1331 0 : printf("Fitting modules: %d \n",size2);
1332 :
1333 0 : TArrayI *volIDs=GetLayersVolUID(layers);
1334 0 : layers[0]=0;
1335 0 : layers[1]=0;
1336 0 : layers[2]=1;
1337 0 : layers[3]=1;
1338 0 : layers[4]=1;
1339 0 : layers[5]=1;
1340 0 : TArrayI *volIDsFit=GetLayersVolUID(layers);
1341 :
1342 0 : AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSDD1,AliGeomManager::kTPC1,iterations);
1343 :
1344 0 : return kTRUE;
1345 0 : }
1346 :
1347 : //______________________
1348 : Bool_t AliITSRealignTracks::AlignSPDHalfBarrel(Int_t method,Int_t iterations){
1349 : //Align a SPD Half barrel "iterations" times
1350 : //method 0 : align SPDHalfBarrel Up without using the points on SPD Half Barrel down in the fits (only outer layers)
1351 : //method 1 : align SPDHalfBarrel Down without using the points on SPD Half Barrel up in the fits (only outer layers)
1352 : //method 10 : align SPDHalfBarrel Up using also the points on SPD Half Barrel down in the fits (and points on outer layers)
1353 : //method 11 : align SPDHalfBarrel Down using also the points on SPD Half Barrel up in the fits (and points on outer layers)
1354 :
1355 : Int_t size=0,size2=0;
1356 0 : Int_t layers[6]={0,0,1,1,1,1};
1357 0 : Int_t sectorsUp[10]={1,1,1,1,1,0,0,0,0,0};
1358 0 : Int_t sectorsDown[10]={0,0,0,0,0,1,1,1,1,1};
1359 :
1360 0 : TString updownstr;
1361 0 : if(method==0)updownstr="UpNoDown";
1362 0 : else if (method==1)updownstr="DownNoUp";
1363 0 : else if (method==10)updownstr="UpWithDown";
1364 0 : else if (method==11)updownstr="DownWithUp";
1365 : else {
1366 0 : AliWarning("Wrong AlignSPDHalfBarrel method selected ");
1367 0 : return kFALSE;
1368 : }
1369 :
1370 0 : for(Int_t i=1;i<=2;i++){
1371 0 : size+=AliGeomManager::LayerSize(i);
1372 : }
1373 :
1374 0 : for(Int_t i=3;i<=6;i++){
1375 0 : size2+=AliGeomManager::LayerSize(i);
1376 : }
1377 :
1378 0 : size=size/2;
1379 0 : if(method==10||method==11)size2+=size;
1380 :
1381 0 : printf("Aligning SPDHalfBarrel %s: nmodules: %d \n",updownstr.Data(),size);
1382 0 : printf("Fitting modules: %d \n",size2);
1383 : TArrayI *volIDsFit2;
1384 : TArrayI *volids = NULL;
1385 0 : TArrayI *volIDsFit=GetLayersVolUID(layers);
1386 0 : if(method==0||method==10)volids=GetSPDSectorsVolids(sectorsUp);
1387 0 : if(method==1||method==11)volids=GetSPDSectorsVolids(sectorsDown);
1388 :
1389 0 : if(method==10)volIDsFit2=JoinVolArrays(GetSPDSectorsVolids(sectorsDown),volIDsFit);
1390 0 : else if(method==11)volIDsFit2=JoinVolArrays(GetSPDSectorsVolids(sectorsUp),volIDsFit);
1391 : else volIDsFit2=volIDsFit;
1392 :
1393 0 : AlignVolumesITS(volids,volIDsFit2,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
1394 :
1395 : return kTRUE;
1396 0 : }
1397 :
1398 :
1399 : //______________________________________________________
1400 : Bool_t AliITSRealignTracks::AlignLayer(Int_t layer,Int_t iterations){
1401 : //Align the layer "layer" iterations times
1402 :
1403 : Int_t size=0,size2=0;
1404 0 : Int_t layers[6]={0,0,0,0,0,0};
1405 0 : layers[layer-1]=1;
1406 0 : TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
1407 0 : for(Int_t k=1;k<=6;k++){
1408 0 : if(k!=layer)size2+=AliGeomManager::LayerSize(k);
1409 : }
1410 0 : size=AliGeomManager::LayerSize(layer);
1411 :
1412 0 : printf("Aligning layer %s, nmodules %d ,fitted modules %d \n",layerstr[layer-1].Data(),size,size2);
1413 :
1414 :
1415 0 : TArrayI *volIDs=GetLayersVolUID(layers);
1416 0 : layers[0]=1;
1417 0 : layers[1]=1;
1418 0 : layers[2]=1;
1419 0 : layers[3]=1;
1420 0 : layers[4]=1;
1421 0 : layers[5]=1;
1422 0 : layers[layer]=0;
1423 0 : TArrayI *volIDsFit=GetLayersVolUID(layers);
1424 :
1425 0 : AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSDD1,AliGeomManager::kSSD2,iterations);
1426 :
1427 : return kTRUE;
1428 0 : }
1429 :
1430 : //___________________________________________
1431 :
1432 : Bool_t AliITSRealignTracks::AlignLayersToLayers(const Int_t *layer,Int_t iterations){
1433 :
1434 : //Align the set of layers A with respect to the set of layers B iterations time.
1435 : //The two sets A and B are defined into *layer==layer[6] the following way:
1436 : // layer[i]=0 the layer is skipped both in the fits than in the minimization
1437 : // layer[i]=1 the layer is skipped in the fits and considered in the minimization
1438 : // layer[i]=2 the layer is considered in the fits and skipped in the minimization
1439 : // layer[i]=3 the layer is considered both in the fits and in the minimization
1440 :
1441 : UShort_t volid;
1442 : Int_t size=0,size2=0,j=0,k=0;
1443 : Int_t iLayer;
1444 0 : TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
1445 0 : TString command="",str;
1446 0 : for(Int_t i=1;i<=6;i++){
1447 0 : if(layer[i-1]==1||layer[i-1]==3){
1448 0 : size+=AliGeomManager::LayerSize(i);
1449 0 : command.Append(" ");
1450 0 : command.Append(layerstr[i-1]);
1451 : }
1452 0 : if(layer[i-1]==2||layer[i-1]==3){
1453 0 : size2+=AliGeomManager::LayerSize(i);
1454 0 : str.Append(" ");
1455 0 : str.Append(layerstr[i-1]);
1456 : }
1457 : }
1458 :
1459 0 : printf("Aligning layers %s To layers %s, nmodules %d ,fitted modules %d \n",command.Data(),str.Data(),size,size2);
1460 :
1461 :
1462 0 : TArrayI volIDs(size);
1463 0 : TArrayI volIDsFit(size2);
1464 :
1465 0 : for (iLayer=(Int_t)AliGeomManager::kSPD1;iLayer<(Int_t)AliGeomManager::kTPC1;iLayer++){
1466 0 : if(layer[iLayer-AliGeomManager::kFirstLayer]==0)continue;
1467 0 : if(layer[iLayer-AliGeomManager::kFirstLayer]==1){
1468 0 : for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
1469 0 : volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
1470 0 : volIDs.AddAt(volid,j);
1471 0 : j++;
1472 : }
1473 0 : }
1474 0 : else if(layer[iLayer-AliGeomManager::kFirstLayer]==2){
1475 0 : for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
1476 0 : volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
1477 0 : volIDsFit.AddAt(volid,k);
1478 0 : k++;
1479 : }
1480 0 : }
1481 0 : else if(layer[iLayer-AliGeomManager::kFirstLayer]==3){
1482 0 : for (Int_t iModule2=0;iModule2<AliGeomManager::LayerSize(iLayer);iModule2++){
1483 0 : volid = AliGeomManager::LayerToVolUID(iLayer,iModule2);
1484 0 : volIDs.AddAt(volid,j);
1485 0 : j++;
1486 0 : volIDsFit.AddAt(volid,k);
1487 0 : k++;
1488 : }
1489 0 : }
1490 : }
1491 :
1492 0 : AlignVolumesITS(&volIDs,&volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
1493 :
1494 : return kTRUE;
1495 0 : }
1496 :
1497 : //______________________________________________
1498 :
1499 : Bool_t AliITSRealignTracks::AlignSPDSectorToOuterLayers(Int_t sector,Int_t iterations){
1500 : //Align the SPD sector "sector" with respect to outer layers iterations times
1501 :
1502 :
1503 0 : Int_t layers[6]={0,0,1,1,1,1};
1504 : Bool_t spd=kFALSE;
1505 0 : Int_t sectorsIN[10]={0,0,0,0,0,0,0,0,0,0};
1506 0 : Int_t sectorsFit[10]={1,1,1,1,1,1,1,1,1,1};
1507 :
1508 0 : if(sector<0){
1509 0 : sector=-sector;
1510 : spd=kTRUE;
1511 0 : }
1512 0 : sectorsIN[sector]=1;
1513 0 : sectorsFit[sector]=0;
1514 0 : TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1515 : TArrayI *volIDsFit;
1516 0 : if(spd){
1517 0 : volIDsFit=JoinVolArrays(GetSPDSectorsVolids(sectorsFit),GetLayersVolUID(layers));
1518 0 : }
1519 0 : else volIDsFit=GetLayersVolUID(layers);
1520 :
1521 0 : printf("Aligning SPD sector %d: nmodules: %d \n",sector,volIDs->GetSize());
1522 0 : printf("Fitting modules: %d \n",volIDsFit->GetSize());
1523 :
1524 0 : AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1525 :
1526 0 : return kTRUE;
1527 0 : }
1528 :
1529 : //______________________________________________
1530 : Bool_t AliITSRealignTracks::AlignSPDSectorWithSectors(Int_t sector,Int_t iterations){
1531 : //Align the SPD sector "sector" with respect to the other SPD sectors iterations times
1532 :
1533 0 : Int_t sectorsIN[10]={0,0,0,0,0,0,0,0,0,0};
1534 0 : Int_t sectorsFit[10]={1,1,1,1,1,1,1,1,1,1};
1535 :
1536 0 : sectorsIN[sector]=1;
1537 0 : sectorsFit[sector]=0;
1538 0 : TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1539 0 : TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);;
1540 :
1541 0 : printf("Aligning SPD sector %d: nmodules: %d \n",sector,volIDs->GetSize());
1542 0 : printf("Fitting modules: %d \n",volIDsFit->GetSize());
1543 :
1544 :
1545 0 : AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSDD1,iterations);
1546 :
1547 0 : return kTRUE;
1548 0 : }
1549 :
1550 :
1551 :
1552 : //___________________________________________________
1553 : Bool_t AliITSRealignTracks::AlignSPDSectorsWithSectors(const Int_t *sectorsIN,const Int_t *sectorsFit,Int_t iterations){
1554 : //Align SPD sectors defined in "sectorsIN" with respect to
1555 : //SPD sectors defined in "sectorsFit" iterations time
1556 :
1557 0 : TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1558 0 : TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);;
1559 :
1560 0 : printf("Aligning SPD sectors: modules: %d \n",volIDs->GetSize());
1561 0 : printf("Fitting modules: %d \n",volIDsFit->GetSize());
1562 :
1563 :
1564 :
1565 0 : return AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSDD1,iterations);;
1566 : }
1567 :
1568 : //___________________________________________________
1569 : Bool_t AliITSRealignTracks::AlignSPDStaves(const Int_t *staves,const Int_t *sectorsIN,const Int_t *sectorsFit,Int_t iterations){
1570 : //Align SPD staves defined by staves and sectorsIN with respect to sectorsFit volumes iterations times
1571 :
1572 0 : TArrayI *volIDs=GetSPDStavesVolids(sectorsIN,staves);
1573 0 : TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);
1574 :
1575 0 : if(volIDs->GetSize()==0){
1576 0 : printf("EMPTY ARRAY !! \n");
1577 0 : return kFALSE;
1578 : }
1579 0 : printf("Aligning SPD staves: modules: %d \n",volIDs->GetSize());
1580 0 : printf("Fitting modules: %d \n",volIDsFit->GetSize());
1581 :
1582 0 : TArrayI *volIDsFit2=ExcludeVolidsFromVolidsArray(volIDs,volIDsFit);
1583 0 : return AlignVolumesITS(volIDs,volIDsFit2,AliGeomManager::kSPD1,AliGeomManager::kSSD1,iterations);
1584 0 : }
1585 :
1586 :
1587 : //___________________________________________
1588 :
1589 : Bool_t AliITSRealignTracks::AlignLayerToSPDHalfBarrel(Int_t layer,Int_t updown,Int_t iterations){
1590 : //Align the layer "layer" with respect to SPD Half Barrel Up (updowon=0)
1591 : //or Down (updown=1) iterations times
1592 :
1593 :
1594 :
1595 0 : Int_t sectorsDown[10]={0,0,0,0,0,1,1,1,1,1};
1596 0 : Int_t sectorsUp[10]={1,1,1,1,1,0,0,0,0,0};
1597 0 : TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
1598 : TArrayI *volIDsFit;
1599 0 : Int_t layers[6]={0,0,0,0,0,0};
1600 0 : layers[layer-1]=1;
1601 0 : Int_t size=AliGeomManager::LayerSize(layer);
1602 0 : TArrayI *volIDs=GetLayersVolUID(layers);
1603 :
1604 0 : if(updown==0){
1605 0 : volIDsFit=GetSPDSectorsVolids(sectorsUp);
1606 0 : printf("Aligning layer %s, nmodules %d ,to half barrel Up \n",layerstr[layer-1].Data(),size);
1607 : }
1608 0 : else if(updown==1){
1609 0 : volIDsFit=GetSPDSectorsVolids(sectorsDown);
1610 0 : printf("Aligning layer %s, nmodules %d ,to half barrel Down \n",layerstr[layer-1].Data(),size);
1611 : }
1612 : else {
1613 0 : printf("Wrong Half Barrel selection! \n");
1614 0 : return kFALSE;
1615 : }
1616 :
1617 0 : AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
1618 :
1619 0 : return kTRUE;
1620 0 : }
1621 :
1622 : //___________________________________________
1623 :
1624 : Bool_t AliITSRealignTracks::AlignLayerToSector(Int_t layer,Int_t sector,Int_t iterations){
1625 : //Align the layer "layer" with respect to SPD sector "sector" iterations times
1626 :
1627 0 : if(sector>9){
1628 0 : printf("Wrong Sector selection! \n");
1629 0 : return kFALSE;
1630 : }
1631 0 : Int_t sectors[10]={0,0,0,0,0,0,0,0,0,0};
1632 0 : sectors[sector]=1;
1633 0 : TString layerstr[6]={"SPD1","SPD2","SDD1","SDD2","SSD1","SSD2"};
1634 : TArrayI *volIDsFit;
1635 0 : Int_t layers[6]={0,0,0,0,0,0};
1636 0 : layers[layer-1]=1;
1637 0 : TArrayI *volIDs=GetLayersVolUID(layers);
1638 0 : Int_t size=AliGeomManager::LayerSize(layer);
1639 :
1640 :
1641 0 : volIDsFit=GetSPDSectorsVolids(sectors);
1642 0 : printf("Aligning layer %s, nmodules %d ,to half barrel Up \n",layerstr[layer-1].Data(),size);
1643 :
1644 0 : AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,iterations);
1645 :
1646 : return kTRUE;
1647 0 : }
1648 :
1649 : //_______________________________________________
1650 :
1651 : Bool_t AliITSRealignTracks::AlignSPDHalfBarrelToHalfBarrel(Int_t updown,Int_t iterations){
1652 : //Align the SPD Half Barrel Up[Down] with respect to HB Down[Up] iterations time if
1653 : //updown=0[1]
1654 :
1655 :
1656 0 : Int_t sectorsDown[10]={0,0,0,0,0,1,1,1,1,1};
1657 0 : Int_t sectorsUp[10]={1,1,1,1,1,0,0,0,0,0};
1658 :
1659 0 : TArrayI *volIDsUp=GetSPDSectorsVolids(sectorsUp);
1660 0 : TArrayI *volIDsDown=GetSPDSectorsVolids(sectorsDown);
1661 :
1662 0 : if(updown==0){
1663 0 : printf("Aligning SPD HalfBarrel up to half Barrel down : nmodules: %d \n",volIDsUp->GetSize());
1664 0 : printf("Fitting modules: %d \n",volIDsDown->GetSize());
1665 0 : AlignVolumesITS(volIDsUp,volIDsDown,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1666 0 : }
1667 0 : else if(updown==1){
1668 0 : printf("Aligning SPD HalfBarrel down to half Barrel Up : nmodules: %d \n",volIDsDown->GetSize());
1669 0 : printf("Fitting modules: %d \n",volIDsUp->GetSize());
1670 0 : AlignVolumesITS(volIDsDown,volIDsUp,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1671 : }
1672 : else {
1673 0 : printf("Wrong Half Barrel selection! \n");
1674 0 : return kFALSE;
1675 : }
1676 :
1677 0 : return kTRUE;
1678 0 : }
1679 :
1680 :
1681 : //_______________________
1682 : Bool_t AliITSRealignTracks::AlignSPDHalfBarrelToSectorRef(Int_t sector,Int_t iterations){
1683 : //Align the SPD Half Barrel Down with respect to sector "sector" iterations times
1684 :
1685 0 : Int_t sectorsIN[10]={0,0,0,0,0,1,1,1,1,1};
1686 0 : Int_t sectorsFit[10]={0,0,0,0,0,0,0,0,0,0};
1687 :
1688 0 : sectorsFit[sector]=1;
1689 :
1690 0 : TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1691 0 : TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);
1692 :
1693 0 : printf("Aligning SPD HalfBarrel to sector 0 %d: nmodules: %d \n",sector,volIDs->GetSize());
1694 0 : printf("Fitting modules: %d \n",volIDsFit->GetSize());
1695 :
1696 :
1697 0 : AlignVolumesITS(volIDs,volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1698 :
1699 :
1700 0 : return kTRUE;
1701 0 : }
1702 : //_________________________________________
1703 : Bool_t AliITSRealignTracks::AlignSPD1SectorRef(Int_t sector,Int_t iterations){
1704 : //OBSOLETE METHOD: Align the SPD1 modules of sector "sector" with respect
1705 : // to the other SPD volumes iterations times
1706 :
1707 0 : Int_t sectorsIN[10]={0,0,0,0,0,0,0,0,0,0};
1708 0 : Int_t sectorsFit[10]={1,1,1,1,1,1,1,1,1,1};
1709 0 : sectorsIN[sector]=1;
1710 0 : sectorsFit[sector]=0;
1711 0 : TArrayI *volIDs=GetSPDSectorsVolids(sectorsIN);
1712 0 : TArrayI *volIDsFit=GetSPDSectorsVolids(sectorsFit);
1713 0 : Int_t size=volIDs->GetSize();
1714 0 : Int_t size2=volIDsFit->GetSize();
1715 : UShort_t volID;
1716 : Int_t k=0;
1717 :
1718 0 : TArrayI *volIDsSPD1=new TArrayI(size-8);
1719 0 : TArrayI *volIDsFit2=new TArrayI(size2+8);
1720 :
1721 0 : for(Int_t j=0;j<size;j++){
1722 0 : volID=volIDs->At(j);
1723 0 : if(AliGeomManager::VolUIDToLayer(volID)==AliGeomManager::kSPD1){
1724 0 : volIDsSPD1->AddAt(volID,size2+k);
1725 0 : k++;
1726 0 : }
1727 0 : else volIDsFit2->AddAt(volID,j-k);
1728 : }
1729 :
1730 :
1731 0 : for(Int_t j=0;j<size2;j++){
1732 0 : volID=volIDsFit->At(j);
1733 0 : volIDsFit2->AddAt(volID,size-k+j);
1734 : }
1735 :
1736 0 : printf("Aligning SPD Sector %d: nmodules: %d \n",sector,volIDsSPD1->GetSize());
1737 0 : printf("Fitting modules: %d \n",volIDsFit2->GetSize());
1738 :
1739 0 : AlignVolumesITS(volIDsSPD1,volIDsFit2,AliGeomManager::kSPD1,AliGeomManager::kSPD2,iterations);
1740 :
1741 0 : return kTRUE;
1742 0 : }
1743 :
1744 : //_____________________________________________
1745 :
1746 : AliAlignObjParams* AliITSRealignTracks::MediateAlignObj(const TArrayI *volIDs,Int_t lastVolid){
1747 : //TEMPORARY METHOD: perform an average of the values of the parameters of the AlignObjs
1748 : // defined by the array volIDs up to lastVolid position in this array
1749 : //The aim of such a method is to look for collective movement of a given set of modules
1750 :
1751 : // UShort_t volid;
1752 :
1753 0 : TGeoHMatrix hm;
1754 : Double_t *rot,*transl;
1755 0 : Double_t rotSum[9],translSum[3]={0.,0.,0.};
1756 0 : for(Int_t k=0;k<8;k++)rotSum[k]=0.;
1757 :
1758 :
1759 0 : for(Int_t ivol=0;ivol<lastVolid;ivol++){
1760 : // volid=volIDs->At(ivol);
1761 :
1762 0 : GetAlignObj(volIDs->At(ivol))->GetMatrix(hm);
1763 :
1764 0 : rot=hm.GetRotationMatrix();
1765 0 : transl=hm.GetTranslation();
1766 :
1767 0 : for(Int_t j=0;j<9;j++)rotSum[j]+=rot[j];
1768 0 : for(Int_t jt=0;jt<3;jt++)translSum[jt]+=transl[jt];
1769 : }
1770 0 : if(lastVolid!=0){
1771 0 : for(Int_t j=0;j<9;j++)rotSum[j]=rotSum[j]/lastVolid;
1772 0 : for(Int_t jt=0;jt<3;jt++)translSum[jt]=translSum[jt]/lastVolid;
1773 0 : }
1774 0 : else printf("Try to mediate results for zero modules \n");
1775 :
1776 0 : hm.SetRotation(rotSum);
1777 0 : hm.SetTranslation(translSum);
1778 :
1779 :
1780 :
1781 0 : AliAlignObjParams *alignObj=new AliAlignObjParams("average", 0,hm, kTRUE);
1782 : return alignObj;
1783 :
1784 0 : }
1785 :
1786 :
1787 : //________________________________________________
1788 : TArrayI* AliITSRealignTracks::GetSPDStavesVolids(const Int_t *sectors,const Int_t* staves){
1789 :
1790 :
1791 : // This method gets the volID Array for the chosen staves into the
1792 : // chosen sectors. You have to pass an array (10 dim) with a 1 for each
1793 : // selected sector and an array (6 dim) with a 1 for each chosen stave.
1794 : // The staves are numbered in this way: 0,1 for SPD1 and 2,3,4,5 for SPD2
1795 : // i.e. sectors[10] = {1,1,0,0,0,0,0,0,1,0} -> Sector 0, 1, 9 selected.
1796 : // staves[6]={0,1,1,0,0,1} -> Staves 1 on SPD1 and 0 and 3 on SPD2 selected
1797 :
1798 : Int_t nSect=0,nStaves=0;
1799 : Int_t last=0;
1800 :
1801 :
1802 0 : for(Int_t co=0;co<10;co++){ //counts the number of sectors chosen
1803 0 : if(sectors[co]==1) nSect++;
1804 : }
1805 :
1806 0 : for(Int_t co=0;co<6;co++){ //counts the number of sectors chosen
1807 0 : if(staves[co]==1) nStaves++;
1808 : }
1809 :
1810 0 : if(nSect<1||nStaves<1){ //if no sector chosen -> exit
1811 0 : Printf("Error! No Sector/s or staves Selected!");
1812 0 : return 0x0;
1813 : }
1814 :
1815 0 : TArrayI *volIDs = new TArrayI(nSect*nStaves*4);
1816 0 : TString stave="/Stave",str,symn,laystr;
1817 :
1818 0 : TArrayI *sectvol=GetSPDSectorsVolids(sectors);
1819 : //SPD1
1820 0 : laystr="SPD0";
1821 0 : for(Int_t k=0;k<2;k++){
1822 0 : if(staves[k]==1){
1823 0 : str=stave;
1824 0 : str+=k;
1825 0 : for(Int_t i=0;i<sectvol->GetSize();i++){
1826 0 : symn=AliGeomManager::SymName(sectvol->At(i));
1827 0 : if(symn.Contains(str)&&symn.Contains(laystr)){
1828 : // printf("Adding: %s \n",symn.Data());
1829 0 : volIDs->AddAt(sectvol->At(i),last);
1830 0 : last++;
1831 0 : }
1832 : }
1833 0 : }
1834 : }
1835 : //SPD1
1836 0 : laystr="SPD1";
1837 0 : for(Int_t k=2;k<6;k++){
1838 0 : if(staves[k]==1){
1839 0 : str=stave;
1840 0 : str+=k-2;
1841 0 : for(Int_t i=0;i<sectvol->GetSize();i++){
1842 0 : symn=AliGeomManager::SymName(sectvol->At(i));
1843 0 : if(symn.Contains(str)&&symn.Contains(laystr)){
1844 0 : volIDs->AddAt(sectvol->At(i),last);
1845 0 : printf("Adding: %s \n",symn.Data());
1846 0 : last++;
1847 0 : }
1848 : }
1849 0 : }
1850 : }
1851 :
1852 0 : volIDs->Set(last);
1853 : return volIDs;
1854 0 : }
1855 :
1856 : //________________________________________________
1857 : TArrayI* AliITSRealignTracks::GetSPDSectorsVolids(const Int_t *sectors)
1858 : {
1859 : //
1860 : // This method gets the volID Array for the chosen sectors.
1861 : // You have to pass an array with a 1 for each selected sector.
1862 : // i.e. sectors[10] = {1,1,0,0,0,0,0,0,1,0} -> Sector 0, 1, 9 selected.
1863 : //
1864 :
1865 : Int_t nSect=0;
1866 : Int_t iModule=0;
1867 :
1868 :
1869 0 : for(Int_t co=0;co<10;co++){ //counts the number of sectors chosen
1870 0 : if(sectors[co]==1) nSect++;
1871 : }
1872 :
1873 0 : if(nSect<1){ //if no sector chosen -> exit
1874 0 : Printf("Error! No Sector/s Selected!");
1875 0 : return 0x0;
1876 : }
1877 :
1878 0 : TArrayI *volIDs = new TArrayI(nSect*24);
1879 :
1880 0 : if(sectors[0]==1){ //--->cSect = 0 <---
1881 0 : volIDs->AddAt(2048,iModule); iModule++;
1882 0 : volIDs->AddAt(2049,iModule); iModule++;
1883 0 : volIDs->AddAt(2050,iModule); iModule++;
1884 0 : volIDs->AddAt(2051,iModule); iModule++;
1885 0 : volIDs->AddAt(2052,iModule); iModule++;
1886 0 : volIDs->AddAt(2053,iModule); iModule++;
1887 0 : volIDs->AddAt(2054,iModule); iModule++;
1888 0 : volIDs->AddAt(2055,iModule); iModule++;
1889 0 : volIDs->AddAt(4096,iModule); iModule++;
1890 0 : volIDs->AddAt(4097,iModule); iModule++;
1891 0 : volIDs->AddAt(4098,iModule); iModule++;
1892 0 : volIDs->AddAt(4099,iModule); iModule++;
1893 0 : volIDs->AddAt(4100,iModule); iModule++;
1894 0 : volIDs->AddAt(4101,iModule); iModule++;
1895 0 : volIDs->AddAt(4102,iModule); iModule++;
1896 0 : volIDs->AddAt(4103,iModule); iModule++;
1897 0 : volIDs->AddAt(4104,iModule); iModule++;
1898 0 : volIDs->AddAt(4105,iModule); iModule++;
1899 0 : volIDs->AddAt(4106,iModule); iModule++;
1900 0 : volIDs->AddAt(4107,iModule); iModule++;
1901 0 : volIDs->AddAt(4108,iModule); iModule++;
1902 0 : volIDs->AddAt(4109,iModule); iModule++;
1903 0 : volIDs->AddAt(4110,iModule); iModule++;
1904 0 : volIDs->AddAt(4111,iModule); iModule++;
1905 0 : }
1906 0 : if(sectors[1]==1){ //--->cSect = 1 <//---
1907 0 : volIDs->AddAt(2056,iModule); iModule++;
1908 0 : volIDs->AddAt(2057,iModule); iModule++;
1909 0 : volIDs->AddAt(2058,iModule); iModule++;
1910 0 : volIDs->AddAt(2059,iModule); iModule++;
1911 0 : volIDs->AddAt(2060,iModule); iModule++;
1912 0 : volIDs->AddAt(2061,iModule); iModule++;
1913 0 : volIDs->AddAt(2062,iModule); iModule++;
1914 0 : volIDs->AddAt(2063,iModule); iModule++;
1915 0 : volIDs->AddAt(4112,iModule); iModule++;
1916 0 : volIDs->AddAt(4113,iModule); iModule++;
1917 0 : volIDs->AddAt(4114,iModule); iModule++;
1918 0 : volIDs->AddAt(4115,iModule); iModule++;
1919 0 : volIDs->AddAt(4116,iModule); iModule++;
1920 0 : volIDs->AddAt(4117,iModule); iModule++;
1921 0 : volIDs->AddAt(4118,iModule); iModule++;
1922 0 : volIDs->AddAt(4119,iModule); iModule++;
1923 0 : volIDs->AddAt(4120,iModule); iModule++;
1924 0 : volIDs->AddAt(4121,iModule); iModule++;
1925 0 : volIDs->AddAt(4122,iModule); iModule++;
1926 0 : volIDs->AddAt(4123,iModule); iModule++;
1927 0 : volIDs->AddAt(4124,iModule); iModule++;
1928 0 : volIDs->AddAt(4125,iModule); iModule++;
1929 0 : volIDs->AddAt(4126,iModule); iModule++;
1930 0 : volIDs->AddAt(4127,iModule); iModule++;
1931 0 : }
1932 0 : if(sectors[2]==1){//--->cSect = 2 <//---
1933 0 : volIDs->AddAt(2064,iModule); iModule++;
1934 0 : volIDs->AddAt(2065,iModule); iModule++;
1935 0 : volIDs->AddAt(2066,iModule); iModule++;
1936 0 : volIDs->AddAt(2067,iModule); iModule++;
1937 0 : volIDs->AddAt(2068,iModule); iModule++;
1938 0 : volIDs->AddAt(2069,iModule); iModule++;
1939 0 : volIDs->AddAt(2070,iModule); iModule++;
1940 0 : volIDs->AddAt(2071,iModule); iModule++;
1941 0 : volIDs->AddAt(4128,iModule); iModule++;
1942 0 : volIDs->AddAt(4129,iModule); iModule++;
1943 0 : volIDs->AddAt(4130,iModule); iModule++;
1944 0 : volIDs->AddAt(4131,iModule); iModule++;
1945 0 : volIDs->AddAt(4132,iModule); iModule++;
1946 0 : volIDs->AddAt(4133,iModule); iModule++;
1947 0 : volIDs->AddAt(4134,iModule); iModule++;
1948 0 : volIDs->AddAt(4135,iModule); iModule++;
1949 0 : volIDs->AddAt(4136,iModule); iModule++;
1950 0 : volIDs->AddAt(4137,iModule); iModule++;
1951 0 : volIDs->AddAt(4138,iModule); iModule++;
1952 0 : volIDs->AddAt(4139,iModule); iModule++;
1953 0 : volIDs->AddAt(4140,iModule); iModule++;
1954 0 : volIDs->AddAt(4141,iModule); iModule++;
1955 0 : volIDs->AddAt(4142,iModule); iModule++;
1956 0 : volIDs->AddAt(4143,iModule); iModule++;
1957 0 : }
1958 0 : if(sectors[3]==1){//--->cSect = 3 <//---
1959 0 : volIDs->AddAt(2072,iModule); iModule++;
1960 0 : volIDs->AddAt(2073,iModule); iModule++;
1961 0 : volIDs->AddAt(2074,iModule); iModule++;
1962 0 : volIDs->AddAt(2075,iModule); iModule++;
1963 0 : volIDs->AddAt(2076,iModule); iModule++;
1964 0 : volIDs->AddAt(2077,iModule); iModule++;
1965 0 : volIDs->AddAt(2078,iModule); iModule++;
1966 0 : volIDs->AddAt(2079,iModule); iModule++;
1967 0 : volIDs->AddAt(4144,iModule); iModule++;
1968 0 : volIDs->AddAt(4145,iModule); iModule++;
1969 0 : volIDs->AddAt(4146,iModule); iModule++;
1970 0 : volIDs->AddAt(4147,iModule); iModule++;
1971 0 : volIDs->AddAt(4148,iModule); iModule++;
1972 0 : volIDs->AddAt(4149,iModule); iModule++;
1973 0 : volIDs->AddAt(4150,iModule); iModule++;
1974 0 : volIDs->AddAt(4151,iModule); iModule++;
1975 0 : volIDs->AddAt(4152,iModule); iModule++;
1976 0 : volIDs->AddAt(4153,iModule); iModule++;
1977 0 : volIDs->AddAt(4154,iModule); iModule++;
1978 0 : volIDs->AddAt(4155,iModule); iModule++;
1979 0 : volIDs->AddAt(4156,iModule); iModule++;
1980 0 : volIDs->AddAt(4157,iModule); iModule++;
1981 0 : volIDs->AddAt(4158,iModule); iModule++;
1982 0 : volIDs->AddAt(4159,iModule); iModule++;
1983 0 : }
1984 0 : if(sectors[4]==1){//--->cSect = 4 <//---
1985 0 : volIDs->AddAt(2080,iModule); iModule++;
1986 0 : volIDs->AddAt(2081,iModule); iModule++;
1987 0 : volIDs->AddAt(2082,iModule); iModule++;
1988 0 : volIDs->AddAt(2083,iModule); iModule++;
1989 0 : volIDs->AddAt(2084,iModule); iModule++;
1990 0 : volIDs->AddAt(2085,iModule); iModule++;
1991 0 : volIDs->AddAt(2086,iModule); iModule++;
1992 0 : volIDs->AddAt(2087,iModule); iModule++;
1993 0 : volIDs->AddAt(4160,iModule); iModule++;
1994 0 : volIDs->AddAt(4161,iModule); iModule++;
1995 0 : volIDs->AddAt(4162,iModule); iModule++;
1996 0 : volIDs->AddAt(4163,iModule); iModule++;
1997 0 : volIDs->AddAt(4164,iModule); iModule++;
1998 0 : volIDs->AddAt(4165,iModule); iModule++;
1999 0 : volIDs->AddAt(4166,iModule); iModule++;
2000 0 : volIDs->AddAt(4167,iModule); iModule++;
2001 0 : volIDs->AddAt(4168,iModule); iModule++;
2002 0 : volIDs->AddAt(4169,iModule); iModule++;
2003 0 : volIDs->AddAt(4170,iModule); iModule++;
2004 0 : volIDs->AddAt(4171,iModule); iModule++;
2005 0 : volIDs->AddAt(4172,iModule); iModule++;
2006 0 : volIDs->AddAt(4173,iModule); iModule++;
2007 0 : volIDs->AddAt(4174,iModule); iModule++;
2008 0 : volIDs->AddAt(4175,iModule); iModule++;
2009 0 : }
2010 0 : if(sectors[5]==1){//--->cSect = 5 <//---
2011 0 : volIDs->AddAt(2088,iModule); iModule++;
2012 0 : volIDs->AddAt(2089,iModule); iModule++;
2013 0 : volIDs->AddAt(2090,iModule); iModule++;
2014 0 : volIDs->AddAt(2091,iModule); iModule++;
2015 0 : volIDs->AddAt(2092,iModule); iModule++;
2016 0 : volIDs->AddAt(2093,iModule); iModule++;
2017 0 : volIDs->AddAt(2094,iModule); iModule++;
2018 0 : volIDs->AddAt(2095,iModule); iModule++;
2019 0 : volIDs->AddAt(4176,iModule); iModule++;
2020 0 : volIDs->AddAt(4177,iModule); iModule++;
2021 0 : volIDs->AddAt(4178,iModule); iModule++;
2022 0 : volIDs->AddAt(4179,iModule); iModule++;
2023 0 : volIDs->AddAt(4180,iModule); iModule++;
2024 0 : volIDs->AddAt(4181,iModule); iModule++;
2025 0 : volIDs->AddAt(4182,iModule); iModule++;
2026 0 : volIDs->AddAt(4183,iModule); iModule++;
2027 0 : volIDs->AddAt(4184,iModule); iModule++;
2028 0 : volIDs->AddAt(4185,iModule); iModule++;
2029 0 : volIDs->AddAt(4186,iModule); iModule++;
2030 0 : volIDs->AddAt(4187,iModule); iModule++;
2031 0 : volIDs->AddAt(4188,iModule); iModule++;
2032 0 : volIDs->AddAt(4189,iModule); iModule++;
2033 0 : volIDs->AddAt(4190,iModule); iModule++;
2034 0 : volIDs->AddAt(4191,iModule); iModule++;
2035 0 : }
2036 0 : if(sectors[6]==1){//--->cSect = 6 <//---
2037 0 : volIDs->AddAt(2096,iModule); iModule++;
2038 0 : volIDs->AddAt(2097,iModule); iModule++;
2039 0 : volIDs->AddAt(2098,iModule); iModule++;
2040 0 : volIDs->AddAt(2099,iModule); iModule++;
2041 0 : volIDs->AddAt(2100,iModule); iModule++;
2042 0 : volIDs->AddAt(2101,iModule); iModule++;
2043 0 : volIDs->AddAt(2102,iModule); iModule++;
2044 0 : volIDs->AddAt(2103,iModule); iModule++;
2045 0 : volIDs->AddAt(4192,iModule); iModule++;
2046 0 : volIDs->AddAt(4193,iModule); iModule++;
2047 0 : volIDs->AddAt(4194,iModule); iModule++;
2048 0 : volIDs->AddAt(4195,iModule); iModule++;
2049 0 : volIDs->AddAt(4196,iModule); iModule++;
2050 0 : volIDs->AddAt(4197,iModule); iModule++;
2051 0 : volIDs->AddAt(4198,iModule); iModule++;
2052 0 : volIDs->AddAt(4199,iModule); iModule++;
2053 0 : volIDs->AddAt(4200,iModule); iModule++;
2054 0 : volIDs->AddAt(4201,iModule); iModule++;
2055 0 : volIDs->AddAt(4202,iModule); iModule++;
2056 0 : volIDs->AddAt(4203,iModule); iModule++;
2057 0 : volIDs->AddAt(4204,iModule); iModule++;
2058 0 : volIDs->AddAt(4205,iModule); iModule++;
2059 0 : volIDs->AddAt(4206,iModule); iModule++;
2060 0 : volIDs->AddAt(4207,iModule); iModule++;
2061 0 : }
2062 0 : if(sectors[7]==1){ //--->cSect = 7 <//---
2063 0 : volIDs->AddAt(2104,iModule); iModule++;
2064 0 : volIDs->AddAt(2105,iModule); iModule++;
2065 0 : volIDs->AddAt(2106,iModule); iModule++;
2066 0 : volIDs->AddAt(2107,iModule); iModule++;
2067 0 : volIDs->AddAt(2108,iModule); iModule++;
2068 0 : volIDs->AddAt(2109,iModule); iModule++;
2069 0 : volIDs->AddAt(2110,iModule); iModule++;
2070 0 : volIDs->AddAt(2111,iModule); iModule++;
2071 0 : volIDs->AddAt(4208,iModule); iModule++;
2072 0 : volIDs->AddAt(4209,iModule); iModule++;
2073 0 : volIDs->AddAt(4210,iModule); iModule++;
2074 0 : volIDs->AddAt(4211,iModule); iModule++;
2075 0 : volIDs->AddAt(4212,iModule); iModule++;
2076 0 : volIDs->AddAt(4213,iModule); iModule++;
2077 0 : volIDs->AddAt(4214,iModule); iModule++;
2078 0 : volIDs->AddAt(4215,iModule); iModule++;
2079 0 : volIDs->AddAt(4216,iModule); iModule++;
2080 0 : volIDs->AddAt(4217,iModule); iModule++;
2081 0 : volIDs->AddAt(4218,iModule); iModule++;
2082 0 : volIDs->AddAt(4219,iModule); iModule++;
2083 0 : volIDs->AddAt(4220,iModule); iModule++;
2084 0 : volIDs->AddAt(4221,iModule); iModule++;
2085 0 : volIDs->AddAt(4222,iModule); iModule++;
2086 0 : volIDs->AddAt(4223,iModule); iModule++;
2087 0 : }
2088 0 : if(sectors[8]==1){//--->cSect = 8 <//---
2089 0 : volIDs->AddAt(2112,iModule); iModule++;
2090 0 : volIDs->AddAt(2113,iModule); iModule++;
2091 0 : volIDs->AddAt(2114,iModule); iModule++;
2092 0 : volIDs->AddAt(2115,iModule); iModule++;
2093 0 : volIDs->AddAt(2116,iModule); iModule++;
2094 0 : volIDs->AddAt(2117,iModule); iModule++;
2095 0 : volIDs->AddAt(2118,iModule); iModule++;
2096 0 : volIDs->AddAt(2119,iModule); iModule++;
2097 0 : volIDs->AddAt(4224,iModule); iModule++;
2098 0 : volIDs->AddAt(4225,iModule); iModule++;
2099 0 : volIDs->AddAt(4226,iModule); iModule++;
2100 0 : volIDs->AddAt(4227,iModule); iModule++;
2101 0 : volIDs->AddAt(4228,iModule); iModule++;
2102 0 : volIDs->AddAt(4229,iModule); iModule++;
2103 0 : volIDs->AddAt(4230,iModule); iModule++;
2104 0 : volIDs->AddAt(4231,iModule); iModule++;
2105 0 : volIDs->AddAt(4232,iModule); iModule++;
2106 0 : volIDs->AddAt(4233,iModule); iModule++;
2107 0 : volIDs->AddAt(4234,iModule); iModule++;
2108 0 : volIDs->AddAt(4235,iModule); iModule++;
2109 0 : volIDs->AddAt(4236,iModule); iModule++;
2110 0 : volIDs->AddAt(4237,iModule); iModule++;
2111 0 : volIDs->AddAt(4238,iModule); iModule++;
2112 0 : volIDs->AddAt(4239,iModule); iModule++;
2113 0 : }
2114 0 : if(sectors[9]==1){//--->cSect = 9 <//---
2115 0 : volIDs->AddAt(2120,iModule); iModule++;
2116 0 : volIDs->AddAt(2121,iModule); iModule++;
2117 0 : volIDs->AddAt(2122,iModule); iModule++;
2118 0 : volIDs->AddAt(2123,iModule); iModule++;
2119 0 : volIDs->AddAt(2124,iModule); iModule++;
2120 0 : volIDs->AddAt(2125,iModule); iModule++;
2121 0 : volIDs->AddAt(2126,iModule); iModule++;
2122 0 : volIDs->AddAt(2127,iModule); iModule++;
2123 0 : volIDs->AddAt(4240,iModule); iModule++;
2124 0 : volIDs->AddAt(4241,iModule); iModule++;
2125 0 : volIDs->AddAt(4242,iModule); iModule++;
2126 0 : volIDs->AddAt(4243,iModule); iModule++;
2127 0 : volIDs->AddAt(4244,iModule); iModule++;
2128 0 : volIDs->AddAt(4245,iModule); iModule++;
2129 0 : volIDs->AddAt(4246,iModule); iModule++;
2130 0 : volIDs->AddAt(4247,iModule); iModule++;
2131 0 : volIDs->AddAt(4248,iModule); iModule++;
2132 0 : volIDs->AddAt(4249,iModule); iModule++;
2133 0 : volIDs->AddAt(4250,iModule); iModule++;
2134 0 : volIDs->AddAt(4251,iModule); iModule++;
2135 0 : volIDs->AddAt(4252,iModule); iModule++;
2136 0 : volIDs->AddAt(4253,iModule); iModule++;
2137 0 : volIDs->AddAt(4254,iModule); iModule++;
2138 0 : volIDs->AddAt(4255,iModule); iModule++;
2139 0 : }
2140 :
2141 : return volIDs;
2142 0 : }
2143 :
2144 : //___________________________________
2145 : TArrayI* AliITSRealignTracks::GetLayersVolUID(const Int_t *layer){
2146 :
2147 : //return a TArrayI with the volUIDs of the modules into the set of layers
2148 : //defined by layer[6]
2149 :
2150 0 : TArrayI *out=new TArrayI(2198);
2151 : Int_t last=0;
2152 : UShort_t voluid;
2153 0 : for(Int_t i=0;i<6;i++){
2154 0 : if(layer[i]==1){
2155 0 : for(Int_t mod=0;mod<AliGeomManager::LayerSize(i+AliGeomManager::kFirstLayer);mod++){
2156 0 : voluid=AliGeomManager::LayerToVolUID(i+AliGeomManager::kFirstLayer,mod);
2157 0 : out->AddAt(voluid,last);
2158 : // printf("voluid %d at position %d \n",out->At(last),last);
2159 0 : last++;
2160 : }
2161 0 : }
2162 : }
2163 0 : out->Set(last);
2164 0 : return out;
2165 0 : }
2166 :
2167 : //_________________
2168 : TArrayI* AliITSRealignTracks::SelectLayerInVolids(const TArrayI *volidsIN,AliGeomManager::ELayerID layer){
2169 : //Select between the modules specified by their volUIDs in volidsIN only those
2170 : // of a given layer "layer"
2171 :
2172 0 : Int_t size=volidsIN->GetSize();
2173 : Int_t count=0;
2174 0 : for(Int_t j=0;j<size;j++){
2175 0 : if(AliGeomManager::VolUIDToLayer(volidsIN->At(j))==layer)count++;
2176 : }
2177 0 : TArrayI *volidsOUT=new TArrayI(count);
2178 : count=0;
2179 0 : for(Int_t j=0;j<size;j++){
2180 0 : if(AliGeomManager::VolUIDToLayer(volidsIN->At(j))==layer){
2181 0 : volidsOUT->AddAt(volidsIN->At(j),count);
2182 0 : count++;
2183 0 : }
2184 : }
2185 0 : return volidsOUT;
2186 0 : }
2187 :
2188 : //______________________________________________
2189 :
2190 : TArrayI* AliITSRealignTracks::IntersectVolArray(const TArrayI *vol1,const TArrayI *vol2){
2191 :
2192 : //Perform the intersection between the array vol1 and vol2
2193 :
2194 0 : Int_t size1=vol1->GetSize();
2195 0 : Int_t size2=vol2->GetSize();
2196 : Int_t last=0,volid;
2197 : Bool_t found;
2198 0 : TArrayI *volidOut=new TArrayI(size1+size2);
2199 :
2200 0 : for(Int_t k=0;k<size1;k++){
2201 : found=kFALSE;
2202 0 : volid=vol1->At(k);
2203 0 : for(Int_t j=0;j<size2;j++){
2204 0 : if(vol2->At(j)==volid)found=kTRUE;
2205 : }
2206 0 : if(found){
2207 0 : volidOut->AddAt(volid,last);
2208 0 : last++;
2209 0 : }
2210 : }
2211 0 : volidOut->Set(last);
2212 0 : return volidOut;
2213 0 : }
2214 : //_________________________________________
2215 :
2216 : TArrayI* AliITSRealignTracks::JoinVolArrays(const TArrayI *vol1,const TArrayI *vol2){
2217 : //!BE CAREFUL: If an index is repeated into vol1 or into vol2 will be repeated also in the final array
2218 :
2219 0 : Int_t size1=vol1->GetSize();
2220 0 : Int_t size2=vol2->GetSize();
2221 : Int_t count=0;
2222 : UShort_t volid;
2223 : Bool_t found;
2224 0 : TArrayI *volidOut=new TArrayI(size1+size2);
2225 :
2226 0 : for(Int_t k=0;k<size1;k++){
2227 0 : volid=vol1->At(k);
2228 0 : volidOut->AddAt(volid,k);
2229 : }
2230 :
2231 0 : for(Int_t k=0;k<size2;k++){
2232 : found=kFALSE;
2233 0 : volid=vol2->At(k);
2234 0 : for(Int_t j=0;j<size1;j++){
2235 0 : if(volidOut->At(j)==volid)found=kTRUE;
2236 : }
2237 0 : if(!found){
2238 0 : volidOut->AddAt(volid,size1+count);
2239 0 : count++;
2240 0 : }
2241 : }
2242 0 : volidOut->Set(size1+count);
2243 0 : return volidOut;
2244 0 : }
2245 :
2246 : //______________________________________
2247 :
2248 : TArrayI* AliITSRealignTracks::ExcludeVolidsFromVolidsArray(const TArrayI *volidsToExclude,const TArrayI *volStart){
2249 : //Excludes the modules defined by their volUID in the array volidsToExclude from the array volStart
2250 :
2251 0 : Int_t size1=volidsToExclude->GetSize();
2252 0 : Int_t size2=volStart->GetSize();
2253 : Int_t last=0;
2254 : UShort_t volid;
2255 : Bool_t found;
2256 0 : TArrayI *volidOut=new TArrayI(size2);
2257 :
2258 0 : for(Int_t k=0;k<size2;k++){
2259 : found=kFALSE;
2260 0 : volid=volStart->At(k);
2261 0 : for(Int_t j=0;j<size1;j++){
2262 0 : if(volidsToExclude->At(j)==volid){
2263 : found=kTRUE;
2264 0 : break;
2265 : }
2266 : }
2267 0 : if(!found){
2268 0 : volidOut->AddAt(volid,last);
2269 0 : last++;
2270 0 : }
2271 : }
2272 0 : volidOut->Set(last);
2273 0 : return volidOut;
2274 0 : }
2275 :
2276 :
2277 : //________________________________________
2278 :
2279 : TArrayI* AliITSRealignTracks::GetLayerVolumes(const Int_t *layer){
2280 : //returns a TArrayI with the volUIDs of the modules of the layers
2281 : //specified into *layer
2282 :
2283 0 : TArrayI *out=new TArrayI(2198);
2284 : Int_t last=0;
2285 : UShort_t voluid;
2286 0 : for(Int_t i=0;i<6;i++){
2287 0 : if(layer[i]==1){
2288 0 : for(Int_t mod=0;mod<AliGeomManager::LayerSize(i+AliGeomManager::kFirstLayer);mod++){
2289 0 : voluid=AliGeomManager::LayerToVolUID(i+AliGeomManager::kFirstLayer,mod);
2290 0 : out->AddAt(voluid,last);
2291 : // printf("voluid %d at position %d \n",out->At(last),last);
2292 0 : last++;
2293 : }
2294 0 : }
2295 : }
2296 0 : out->Set(last);
2297 0 : return out;
2298 0 : }
2299 :
2300 :
2301 :
2302 : //______________________________
2303 : TArrayI* AliITSRealignTracks::GetAlignedVolumes(char *filename){
2304 : //Open the file "filename" which is expected to contain
2305 : //a TClonesArray named "ITSAlignObjs" with stored a set of AlignObjs
2306 : //returns an array with the volumes UID of the modules considered realigned
2307 :
2308 0 : if(gSystem->AccessPathName(filename)){
2309 0 : printf("Wrong Realignment file name \n");
2310 0 : return 0x0;
2311 : }
2312 0 : TFile *f=TFile::Open(filename,"READ");
2313 0 : TClonesArray *array=(TClonesArray*)f->Get("ITSAlignObjs");
2314 : AliAlignObjParams *a;
2315 : Int_t last=0;
2316 0 : TArrayI *volidOut=new TArrayI(2200);
2317 0 : for(Int_t j=0;j<array->GetSize();j++){
2318 0 : a=(AliAlignObjParams*)array->At(j);
2319 0 : if(a->GetUniqueID()==0)continue;
2320 :
2321 : else {
2322 0 : volidOut->AddAt(a->GetVolUID(),last);
2323 0 : last++;
2324 : }
2325 0 : }
2326 0 : volidOut->Set(last);
2327 0 : f->Close();
2328 : return volidOut;
2329 0 : }
2330 :
2331 :
2332 : //________________________________________
2333 : void AliITSRealignTracks::SetDraw(Bool_t draw,Bool_t refresh){
2334 : //TEPMORARY METHOD: method to switch on/off the drawing of histograms
2335 : // if refresh=kTRUE deletes the old histos and constructs new ones
2336 :
2337 0 : if(refresh){
2338 : // WriteHists();
2339 0 : if(fAlignDrawObjs)DeleteDrawHists();
2340 0 : InitDrawHists();
2341 0 : }
2342 0 : fDraw=draw;
2343 0 : return;
2344 : }
2345 :
2346 : void AliITSRealignTracks::DeleteDrawHists(){
2347 : //Delete the pointers to the histograms
2348 :
2349 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
2350 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
2351 0 : delete fAlignDrawObjs[iLayer][iModule];
2352 : }
2353 0 : if(fAlignDrawObjs[iLayer])delete [] fAlignDrawObjs[iLayer];
2354 : }
2355 :
2356 0 : delete [] fAlignDrawObjs;
2357 0 : fAlignDrawObjs = 0;
2358 :
2359 :
2360 0 : delete fCanvPar;
2361 0 : delete fCanvGr;
2362 0 : delete fgrIterMeanX;
2363 0 : delete fgrIterRMSX;
2364 0 : delete fgrIterMeanY;
2365 0 : delete fgrIterRMSY;
2366 0 : delete fgrIterMeanZ;
2367 0 : delete fgrIterRMSZ;
2368 0 : delete fgrIterMeanPsi;
2369 0 : delete fgrIterRMSPsi;
2370 0 : delete fgrIterMeanTheta;
2371 0 : delete fgrIterRMSTheta;
2372 0 : delete fgrIterMeanPhi;
2373 0 : delete fgrIterRMSPhi;
2374 :
2375 0 : }
2376 :
2377 : void AliITSRealignTracks::InitDrawHists(){
2378 : //Initialize the histograms to monitor the results
2379 :
2380 : Int_t nLayers = AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer;
2381 0 : fAlignDrawObjs = new AliAlignObj**[nLayers];
2382 0 : for (Int_t iLayer = 0; iLayer < (AliGeomManager::kLastLayer - AliGeomManager::kFirstLayer); iLayer++) {
2383 0 : fAlignDrawObjs[iLayer] = new AliAlignObj*[AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer)];
2384 0 : for (Int_t iModule = 0; iModule < AliGeomManager::LayerSize(iLayer + AliGeomManager::kFirstLayer); iModule++) {
2385 0 : UShort_t volid = AliGeomManager::LayerToVolUID(iLayer+ AliGeomManager::kFirstLayer,iModule);
2386 0 : fAlignDrawObjs[iLayer][iModule] = new AliAlignObjParams(AliGeomManager::SymName(volid),volid,0,0,0,0,0,0,kTRUE);
2387 0 : fAlignDrawObjs[iLayer][iModule]->SetUniqueID(1);
2388 : }
2389 : }
2390 :
2391 :
2392 0 : TH1F *hX=new TH1F("hX","hX",1000,-10000.,10000.);
2393 0 : TH1F *hY=new TH1F("hY","hY",1000,-10000.,10000.);
2394 0 : TH1F *hZ=new TH1F("hZ","hZ",1000,-10000.,10000.);
2395 0 : TH1F *hPsi=new TH1F("hPsi","hPsi",1000,-5000.,5000.);
2396 0 : TH1F *hTheta=new TH1F("hTheta","hTheta",1000,-5000.,5000.);
2397 0 : TH1F *hPhi=new TH1F("hPhi","hPhi",1000,-5000.,5000.);
2398 :
2399 0 : fCanvPar=new TCanvas("fCanvPar","Parameters trend during iterations: Convergence \n");
2400 0 : fCanvPar->Divide(3,2);
2401 0 : fCanvPar->cd(1);
2402 0 : hX->Draw();
2403 0 : hX->SetXTitle("#mum");
2404 0 : fCanvPar->cd(2);
2405 0 : hY->Draw();
2406 0 : hY->SetXTitle("#mum");
2407 0 : fCanvPar->cd(3);
2408 0 : hZ->SetXTitle("#mum");
2409 0 : hZ->Draw();
2410 0 : fCanvPar->cd(4);
2411 0 : hPsi->SetXTitle("mdeg");
2412 0 : hPsi->Draw();
2413 0 : fCanvPar->cd(5);
2414 0 : hTheta->SetXTitle("mdeg");
2415 0 : hTheta->Draw();
2416 0 : fCanvPar->cd(6);
2417 0 : hPhi->SetXTitle("mdeg");
2418 0 : hPhi->Draw();
2419 0 : fCanvPar->Update();
2420 :
2421 :
2422 0 : fCanvGr=new TCanvas("fCanvGr","Parameters trend during iterations: Convergence \n");
2423 0 : fCanvGr->Divide(3,2);
2424 :
2425 0 : fCanvGr->cd(1);
2426 0 : fgrIterMeanX=new TGraph(1);
2427 0 : fgrIterRMSX=new TGraph(1);
2428 0 : fgrIterRMSX->GetYaxis()->SetRangeUser(-1000.,1000.);
2429 0 : fgrIterRMSX->SetName("fgrIterRMSX");
2430 0 : fgrIterRMSX->SetLineColor(2);
2431 0 : fgrIterMeanX->SetName("fgrIterMeanX");
2432 0 : fgrIterMeanX->SetTitle("Convergence of #deltaX \n");
2433 0 : fgrIterMeanX->GetXaxis()->SetTitle("#mum");
2434 0 : fgrIterRMSX->Draw("acp");
2435 0 : fgrIterMeanX->Draw("cp");
2436 :
2437 0 : fCanvGr->cd(2);
2438 0 : fgrIterMeanY=new TGraph(1);
2439 0 : fgrIterRMSY=new TGraph(1);
2440 0 : fgrIterRMSY->GetYaxis()->SetRangeUser(-1000.,1000.);
2441 0 : fgrIterRMSY->SetName("fgrIterRMSY");
2442 0 : fgrIterRMSY->SetLineColor(2);
2443 0 : fgrIterMeanY->SetName("fgrIterMeanY");
2444 0 : fgrIterMeanY->SetTitle("Convergence of #deltaY \n");
2445 0 : fgrIterMeanY->GetXaxis()->SetTitle("#mum");
2446 0 : fgrIterRMSY->Draw("acp");
2447 0 : fgrIterMeanY->Draw("cp");
2448 :
2449 0 : fCanvGr->cd(3);
2450 0 : fgrIterMeanZ=new TGraph(1);
2451 0 : fgrIterRMSZ=new TGraph(1);
2452 0 : fgrIterRMSZ->GetYaxis()->SetRangeUser(-1000.,1000.);
2453 0 : fgrIterRMSZ->SetName("fgrIterRMSZ");
2454 0 : fgrIterRMSZ->SetLineColor(2);
2455 0 : fgrIterMeanZ->SetName("fgrIterMeanZ");
2456 0 : fgrIterMeanZ->SetTitle("Convergence of #deltaZ \n");
2457 0 : fgrIterMeanZ->GetXaxis()->SetTitle("#mum");
2458 0 : fgrIterRMSZ->Draw("acp");
2459 0 : fgrIterMeanZ->Draw("cp");
2460 :
2461 0 : fCanvGr->cd(4);
2462 0 : fgrIterMeanPsi=new TGraph(1);
2463 0 : fgrIterRMSPsi=new TGraph(1);
2464 0 : fgrIterRMSPsi->GetYaxis()->SetRangeUser(-1000.,1000.);
2465 0 : fgrIterRMSPsi->SetName("fgrIterRMSPsi");
2466 0 : fgrIterRMSPsi->SetLineColor(2);
2467 0 : fgrIterMeanPsi->SetName("fgrIterMeanPsi");
2468 0 : fgrIterMeanPsi->SetTitle("Convergence of #deltaPsi \n");
2469 0 : fgrIterMeanPsi->GetXaxis()->SetTitle("mdeg");
2470 0 : fgrIterRMSPsi->Draw("acp");
2471 0 : fgrIterMeanPsi->Draw("cp");
2472 :
2473 0 : fCanvGr->cd(5);
2474 0 : fgrIterMeanTheta=new TGraph(1);
2475 0 : fgrIterRMSTheta=new TGraph(1);
2476 0 : fgrIterRMSTheta->GetYaxis()->SetRangeUser(-1000.,1000.);
2477 0 : fgrIterRMSTheta->SetName("fgrIterRMSTheta");
2478 0 : fgrIterRMSTheta->SetLineColor(2);
2479 0 : fgrIterMeanTheta->SetName("fgrIterMeanTheta");
2480 0 : fgrIterMeanTheta->SetTitle("Convergence of #deltaTheta \n");
2481 0 : fgrIterMeanTheta->GetXaxis()->SetTitle("mdeg");
2482 0 : fgrIterRMSTheta->Draw("acp");
2483 0 : fgrIterMeanTheta->Draw("cp");
2484 :
2485 0 : fCanvGr->cd(6);
2486 0 : fgrIterMeanPhi=new TGraph(1);
2487 0 : fgrIterRMSPhi=new TGraph(1);
2488 0 : fgrIterRMSPhi->GetYaxis()->SetRangeUser(-1000.,1000.);
2489 0 : fgrIterRMSPhi->SetName("fgrIterRMSPhi");
2490 0 : fgrIterRMSPhi->SetLineColor(2);
2491 0 : fgrIterMeanPhi->SetName("fgrIterMeanPhi");
2492 0 : fgrIterMeanPhi->SetTitle("Convergence of #deltaPhi \n");
2493 0 : fgrIterMeanPhi->GetXaxis()->SetTitle("mdeg");
2494 0 : fgrIterRMSPhi->Draw("acp");
2495 0 : fgrIterMeanPhi->Draw("cp");
2496 :
2497 :
2498 :
2499 0 : }
2500 :
2501 : void AliITSRealignTracks::UpdateDraw(TArrayI *volids,Int_t iter,Int_t color){
2502 : //Updates the histograms to monitor the results. Only the histograms
2503 : //of the volumes specified in *volids will be updated.
2504 : // iter is just a flag for the names of the histo
2505 : // color specifies the color of the lines of the histograms for this update
2506 :
2507 0 : TString name="hX_";
2508 0 : name+=iter;
2509 0 : name.Append("iter");
2510 0 : TH1F *hX=new TH1F("hX",name.Data(),1000,-10000.,10000.);
2511 :
2512 0 : name="hY_";
2513 0 : name+=iter;
2514 0 : name.Append("iter");
2515 0 : TH1F *hY=new TH1F("hY",name.Data(),1000,-10000.,10000.);
2516 :
2517 0 : name="hZ_";
2518 0 : name+=iter;
2519 0 : name.Append("iter");
2520 0 : TH1F *hZ=new TH1F("hZ",name.Data(),1000,-10000.,10000.);
2521 :
2522 0 : name="hPsi_";
2523 0 : name+=iter;
2524 0 : name.Append("iter");
2525 0 : TH1F *hPsi=new TH1F("hPsi",name.Data(),1000,-5000.,5000.);
2526 :
2527 0 : name="hTheta_";
2528 0 : name+=iter;
2529 0 : name.Append("iter");
2530 0 : TH1F *hTheta=new TH1F("hTheta",name.Data(),1000,-5000.,5000.);
2531 :
2532 0 : name="hPhi_";
2533 0 : name+=iter;
2534 0 : name.Append("iter");
2535 0 : TH1F *hPhi=new TH1F("hPhi",name.Data(),1000,-5000.,5000.);
2536 :
2537 0 : Int_t layer,mod;
2538 0 : Double_t transl[3],rot[3],transldr[3],rotdr[3];
2539 :
2540 0 : for(Int_t i=0;i<volids->GetSize();i++){
2541 0 : layer=AliGeomManager::VolUIDToLayer(volids->At(i),mod);
2542 0 : fAlignObjs[layer-AliGeomManager::kFirstLayer][mod]->GetPars(transl,rot);
2543 0 : fAlignDrawObjs[layer-AliGeomManager::kFirstLayer][mod]->GetPars(transldr,rotdr);
2544 :
2545 0 : hX->Fill(10000.*(transl[0]-transldr[0]));
2546 0 : hY->Fill(10000.*(transl[1]-transldr[1]));
2547 0 : hZ->Fill(10000.*(transl[2]-transldr[2]));
2548 0 : hPsi->Fill(1000.*(rot[0]-rotdr[0]));
2549 0 : hTheta->Fill(1000.*(rot[1]-rotdr[1]));
2550 0 : hPhi->Fill(1000.*(rot[1]-rotdr[2]));
2551 : //Update the pars of the draw object
2552 0 : fAlignDrawObjs[layer-AliGeomManager::kFirstLayer][mod]->SetPars(transl[0],transl[1],transl[2],rot[0],rot[1],rot[2]);
2553 : }
2554 :
2555 0 : hX->SetLineColor(color);
2556 0 : hY->SetLineColor(color);
2557 0 : hZ->SetLineColor(color);
2558 0 : hPsi->SetLineColor(color);
2559 0 : hTheta->SetLineColor(color);
2560 0 : hPhi->SetLineColor(color);
2561 :
2562 :
2563 0 : fCanvPar->cd(1);
2564 0 : hX->Draw("Same");
2565 0 : fCanvPar->cd(2);
2566 0 : hY->Draw("Same");
2567 0 : fCanvPar->cd(3);
2568 0 : hZ->Draw("Same");
2569 0 : fCanvPar->cd(4);
2570 0 : hPsi->Draw("Same");
2571 0 : fCanvPar->cd(5);
2572 0 : hTheta->Draw("Same");
2573 0 : fCanvPar->cd(6);
2574 0 : hPhi->Draw("Same");
2575 0 : gPad->Modified();
2576 0 : fCanvPar->Update();
2577 0 : fCanvPar->Modified();
2578 :
2579 0 : fgrIterMeanX->SetPoint(fgrIterMeanX->GetN()+1,iter,hX->GetMean());
2580 0 : fgrIterRMSX->SetPoint(fgrIterRMSX->GetN()+1,iter,hX->GetRMS());
2581 0 : fgrIterMeanY->SetPoint(fgrIterMeanY->GetN()+1,iter,hY->GetMean());
2582 0 : fgrIterRMSY->SetPoint(fgrIterRMSY->GetN()+1,iter,hY->GetRMS());
2583 0 : fgrIterMeanZ->SetPoint(fgrIterMeanZ->GetN()+1,iter,hZ->GetMean());
2584 0 : fgrIterRMSZ->SetPoint(fgrIterRMSZ->GetN()+1,iter,hZ->GetRMS());
2585 0 : fgrIterMeanPsi->SetPoint(fgrIterMeanPsi->GetN()+1,iter,hPsi->GetMean());
2586 0 : fgrIterRMSPsi->SetPoint(fgrIterRMSPsi->GetN()+1,iter,hPsi->GetRMS());
2587 0 : fgrIterMeanTheta->SetPoint(fgrIterMeanTheta->GetN()+1,iter,hTheta->GetMean());
2588 0 : fgrIterRMSTheta->SetPoint(fgrIterRMSTheta->GetN()+1,iter,hTheta->GetRMS());
2589 0 : fgrIterMeanPhi->SetPoint(fgrIterMeanPhi->GetN()+1,iter,hPhi->GetMean());
2590 0 : fgrIterRMSPhi->SetPoint(fgrIterRMSPhi->GetN()+1,iter,hPhi->GetRMS());
2591 :
2592 0 : gPad->Modified();
2593 0 : fCanvGr->Update();
2594 0 : fCanvGr->Update();
2595 0 : }
2596 :
2597 : void AliITSRealignTracks::WriteHists(const char *outfile){
2598 : //Writes the histograms for the monitoring of the results
2599 : // in a file named "outfile"
2600 :
2601 0 : TFile *f=new TFile(outfile,"RECREATE");
2602 0 : f->cd();
2603 0 : fCanvPar->Write();
2604 0 : fCanvGr->Write();
2605 0 : fgrIterMeanX->Write();
2606 0 : fgrIterRMSX->Write();
2607 0 : fgrIterMeanY->Write();
2608 0 : fgrIterRMSY->Write();
2609 0 : fgrIterMeanZ->Write();
2610 0 : fgrIterRMSZ->Write();
2611 0 : fgrIterMeanPsi->Write();
2612 0 : fgrIterRMSPsi->Write();
2613 0 : fgrIterMeanTheta->Write();
2614 0 : fgrIterRMSTheta->Write();
2615 0 : fgrIterMeanPhi->Write();
2616 0 : fgrIterRMSPhi->Write();
2617 :
2618 0 : f->Close();
2619 : return;
2620 :
2621 0 : }
|