]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ACORDE/AliACORDEAlign.cxx
Fixing problems dscovered by test/gun
[u/mrichter/AliRoot.git] / ACORDE / AliACORDEAlign.cxx
CommitLineData
091f76f8 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#include "AliACORDEAlign.h"
17#include "TROOT.h"
18#include "Riostream.h"
19#include "TFile.h"
20#include "TMath.h"
21#include "TSystem.h"
22#include "AliSurveyObj.h"
23#include "AliAlignObjParams.h"
24#include "AliCDBStorage.h"
25#include <TClonesArray.h>
26#include <TFile.h>
27#include "AliLog.h"
28#include "AliCDBManager.h"
29#include "AliSurveyPoint.h"
30#include "AliACORDEConstants.h"
31
32// Class creating the ACORDE aligmnent objects
33// from the surveys done by surveyers at Point2.
34// Survey results are fetched from
35// Survey Depot, based on survey results
36// position of ACORDE alignment objects is computed.
37
38
39ClassImp(AliACORDEAlign)
40
41
42//________________________________________________________________________
43AliACORDEAlign::AliACORDEAlign() :
44 TObject(),
45 fFileGlob(0x0),
46 fRepLoc(0),
47 fRepGlob(0),
48 fUser(0x0),
49 fX(),
50 fAlignACORDEObjArray(0x0),
51 fDebug(0)
52{
53 //
54 // default constructor
55 //
56}
57
8f63aa5d 58AliACORDEAlign::AliACORDEAlign(/*Int_t reportloc,*/Int_t reportglob):
091f76f8 59 TObject(),
8f63aa5d 60 fFileGlob(0x0),
61 fRepLoc(0),
62 fRepGlob(0),
63 fUser(0x0),
091f76f8 64 fX(120,4),
65 fAlignACORDEObjArray(0x0),
66 fDebug(0)
67{
68
69//
70 // constructor
71 //fRepLoc = new reportloc[80];
72 //fRepGlob = new reportglob[80];
73 Char_t path[50];
8f63aa5d 74 fFileGlob = new Char_t[80];
75 fUser = new Char_t[10];
091f76f8 76 snprintf(path,50,gSystem->Getenv("ALICE_ROOT"));
77 //
78 snprintf(fFileGlob,80,"%s/ACORDE/Survey_%d_ACORDE.txt",path,reportglob);
79 //
10e05d9d 80 snprintf(fUser,10,gSystem->Getenv("alien_API_USER"));
091f76f8 81
82}
83
84
85
86
87AliACORDEAlign::AliACORDEAlign(const AliACORDEAlign &align):
88 TObject(),
89 fFileGlob(0x0),
90 fRepLoc(0),
91 fRepGlob(0),
92 fUser(0x0),
93 fX(),
94 fAlignACORDEObjArray(0x0),
95 fDebug(0)
96{
97 //
98 // default copy constructor
99fDebug = align.fDebug;
100}
101
102//__________________________________________________________________________
103AliACORDEAlign & AliACORDEAlign::operator =(const AliACORDEAlign &align)
104
105
106{
107 //
108 // assignment operator - dummy
109
110 //
111fDebug = align.fDebug;
112 return (*this);
113}
114
115//__________________________________________________________________________
116AliACORDEAlign::~AliACORDEAlign(){
117 //
118 // destructor
119 //
120if(fAlignACORDEObjArray) delete fAlignACORDEObjArray;
121 if(fFileGlob) delete[] fFileGlob;
122 if(fUser) delete[] fUser;
123}
124
125
126void AliACORDEAlign::LoadSurveyData()
127{
128
129//
130// Create a new survey object and fill it.
131
132AliSurveyObj * s1 = new AliSurveyObj();
133
134if(fRepLoc != 0)
135 {
136 // Filling from DCDB (via GRID)
137 s1->SetGridUser(fUser);
138 s1->Fill("ACORDE",1014872,1,fUser);
139 }
140 else
141 {
142 s1->FillFromLocalFile(fFileGlob);
143 }
144
145
146 //s1->GetEntries();
147 //s1->GetUnits();
0415bcff 148 //TObjArray* arr = s1->GetData();
091f76f8 149 //cout<< "number of entries " << arr->GetEntries() <<endl;
150 //arr->UncheckedAt(0)->ClassName();
151 //AliSurveyPoint *sp0 = (AliSurveyPoint*) arr->UncheckedAt(0);
152 //cout << "point name " << sp0->GetPointName() << endl ;
153
154
155//
156TString ML= "M" ;
157//TString PL= "P";
158TString underscore = "_";
159TString endInner = "_I";
160TString endOuter = "_O";
161TString endCenter = "_P";
162//
163TString surveyname;
164TString surveynameInner;
165TString surveynameOuter;
166TString surveynameCenter;
167
168//TString surveynameAngles;
169//
170TString pointNamesInner[60];
171TString pointNamesOuter[60];
172TString pointNamesCenter[60];
173
174//
175Int_t nid=0;
176//
177 //for regular modules
178 for (Int_t ncolum=0; ncolum<6; ncolum++)
179 {
180 for (Int_t nrow=0; nrow<10; nrow++)
181 {
182
183 surveyname=ML;
184 surveyname+=ncolum;
185 surveyname+=underscore;
186 surveyname+=nrow;
187
188 surveynameInner=surveyname;
189 surveynameInner+=endInner;
190
191 surveynameOuter=surveyname;
192 surveynameOuter+=endOuter;
193
194 surveynameCenter=surveyname;
195 surveynameCenter+=endCenter;
196
197 pointNamesInner[nid] = surveynameInner;
198 pointNamesOuter[nid] = surveynameOuter;
199 pointNamesCenter[nid] = surveynameCenter;
200 ++nid;
201 }
202 }
203
204
205//Read two points
206AliSurveyPoint *InnerPoint;
8f63aa5d 207AliSurveyPoint *OuterPoint
208;
091f76f8 209AliSurveyPoint *CenterPoint;
210
211
212 for(Int_t i=0;i<60;i++)
213 {
214
215 InnerPoint=0;
216 OuterPoint=0;
217 CenterPoint=0;
218
219 InnerPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesInner[i]);
220 OuterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesOuter[i]);
221 CenterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesCenter[i]);
222
223
224
225 if(InnerPoint && OuterPoint)
226 {
227 //Use center if it is available
228 if(CenterPoint)
229 {
230 fX(i+60,0) = CenterPoint->GetX()*100;
231 fX(i+60,1) = CenterPoint->GetY()*100;
232 fX(i+60,2) = CenterPoint->GetZ()*100;
233 }
234 else
235 {
236 //calculate center point
237 fX(i+60,0) = 100*(InnerPoint->GetX() + OuterPoint->GetX())/2.0;
238 fX(i+60,1) = 100*(InnerPoint->GetY() + OuterPoint->GetY())/2.0;
239 fX(i+60,2) = 100*(InnerPoint->GetZ() + OuterPoint->GetZ())/2.0;
240 }
241
242 fX(i,0) = OuterPoint->GetX()*100;
243 fX(i,1) = OuterPoint->GetY()*100;
244 fX(i,2) = OuterPoint->GetZ()*100;
245 }
246 else
247 {
248 if(InnerPoint && CenterPoint)
249 {
250
251 fX(i+60,0) = CenterPoint->GetX()*100;
252 fX(i+60,1) = CenterPoint->GetY()*100;
253 fX(i+60,2) = CenterPoint->GetZ()*100;
254
255 fX(i,0) = InnerPoint->GetX()*100;
256 fX(i,1) = InnerPoint->GetY()*100;
257 fX(i,2) = InnerPoint->GetZ()*100;
258 }
259 else
260 {
261 if(OuterPoint && CenterPoint)
262 {
263
264 fX(i+60,0) = CenterPoint->GetX()*100;
265 fX(i+60,1) = CenterPoint->GetY()*100;
266 fX(i+60,2) = CenterPoint->GetZ()*100;
267
268 fX(i,0) = OuterPoint->GetX()*100;
269 fX(i,1) = OuterPoint->GetY()*100;
270 fX(i,2) = OuterPoint->GetZ()*100;
271 }
272 else
273 {
274
275 fX(i+60,0) = -99.0;
276 fX(i+60,1) = -99.0;
277 fX(i+60,2) = -99.0;
278
279 fX(i,0) = -99.0;
280 fX(i,1) = -99.0;
281 fX(i,2) = -99.0;
282
283 }
284 }
285 }
286
287
288 }//ends for
289
290 delete s1;
291
292}
293
294void AliACORDEAlign::ComputePosition()
295{
296
297
298//Residuals for rotations
299
300Double_t theta;
301Double_t resphi[60];
302Double_t resiphi;
303
304for (Int_t imod=0; imod<60; imod++)
305 {
306 if(TMath::Abs(fX(imod+60,0)-fX(imod,0))>=0.000001)
307 {
308 theta = (fX(imod+60,1)-fX(imod,1))/(fX(imod+60,0)-fX(imod,0));
309 resiphi = TMath::ATan(theta)*(180.0/TMath::Pi());
310 // calculate the residuals special modules
311 if(imod==0 || imod==9 || imod==50 || imod==59 )
312 {
313 resphi[imod] = 0.0-resiphi;
314 continue;
315 }
316 // for module with no measurements
317 if(imod == 42 )
318 {
319 resphi[imod]= 0.0;
320 continue;
321 }
322 //face A
323 if(imod>0 && imod <20)
324 {
325 resphi[imod] = resiphi + 45.0;
326 }
327 //face B
328 if(imod>=20 && imod <40)
329 {
330 resphi[imod] = -resiphi;
331 }
332 //face C
333 if(imod>=40 && imod <60)
334 {
335 resphi[imod] = resiphi - 45.0;
336 }
337
338 }
339
340}
341
342
343//Get the residuals for translations
344
345AliCDBManager* cdb = AliCDBManager::Instance();
346if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
347cdb->SetRun(0);
348
349//AliCDBStorage* storage;
350AliGeomManager::LoadGeometry();
351
352
353TString symname;
354TString basename = "ACORDE/Array";
355
356
357// Get the ideal directly from the geometry
358 Double_t *tr;
359 TGeoHMatrix *matrix;
360 for (Int_t imod=0; imod<60; imod++)
361 {
362 symname = basename;
363 symname += imod;
364 cout<< symname << endl;
365 matrix = AliGeomManager::GetMatrix(symname);
366 tr=matrix->GetTranslation();
367
368 if(imod == 42)
369 {
370 fX(imod+60,0) = 0.0;
371 fX(imod+60,1) = 0.0;
372 fX(imod+60,2) = 0.0;
373 fX(imod,0) = 0.0;
374 fX(imod,1) = 0.0;
375 fX(imod,2) = 0.0;
376 continue;
377 }
378
379 fX(imod+60,0)=fX(imod+60,0)- tr[0];
380 fX(imod+60,1)=fX(imod+60,1)- tr[1]- 4.0;
381 fX(imod+60,2)=fX(imod+60,2)- tr[2];
382
383 fX(imod,0) = resphi[imod];
384 fX(imod,1) = 0.0;
385 fX(imod,2) = 0.0;
386
387 }
388
389
390
391
392}
393
394//______________________________________________________________________
395void AliACORDEAlign::Run(){
396 //
397 // runs the full chain
398 //
399
400 //if(!LoadSurveyFromAlienFile("ACORDE",999999,1))
401 //{
402 // cout<<"Missing points"<<endl;
403 //return;
404 //}
405 //else
406 //{
407 //LoadSurveyfromLocalFile("ACORDE",99999,1);
408 //}
409
410
411 LoadSurveyData();
412 ComputePosition();
413 //CreateACORDEAlignObjs();
414 StoreAlignObj();
415
416}
417
418//_________________________________________________________________________
419
420void AliACORDEAlign::StoreAlignObj()
421{
422 //
423 // Storing ACORDE alignment objects
424 //
425
426 AliCDBManager* cdb = AliCDBManager::Instance();
427 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
428
429 TClonesArray *array = new TClonesArray("AliAlignObjParams",60);
430 //
431 // storing either in the OCDB or local file
432 //
433
434 TString symname;
435 TString basename = "ACORDE/Array";
436 Int_t iIndex=0;
437
438 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
439 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
440
441 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.0;
442
443 for (Int_t imod=0; imod<60; imod++)
444 {
445
446 dphi = fX(imod,0);
447 dtheta = fX(imod,1);
448 dpsi = fX(imod,2);
449 dx = fX(imod+60,0);
450 dy = fX(imod+60,1);
451 dz = fX(imod+60,2);
452 symname = basename;
453 symname += imod;
454 new((*array)[imod]) AliAlignObjParams(symname,volid,dx,dy,dz,dpsi,dtheta,dphi,kFALSE);
455 }
456
457
458 if( TString(gSystem->Getenv("TOCDB"))!= TString("kTRUE") )
459 {
460
461
462
463 // save on file
464 const char* filename = "ACORDESurveyMisalignment.root";
465 Char_t fullname[80];
466
467
468
0415bcff 469 snprintf(fullname,80,filename);
091f76f8 470
471
472 TFile *f = new TFile(fullname,"RECREATE");
473
474
475 if(!f)
476 {
477 AliError("cannot open file for output\n");
478 return;
479 }
480 AliInfo(Form("Saving alignment objects to the file %s", filename));
481 f->cd();
482 f->WriteObject(array,"ACORDEAlignObjs","kSingleKey");
483 f->Close();
484 }
485 else
486 {
487 // save in CDB storage
488 AliCDBStorage* storage;
489 //
490 TString Storage = gSystem->Getenv("STORAGE");
491 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://"))
492 {
493 AliError(Form("STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
494 return;
495 }
496 storage = cdb->GetStorage(Storage.Data());
497 if(!storage)
498 {
499 AliError(Form("Unable to open storage %s\n",Storage.Data()));
500 return;
501 }
502 //
503 AliCDBMetaData* md = new AliCDBMetaData();
504 md->SetResponsible("Pedro Podesta");
505 md->SetComment("Full misalignment of ACORDE from surveyors");
506 AliCDBId id("ACORDE/Align/Data",0,AliCDBRunRange::Infinity());
507 storage->Put(fAlignACORDEObjArray,id,md);
508 }
509
510}