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