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