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