LCOV - code coverage report
Current view: top level - TPC/TPCutil - AliTPCAlign.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 163 0.6 %
Date: 2016-06-14 17:26:59 Functions: 1 16 6.2 %

          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             : $Log$
      18             : Revision 1.3  2007/10/22 14:20:25  kowal2
      19             : Hardwired "ideal" coordinates replaced with those from the DCDB.
      20             : Corrected bug in SetDebug method
      21             : 
      22             : Revision 1.2  2007/10/03 09:27:50  marian
      23             : Extra semicolon removed (Marian)
      24             : 
      25             : Revision 1.1  2007/10/01 14:12:45  kowal2
      26             : Class creating the aligmnent object fro the surveyor measurements.
      27             : 
      28             : */ 
      29             : 
      30             : //
      31             : //  Creates the TPC align object
      32             : //
      33             : 
      34             : #include "AliTPCAlign.h"
      35             : #include "AliSurveyPoint.h"
      36             : #include "AliSurveyPoint.h"
      37             : //
      38             : #include "TROOT.h"
      39             : #include "Riostream.h"
      40             : #include "TFile.h"
      41             : #include "TMath.h"
      42             : #include "TSystem.h"
      43             : #include "AliSurveyObj.h"
      44             : #include "AliSurveyPoint.h"
      45             : #include "AliAlignObjParams.h"
      46             : #include "AliCDBStorage.h"
      47             : #include <TClonesArray.h>
      48             : #include <TFile.h>
      49             : #include "AliLog.h"
      50             : #include "AliCDBManager.h"
      51             : 
      52             : using std::cout;
      53             : using std::endl;
      54          12 : ClassImp(AliTPCAlign)
      55             : 
      56             : AliTPCAlign::AliTPCAlign() :
      57           0 :   TObject(),
      58           0 :   fFileLoc(0x0),
      59           0 :   fFileGlob(0x0),
      60           0 :   fTPCAlignObj(0x0),
      61           0 :   fX(),
      62           0 :   fA(),
      63           0 :   fY(),
      64           0 :   fDebug(0)
      65           0 : {
      66             :   //
      67             :   //  default constructor
      68             :   //
      69           0 : }   
      70             : //________________________________________________________________________
      71             : AliTPCAlign::AliTPCAlign(Int_t reportloc, Int_t reportglob) :
      72           0 :   TObject(),
      73           0 :   fFileLoc(0x0),
      74           0 :   fFileGlob(0x0),
      75           0 :   fTPCAlignObj(0x0),
      76           0 :   fX(6,1),
      77           0 :   fA(24,6),
      78           0 :   fY(24,1),
      79           0 :   fDebug(0)
      80           0 : {
      81             :   //
      82             :   // constructor - defines data files
      83             :   //
      84           0 :   fFileLoc = new Char_t[80];
      85           0 :   fFileGlob = new Char_t[80];
      86           0 :   Char_t path[50];
      87             :   //sprintf(path,gSystem->Getenv("ALICE_ROOT")); 
      88           0 :   snprintf(path,50,"%s",gSystem->Getenv("ALICE_ROOT"));
      89             :   //
      90             :   //sprintf(fFileLoc,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
      91           0 :   snprintf(fFileLoc,80,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
      92             :   //sprintf(fFileGlob,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
      93           0 :   snprintf(fFileGlob,80,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
      94             :   //
      95             : 
      96           0 : }
      97             : //_________________________________________________________________________
      98             : AliTPCAlign::AliTPCAlign(const AliTPCAlign &align) :
      99           0 :   TObject(),
     100           0 :   fFileLoc(0x0),
     101           0 :   fFileGlob(0x0),
     102           0 :   fTPCAlignObj(0x0),
     103           0 :   fX(),
     104           0 :   fA(),
     105           0 :   fY(),
     106           0 :   fDebug(0)
     107           0 : {
     108             :   //
     109             :   //  copy constructor - dummy
     110             :   //
     111           0 :   fDebug = align.fDebug;
     112           0 : }
     113             : //__________________________________________________________________________
     114             : AliTPCAlign & AliTPCAlign::operator =(const AliTPCAlign & align)
     115             : {
     116             :   //
     117             :   // assignment operator - dummy
     118             :   //
     119           0 :   if(this!=&align){
     120           0 :     fDebug=align.fDebug;
     121           0 :   }
     122           0 :   return (*this);
     123             : }
     124             : 
     125             : //__________________________________________________________________________
     126           0 : AliTPCAlign::~AliTPCAlign(){
     127             :   //
     128             :   // destructor
     129             :   //
     130           0 :   if(fTPCAlignObj) delete fTPCAlignObj;
     131           0 : }
     132             : //__________________________________________________________________________
     133             : Bool_t AliTPCAlign::LoadSurveyData(){
     134             :   //
     135             :   // for a time being it loads from the local file the surveyed point
     136             :   // and has the ideal points hardwired. I am waiting until Ricardo
     137             :   // completes his job
     138             :   // 
     139             : 
     140           0 :  AliSurveyObj * s1 = new AliSurveyObj();
     141           0 :  s1->FillFromLocalFile(fFileGlob);
     142             :  //
     143             :  Int_t numberPoints = 8;
     144             :  //
     145           0 :  TString pointNames[8] = {"T1Final_R04241","T1Final_R05241","T1Final_R06241",
     146           0 :                           "T1Final_R07241","T1Final_R08241","T1Final_R10241",
     147           0 :                           "T1Final_R11241","T1Final_R12241"};
     148             :  //
     149           0 :  Float_t surveyedPoints[8][3];
     150             :  AliSurveyPoint *currPoint;
     151             :  //
     152           0 :  for(Int_t i=0;i<numberPoints;i++){
     153             :    currPoint=0;
     154           0 :    currPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNames[i]);
     155             :    //
     156           0 :    if(currPoint){
     157           0 :      surveyedPoints[i][0]=currPoint->GetX();
     158           0 :      surveyedPoints[i][1]=currPoint->GetY();
     159           0 :      surveyedPoints[i][2]=currPoint->GetZ();
     160           0 :      if(fDebug)
     161           0 :      Printf("INFO: Point \"%s\" coordinates read.", pointNames[i].Data());
     162             :    }
     163             :    else {
     164           0 :      if(fDebug){
     165           0 :     Printf("ERROR: Essential point missing: \"%s\"", pointNames[i].Data());
     166           0 :     return 1;
     167             :      }
     168             :    }  
     169             :  }
     170             :  //
     171             :  //  Ideal points
     172             :  //
     173           0 :  Float_t idealPoints[8][3];
     174             :  //
     175           0 :  AliSurveyObj * s2 = new AliSurveyObj();
     176           0 :  s2->FillFromLocalFile(fFileLoc);
     177             :  //
     178           0 :  TString pointNamesL[8] ={"R04","R05","R06","R07","R08","R10","R11","R12"};
     179             :  //
     180             :   AliSurveyPoint *currPointL;
     181             :   //
     182           0 :  for(Int_t i=0;i<numberPoints;i++){
     183             :    currPointL=0;
     184           0 :    currPointL = (AliSurveyPoint *) s2->GetData()->FindObject(pointNamesL[i]);
     185           0 :    if(currPointL){
     186           0 :      idealPoints[i][0]=currPointL->GetY();
     187           0 :      idealPoints[i][1]=currPointL->GetZ();
     188           0 :      idealPoints[i][2]=currPointL->GetX();
     189           0 :           if(fDebug)
     190           0 :      Printf("INFO: Point \"%s\" coordinates read.", pointNamesL[i].Data());
     191             :    }
     192             :    else{
     193           0 :      if(fDebug){
     194           0 :     Printf("ERROR: Essential point missing: \"%s\"", pointNamesL[i].Data());
     195           0 :     return 1; }
     196             :    }
     197             :  }
     198             :  //
     199             :  // Create and fill matrices a & y
     200             :  //
     201           0 :  for(Int_t i = 0;i<numberPoints;i++){
     202           0 :    for(Int_t j=0;j<3;j++){
     203           0 :      fY(i*3+j,0)=surveyedPoints[i][j]-idealPoints[i][j];
     204             : 
     205             :    }
     206             :  }
     207           0 :  fA.Zero(); 
     208             :  //
     209             :  //
     210             :  // setting matrix a
     211             :  //
     212           0 :  for(Int_t i=0;i<numberPoints;i++){
     213           0 :    fA(3*i,0)=    -idealPoints[i][1];
     214           0 :    fA(3*i,1)=    idealPoints[i][2];
     215           0 :    fA(3*i,3)=1.; 
     216           0 :    fA(3*i+1,0)=    idealPoints[i][0];
     217           0 :    fA(3*i+1,2)=    -idealPoints[i][2];
     218           0 :    fA(3*i+1,4)=    1.;
     219           0 :    fA(3*i+2,1)=   -idealPoints[i][0];
     220           0 :    fA(3*i+2,2)=   idealPoints[i][1];
     221           0 :    fA(3*i+2,5)=1.; 
     222             :  }
     223             :  //
     224           0 :  delete s1;
     225             :  //
     226           0 :  return 0;
     227           0 : }
     228             : //_________________________________________________________________
     229             : Double_t AliTPCAlign::ComputeTransform(){
     230             :   //
     231             :   // Here simple matrix operations for the linear least square
     232             :   // The trigonometric function sin is approximated by the angle
     233             :   // and the cos by "1", because angles are very small (Y-convention!)
     234             :   // This secures the linearity of the problem
     235             :   // This method returns a sum of squares of residuals
     236             :   //
     237           0 :   TMatrixD tt1(TMatrixD::kInverted,(TMatrixD(fA,TMatrixD::kTransposeMult,fA)));
     238           0 :   fX=TMatrixD(tt1,TMatrixD::kMult,TMatrixD(fA,TMatrixD::kTransposeMult,fY));
     239             :   //
     240           0 :  TMatrixD Unit(24,24);
     241           0 :  Unit.UnitMatrix();
     242           0 :  TMatrixD xxt1(TMatrixD::kInverted,TMatrixD(fA,TMatrixD::kTransposeMult,fA));
     243           0 :  TMatrixD t(fA,TMatrixD::kMult,TMatrixD(xxt1,TMatrixD::kMultTranspose,fA));
     244           0 :  TMatrixD t2(Unit,TMatrixD::kMinus,t);
     245           0 :  TMatrixD chi2(fY,TMatrixD::kTransposeMult,TMatrixD(t2,TMatrixD::kMult,fY));
     246             :  //
     247             : 
     248           0 :  return chi2(0,0);
     249             :             
     250           0 : }
     251             : //_______________________________________________________________________
     252             : void AliTPCAlign::CreateAlignObj(){
     253             :   //
     254             :   // This method creates AliAlignObj and fills it with Euler angles
     255             :   // and shifts. The units are degrees and cm.
     256             :   // 
     257           0 :  fTPCAlignObj = new AliAlignObjParams();
     258           0 :  fTPCAlignObj->SetSymName("ALIC_1/TPC_M_1");
     259           0 :  fTPCAlignObj->SetVolUID(0);
     260           0 :  Double_t raddeg = TMath::RadToDeg();
     261             :  Double_t phi,theta,psi;
     262             :  //
     263           0 :  phi=fX(0,0)*raddeg;
     264           0 :  theta=fX(1,0)*raddeg;
     265           0 :  psi=fX(2,0)*raddeg;
     266             :  //
     267             :  Double_t dx,dy,dz;
     268           0 :  dx=fX(3,0)*100.;
     269           0 :  dy=fX(4,0)*100.;
     270           0 :  dz=fX(5,0)*100.;
     271           0 :  fTPCAlignObj->SetRotation(psi,theta,phi);
     272           0 :  fTPCAlignObj->SetTranslation(dx,dy,dz);
     273           0 :  fTPCAlignObj->Print("");
     274           0 : }
     275             : //______________________________________________________________________
     276             : void AliTPCAlign::Run(){
     277             :   //
     278             :   // runs the full chain
     279             :   //
     280           0 :   SetDebug(0);
     281           0 :   Bool_t flag = LoadSurveyData();
     282           0 :   if(flag) {
     283           0 :     cout<<"Missing points"<<endl;
     284           0 :     return;
     285             :   }
     286           0 :   Double_t chi2 = ComputeTransform();
     287           0 :   if(chi2>0.01) return;
     288           0 :   CreateAlignObj();
     289           0 :   StoreAlignObj();
     290             :   //
     291           0 : }
     292             : //_________________________________________________________________________
     293             : void AliTPCAlign::StoreAlignObj(){
     294             :   //
     295           0 : AliCDBManager* cdb = AliCDBManager::Instance();
     296           0 :  if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
     297             :  //
     298           0 : TClonesArray *array = new TClonesArray("AliAlignObjParams",1);
     299             : //
     300           0 :  Double_t shifts[3];
     301           0 :  Double_t rots[3];
     302             :  //
     303           0 :  fTPCAlignObj->GetPars(shifts,rots);
     304           0 :  new((*array)[0]) AliAlignObjParams(fTPCAlignObj->GetSymName(),0,shifts[0],
     305           0 :                    shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
     306             : 
     307             : //
     308             : // storing either in the OCDB or local file
     309             : //
     310           0 :   if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
     311             :     // save on file
     312             :     const char* filename = "TPCSurveyMisalignment.root";
     313           0 :     Char_t fullname[80];
     314             :     //sprintf(fullname,"%s/TPC/%s",gSystem->Getenv("ALICE_ROOT"),filename);
     315           0 :     snprintf(fullname,80,"%s/TPC/%s",gSystem->Getenv("ALICE_ROOT"),filename);
     316           0 :     TFile *f = new TFile(fullname,"RECREATE");
     317           0 :     if(!f){
     318           0 :       AliError("cannot open file for output\n");
     319           0 :       return;
     320             :     }
     321           0 :     AliInfo(Form("Saving alignment objects to the file %s", filename));
     322           0 :     f->cd();
     323           0 :     f->WriteObject(array,"TPCAlignObjs","kSingleKey");
     324           0 :     f->Close();
     325           0 :   }else{
     326             :     // save in CDB storage
     327             :     AliCDBStorage* storage;
     328             :     //
     329           0 :    TString Storage = gSystem->Getenv("STORAGE");
     330           0 :     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
     331           0 :       AliError(Form(
     332             :       "STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
     333           0 :       return;
     334             :     }
     335           0 :     storage = cdb->GetStorage(Storage.Data());
     336           0 :     if(!storage){
     337           0 :       AliError(Form("Unable to open storage %s\n",Storage.Data()));
     338           0 :       return;
     339             :     }
     340             :     //
     341           0 :     AliCDBMetaData* md = new AliCDBMetaData();
     342           0 :     md->SetResponsible("Marek Kowalski");
     343           0 :     md->SetComment("Full misalignment of entire TPC from surveyors");
     344           0 :     AliCDBId id("TPC/Align/Data",0,AliCDBRunRange::Infinity());
     345           0 :     storage->Put(array,id,md);
     346           0 :   }
     347             : 
     348           0 : }

Generated by: LCOV version 1.11