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