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)
113 // assignment operator - dummy
116 if (&align==this) return *this;
117 new (this) AliACORDEAlign(align);
121 //__________________________________________________________________________
122 AliACORDEAlign::~AliACORDEAlign(){
126 if(fAlignACORDEObjArray) delete fAlignACORDEObjArray;
127 if(fFileGlob) delete[] fFileGlob;
128 if(fUser) delete[] fUser;
132 void AliACORDEAlign::LoadSurveyData()
136 // Create a new survey object and fill it.
138 AliSurveyObj * s1 = new AliSurveyObj();
142 // Filling from DCDB (via GRID)
143 s1->SetGridUser(fUser);
144 s1->Fill("ACORDE",1014872,1,fUser);
148 s1->FillFromLocalFile(fFileGlob);
154 //TObjArray* arr = s1->GetData();
155 //cout<< "number of entries " << arr->GetEntries() <<endl;
156 //arr->UncheckedAt(0)->ClassName();
157 //AliSurveyPoint *sp0 = (AliSurveyPoint*) arr->UncheckedAt(0);
158 //cout << "point name " << sp0->GetPointName() << endl ;
164 TString underscore = "_";
165 TString endInner = "_I";
166 TString endOuter = "_O";
167 TString endCenter = "_P";
170 TString surveynameInner;
171 TString surveynameOuter;
172 TString surveynameCenter;
174 //TString surveynameAngles;
176 TString pointNamesInner[60];
177 TString pointNamesOuter[60];
178 TString pointNamesCenter[60];
183 //for regular modules
184 for (Int_t ncolum=0; ncolum<6; ncolum++)
186 for (Int_t nrow=0; nrow<10; nrow++)
191 surveyname+=underscore;
194 surveynameInner=surveyname;
195 surveynameInner+=endInner;
197 surveynameOuter=surveyname;
198 surveynameOuter+=endOuter;
200 surveynameCenter=surveyname;
201 surveynameCenter+=endCenter;
203 pointNamesInner[nid] = surveynameInner;
204 pointNamesOuter[nid] = surveynameOuter;
205 pointNamesCenter[nid] = surveynameCenter;
212 AliSurveyPoint *InnerPoint;
213 AliSurveyPoint *OuterPoint
215 AliSurveyPoint *CenterPoint;
218 for(Int_t i=0;i<60;i++)
225 InnerPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesInner[i]);
226 OuterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesOuter[i]);
227 CenterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesCenter[i]);
231 if(InnerPoint && OuterPoint)
233 //Use center if it is available
236 fX(i+60,0) = CenterPoint->GetX()*100;
237 fX(i+60,1) = CenterPoint->GetY()*100;
238 fX(i+60,2) = CenterPoint->GetZ()*100;
242 //calculate center point
243 fX(i+60,0) = 100*(InnerPoint->GetX() + OuterPoint->GetX())/2.0;
244 fX(i+60,1) = 100*(InnerPoint->GetY() + OuterPoint->GetY())/2.0;
245 fX(i+60,2) = 100*(InnerPoint->GetZ() + OuterPoint->GetZ())/2.0;
248 fX(i,0) = OuterPoint->GetX()*100;
249 fX(i,1) = OuterPoint->GetY()*100;
250 fX(i,2) = OuterPoint->GetZ()*100;
254 if(InnerPoint && CenterPoint)
257 fX(i+60,0) = CenterPoint->GetX()*100;
258 fX(i+60,1) = CenterPoint->GetY()*100;
259 fX(i+60,2) = CenterPoint->GetZ()*100;
261 fX(i,0) = InnerPoint->GetX()*100;
262 fX(i,1) = InnerPoint->GetY()*100;
263 fX(i,2) = InnerPoint->GetZ()*100;
267 if(OuterPoint && CenterPoint)
270 fX(i+60,0) = CenterPoint->GetX()*100;
271 fX(i+60,1) = CenterPoint->GetY()*100;
272 fX(i+60,2) = CenterPoint->GetZ()*100;
274 fX(i,0) = OuterPoint->GetX()*100;
275 fX(i,1) = OuterPoint->GetY()*100;
276 fX(i,2) = OuterPoint->GetZ()*100;
300 void AliACORDEAlign::ComputePosition()
304 //Residuals for rotations
310 for (Int_t imod=0; imod<60; imod++)
312 if(TMath::Abs(fX(imod+60,0)-fX(imod,0))>=0.000001)
314 theta = (fX(imod+60,1)-fX(imod,1))/(fX(imod+60,0)-fX(imod,0));
315 resiphi = TMath::ATan(theta)*(180.0/TMath::Pi());
316 // calculate the residuals special modules
317 if(imod==0 || imod==9 || imod==50 || imod==59 )
319 resphi[imod] = 0.0-resiphi;
322 // for module with no measurements
329 if(imod>0 && imod <20)
331 resphi[imod] = resiphi + 45.0;
334 if(imod>=20 && imod <40)
336 resphi[imod] = -resiphi;
339 if(imod>=40 && imod <60)
341 resphi[imod] = resiphi - 45.0;
349 //Get the residuals for translations
351 AliCDBManager* cdb = AliCDBManager::Instance();
352 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
355 //AliCDBStorage* storage;
356 AliGeomManager::LoadGeometry();
360 TString basename = "ACORDE/Array";
363 // Get the ideal directly from the geometry
366 for (Int_t imod=0; imod<60; imod++)
370 cout<< symname << endl;
371 matrix = AliGeomManager::GetMatrix(symname);
372 tr=matrix->GetTranslation();
385 fX(imod+60,0)=fX(imod+60,0)- tr[0];
386 fX(imod+60,1)=fX(imod+60,1)- tr[1]- 4.0;
387 fX(imod+60,2)=fX(imod+60,2)- tr[2];
389 fX(imod,0) = resphi[imod];
400 //______________________________________________________________________
401 void AliACORDEAlign::Run(){
403 // runs the full chain
406 //if(!LoadSurveyFromAlienFile("ACORDE",999999,1))
408 // cout<<"Missing points"<<endl;
413 //LoadSurveyfromLocalFile("ACORDE",99999,1);
419 //CreateACORDEAlignObjs();
424 //_________________________________________________________________________
426 void AliACORDEAlign::StoreAlignObj()
429 // Storing ACORDE alignment objects
432 AliCDBManager* cdb = AliCDBManager::Instance();
433 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
435 TClonesArray *array = new TClonesArray("AliAlignObjParams",60);
437 // storing either in the OCDB or local file
441 TString basename = "ACORDE/Array";
444 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
445 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
447 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.0;
449 for (Int_t imod=0; imod<60; imod++)
460 new((*array)[imod]) AliAlignObjParams(symname,volid,dx,dy,dz,dpsi,dtheta,dphi,kFALSE);
464 if( TString(gSystem->Getenv("TOCDB"))!= TString("kTRUE") )
470 const char* filename = "ACORDESurveyMisalignment.root";
475 snprintf(fullname,80,"%s",filename);
478 TFile *f = new TFile(fullname,"RECREATE");
483 AliError("cannot open file for output\n");
486 AliInfo(Form("Saving alignment objects to the file %s", filename));
488 f->WriteObject(array,"ACORDEAlignObjs","kSingleKey");
493 // save in CDB storage
494 AliCDBStorage* storage;
496 TString Storage = gSystem->Getenv("STORAGE");
497 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://"))
499 AliError(Form("STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
502 storage = cdb->GetStorage(Storage.Data());
505 AliError(Form("Unable to open storage %s\n",Storage.Data()));
509 AliCDBMetaData* md = new AliCDBMetaData();
510 md->SetResponsible("Pedro Podesta");
511 md->SetComment("Full misalignment of ACORDE from surveyors");
512 AliCDBId id("ACORDE/Align/Data",0,AliCDBRunRange::Infinity());
513 storage->Put(fAlignACORDEObjArray,id,md);