1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
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
22 Revision 1.2 2007/10/03 09:27:50 marian
23 Extra semicolon removed (Marian)
25 Revision 1.1 2007/10/01 14:12:45 kowal2
26 Class creating the aligmnent object fro the surveyor measurements.
31 // Creates the TPC align object
34 #include "AliTPCAlign.h"
35 #include "AliSurveyPoint.h"
36 #include "AliSurveyPoint.h"
39 #include "Riostream.h"
43 #include "AliSurveyObj.h"
44 #include "AliSurveyPoint.h"
45 #include "AliAlignObjParams.h"
46 #include "AliCDBStorage.h"
47 #include <TClonesArray.h>
50 #include "AliCDBManager.h"
54 AliTPCAlign::AliTPCAlign() :
65 // default constructor
68 //________________________________________________________________________
69 AliTPCAlign::AliTPCAlign(Int_t reportloc, Int_t reportglob) :
80 // constructor - defines data files
82 fFileLoc = new Char_t[80];
83 fFileGlob = new Char_t[80];
85 //sprintf(path,gSystem->Getenv("ALICE_ROOT"));
86 snprintf(path,50,"%s",gSystem->Getenv("ALICE_ROOT"));
88 //sprintf(fFileLoc,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
89 snprintf(fFileLoc,80,"%s/TPC/Survey_%d_TPC.txt",path,reportloc);
90 //sprintf(fFileGlob,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
91 snprintf(fFileGlob,80,"%s/TPC/Survey_%d_TPC.txt",path,reportglob);
95 //_________________________________________________________________________
96 AliTPCAlign::AliTPCAlign(const AliTPCAlign &align) :
107 // copy constructor - dummy
109 fDebug = align.fDebug;
111 //__________________________________________________________________________
112 AliTPCAlign & AliTPCAlign::operator =(const AliTPCAlign & align)
115 // assignment operator - dummy
123 //__________________________________________________________________________
124 AliTPCAlign::~AliTPCAlign(){
128 if(fTPCAlignObj) delete fTPCAlignObj;
130 //__________________________________________________________________________
131 Bool_t AliTPCAlign::LoadSurveyData(){
133 // for a time being it loads from the local file the surveyed point
134 // and has the ideal points hardwired. I am waiting until Ricardo
138 AliSurveyObj * s1 = new AliSurveyObj();
139 s1->FillFromLocalFile(fFileGlob);
141 Int_t numberPoints = 8;
143 TString pointNames[8] = {"T1Final_R04241","T1Final_R05241","T1Final_R06241",
144 "T1Final_R07241","T1Final_R08241","T1Final_R10241",
145 "T1Final_R11241","T1Final_R12241"};
147 Float_t surveyedPoints[8][3];
148 AliSurveyPoint *currPoint;
150 for(Int_t i=0;i<numberPoints;i++){
152 currPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNames[i]);
155 surveyedPoints[i][0]=currPoint->GetX();
156 surveyedPoints[i][1]=currPoint->GetY();
157 surveyedPoints[i][2]=currPoint->GetZ();
159 Printf("INFO: Point \"%s\" coordinates read.", pointNames[i].Data());
163 Printf("ERROR: Essential point missing: \"%s\"", pointNames[i].Data());
171 Float_t idealPoints[8][3];
173 AliSurveyObj * s2 = new AliSurveyObj();
174 s2->FillFromLocalFile(fFileLoc);
176 TString pointNamesL[8] ={"R04","R05","R06","R07","R08","R10","R11","R12"};
178 AliSurveyPoint *currPointL;
180 for(Int_t i=0;i<numberPoints;i++){
182 currPointL = (AliSurveyPoint *) s2->GetData()->FindObject(pointNamesL[i]);
184 idealPoints[i][0]=currPointL->GetY();
185 idealPoints[i][1]=currPointL->GetZ();
186 idealPoints[i][2]=currPointL->GetX();
188 Printf("INFO: Point \"%s\" coordinates read.", pointNamesL[i].Data());
192 Printf("ERROR: Essential point missing: \"%s\"", pointNamesL[i].Data());
197 // Create and fill matrices a & y
199 for(Int_t i = 0;i<numberPoints;i++){
200 for(Int_t j=0;j<3;j++){
201 fY(i*3+j,0)=surveyedPoints[i][j]-idealPoints[i][j];
210 for(Int_t i=0;i<numberPoints;i++){
211 fA(3*i,0)= -idealPoints[i][1];
212 fA(3*i,1)= idealPoints[i][2];
214 fA(3*i+1,0)= idealPoints[i][0];
215 fA(3*i+1,2)= -idealPoints[i][2];
217 fA(3*i+2,1)= -idealPoints[i][0];
218 fA(3*i+2,2)= idealPoints[i][1];
226 //_________________________________________________________________
227 Double_t AliTPCAlign::ComputeTransform(){
229 // Here simple matrix operations for the linear least square
230 // The trigonometric function sin is approximated by the angle
231 // and the cos by "1", because angles are very small (Y-convention!)
232 // This secures the linearity of the problem
233 // This method returns a sum of squares of residuals
235 TMatrixD tt1(TMatrixD::kInverted,(TMatrixD(fA,TMatrixD::kTransposeMult,fA)));
236 fX=TMatrixD(tt1,TMatrixD::kMult,TMatrixD(fA,TMatrixD::kTransposeMult,fY));
238 TMatrixD Unit(24,24);
240 TMatrixD xxt1(TMatrixD::kInverted,TMatrixD(fA,TMatrixD::kTransposeMult,fA));
241 TMatrixD t(fA,TMatrixD::kMult,TMatrixD(xxt1,TMatrixD::kMultTranspose,fA));
242 TMatrixD t2(Unit,TMatrixD::kMinus,t);
243 TMatrixD chi2(fY,TMatrixD::kTransposeMult,TMatrixD(t2,TMatrixD::kMult,fY));
249 //_______________________________________________________________________
250 void AliTPCAlign::CreateAlignObj(){
252 // This method creates AliAlignObj and fills it with Euler angles
253 // and shifts. The units are degrees and cm.
255 fTPCAlignObj = new AliAlignObjParams();
256 fTPCAlignObj->SetSymName("ALIC_1/TPC_M_1");
257 fTPCAlignObj->SetVolUID(0);
258 Double_t raddeg = TMath::RadToDeg();
259 Double_t phi,theta,psi;
262 theta=fX(1,0)*raddeg;
269 fTPCAlignObj->SetRotation(psi,theta,phi);
270 fTPCAlignObj->SetTranslation(dx,dy,dz);
271 fTPCAlignObj->Print("");
273 //______________________________________________________________________
274 void AliTPCAlign::Run(){
276 // runs the full chain
279 Bool_t flag = LoadSurveyData();
281 cout<<"Missing points"<<endl;
284 Double_t chi2 = ComputeTransform();
285 if(chi2>0.01) return;
290 //_________________________________________________________________________
291 void AliTPCAlign::StoreAlignObj(){
293 AliCDBManager* cdb = AliCDBManager::Instance();
294 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
296 TClonesArray *array = new TClonesArray("AliAlignObjParams",1);
301 fTPCAlignObj->GetPars(shifts,rots);
302 new((*array)[0]) AliAlignObjParams(fTPCAlignObj->GetSymName(),0,shifts[0],
303 shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
306 // storing either in the OCDB or local file
308 if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
310 const char* filename = "TPCSurveyMisalignment.root";
312 //sprintf(fullname,"%s/TPC/%s",gSystem->Getenv("ALICE_ROOT"),filename);
313 snprintf(fullname,80,"%s/TPC/%s",gSystem->Getenv("ALICE_ROOT"),filename);
314 TFile *f = new TFile(fullname,"RECREATE");
316 AliError("cannot open file for output\n");
319 AliInfo(Form("Saving alignment objects to the file %s", filename));
321 f->WriteObject(array,"TPCAlignObjs","kSingleKey");
324 // save in CDB storage
325 AliCDBStorage* storage;
327 TString Storage = gSystem->Getenv("STORAGE");
328 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
330 "STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
333 storage = cdb->GetStorage(Storage.Data());
335 AliError(Form("Unable to open storage %s\n",Storage.Data()));
339 AliCDBMetaData* md = new AliCDBMetaData();
340 md->SetResponsible("Marek Kowalski");
341 md->SetComment("Full misalignment of entire TPC from surveyors");
342 AliCDBId id("TPC/Align/Data",0,AliCDBRunRange::Infinity());
343 storage->Put(array,id,md);