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 //TObject = align.TObject;
100 fFileGlob = align.fFileGlob;
101 fRepLoc = align.fRepLoc;
102 fRepGlob = align.fRepGlob;
105 fAlignACORDEObjArray = align.fAlignACORDEObjArray;
106 fDebug = align.fDebug;
109 //__________________________________________________________________________
110 AliACORDEAlign & AliACORDEAlign::operator =(const AliACORDEAlign &align)
114 // assignment operator - dummy
116 if (this != &align) ((AliACORDEAlign &) align).Copy(*this);
122 //__________________________________________________________________________
123 AliACORDEAlign::~AliACORDEAlign(){
127 if(fAlignACORDEObjArray) delete fAlignACORDEObjArray;
128 if(fFileGlob) delete[] fFileGlob;
129 if(fUser) delete[] fUser;
133 void AliACORDEAlign::LoadSurveyData()
137 // Create a new survey object and fill it.
139 AliSurveyObj * s1 = new AliSurveyObj();
143 // Filling from DCDB (via GRID)
144 s1->SetGridUser(fUser);
145 s1->Fill("ACORDE",1014872,1,fUser);
149 s1->FillFromLocalFile(fFileGlob);
155 //TObjArray* arr = s1->GetData();
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 ;
165 TString underscore = "_";
166 TString endInner = "_I";
167 TString endOuter = "_O";
168 TString endCenter = "_P";
171 TString surveynameInner;
172 TString surveynameOuter;
173 TString surveynameCenter;
175 //TString surveynameAngles;
177 TString pointNamesInner[60];
178 TString pointNamesOuter[60];
179 TString pointNamesCenter[60];
184 //for regular modules
185 for (Int_t ncolum=0; ncolum<6; ncolum++)
187 for (Int_t nrow=0; nrow<10; nrow++)
192 surveyname+=underscore;
195 surveynameInner=surveyname;
196 surveynameInner+=endInner;
198 surveynameOuter=surveyname;
199 surveynameOuter+=endOuter;
201 surveynameCenter=surveyname;
202 surveynameCenter+=endCenter;
204 pointNamesInner[nid] = surveynameInner;
205 pointNamesOuter[nid] = surveynameOuter;
206 pointNamesCenter[nid] = surveynameCenter;
213 AliSurveyPoint *InnerPoint;
214 AliSurveyPoint *OuterPoint
216 AliSurveyPoint *CenterPoint;
219 for(Int_t i=0;i<60;i++)
226 InnerPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesInner[i]);
227 OuterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesOuter[i]);
228 CenterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesCenter[i]);
232 if(InnerPoint && OuterPoint)
234 //Use center if it is available
237 fX(i+60,0) = CenterPoint->GetX()*100;
238 fX(i+60,1) = CenterPoint->GetY()*100;
239 fX(i+60,2) = CenterPoint->GetZ()*100;
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;
249 fX(i,0) = OuterPoint->GetX()*100;
250 fX(i,1) = OuterPoint->GetY()*100;
251 fX(i,2) = OuterPoint->GetZ()*100;
255 if(InnerPoint && CenterPoint)
258 fX(i+60,0) = CenterPoint->GetX()*100;
259 fX(i+60,1) = CenterPoint->GetY()*100;
260 fX(i+60,2) = CenterPoint->GetZ()*100;
262 fX(i,0) = InnerPoint->GetX()*100;
263 fX(i,1) = InnerPoint->GetY()*100;
264 fX(i,2) = InnerPoint->GetZ()*100;
268 if(OuterPoint && CenterPoint)
271 fX(i+60,0) = CenterPoint->GetX()*100;
272 fX(i+60,1) = CenterPoint->GetY()*100;
273 fX(i+60,2) = CenterPoint->GetZ()*100;
275 fX(i,0) = OuterPoint->GetX()*100;
276 fX(i,1) = OuterPoint->GetY()*100;
277 fX(i,2) = OuterPoint->GetZ()*100;
301 void AliACORDEAlign::ComputePosition()
305 //Residuals for rotations
311 for (Int_t imod=0; imod<60; imod++)
313 if(TMath::Abs(fX(imod+60,0)-fX(imod,0))>=0.000001)
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 )
320 resphi[imod] = 0.0-resiphi;
323 // for module with no measurements
330 if(imod>0 && imod <20)
332 resphi[imod] = resiphi + 45.0;
335 if(imod>=20 && imod <40)
337 resphi[imod] = -resiphi;
340 if(imod>=40 && imod <60)
342 resphi[imod] = resiphi - 45.0;
350 //Get the residuals for translations
352 AliCDBManager* cdb = AliCDBManager::Instance();
353 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
356 //AliCDBStorage* storage;
357 AliGeomManager::LoadGeometry();
361 TString basename = "ACORDE/Array";
364 // Get the ideal directly from the geometry
367 for (Int_t imod=0; imod<60; imod++)
371 cout<< symname << endl;
372 matrix = AliGeomManager::GetMatrix(symname);
373 tr=matrix->GetTranslation();
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];
390 fX(imod,0) = resphi[imod];
401 //______________________________________________________________________
402 void AliACORDEAlign::Run(){
404 // runs the full chain
407 //if(!LoadSurveyFromAlienFile("ACORDE",999999,1))
409 // cout<<"Missing points"<<endl;
414 //LoadSurveyfromLocalFile("ACORDE",99999,1);
420 //CreateACORDEAlignObjs();
425 //_________________________________________________________________________
427 void AliACORDEAlign::StoreAlignObj()
430 // Storing ACORDE alignment objects
433 AliCDBManager* cdb = AliCDBManager::Instance();
434 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
436 TClonesArray *array = new TClonesArray("AliAlignObjParams",60);
438 // storing either in the OCDB or local file
442 TString basename = "ACORDE/Array";
445 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
446 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
448 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.0;
450 for (Int_t imod=0; imod<60; imod++)
461 new((*array)[imod]) AliAlignObjParams(symname,volid,dx,dy,dz,dpsi,dtheta,dphi,kFALSE);
465 if( TString(gSystem->Getenv("TOCDB"))!= TString("kTRUE") )
471 const char* filename = "ACORDESurveyMisalignment.root";
476 snprintf(fullname,80,"%s",filename);
479 TFile *f = new TFile(fullname,"RECREATE");
484 AliError("cannot open file for output\n");
487 AliInfo(Form("Saving alignment objects to the file %s", filename));
489 f->WriteObject(array,"ACORDEAlignObjs","kSingleKey");
494 // save in CDB storage
495 AliCDBStorage* storage;
497 TString Storage = gSystem->Getenv("STORAGE");
498 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://"))
500 AliError(Form("STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
503 storage = cdb->GetStorage(Storage.Data());
506 AliError(Form("Unable to open storage %s\n",Storage.Data()));
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);