1 /**************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-----------------------------------------------------------------
17 // Implementation of the tracks residuals analysis class
18 // It provides an access to the track space points
19 // written along the esd tracks. The class enables
20 // the user to plug any track fitter (deriving from
21 // AliTrackFitter class) and minimization fo the
22 // track residual sums (deriving from the AliTrackResiduals).
23 //-----------------------------------------------------------------
25 #include <Riostream.h>
30 #include <TClonesArray.h>
37 #include <TGraphErrors.h>
38 #include "TGeoMatrix.h"
39 #include "TGeoManager.h"
40 #include "TGeoPhysicalNode.h"
41 #include "TMatrixDSym.h"
42 #include "TMatrixDSymEigen.h"
46 #include "AliAlignmentTracks.h"
47 #include "AliTrackPointArray.h"
48 #include "AliAlignObjParams.h"
49 #include "AliTrackResiduals.h"
50 #include "AliTrackFitter.h"
51 #include "AliTrackFitterKalman.h"
52 #include "AliTrackFitterRieman.h"
53 #include "AliTrackResiduals.h"
54 #include "AliTrackResidualsChi2.h"
55 #include "AliTrackResidualsFast.h"
58 #include "AliITSResidualsAnalysis.h"
61 // Structure of the RealignmentAnalysisLayer.C
70 ClassImp(AliITSResidualsAnalysis)
72 //____________________________________________________________________________
73 AliITSResidualsAnalysis::AliITSResidualsAnalysis():
90 fTrackDirLambdaAll(0),
91 fTrackDirLambda2All(0),
109 fRealignObjFileIsOpen(kFALSE),
111 fAliTrackPoints("AliTrackPoints.root"),
112 fGeom("geometry.root")
123 //____________________________________________________________________________
124 AliITSResidualsAnalysis::AliITSResidualsAnalysis(const TString aliTrackPoints,
126 AliAlignmentTracks(),
142 fTrackDirLambdaAll(0),
143 fTrackDirLambda2All(0),
144 fTrackDirAlphaAll(0),
161 fRealignObjFileIsOpen(kFALSE),
163 fAliTrackPoints(aliTrackPoints),
167 // Constructor (alitrackpoints)
173 //____________________________________________________________________________
174 AliITSResidualsAnalysis::AliITSResidualsAnalysis(const TArrayI *volIDs):
175 AliAlignmentTracks(),
191 fTrackDirLambdaAll(0),
192 fTrackDirLambda2All(0),
193 fTrackDirAlphaAll(0),
210 fRealignObjFileIsOpen(kFALSE),
212 fAliTrackPoints("AliTrackPoints.root"),
213 fGeom("geometry.root")
217 // Original Constructor
220 InitHistograms(volIDs);
224 //____________________________________________________________________________
225 AliITSResidualsAnalysis::AliITSResidualsAnalysis(TArrayI *volIDs,AliTrackPointArray **tracksClustArray,AliTrackPointArray **tracksFitPointsArray):
226 AliAlignmentTracks(),
242 fTrackDirLambdaAll(0),
243 fTrackDirLambda2All(0),
244 fTrackDirAlphaAll(0),
261 fRealignObjFileIsOpen(kFALSE),
263 fAliTrackPoints("AliTrackPoints.root"),
264 fGeom("geometry.root")
268 // Detailed Constructor (deprecated)
272 TString histnameRPHI="HistRPHI_volID_",aux;
273 TString histnameZ="HistZ_volID_";
274 TString histnameGlob="HistGlob_volID_";
275 TString histnameCorrVol="HistCorrVol_volID";
276 TString histnamePullRPHI="HistPullRPHI_volID_";
277 TString histnamePullZ="HistPullZ_volID_";
278 fnHist=volIDs->GetSize();
279 fVolResHistRPHI=new TH1F*[fnHist];
280 fResHistGlob=new TH1F*[fnHist];
281 fResHistZ=new TH1F*[fnHist];
282 fPullHistRPHI=new TH1F*[fnHist];
283 fPullHistZ=new TH1F*[fnHist];
284 fhistCorrVol=new TH2F*[fnHist];
285 Float_t **binningZPhi=CheckSingleLayer(volIDs);
286 fvolidsToBin=new Int_t*[fnPhi*fnZ];
287 Float_t *binningphi=binningZPhi[0];
288 Float_t *binningz=binningZPhi[1];
289 Bool_t binning=SetBinning(volIDs,binningphi,binningz);
291 fVolNTracks=new TH2F("fVolNTracks","Hist with N tracks passing through a given module==(r,phi) zone",fnPhi,binningphi,fnZ,binningz);
292 fhistVolNptsUsed=new TH2F("fhistVolNptsUsed","Hist with N points used for given module==(r,phi) ",fnPhi,binningphi,fnZ,binningz);
293 fhistVolUsed=new TH2F("fhistVolUsed","Hist with N modules used for a given module==(r,phi) zone",fnPhi,binningphi,fnZ,binningz);
294 fSigmaVolZ=new TH2F("fSigmaVolZ","Hist with Sigma of Residual distribution for each module",fnPhi,binningphi,fnZ,binningz);
295 fhEmpty=new TH2F("fhEmpty","Hist for getting binning",fnPhi,binningphi,fnZ,binningz);
296 fVolNTracks->SetXTitle("Volume #phi");
297 fVolNTracks->SetYTitle("Volume z ");
298 fhistVolNptsUsed->SetXTitle("Volume #phi");
299 fhistVolNptsUsed->SetYTitle("Volume z ");
300 fhistVolUsed->SetXTitle("Volume #phi");
301 fhistVolUsed->SetYTitle("Volume z ");
302 fSigmaVolZ->SetXTitle("Volume #phi");
303 fSigmaVolZ->SetYTitle("Volume z ");
306 fVolNTracks=new TH2F("fVolNTracks","Hist with N tracks passing through a given module==(r,phi) zone",50,-3.2,3.2,100,-80,80);
307 fhistVolNptsUsed=new TH2F("fhistVolNptsUsed","Hist with N points used for given module==(r,phi) ",50,-3.2,3.2,100,-80,80);
308 fhistVolUsed=new TH2F("fhistVolUsed","Hist with N modules used for a given module==(r,phi) zone",50,-3.2,3.2,100,-80,80);
309 fSigmaVolZ=new TH2F("fSigmaVolZ","Hist with Sigma of Residual distribution for each module",50,-3.2,3.2,100,-80,80);
310 fhEmpty=new TH2F("fhEmpty","Hist for getting binning",50,-3.2,3.2,100,-80,80);
311 fVolNTracks->SetXTitle("Volume #phi");
312 fVolNTracks->SetYTitle("Volume z ");
313 fhistVolNptsUsed->SetXTitle("Volume #phi");
314 fhistVolNptsUsed->SetYTitle("Volume z ");
315 fhistVolUsed->SetXTitle("Volume #phi");
316 fhistVolUsed->SetYTitle("Volume z ");
317 fSigmaVolZ->SetXTitle("Volume #phi");
318 fSigmaVolZ->SetYTitle("Volume z ");
321 fpTrackVolIDs=new TArrayI(fnHist);
322 fVolUsed=new TArrayI*[fnHist];
323 fVolVolids=new TArrayI*[fnHist];
324 fLastVolVolid=new Int_t[fnHist];
326 for (Int_t nhist=0;nhist<fnHist;nhist++){
327 fpTrackVolIDs->AddAt(volIDs->At(nhist),nhist);
329 aux+=volIDs->At(nhist);
330 fVolResHistRPHI[nhist]=new TH1F("namehist","histname",200,-0.02,0.02);
331 fVolResHistRPHI[nhist]->SetName(aux.Data());
332 fVolResHistRPHI[nhist]->SetTitle(aux.Data());
335 aux+=volIDs->At(nhist);
336 fResHistZ[nhist]=new TH1F("histname","histname",400,-0.08,0.08);
337 fResHistZ[nhist]->SetName(aux.Data());
338 fResHistZ[nhist]->SetTitle(aux.Data());
340 aux=histnamePullRPHI;
341 aux+=volIDs->At(nhist);
342 fPullHistRPHI[nhist]=new TH1F("histname","histname",100,-7.,7.);
343 fPullHistRPHI[nhist]->SetName(aux.Data());
344 fPullHistRPHI[nhist]->SetTitle(aux.Data());
347 aux+=volIDs->At(nhist);
348 fPullHistZ[nhist]=new TH1F("histname","histname",100,-7.,7.);
349 fPullHistZ[nhist]->SetName(aux.Data());
350 fPullHistZ[nhist]->SetTitle(aux.Data());
353 aux+=volIDs->At(nhist);
354 fResHistGlob[nhist]=new TH1F("histname","histname",400,-0.08,0.08);
355 fResHistGlob[nhist]->SetName(aux.Data());
356 fResHistGlob[nhist]->SetTitle(aux.Data());
359 aux+=volIDs->At(nhist);
360 fhistCorrVol[nhist]=new TH2F("histname","histname",50,-3.2,3.2,100,-80,80);
361 fhistCorrVol[nhist]->SetName(aux.Data());
362 fhistCorrVol[nhist]->SetTitle(aux.Data());
363 fhistCorrVol[nhist]->SetXTitle("Volume #varphi");
364 fhistCorrVol[nhist]->SetYTitle("Volume z ");
366 fVolVolids[nhist]=new TArrayI(1000);
367 fVolUsed[nhist]=new TArrayI(1000);
368 fLastVolVolid[nhist]=0;
369 FillResHists(tracksClustArray[nhist],tracksFitPointsArray[nhist]);
374 SetFileNameTrackPoints(""); // Filename with the AliTrackPoints
375 SetFileNameGeometry(""); // Filename with the Geometry
380 //____________________________________________________________________________
381 AliITSResidualsAnalysis::~AliITSResidualsAnalysis()
387 if(fvolidsToBin) delete[] fvolidsToBin;
388 if(fLastVolVolid) delete[] fLastVolVolid;
389 if(fCoordToBinTable) delete[] fCoordToBinTable;
390 if(fVolResHistRPHI) delete fVolResHistRPHI;
391 if(fResHistZ) delete fResHistZ;
392 if(fPullHistRPHI) delete fPullHistRPHI;
393 if(fPullHistZ) delete fPullHistZ;
394 if(fTrackDirPhi) delete fTrackDirPhi;
395 if(fTrackDirLambda) delete fTrackDirLambda;
396 if(fTrackDirLambda2) delete fTrackDirLambda2;
397 if(fTrackDirAlpha) delete fTrackDirAlpha;
398 if(fTrackDirPhiAll) delete fTrackDirPhiAll;
399 if(fTrackDirLambdaAll) delete fTrackDirLambdaAll;
400 if(fTrackDirLambda2All) delete fTrackDirLambda2All;
401 if(fTrackDirAlphaAll) delete fTrackDirAlphaAll;
402 if(fTrackDir) delete fTrackDir;
403 if(fTrackDirAll) delete fTrackDirAll;
404 if(fTrackDir2All) delete fTrackDir2All;
405 if(fTrackDirXZAll) delete fTrackDirXZAll;
406 if(fResHistGlob) delete fResHistGlob;
407 if(fhistCorrVol) delete fhistCorrVol;
408 if(fVolNTracks) delete fVolNTracks;
409 if(fhEmpty) delete fhEmpty;
410 if(fhistVolNptsUsed) delete fhistVolNptsUsed;
411 if(fhistVolUsed) delete fhistVolUsed;
412 if(fSigmaVolZ) delete fSigmaVolZ;
413 if(fpTrackVolIDs) delete fpTrackVolIDs;
414 if(fVolVolids) delete fVolVolids;
415 if(fVolUsed) delete fVolUsed;
416 if(fClonesArray) delete fClonesArray;
418 SetFileNameTrackPoints("");
419 SetFileNameGeometry("");
423 //____________________________________________________________________________
424 void AliITSResidualsAnalysis::InitHistograms(const TArrayI *volIDs)
427 // Method that sets and creates the required hisstrograms
428 // with the correct binning (it dos not fill them)
431 TString histnameRPHI="HistRPHI_volID_",aux;
432 TString histnameZ="HistZ_volID_";
433 TString histnameGlob="HistGlob_volID_";
434 TString histnameCorrVol="HistCorrVol_volID";
435 TString histnamePullRPHI="HistPullRPHI_volID_";
436 TString histnamePullZ="HistPullZ_volID_";
438 TString histnameDirPhi="HistTrackDirPhi_volID_";
439 TString histnameDirLambda="HistTrackDirLambda_volID_";
440 TString histnameDirLambda2="HistTrackDirLambda2_volID_";
441 TString histnameDirAlpha="HistTrackDirAlpha_volID_";
442 TString histnameDir="HistTrackDir_volID_";
445 fnHist=volIDs->GetSize();
446 fVolResHistRPHI=new TH1F*[fnHist];
447 fResHistGlob=new TH1F*[fnHist];
448 fResHistZ=new TH1F*[fnHist];
449 fPullHistRPHI=new TH1F*[fnHist];
450 fPullHistZ=new TH1F*[fnHist];
451 fhistCorrVol=new TH2F*[fnHist];
454 fTrackDirPhi=new TH1F*[fnHist];
455 fTrackDirLambda=new TH1F*[fnHist];
456 fTrackDirLambda2=new TH1F*[fnHist];
457 fTrackDirAlpha=new TH1F*[fnHist];
460 fTrackDirPhiAll=new TH1F("fTrackDirPhiAll","fTrackDirPhiAll",100,-180,180);
461 fTrackDirLambdaAll=new TH1F("fTrackDirLambdaAll","fTrackDirLambdaAll",100,-180,180);
462 fTrackDirLambda2All=new TH1F("fTrackDirLambda2All","fTrackDirLambda2All",100,0,180);
463 fTrackDirAlphaAll=new TH1F("fTrackDirAlphaAll","fTrackDirAlphaAll",100,-180,180);
465 fTrackDirAll=new TH2F("fTrackDirAll","Hist with trakcs directions",100,-180,180,100,-180,180);
466 fTrackDir2All=new TH2F("fTrackDir2All","Hist with trakcs directions",100,-180,180,100,-180,180);
467 fTrackDirXZAll=new TH2F("fTrackDirXZAll","Hist with trakcs directions from XZ ",100,-3.,3.,100,-3.,3.);
469 fTrackDir=new TH2F*[fnHist];
471 Float_t **binningZPhi=CheckSingleLayer(volIDs);
472 fvolidsToBin=new Int_t*[fnPhi*fnZ];
474 Float_t *binningphi=binningZPhi[0];
475 Float_t *binningz=binningZPhi[1];
476 Bool_t binning=SetBinning(volIDs,binningphi,binningz);
479 fVolNTracks=new TH2F("fVolNTracks","Hist with N tracks passing through a given module==(r,phi) zone",fnPhi,binningphi,fnZ,binningz);
480 fhistVolNptsUsed=new TH2F("fhistVolNptsUsed","Hist with N points used for given module==(r,phi) ",fnPhi,binningphi,fnZ,binningz);
481 fhistVolUsed=new TH2F("fhistVolUsed","Hist with N modules used for a given module==(r,phi) zone",fnPhi,binningphi,fnZ,binningz);
482 fSigmaVolZ=new TH2F("fSigmaVolZ","Hist with Sigma of Residual distribution for each module",fnPhi,binningphi,fnZ,binningz);
483 fhEmpty=new TH2F("fhEmpty","Hist for getting binning",fnPhi,binningphi,fnZ,binningz);
484 fVolNTracks->SetXTitle("Volume #phi");
485 fVolNTracks->SetYTitle("Volume z ");
486 fhistVolNptsUsed->SetXTitle("Volume #phi");
487 fhistVolNptsUsed->SetYTitle("Volume z ");
488 fhistVolUsed->SetXTitle("Volume #phi");
489 fhistVolUsed->SetYTitle("Volume z ");
490 fSigmaVolZ->SetXTitle("Volume #phi");
491 fSigmaVolZ->SetYTitle("Volume z ");
494 fVolNTracks=new TH2F("fVolNTracks","Hist with N tracks passing through a given module==(r,phi) zone",50,-3.2,3.2,100,-80,80);
495 fhistVolNptsUsed=new TH2F("fhistVolNptsUsed","Hist with N points used for given module==(r,phi) ",50,-3.2,3.2,100,-80,80);
496 fhistVolUsed=new TH2F("fhistVolUsed","Hist with N modules used for a given module==(r,phi) zone",50,-3.2,3.2,100,-80,80);
497 fSigmaVolZ=new TH2F("fSigmaVolZ","Hist with Sigma of Residual distribution for each module",50,-3.2,3.2,100,-80,80);
498 fhEmpty=new TH2F("fhEmpty","Hist for getting binning",50,-3.2,3.2,100,-80,80);
499 fVolNTracks->SetXTitle("Volume #phi");
500 fVolNTracks->SetYTitle("Volume z ");
501 fhistVolNptsUsed->SetXTitle("Volume #phi");
502 fhistVolNptsUsed->SetYTitle("Volume z ");
503 fhistVolUsed->SetXTitle("Volume #phi");
504 fhistVolUsed->SetYTitle("Volume z ");
505 fSigmaVolZ->SetXTitle("Volume #phi");
506 fSigmaVolZ->SetYTitle("Volume z ");
508 fpTrackVolIDs=new TArrayI(fnHist);
509 fVolUsed=new TArrayI*[fnHist];
510 fVolVolids=new TArrayI*[fnHist];
511 fLastVolVolid=new Int_t[fnHist];
513 for (Int_t nhist=0;nhist<fnHist;nhist++){
514 fpTrackVolIDs->AddAt(volIDs->At(nhist),nhist);
516 aux+=volIDs->At(nhist);
517 fVolResHistRPHI[nhist]=new TH1F("histname","histname",200,-0.02,0.02);
518 fVolResHistRPHI[nhist]->SetName(aux.Data());
519 fVolResHistRPHI[nhist]->SetTitle(aux.Data());
522 aux+=volIDs->At(nhist);
523 fResHistZ[nhist]=new TH1F("histname","histname",400,-0.08,0.08);
524 fResHistZ[nhist]->SetName(aux.Data());
525 fResHistZ[nhist]->SetTitle(aux.Data());
527 aux=histnamePullRPHI;
528 aux+=volIDs->At(nhist);
529 fPullHistRPHI[nhist]=new TH1F("histname","histname",100,-7.,7.);
530 fPullHistRPHI[nhist]->SetName(aux.Data());
531 fPullHistRPHI[nhist]->SetTitle(aux.Data());
534 aux+=volIDs->At(nhist);
535 fPullHistZ[nhist]=new TH1F("histname","histname",100,-7.,7.);
536 fPullHistZ[nhist]->SetName(aux.Data());
537 fPullHistZ[nhist]->SetTitle(aux.Data());
540 aux+=volIDs->At(nhist);
541 fTrackDirPhi[nhist]=new TH1F("histname","histname",100,-180,180);
542 fTrackDirPhi[nhist]->SetName(aux.Data());
543 fTrackDirPhi[nhist]->SetTitle(aux.Data());
545 aux=histnameDirLambda;
546 aux+=volIDs->At(nhist);
547 fTrackDirLambda[nhist]=new TH1F("histname","histname",100,0,180);
548 fTrackDirLambda[nhist]->SetName(aux.Data());
549 fTrackDirLambda[nhist]->SetTitle(aux.Data());
551 aux=histnameDirLambda2;
552 aux+=volIDs->At(nhist);
553 fTrackDirLambda2[nhist]=new TH1F("histname","histname",100,0,180);
554 fTrackDirLambda2[nhist]->SetName(aux.Data());
555 fTrackDirLambda2[nhist]->SetTitle(aux.Data());
557 aux=histnameDirAlpha;
558 aux+=volIDs->At(nhist);
559 fTrackDirAlpha[nhist]=new TH1F("histname","histname",100,-180,180);
560 fTrackDirAlpha[nhist]->SetName(aux.Data());
561 fTrackDirAlpha[nhist]->SetTitle(aux.Data());
564 aux+=volIDs->At(nhist);
565 fTrackDir[nhist]=new TH2F("histname","histname",100,-90.,90.,100,-180.,180.);
566 fTrackDir[nhist]->SetName(aux.Data());
567 fTrackDir[nhist]->SetTitle(aux.Data());
570 aux+=volIDs->At(nhist);
571 fResHistGlob[nhist]=new TH1F("histname","histname",400,-0.08,0.08);
572 fResHistGlob[nhist]->SetName(aux.Data());
573 fResHistGlob[nhist]->SetTitle(aux.Data());
576 aux+=volIDs->At(nhist);
577 fhistCorrVol[nhist]=new TH2F("histname","histname",50,-3.2,3.2,100,-80,80);
580 fhistCorrVol[nhist]->SetName(aux.Data());
581 fhistCorrVol[nhist]->SetTitle(aux.Data());
582 fhistCorrVol[nhist]->SetXTitle("Volume #varphi");
583 fhistCorrVol[nhist]->SetYTitle("Volume z ");
584 fVolVolids[nhist]=new TArrayI(100);
585 fVolUsed[nhist]=new TArrayI(1000);
586 fLastVolVolid[nhist]=0;
594 //____________________________________________________________________________
595 void AliITSResidualsAnalysis::ListVolUsed(TTree *pointsTree,TArrayI ***arrayIndex,Int_t **lastIndex)
598 // This is copied from AliAlignmentClass::LoadPoints() method
601 Int_t volIDalignable,volIDpoint,iModule;
603 AliTrackPointArray* array = 0;
604 pointsTree->SetBranchAddress("SP", &array);
607 for(Int_t ivol=0;ivol<fnHist;ivol++){
609 volIDalignable=fpTrackVolIDs->At(ivol);
610 AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer((UShort_t)volIDalignable,iModule);
612 Int_t nArraysId = lastIndex[iLayer-AliGeomManager::kFirstLayer][iModule];
613 printf("volume %d (Layer %d, Modulo %d) , numero di elementi per volume %d \n",volIDalignable,iLayer,iModule,nArraysId);
614 TArrayI *index = arrayIndex[iLayer-AliGeomManager::kFirstLayer][iModule];
615 for (Int_t iArrayId = 0;iArrayId < nArraysId; iArrayId++) {
618 Int_t entry = (*index)[iArrayId];
620 pointsTree->GetEvent(entry);
622 AliWarning("Wrong space point array index!");
626 // Get the space-point array
627 Int_t modnum,nPoints = array->GetNPoints();
629 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
630 array->GetPoint(p,iPoint);
632 AliGeomManager::ELayerID layer = AliGeomManager::VolUIDToLayer(p.GetVolumeID(),modnum);
633 // check if the layer id is valid
634 if ((layer < AliGeomManager::kFirstLayer) ||
635 (layer >= AliGeomManager::kLastLayer)) {
636 AliError(Form("Layer index is invalid: %d (%d -> %d) !",
637 layer,AliGeomManager::kFirstLayer,AliGeomManager::kLastLayer-1));
640 if ((modnum >= AliGeomManager::LayerSize(layer)) ||
642 AliError(Form("Module number inside layer %d is invalid: %d (0 -> %d)",
643 layer,modnum,AliGeomManager::LayerSize(layer)));
646 if (layer > AliGeomManager::kSSD2) continue; // ITS only
648 volIDpoint=(Int_t)p.GetVolumeID();
649 if (volIDpoint==volIDalignable)continue;
650 Int_t size = fVolVolids[ivol]->GetSize();
651 // If needed allocate new size
652 if (fLastVolVolid[ivol]>=size){// Warning: fLAST[NHIST] is useless
653 fVolVolids[ivol]->Set(size + 1000);
655 fVolVolids[ivol]->AddAt(volIDpoint,fLastVolVolid[ivol]);
656 fLastVolVolid[ivol]++;
657 Bool_t usedVol=kFALSE;
658 for(Int_t used=0;used<lastused;used++){
659 if(fVolUsed[ivol]->At(used)==volIDpoint){
665 size = fVolUsed[ivol]->GetSize();
666 // If needed allocate new size
667 if (lastused>= size){
668 fVolUsed[ivol]->Set(size + 1000);
670 fVolUsed[ivol]->AddAt(volIDpoint,lastused);
674 FillVolumeCorrelationHists(ivol,volIDalignable,volIDpoint,usedVol);
682 //____________________________________________________________________________
683 void AliITSResidualsAnalysis::FillVolumeCorrelationHists(Int_t ivol,Int_t volIDalignable,Int_t volIDpoint,Bool_t usedVol) const
686 // Fill the histograms with the correlations between volumes
689 if(!gGeoManager)AliGeomManager::LoadGeometry(GetFileNameGeometry());
690 Double_t *transGlobal,radius,phi;
691 const char *symname,*volpath;
693 TGeoPhysicalNode *pn;
694 TGeoHMatrix *globMatrix;
696 symname = AliGeomManager::SymName(volIDalignable);
697 pne = gGeoManager->GetAlignableEntry(symname);
698 volpath=pne->GetTitle();
699 pn=gGeoManager->MakePhysicalNode(volpath);
700 globMatrix=pn->GetMatrix();
702 transGlobal=globMatrix->GetTranslation();
703 radius=TMath::Sqrt(transGlobal[0]*transGlobal[0]+transGlobal[1]*transGlobal[1]);
704 phi=TMath::ATan2(transGlobal[1],transGlobal[0]);
705 fhistVolNptsUsed->Fill(phi,transGlobal[2]);
706 if(!usedVol)fhistVolUsed->Fill(phi,transGlobal[2]);
708 symname = AliGeomManager::SymName(volIDpoint);
709 pne = gGeoManager->GetAlignableEntry(symname);
710 volpath=pne->GetTitle();
711 pn=gGeoManager->MakePhysicalNode(volpath);
712 globMatrix=pn->GetMatrix();
714 transGlobal=globMatrix->GetTranslation();
715 radius=TMath::Sqrt(transGlobal[0]*transGlobal[0]+transGlobal[1]*transGlobal[1]);
716 phi=TMath::ATan2(transGlobal[1],transGlobal[0]);
718 fhistCorrVol[ivol]->Fill(phi,transGlobal[2]);
724 //____________________________________________________________________________
725 void AliITSResidualsAnalysis::FillResHists(AliTrackPointArray *points,AliTrackPointArray *pTrack) const
728 // Method that fills the histograms with the residuals
732 Float_t xyz[3],xyz2[3];
733 const Float_t *cov,*cov2;
734 Float_t resRPHI,resGlob,resZ;
735 Double_t pullz,pullrphi,sign;
736 Double_t phi,lambda,lambda2,alpha,xovery,zovery;
738 for(Int_t ipoint=0;ipoint<points->GetNPoints();ipoint++){
739 points->GetPoint(p,ipoint);
740 volIDpoint=(Int_t)p.GetVolumeID();
743 pTrack->GetPoint(pTr,ipoint);
744 GetTrackDirClusterCov(&pTr,phi,lambda,lambda2,alpha,xovery,zovery);
747 resRPHI=TMath::Sqrt((xyz2[0]-xyz[0])*(xyz2[0]-xyz[0])+(xyz2[1]-xyz[1])*(xyz2[1]-xyz[1]));
748 //resRPHI is always positive value
749 sign=TMath::ATan2(xyz2[1],xyz2[0])-TMath::ATan2(xyz[1],xyz[0]);
751 sign=sign/TMath::Abs(sign);
752 resRPHI=resRPHI*sign;
753 pullrphi=sign*resRPHI*resRPHI/TMath::Sqrt((xyz2[0]-xyz[0])*(xyz2[0]-xyz[0])*(cov2[0]/100000000.+cov[0])+(xyz2[1]-xyz[1])*(xyz2[1]-xyz[1])*(cov2[3]/100000000.+cov[3]));
761 pullz=resZ/(TMath::Sqrt(cov2[5])/10000.);
762 resGlob=TMath::Sqrt((xyz2[0]-xyz[0])*(xyz2[0]-xyz[0])+(xyz2[1]-xyz[1])*(xyz2[1]-xyz[1])+(xyz2[2]-xyz[2])*(xyz2[2]-xyz[2]));
763 for(Int_t ivolIDs=0;ivolIDs<fpTrackVolIDs->GetSize();ivolIDs++){
764 if(volIDpoint==fpTrackVolIDs->At(ivolIDs)){
765 fVolResHistRPHI[ivolIDs]->Fill(resRPHI);
766 fResHistZ[ivolIDs]->Fill(resZ);
767 fResHistGlob[ivolIDs]->Fill(resGlob);
770 fTrackDirPhi[ivolIDs]->Fill(phi);
771 fTrackDirLambda[ivolIDs]->Fill(lambda);
772 fTrackDirLambda2[ivolIDs]->Fill(lambda2);
773 fTrackDirAlpha[ivolIDs]->Fill(alpha);
775 fTrackDirPhiAll->Fill(phi);
776 fTrackDirLambdaAll->Fill(lambda);
777 fTrackDirLambda2All->Fill(lambda2);
778 fTrackDirAlphaAll->Fill(alpha);
780 fTrackDirAll->Fill(lambda,alpha);
781 fTrackDir2All->Fill(lambda2,phi);
782 fTrackDirXZAll->Fill(xovery,zovery);
783 fTrackDir[ivolIDs]->Fill(lambda,alpha);
785 fPullHistRPHI[ivolIDs]->Fill(pullrphi);
786 fPullHistZ[ivolIDs]->Fill(pullz);
790 Float_t globalPhi,globalZ;
791 if(kTRUE||(fvolidsToBin[ivolIDs][0]!=volIDpoint)){
792 binphi=GetBinPhiZ((Int_t)volIDpoint,&binz);
794 else{//this in the case of alignment of one entire layer (fnHIst=layersize) may reduce iterations: remind of that fsingleLayer->fnHista<layerSize
795 binphi=fvolidsToBin[ivolIDs][1];
796 binz=fvolidsToBin[ivolIDs][2];
798 globalPhi=fCoordToBinTable[binphi][binz][0];
799 globalZ=fCoordToBinTable[binphi][binz][1];
801 fVolNTracks->Fill(globalPhi,globalZ);
803 else fVolNTracks->Fill(TMath::ATan2(xyz[1],xyz[0]),xyz[2]);
810 //____________________________________________________________________________
811 Bool_t AliITSResidualsAnalysis::AnalyzeHists(Int_t minNpoints) const
814 // Saves the histograms into a tree and saves the tree into a file
817 TString outname = "ResidualsAnalysisTree.root";
818 TFile *hFile=new TFile(outname.Data(),"RECREATE","The Files containing the TREE with Align. Vol. hists nd Prop.");
819 TTree *analysisTree=new TTree("analysisTree","Tree whith residuals analysis data for alignable volumes");
820 static histProperties_t histRPHIprop,histZprop,histGlobprop;
824 TH1F *histRPHI,*histZ,*histGlob,*histPullRPHI,*histPullZ,*hTrackDirPhi,*hTrackDirLambda,*hTrackDirLambda2,*hTrackDirAlpha;
826 TH2F *histCorrVol,*hTrackDir;
830 histPullRPHI=new TH1F();
831 histPullZ=new TH1F();
832 hTrackDirPhi=new TH1F();
833 hTrackDirLambda=new TH1F();
834 hTrackDirLambda2=new TH1F();
835 hTrackDirAlpha=new TH1F();
836 hTrackDir=new TH2F();
838 histCorrVol=new TH2F();
839 Float_t globalPhi,globalZ;
841 Int_t nHistAnalyzed=0,entries;
842 analysisTree->Branch("volID",&volID,"volID/I");
844 analysisTree->Branch("globalPhi",&globalPhi,"globalPhi/F");
845 analysisTree->Branch("globalZ",&globalZ,"globalZ/F");
847 analysisTree->Branch("histRPHI","TH1F",&histRPHI,128000,0);
848 analysisTree->Branch("histPullRPHI","TH1F",&histPullRPHI,128000,0);
850 analysisTree->Branch("histRPHIprop",&histRPHIprop,"nentries/I:rms/F:meanFit:errmeanFit:sigmaFit");
851 analysisTree->Branch("histZ","TH1F",&histZ,128000,0);
852 analysisTree->Branch("histPullZ","TH1F",&histPullZ,128000,0);
853 analysisTree->Branch("hTrackDirPhi","TH1F",&hTrackDirPhi,128000,0);
854 analysisTree->Branch("hTrackDirLambda","TH1F",&hTrackDirLambda,128000,0);
855 analysisTree->Branch("hTrackDirLambda2","TH1F",&hTrackDirLambda2,128000,0);
856 analysisTree->Branch("hTrackDirAlpha","TH1F",&hTrackDirAlpha,128000,0);
857 analysisTree->Branch("hTrackDir","TH2F",&hTrackDir,128000,0);
859 analysisTree->Branch("histZprop",&histZprop,"nentries/I:rms/F:meanFit:errmeanFit:sigmaFit");
860 analysisTree->Branch("histGlob","TH1F",&histGlob,128000,0);
861 analysisTree->Branch("histGlobprop",&histGlobprop,"nentries/I:rms/F:meanFit:errmeanFit:sigmaFit");
863 analysisTree->Branch("histCorrVol","TH2F",&histCorrVol,128000,0);
866 for(Int_t j=0;j<fnHist;j++){
867 volID=fpTrackVolIDs->At(j);
868 if((entries=(fResHistGlob[j]->GetEntries())>=minNpoints)||fsingleLayer){
871 histRPHI=fVolResHistRPHI[j];
872 histPullRPHI=fPullHistRPHI[j];
873 histRPHIprop.nentries=(Int_t)fVolResHistRPHI[j]->GetEntries();
874 rms=fVolResHistRPHI[j]->GetRMS();
875 histRPHIprop.rms=rms;
876 gauss=new TF1("gauss","gaus",-3*rms,3*rms);
877 fVolResHistRPHI[j]->Fit("gauss","RN");
878 histRPHIprop.meanFit=gauss->GetParameter(1);
879 histRPHIprop.errmeanFit=gauss->GetParError(1);
880 histRPHIprop.sigmaFit=gauss->GetParameter(2);
883 histPullZ=fPullHistZ[j];
884 histZprop.nentries=(Int_t)fResHistZ[j]->GetEntries();
885 rms=fResHistZ[j]->GetRMS();
887 gauss=new TF1("gauss","gaus",-3*rms,3*rms);
888 fResHistZ[j]->Fit("gauss","RN");
889 histZprop.meanFit=gauss->GetParameter(1);
890 histZprop.errmeanFit=gauss->GetParError(1);
891 histZprop.sigmaFit=gauss->GetParameter(2);
893 histGlob=fResHistGlob[j];
894 histGlobprop.nentries=(Int_t)fResHistGlob[j]->GetEntries();
895 rms=fResHistGlob[j]->GetRMS();
896 histGlobprop.rms=rms;
897 gauss=new TF1("gauss","gaus",-3*rms,3*rms);
898 fResHistGlob[j]->Fit("gauss","RN");
899 histGlobprop.meanFit=gauss->GetParameter(1);
900 histGlobprop.errmeanFit=gauss->GetParError(1);
901 histGlobprop.sigmaFit=gauss->GetParameter(2);
904 hTrackDirPhi=fTrackDirPhi[j];
905 hTrackDirLambda=fTrackDirLambda[j];
906 hTrackDirLambda2=fTrackDirLambda2[j];
907 hTrackDirAlpha=fTrackDirAlpha[j];
908 hTrackDir=fTrackDir[j];
912 if (fvolidsToBin[j][0]!=volID)binphi=GetBinPhiZ((Int_t)volID,&binz);
914 binphi=fvolidsToBin[j][1];
915 binz=fvolidsToBin[j][2];
917 globalPhi=fCoordToBinTable[binphi][binz][0];
918 globalZ=fCoordToBinTable[binphi][binz][1];
921 histCorrVol=fhistCorrVol[j];
922 fSigmaVolZ->SetBinContent(binphi+1,binz+1,histRPHIprop.sigmaFit);//+1 is for underflow
924 analysisTree->Fill();
930 analysisTree->Print();
931 fVolNTracks->Write();
935 fhistVolUsed->Draw();
938 fhistVolUsed->Write();
939 fTrackDirPhiAll->Write();
940 fTrackDirLambdaAll->Write();
941 fTrackDirLambda2All->Write();
942 fTrackDirAlphaAll->Write();
943 fTrackDirAll->Write();
944 fTrackDir2All->Write();
945 fTrackDirXZAll->Write();
946 fhistVolNptsUsed->Write();
958 //____________________________________________________________________________
959 void AliITSResidualsAnalysis::DrawHists() const
962 // Draws the histograms of the residuals and of the number of tracks
966 for(Int_t canv=0;canv<fnHist;canv++){
967 cname="canv Residuals";
969 TCanvas *c=new TCanvas(cname.Data(),cname.Data(),700,700);
972 fVolResHistRPHI[canv]->Draw();
974 fResHistZ[canv]->Draw();
976 fResHistGlob[canv]->Draw();
978 cname="canv NVolTracks";
980 TCanvas *c2=new TCanvas(cname.Data(),cname.Data(),700,700);
987 //____________________________________________________________________________
988 Float_t** AliITSResidualsAnalysis::CheckSingleLayer(const TArrayI *volids)
991 // Checks if volumes array is a single (ITS) layer or not
994 Float_t **binningzphi=new Float_t*[2];
996 AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer((UShort_t)volids->At(0),iModule);
997 //Check that one single Layer is going to be aligned
998 for(Int_t nvol=0;nvol<volids->GetSize();nvol++){
999 if(iLayer != AliGeomManager::VolUIDToLayer((UShort_t)volids->At(nvol),iModule)){
1000 printf("Wrong Layer! \n %d , %d , %d ,%d \n",(Int_t)AliGeomManager::VolUIDToLayer((UShort_t)volids->At(nvol),iModule),nvol,volids->GetSize(),iModule);
1001 fsingleLayer=kFALSE;
1006 //Bool_t used=kFALSE;
1008 case AliGeomManager::kSPD1:{
1009 fnPhi=fkPhiSPD1;//fkPhiSPD1;
1010 fnZ=fkZSPD1;//nZSPD1;
1011 binningzphi[0]=new Float_t[fkPhiSPD1+1];
1012 binningzphi[1]=new Float_t[fkZSPD1+1];
1013 fCoordToBinTable=new Double_t**[fkPhiSPD1];
1014 for(Int_t j=0;j<fnPhi;j++){
1015 fCoordToBinTable[j]=new Double_t*[fkZSPD1];
1018 case AliGeomManager::kSPD2:{
1019 fnPhi=fkPhiSPD2;//fkPhiSPD1;
1020 fnZ=fkZSPD2;//nZSPD1;
1021 binningzphi[0]=new Float_t[fkPhiSPD2+1];
1022 binningzphi[1]=new Float_t[fkZSPD2+1];
1023 fCoordToBinTable=new Double_t**[fkPhiSPD2];
1024 for(Int_t j=0;j<fnPhi;j++){
1025 fCoordToBinTable[j]=new Double_t*[fkZSPD2];
1028 }; break; case AliGeomManager::kSDD1:{
1029 fnPhi=fkPhiSDD1;//fkPhiSPD1;
1030 fnZ=fkZSDD1;//nZSPD1;
1031 binningzphi[0]=new Float_t[fkPhiSDD1+1];
1032 binningzphi[1]=new Float_t[fkZSDD1+1];
1033 fCoordToBinTable=new Double_t**[fkPhiSDD1];
1034 for(Int_t j=0;j<fnPhi;j++){
1035 fCoordToBinTable[j]=new Double_t*[fkZSDD1];
1037 }; break; case AliGeomManager::kSDD2:{
1038 fnPhi=fkPhiSDD2;//fkPhiSPD1;
1039 fnZ=fkZSDD2;//nZSPD1;
1040 binningzphi[0]=new Float_t[fkPhiSDD2+1];
1041 binningzphi[1]=new Float_t[fkZSDD2+1];
1042 fCoordToBinTable=new Double_t**[fkPhiSDD2];
1043 for(Int_t j=0;j<fnPhi;j++){
1044 fCoordToBinTable[j]=new Double_t*[fkZSDD2];
1046 }; break; case AliGeomManager::kSSD1:{
1047 fnPhi=fkPhiSSD1;//fkPhiSPD1;
1048 fnZ=fkZSSD1;//nZSPD1;
1049 binningzphi[0]=new Float_t[fkPhiSSD1+1];
1050 binningzphi[1]=new Float_t[fkZSSD1+1];
1051 fCoordToBinTable=new Double_t**[fkPhiSSD1];
1052 for(Int_t j=0;j<fnPhi;j++){
1053 fCoordToBinTable[j]=new Double_t*[fkZSSD1];
1055 }; break; case AliGeomManager::kSSD2:{
1056 fnPhi=fkPhiSSD2;//fkPhiSPD1;
1057 fnZ=fkZSSD2;//nZSPD1;
1058 binningzphi[0]=new Float_t[fkPhiSSD2+1];
1059 binningzphi[1]=new Float_t[fkZSSD2+1];
1060 fCoordToBinTable=new Double_t**[fkPhiSSD2];
1061 for(Int_t j=0;j<fnPhi;j++){
1062 fCoordToBinTable[j]=new Double_t*[fkZSSD2];
1067 printf("Wrong Layer Label! \n");
1068 fsingleLayer=kFALSE;
1076 //____________________________________________________________________________
1077 Bool_t AliITSResidualsAnalysis::SetBinning(const TArrayI *volids,Float_t *phiBin,Float_t *zBin)
1080 // Sets the correct binning
1083 if(!fsingleLayer)return kFALSE;
1084 const char *volpath,*symname;
1086 Int_t *orderArrayPhi,*orderArrayZ;
1088 Double_t *phiArray,*zArray,*transGlobal,*phiArrayOrdered,*zArrayOrdered;
1089 Double_t lastPhimin=-10;
1090 Double_t lastZmin=-99;
1093 TGeoPhysicalNode *pn;
1094 TGeoHMatrix *globMatrix;
1098 orderPhiZ=new Int_t**[fnPhi];
1099 phiArray=new Double_t[fnPhi];//phiBin[nModulesPhi+1];
1100 zArray=new Double_t[fnZ];//zBin[nModulesZ+1];
1101 phiArrayOrdered=new Double_t[fnPhi];
1102 zArrayOrdered=new Double_t[fnZ];
1103 orderArrayPhi=new Int_t[fnPhi];
1104 orderArrayZ=new Int_t[fnZ];
1105 for(Int_t k=0;k<fnZ;k++){
1109 for(Int_t k=0;k<fnPhi;k++){
1112 orderPhiZ[k]=new Int_t*[fnZ];
1116 AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer((UShort_t)volids->At(0),iModule);
1118 Int_t lastPhi=0,lastZ=0;
1119 for(iModule=0;iModule<AliGeomManager::LayerSize(iLayer);iModule++){
1120 fvolidsToBin[iModule]=new Int_t[3];
1121 volID=AliGeomManager::LayerToVolUID(iLayer,iModule);
1122 fvolidsToBin[iModule][0]=volID;
1123 symname = AliGeomManager::SymName(volID);
1124 pne = gGeoManager->GetAlignableEntry(symname);
1125 volpath=pne->GetTitle();
1126 pn=gGeoManager->MakePhysicalNode(volpath);
1127 globMatrix=pn->GetMatrix();
1128 transGlobal=globMatrix->GetTranslation();
1130 for(Int_t j=0;j<lastPhi;j++){
1132 if(TMath::Abs(phiArray[j]-TMath::ATan2(transGlobal[1],transGlobal[0]))<2*TMath::Pi()/(10*fnPhi)){//10 is a safety factor but....
1133 fvolidsToBin[iModule][1]=j;
1139 phiArray[lastPhi]=TMath::ATan2(transGlobal[1],transGlobal[0]);
1140 fvolidsToBin[iModule][1]=lastPhi;
1141 if(phiArray[lastPhi]<lastPhimin)lastPhimin=phiArray[lastPhi];
1144 printf("Wrong Phi! \n");
1148 for(Int_t j=0;j<lastZ;j++){
1150 if(TMath::Abs(zArray[j]-transGlobal[2])<0.1){
1151 fvolidsToBin[iModule][2]=j;
1157 fvolidsToBin[iModule][2]=lastZ;
1158 zArray[lastZ]=transGlobal[2];
1159 if(zArray[lastZ]<lastZmin)lastZmin=zArray[lastZ];
1162 printf("Wrong Z! \n");
1168 //ORDERING THE ARRAY OF PHI AND Z VALUES
1169 for(Int_t order=0;order<fnPhi;order++){
1170 for(Int_t j=0;j<fnPhi;j++){
1171 if((j!=order)&&(phiArray[order]>phiArray[j]))orderArrayPhi[order]++;
1175 for(Int_t order=0;order<fnPhi;order++){
1176 for(Int_t j=0;j<fnPhi;j++){
1177 if(orderArrayPhi[j]==order){
1178 phiArrayOrdered[order]=phiArray[j];
1185 for(Int_t order=0;order<fnZ;order++){
1186 for(Int_t j=0;j<fnZ;j++){
1187 if((j!=order)&&(zArray[order]>zArray[j]))orderArrayZ[order]++;
1192 for(Int_t order=0;order<fnZ;order++){
1193 for(Int_t j=0;j<fnZ;j++){
1194 if(orderArrayZ[j]==order){
1195 zArrayOrdered[order]=zArray[j];
1202 //Filling the fCoordToBinTable
1203 for(Int_t j=0;j<fnPhi;j++){
1204 for(Int_t i=0;i<fnZ;i++){
1205 orderPhiZ[j][i]=new Int_t[2];
1206 orderPhiZ[j][i][0]=orderArrayPhi[j];
1207 orderPhiZ[j][i][1]=orderArrayZ[i];
1212 for(Int_t j=0;j<fnPhi;j++){
1213 for(Int_t i=0;i<fnZ;i++){
1214 fCoordToBinTable[j][i]=new Double_t[2];
1215 fCoordToBinTable[j][i][0]=phiArrayOrdered[j];
1216 fCoordToBinTable[j][i][1]=zArrayOrdered[i];
1217 printf("ecco (binphi,binz)= %d, %d e (phi,z)=%f,%f \n",j,i,fCoordToBinTable[j][i][0],fCoordToBinTable[j][i][1]);
1221 for(iModule=0;iModule<fnPhi*fnZ;iModule++){
1222 istar=fvolidsToBin[iModule][1];
1223 jstar=fvolidsToBin[iModule][2];
1224 fvolidsToBin[iModule][1]=orderPhiZ[istar][jstar][0];
1225 fvolidsToBin[iModule][2]=orderPhiZ[istar][jstar][1];
1229 //now constructing the binning
1230 for(Int_t iModPhi=0;iModPhi<fnPhi-1;iModPhi++){
1231 phiBin[iModPhi+1]=(Float_t)phiArrayOrdered[iModPhi]+0.5*(phiArrayOrdered[iModPhi+1]-phiArrayOrdered[iModPhi]);
1234 phiBin[0]=(Float_t)phiArrayOrdered[0]-(phiArrayOrdered[1]-phiArrayOrdered[0])/2.;
1236 phiBin[fnPhi]=(Float_t)phiArrayOrdered[fnPhi-1]+(phiArrayOrdered[fnPhi-1]-phiArrayOrdered[fnPhi-2])/2.;
1237 for(Int_t iModPhi=0;iModPhi<fnPhi+1;iModPhi++){
1238 printf("Mean Phi mod %d su %d: %f \n",iModPhi+1,fnPhi,phiBin[iModPhi]);
1241 for(Int_t iModZ=0;iModZ<fnZ-1;iModZ++){
1242 zBin[iModZ+1]=(Float_t)zArrayOrdered[iModZ]+0.5*(zArrayOrdered[iModZ+1]-zArrayOrdered[iModZ]);
1244 zBin[0]=(Float_t)zArrayOrdered[0]-0.5*(zArrayOrdered[1]-zArrayOrdered[0]);
1245 zBin[fnZ]=(Float_t)zArrayOrdered[fnZ-1]+0.5*(zArrayOrdered[1]-zArrayOrdered[0]);
1248 for(Int_t iModPhi=0;iModPhi<fnZ+1;iModPhi++){
1249 printf("Mean Z mod %d su %d: %f \n",iModPhi+1,fnZ,zBin[iModPhi]);
1255 //____________________________________________________________________________
1256 Int_t AliITSResidualsAnalysis::GetBinPhiZ(const Int_t volID,Int_t *binz) const
1259 // Returns the correct Phi-Z bin
1263 printf("No Single Layer reAlignment! \n");
1267 for(Int_t j=0;j<fnPhi*fnZ;j++){
1269 printf("Wrong volume UID introduced! fnHist: %d volID: %d iter: %d \n",fnHist,volID,j);
1272 if(fvolidsToBin[j][0]==volID){
1274 *binz=fvolidsToBin[j][2];
1275 return fvolidsToBin[j][1];
1283 //____________________________________________________________________________
1284 TArrayI* AliITSResidualsAnalysis::GetSingleLayerVolids(Int_t layer) const
1287 // Translates the layer number into a Volumes Array
1290 if(!gGeoManager) AliGeomManager::LoadGeometry(GetFileNameGeometry());
1292 if(layer<1 || layer>6){
1293 printf("WRONG LAYER SET! \n");
1298 size = AliGeomManager::LayerSize(layer);
1299 TArrayI *volIDs = new TArrayI(size);
1300 for(iModule=0;iModule<size;iModule++){
1301 volid = AliGeomManager::LayerToVolUID(layer,iModule);
1302 volIDs->AddAt(volid,iModule);
1309 //____________________________________________________________________________
1310 void AliITSResidualsAnalysis::GetTrackDirClusterCov(AliTrackPoint *point,Double_t &phi,Double_t &lambda,Double_t &lambda2,Double_t &alpha,Double_t &xovery,Double_t &zovery) const
1317 const Float_t *covvector=point->GetCov();
1318 cov(0,0)=covvector[0];
1319 cov(1,0)=cov(0,1)=covvector[1];
1320 cov(2,0)=cov(0,2)=covvector[2];
1321 cov(1,1)=covvector[3];
1322 cov(1,2)=cov(2,1)=covvector[4];
1323 cov(2,2)=covvector[5];
1325 Double_t determinant=cov.Determinant();
1326 if(determinant!=0.){
1328 TVectorD eigenvalues(3);
1329 const TMatrixDSymEigen keigen(cov);
1330 eigenvalues=keigen.GetEigenValues();
1331 vect=keigen.GetEigenVectors();
1332 Double_t mainvect[3];
1333 mainvect[0]=vect(0,0);
1334 mainvect[1]=vect(1,0);
1335 mainvect[2]=vect(2,0);
1336 if(mainvect[1]!=0.){
1337 xovery=mainvect[0]/mainvect[1];
1338 zovery=mainvect[2]/mainvect[1];
1345 mainvect[0]=-1.*mainvect[0];
1346 mainvect[1]=-1.*mainvect[1];
1347 mainvect[2]=-1.*mainvect[2];
1349 lambda2=TMath::ATan2(TMath::Sqrt(mainvect[0]*mainvect[0]+mainvect[2]*mainvect[2]),mainvect[1])*TMath::RadToDeg();
1350 lambda=TMath::ATan2(mainvect[2],TMath::Sqrt(mainvect[0]*mainvect[0]+mainvect[1]*mainvect[1]))*TMath::RadToDeg();
1351 phi=TMath::ATan2(mainvect[0],mainvect[2])*TMath::RadToDeg();
1352 alpha=TMath::ATan2(mainvect[1],mainvect[0])*TMath::RadToDeg();
1354 else printf("determinant =0!, skip this point \n");
1359 //____________________________________________________________________________
1360 void AliITSResidualsAnalysis::CalculateResiduals(const TArrayI *volids,
1361 const TArrayI *volidsfit,
1362 AliGeomManager::ELayerID layerRangeMin,
1363 AliGeomManager::ELayerID layerRangeMax,
1367 // CalculateResiduals for a set of detector volumes.
1368 // Tracks are fitted only within
1369 // the range defined by the user
1370 // (by layerRangeMin and layerRangeMax)
1371 // or within the set of volidsfit
1372 // Repeat the procedure 'iterations' times
1375 Int_t nVolIds = volids->GetSize();
1377 AliError("Volume IDs array is empty!");
1381 // Load only the tracks with at least one
1382 // space point in the set of volume (volids)
1384 //AliAlignmentTracks::SetPointsFilename(GetFileNameTrackPoints());
1385 AliAlignmentTracks::BuildIndex();
1387 cout<<" Index Built!"<<endl;
1389 if(draw) ListVolUsed(fPointsTree,fArrayIndex,fLastIndex);
1391 AliTrackPointArray **points;
1393 // Start the iterations
1394 while (iterations > 0) {
1395 Int_t nArrays = LoadPoints(volids, points);
1396 if (nArrays == 0) return;
1398 AliTrackResiduals *minimizer = CreateMinimizer();
1399 minimizer->SetNTracks(nArrays);
1400 minimizer->InitAlignObj();
1401 AliTrackFitter *fitter = CreateFitter();
1403 for (Int_t iArray = 0; iArray < nArrays; iArray++) {
1404 if (!points[iArray]) continue;
1407 fitter->SetTrackPointArray(points[iArray],kFALSE);
1408 if (fitter->Fit(volids,volidsfit,layerRangeMin,layerRangeMax) == kFALSE) continue;
1409 AliTrackPointArray *pVolId,*pTrack;
1412 fitter->GetTrackResiduals(pVolId,pTrack);
1413 if(draw) FillResHists(pVolId,pTrack); // WARNING!
1415 minimizer->AddTrackPointArrays(pVolId,pTrack);
1419 if(minimizer->GetNFilledTracks()<=1){
1420 printf("No good tracks found: could not find parameter for volume %d (and following in volids)\n",volids->At(0));
1421 UnloadPoints(nArrays, points);
1425 minimizer->Minimize();
1427 // Update the alignment object(s)
1430 if(fRealignObjFileIsOpen)last=fClonesArray->GetLast();
1433 if (fDoUpdate) for (Int_t iVolId = 0; iVolId < nVolIds; iVolId++) {
1434 UShort_t volid = (*volids)[iVolId];
1436 AliGeomManager::ELayerID iLayer = AliGeomManager::VolUIDToLayer(volid,iModule);
1437 AliAlignObj *alignObj = fAlignObjs[iLayer-AliGeomManager::kFirstLayer][iModule];
1438 *alignObj *= *minimizer->GetAlignObj();
1440 if(iterations==1)alignObj->Print("");
1441 if(iterations==1&&fRealignObjFileIsOpen){
1442 TClonesArray &alo=*fClonesArray;
1443 new(alo[last+1+(Int_t)iVolId])AliAlignObjParams(*alignObj);
1450 UnloadPoints(nArrays, points);
1455 if(draw && iterations==0) AnalyzeHists(30);
1464 //______________________________________________________________________________
1465 void AliITSResidualsAnalysis::ProcessPoints(TString minimizer,
1467 AliGeomManager::ELayerID iLayerToAlign,
1468 AliGeomManager::ELayerID iLayerToExclude,
1469 TString misalignmentFile)
1472 // This function process the AliTrackPoints (into residuals)
1475 SetPointsFilename(GetFileNameTrackPoints());
1476 AliTrackFitter *fitter;
1479 fitter = new AliTrackFitterKalman();
1480 }else fitter = new AliTrackFitterRieman();
1482 fitter->SetMinNPoints(4);
1483 SetTrackFitter(fitter);
1486 AliTrackResiduals *res;
1488 if(minimizer=="minuit"){
1489 res = new AliTrackResidualsChi2();
1490 }else if(minimizer=="minuitnorot"){
1491 res = new AliTrackResidualsChi2();
1492 res->FixParameter(3);
1493 res->FixParameter(4);
1494 res->FixParameter(5);
1495 }else if(minimizer=="fast"){
1496 res = new AliTrackResidualsFast();
1498 printf("Trying to set a non existing minimizer! \n");
1502 res->SetMinNPoints(1);
1504 Bool_t draw = kTRUE;
1506 if(misalignmentFile=="")printf("NO FAKE MISALIGNMENT\n");
1508 Bool_t misal=Misalign(misalignmentFile,"ITSAlignObjs");
1512 if(!gGeoManager) AliGeomManager::LoadGeometry(GetFileNameGeometry());
1514 TArrayI volIDsFit(2200);
1516 for (iLayer=(Int_t)AliGeomManager::kSPD1;iLayer<(Int_t)AliGeomManager::kTPC1;iLayer++){
1517 for (Int_t iModule=0;iModule<AliGeomManager::LayerSize(iLayer);iModule++){
1518 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iModule);
1520 if((iLayer!=iLayerToAlign)&&(iLayer!=iLayerToExclude))volIDsFit.AddAt(volid,j);
1526 Int_t size=AliGeomManager::LayerSize(iLayerToAlign);
1527 TArrayI volIDs(size);
1530 for (Int_t iModule=0;iModule<AliGeomManager::LayerSize(iLayerToAlign);iModule++){
1532 UShort_t volid = AliGeomManager::LayerToVolUID(iLayerToAlign,iModule);
1533 volIDs.AddAt(volid,j);
1537 if(j==0){printf("j=0 \n");return;}
1539 CalculateResiduals(&volIDs,&volIDsFit,AliGeomManager::kSPD1,AliGeomManager::kSSD2,1,draw);
1547 //______________________________________________________________________________
1548 void AliITSResidualsAnalysis::ExtractResiduals(Int_t layer,
1550 TString filename) const
1555 // Function that saves the residuals into a Entuple
1558 TString title,strminEnt=" (Npts > ";
1559 histProperties_t histRPHIprop,histZprop;
1561 // Labels for the plots
1563 strminEnt.Append(")");
1565 // name of the output file
1566 title="resPlot_MA_layer";
1568 title.Append(".root");
1570 // Load INfiles, OUTfiles and TTrees and labels them
1571 TFile *f1=TFile::Open(filename.Data());
1573 TFile *outfile2=new TFile(title.Data(),"RECREATE");
1574 TFile &outfile=*outfile2;
1575 TTree *tRealign2=(TTree*)f2.Get("analysisTree"); // TTree with the DATA
1576 TTree &tRealign=*tRealign2;
1579 // Setting variables
1583 TH2F *hVolCorrBranch;
1591 TH2F *hEmpty=(TH2F*)f2.Get("fhEmpty");
1592 hEmpty->SetName("hEmpty");
1595 // Creates histos using the "hEmpty" template (binning!)
1596 TH2F *hSigmaMeanRPHI=new TH2F();
1597 TH2F *hSigmaRPHI=new TH2F();
1598 TH2F *hSigmaMeanZ=new TH2F();
1599 hEmpty->Copy(*hSigmaMeanRPHI);
1600 hSigmaMeanRPHI->SetName("hSigmaMeanRPHI");
1601 hSigmaMeanRPHI->GetZaxis()->SetRangeUser(0.,200);
1602 hEmpty->Copy(*hSigmaRPHI);
1603 hSigmaRPHI->SetName("hSigmaRPHI");
1604 hSigmaRPHI->GetZaxis()->SetRangeUser(0.,200);
1605 hEmpty->Copy(*hSigmaMeanZ);
1606 hSigmaMeanZ->SetName("hSigmaMeanZ");
1607 hSigmaMeanZ->GetZaxis()->SetRangeUser(0.,400);
1610 // Branching of the DATA TTree
1611 tRealign.SetBranchAddress("globalPhi",&phi);
1612 tRealign.SetBranchAddress("globalZ",&z);
1613 tRealign.SetBranchAddress("histZ",&hResZ);
1614 tRealign.SetBranchAddress("histRPHI",&hResRPhi);
1615 tRealign.SetBranchAddress("volID",&volid);
1616 tRealign.SetBranchAddress("histCorrVol",&hVolCorrBranch);
1617 tRealign.SetBranchAddress("histRPHIprop",&histRPHIprop);
1618 tRealign.SetBranchAddress("histZprop",&histZprop);
1620 TNtuple *ntMonA = new TNtuple("ntMonA","Residuals","layer:volID:phi:z:nentries:meanFitRPHI:meanFitZ:RMS_RPHI");
1621 nEntries=tRealign.GetEntries();
1622 printf("entries: %d\n",nEntries);
1623 Float_t volidfill = 0;
1625 for(Int_t j=0;j<nEntries;j++){ // LOOP OVER THE ENTRIES
1627 printf(" Loading Event %d \n",j);
1629 tRealign.GetEvent(j);
1631 // Saving data in an entuple -> To be turned into a Tree
1632 ntMonA->Fill((Float_t)layer,
1633 volidfill, // WRONG! To be corrected!
1636 10000*(Float_t)histRPHIprop.nentries,
1637 10000*(Float_t)histRPHIprop.meanFit,
1638 10000*(Float_t)histZprop.meanFit,
1639 10000*(Float_t)histRPHIprop.rms);
1641 } // END LOOP OVER ENTRIES
1645 outfile.cd();//return to top directory
1656 //______________________________________________________________________________
1657 Int_t AliITSResidualsAnalysis::PlotResiduals(Int_t layer,TString filename) const
1660 // Function that plots the residual distributions
1663 filename.Append(".root");
1664 TFile *f1 = TFile::Open(filename.Data());
1667 TH2F *hEmpty=(TH2F*)f1->Get("hEmpty");
1668 TNtuple *ntData=(TNtuple*)f1->Get("ntMonA");
1669 if(!ntData) return 2;
1672 TH2F *hMeanZ = new TH2F("hMeanZ","Hist for getting banged",40,-20,20,30,-15,15);
1676 Float_t x[4],y[4],ex[4],ey[4],yZ[4],eyZ[4];
1683 TH2F *hStatGlob = new TH2F();
1684 TH2F *hMeanGlob = new TH2F();
1688 TH1F *hGlobPhi = new TH1F("hGlobPhi","hGlobPhi",41,-(TMath::Pi())-(TMath::Pi()/40),(TMath::Pi())+(TMath::Pi()/40));
1689 //TH1F *hGlobPhi = new TH1F("hGlobPhi","hGlobPhi",40,-(TMath::Pi()),(TMath::Pi()));
1691 hMeanPHI = new TH1F*[40]; //watch out!
1692 hMeanPHIz = new TH1F*[40];
1696 for(Int_t bPhi = 0; bPhi<40; bPhi++){
1699 hMeanPHI[bPhi]=new TH1F(title.Data(),title.Data(),300,-150,150);
1702 hMeanPHIz[bPhi]=new TH1F(title.Data(),title.Data(),300,-150,150);
1705 // Setting the binning of the histos
1706 hEmpty->Copy(*hStatGlob);
1707 hStatGlob->SetName("hStatGlob");
1708 hEmpty->Copy(*hMeanGlob);
1709 hMeanGlob->SetName("hMeanGlob");
1712 Float_t volID,phi,z,nentries,meanFitRPHI,meanFitZ,rms;
1713 entries = (Int_t)ntData->GetEntries();
1716 //ntData->SetBranchAddress("layer",&layernt);
1717 ntData->SetBranchAddress("volID",&volID);
1718 ntData->SetBranchAddress("phi",&phi);
1719 ntData->SetBranchAddress("z",&z);
1720 ntData->SetBranchAddress("nentries",&nentries);
1721 ntData->SetBranchAddress("meanFitRPHI",&meanFitRPHI);
1722 ntData->SetBranchAddress("meanFitZ",&meanFitZ);
1723 ntData->SetBranchAddress("RMS_RPHI",&rms);
1727 Double_t c1,c2,c3,c4;
1728 Double_t m1,m2,m3,m4;
1729 Double_t n1,n2,n3,n4;
1735 TH1F *hMeanFit1 = new TH1F("hMeanFit1","lol",1000,-500,500);
1736 TH1F *hMeanFit2 = new TH1F("hMeanFit2","lol",1000,-500,500);
1737 TH1F *hMeanFit3 = new TH1F("hMeanFit3","lol",1000,-500,500);
1738 TH1F *hMeanFit4 = new TH1F("hMeanFit4","lol",1000,-500,500);
1740 TH1F *hMeanFitZ1 = new TH1F("hMeanFitZ1","lol",1000,-500,500);
1741 TH1F *hMeanFitZ2 = new TH1F("hMeanFitZ2","lol",1000,-500,500);
1742 TH1F *hMeanFitZ3 = new TH1F("hMeanFitZ3","lol",1000,-500,500);
1743 TH1F *hMeanFitZ4 = new TH1F("hMeanFitZ4","lol",1000,-500,500);
1745 for(Int_t j=0;j<entries;j++){
1747 nbytes += ntData->GetEvent(j);
1750 bin=hStatGlob->FindBin(phi,z);
1751 bin2=hMeanZ->FindBin(meanFitRPHI,z);
1753 // Global Histograms
1754 hStatGlob->AddBinContent(bin,nentries);
1755 hMeanGlob->AddBinContent(bin,meanFitRPHI);
1756 hMeanZ->AddBinContent(bin2,1);
1758 bin=hGlobPhi->FindBin(phi);
1759 bin2=hMeanPHI[bin-2]->FindBin(meanFitRPHI);
1760 hMeanPHI[bin-2]->AddBinContent(bin2,1);
1761 bin2=hMeanPHIz[bin-2]->FindBin(meanFitZ);
1762 hMeanPHIz[bin-2]->AddBinContent(bin2,1);
1767 m1+=(meanFitRPHI*nentries);
1769 ban=hMeanFit1->FindBin(meanFitRPHI);
1770 //hMeanFit1->AddBinContent(ban,1);
1771 hMeanFit1->AddBinContent(ban,1);
1772 ban=hMeanFitZ1->FindBin(meanFitZ);
1773 hMeanFitZ1->AddBinContent(ban,1);
1774 } else if(z<5 && z>2){
1776 m2+=(meanFitRPHI*nentries);
1778 ban=hMeanFit2->FindBin(meanFitRPHI);
1779 //hMeanFit2->AddBinContent(ban,1);
1780 hMeanFit2->AddBinContent(ban,1);
1781 ban=hMeanFitZ2->FindBin(meanFitZ);
1782 hMeanFitZ2->AddBinContent(ban,1);
1783 } else if(z<-2 && z>-5){
1785 m3+=(meanFitRPHI*nentries);
1787 ban=hMeanFit3->FindBin(meanFitRPHI);
1788 //hMeanFit3->AddBinContent(ban,1);
1789 hMeanFit3->AddBinContent(ban,1);
1790 ban=hMeanFitZ3->FindBin(meanFitZ);
1791 hMeanFitZ3->AddBinContent(ban,1);
1792 } else if(z<-9 && z>-12){
1794 m4+=(meanFitRPHI*nentries);
1796 ban=hMeanFit4->FindBin(meanFitRPHI);
1797 //hMeanFit4->AddBinContent(ban,1);
1798 hMeanFit4->AddBinContent(ban,1);
1799 ban=hMeanFitZ4->FindBin(meanFitZ);
1800 hMeanFitZ4->AddBinContent(ban,1);
1810 y[0]=hMeanFit1->GetMean();
1811 y[1]=hMeanFit2->GetMean();
1812 y[2]=hMeanFit3->GetMean();
1813 y[3]=hMeanFit4->GetMean();
1815 ey[0]=hMeanFit1->GetRMS();
1816 ey[1]=hMeanFit2->GetRMS();
1817 ey[2]=hMeanFit3->GetRMS();
1818 ey[3]=hMeanFit4->GetRMS();
1820 yZ[0]=hMeanFitZ1->GetMean();
1821 yZ[1]=hMeanFitZ2->GetMean();
1822 yZ[2]=hMeanFitZ3->GetMean();
1823 yZ[3]=hMeanFitZ4->GetMean();
1825 eyZ[0]=hMeanFitZ1->GetRMS();
1826 eyZ[1]=hMeanFitZ2->GetRMS();
1827 eyZ[2]=hMeanFitZ3->GetRMS();
1828 eyZ[3]=hMeanFitZ4->GetRMS();
1830 TGraphErrors *gZres = new TGraphErrors(nn,x,y,ex,ey);
1831 TGraphErrors *gZresZ = new TGraphErrors(nn,x,yZ,ex,eyZ);
1833 TCanvas *cc1 = new TCanvas("cc1","Title1",1);
1835 hStatGlob->DrawCopy("LEGO2");
1837 Double_t xx[40],yy[40],exx[40],eyy[40];
1839 for(Int_t bp = 0; bp<40;bp++){
1840 xx[bp]=(bp*(TMath::Pi()/20))-TMath::Pi();
1841 if(TMath::Abs(hMeanPHI[bp]->GetMean())<1e-6) continue;
1842 yy[bp]=hMeanPHI[bp]->GetMean();
1843 eyy[bp]=hMeanPHI[bp]->GetRMS();
1844 exx[bp]=(TMath::Pi())/41;
1846 TGraphErrors *gPHIres = new TGraphErrors(40,xx,yy,exx,eyy);
1847 //gPHIres->Fit("pol1","","same",-3,3);
1849 Double_t xxz[40],yyz[40],exxz[40],eyyz[40];
1851 for(Int_t bp = 0; bp<40;bp++){
1852 xxz[bp]=(bp*(TMath::Pi()/20))-TMath::Pi();
1853 if(TMath::Abs(hMeanPHIz[bp]->GetMean())<1e-6) continue;
1854 yyz[bp]=hMeanPHIz[bp]->GetMean();
1855 eyyz[bp]=hMeanPHIz[bp]->GetRMS();
1856 exxz[bp]=(TMath::Pi())/41;
1858 TGraphErrors *gPHIresZ = new TGraphErrors(40,xxz,yyz,exxz,eyyz);
1860 TCanvas *cc4 = new TCanvas("cc4","meanRes VS Z",1);
1867 TCanvas *cc3 = new TCanvas("cc3","Title3",1);
1870 hMeanFitZ1->DrawCopy();
1872 hMeanFitZ2->DrawCopy();
1874 hMeanFitZ3->DrawCopy();
1876 hMeanFitZ4->DrawCopy();
1878 TCanvas *cc6 = new TCanvas("cc6","meanRes(RPHI) VS PHI",1);
1881 gPHIres->Draw("AP");
1884 gPHIresZ->Draw("AP");
1886 TCanvas *cc7 = new TCanvas("cc7","Title7",1);
1889 hMeanPHI[1]->DrawCopy();
1891 hMeanPHI[2]->DrawCopy();
1893 hMeanPHI[29]->DrawCopy();
1895 hMeanPHI[30]->DrawCopy();