1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include "AliACORDEAlign.h"
18 #include "Riostream.h"
22 #include "AliSurveyObj.h"
23 #include "AliAlignObjParams.h"
24 #include "AliCDBStorage.h"
25 #include <TClonesArray.h>
28 #include "AliCDBManager.h"
29 #include "AliSurveyPoint.h"
30 #include "AliACORDEConstants.h"
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.
39 ClassImp(AliACORDEAlign)
42 //________________________________________________________________________
43 AliACORDEAlign::AliACORDEAlign() :
50 fAlignACORDEObjArray(0x0),
54 // default constructor
58 AliACORDEAlign::AliACORDEAlign(/*Int_t reportloc,*/Int_t reportglob):
65 fAlignACORDEObjArray(0x0),
71 //fRepLoc = new reportloc[80];
72 //fRepGlob = new reportglob[80];
74 fFileGlob = new Char_t[80];
75 fUser = new Char_t[10];
76 snprintf(path,50,"%s",gSystem->Getenv("ALICE_ROOT"));
78 snprintf(fFileGlob,80,"%s/ACORDE/Survey_%d_ACORDE.txt",path,reportglob);
80 snprintf(fUser,10,"%s",gSystem->Getenv("alien_API_USER"));
87 AliACORDEAlign::AliACORDEAlign(const AliACORDEAlign &align):
94 fAlignACORDEObjArray(0x0),
98 // default copy constructor
99 fDebug = align.fDebug;
102 //__________________________________________________________________________
103 AliACORDEAlign & AliACORDEAlign::operator =(const AliACORDEAlign &align)
108 // assignment operator - dummy
111 fDebug = align.fDebug;
115 //__________________________________________________________________________
116 AliACORDEAlign::~AliACORDEAlign(){
120 if(fAlignACORDEObjArray) delete fAlignACORDEObjArray;
121 if(fFileGlob) delete[] fFileGlob;
122 if(fUser) delete[] fUser;
126 void AliACORDEAlign::LoadSurveyData()
130 // Create a new survey object and fill it.
132 AliSurveyObj * s1 = new AliSurveyObj();
136 // Filling from DCDB (via GRID)
137 s1->SetGridUser(fUser);
138 s1->Fill("ACORDE",1014872,1,fUser);
142 s1->FillFromLocalFile(fFileGlob);
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 ;
158 TString underscore = "_";
159 TString endInner = "_I";
160 TString endOuter = "_O";
161 TString endCenter = "_P";
164 TString surveynameInner;
165 TString surveynameOuter;
166 TString surveynameCenter;
168 //TString surveynameAngles;
170 TString pointNamesInner[60];
171 TString pointNamesOuter[60];
172 TString pointNamesCenter[60];
177 //for regular modules
178 for (Int_t ncolum=0; ncolum<6; ncolum++)
180 for (Int_t nrow=0; nrow<10; nrow++)
185 surveyname+=underscore;
188 surveynameInner=surveyname;
189 surveynameInner+=endInner;
191 surveynameOuter=surveyname;
192 surveynameOuter+=endOuter;
194 surveynameCenter=surveyname;
195 surveynameCenter+=endCenter;
197 pointNamesInner[nid] = surveynameInner;
198 pointNamesOuter[nid] = surveynameOuter;
199 pointNamesCenter[nid] = surveynameCenter;
206 AliSurveyPoint *InnerPoint;
207 AliSurveyPoint *OuterPoint
209 AliSurveyPoint *CenterPoint;
212 for(Int_t i=0;i<60;i++)
219 InnerPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesInner[i]);
220 OuterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesOuter[i]);
221 CenterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesCenter[i]);
225 if(InnerPoint && OuterPoint)
227 //Use center if it is available
230 fX(i+60,0) = CenterPoint->GetX()*100;
231 fX(i+60,1) = CenterPoint->GetY()*100;
232 fX(i+60,2) = CenterPoint->GetZ()*100;
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;
242 fX(i,0) = OuterPoint->GetX()*100;
243 fX(i,1) = OuterPoint->GetY()*100;
244 fX(i,2) = OuterPoint->GetZ()*100;
248 if(InnerPoint && CenterPoint)
251 fX(i+60,0) = CenterPoint->GetX()*100;
252 fX(i+60,1) = CenterPoint->GetY()*100;
253 fX(i+60,2) = CenterPoint->GetZ()*100;
255 fX(i,0) = InnerPoint->GetX()*100;
256 fX(i,1) = InnerPoint->GetY()*100;
257 fX(i,2) = InnerPoint->GetZ()*100;
261 if(OuterPoint && CenterPoint)
264 fX(i+60,0) = CenterPoint->GetX()*100;
265 fX(i+60,1) = CenterPoint->GetY()*100;
266 fX(i+60,2) = CenterPoint->GetZ()*100;
268 fX(i,0) = OuterPoint->GetX()*100;
269 fX(i,1) = OuterPoint->GetY()*100;
270 fX(i,2) = OuterPoint->GetZ()*100;
294 void AliACORDEAlign::ComputePosition()
298 //Residuals for rotations
304 for (Int_t imod=0; imod<60; imod++)
306 if(TMath::Abs(fX(imod+60,0)-fX(imod,0))>=0.000001)
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 )
313 resphi[imod] = 0.0-resiphi;
316 // for module with no measurements
323 if(imod>0 && imod <20)
325 resphi[imod] = resiphi + 45.0;
328 if(imod>=20 && imod <40)
330 resphi[imod] = -resiphi;
333 if(imod>=40 && imod <60)
335 resphi[imod] = resiphi - 45.0;
343 //Get the residuals for translations
345 AliCDBManager* cdb = AliCDBManager::Instance();
346 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
349 //AliCDBStorage* storage;
350 AliGeomManager::LoadGeometry();
354 TString basename = "ACORDE/Array";
357 // Get the ideal directly from the geometry
360 for (Int_t imod=0; imod<60; imod++)
364 cout<< symname << endl;
365 matrix = AliGeomManager::GetMatrix(symname);
366 tr=matrix->GetTranslation();
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];
383 fX(imod,0) = resphi[imod];
394 //______________________________________________________________________
395 void AliACORDEAlign::Run(){
397 // runs the full chain
400 //if(!LoadSurveyFromAlienFile("ACORDE",999999,1))
402 // cout<<"Missing points"<<endl;
407 //LoadSurveyfromLocalFile("ACORDE",99999,1);
413 //CreateACORDEAlignObjs();
418 //_________________________________________________________________________
420 void AliACORDEAlign::StoreAlignObj()
423 // Storing ACORDE alignment objects
426 AliCDBManager* cdb = AliCDBManager::Instance();
427 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
429 TClonesArray *array = new TClonesArray("AliAlignObjParams",60);
431 // storing either in the OCDB or local file
435 TString basename = "ACORDE/Array";
438 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
439 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
441 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.0;
443 for (Int_t imod=0; imod<60; imod++)
454 new((*array)[imod]) AliAlignObjParams(symname,volid,dx,dy,dz,dpsi,dtheta,dphi,kFALSE);
458 if( TString(gSystem->Getenv("TOCDB"))!= TString("kTRUE") )
464 const char* filename = "ACORDESurveyMisalignment.root";
469 snprintf(fullname,80,"%s",filename);
472 TFile *f = new TFile(fullname,"RECREATE");
477 AliError("cannot open file for output\n");
480 AliInfo(Form("Saving alignment objects to the file %s", filename));
482 f->WriteObject(array,"ACORDEAlignObjs","kSingleKey");
487 // save in CDB storage
488 AliCDBStorage* storage;
490 TString Storage = gSystem->Getenv("STORAGE");
491 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://"))
493 AliError(Form("STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
496 storage = cdb->GetStorage(Storage.Data());
499 AliError(Form("Unable to open storage %s\n",Storage.Data()));
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);