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"));
84 //__________________________________________________________________________
85 AliACORDEAlign::~AliACORDEAlign(){
89 if(fAlignACORDEObjArray) delete fAlignACORDEObjArray;
90 if(fFileGlob) delete[] fFileGlob;
91 if(fUser) delete[] fUser;
95 void AliACORDEAlign::LoadSurveyData()
99 // Create a new survey object and fill it.
101 AliSurveyObj * s1 = new AliSurveyObj();
105 // Filling from DCDB (via GRID)
106 s1->SetGridUser(fUser);
107 s1->Fill("ACORDE",1014872,1,fUser);
111 s1->FillFromLocalFile(fFileGlob);
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 ;
127 TString underscore = "_";
128 TString endInner = "_I";
129 TString endOuter = "_O";
130 TString endCenter = "_P";
133 TString surveynameInner;
134 TString surveynameOuter;
135 TString surveynameCenter;
137 //TString surveynameAngles;
139 TString pointNamesInner[60];
140 TString pointNamesOuter[60];
141 TString pointNamesCenter[60];
146 //for regular modules
147 for (Int_t ncolum=0; ncolum<6; ncolum++)
149 for (Int_t nrow=0; nrow<10; nrow++)
154 surveyname+=underscore;
157 surveynameInner=surveyname;
158 surveynameInner+=endInner;
160 surveynameOuter=surveyname;
161 surveynameOuter+=endOuter;
163 surveynameCenter=surveyname;
164 surveynameCenter+=endCenter;
166 pointNamesInner[nid] = surveynameInner;
167 pointNamesOuter[nid] = surveynameOuter;
168 pointNamesCenter[nid] = surveynameCenter;
175 AliSurveyPoint *InnerPoint;
176 AliSurveyPoint *OuterPoint
178 AliSurveyPoint *CenterPoint;
181 for(Int_t i=0;i<60;i++)
188 InnerPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesInner[i]);
189 OuterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesOuter[i]);
190 CenterPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNamesCenter[i]);
194 if(InnerPoint && OuterPoint)
196 //Use center if it is available
199 fX(i+60,0) = CenterPoint->GetX()*100;
200 fX(i+60,1) = CenterPoint->GetY()*100;
201 fX(i+60,2) = CenterPoint->GetZ()*100;
205 //calculate center point
206 fX(i+60,0) = 100*(InnerPoint->GetX() + OuterPoint->GetX())/2.0;
207 fX(i+60,1) = 100*(InnerPoint->GetY() + OuterPoint->GetY())/2.0;
208 fX(i+60,2) = 100*(InnerPoint->GetZ() + OuterPoint->GetZ())/2.0;
211 fX(i,0) = OuterPoint->GetX()*100;
212 fX(i,1) = OuterPoint->GetY()*100;
213 fX(i,2) = OuterPoint->GetZ()*100;
217 if(InnerPoint && CenterPoint)
220 fX(i+60,0) = CenterPoint->GetX()*100;
221 fX(i+60,1) = CenterPoint->GetY()*100;
222 fX(i+60,2) = CenterPoint->GetZ()*100;
224 fX(i,0) = InnerPoint->GetX()*100;
225 fX(i,1) = InnerPoint->GetY()*100;
226 fX(i,2) = InnerPoint->GetZ()*100;
230 if(OuterPoint && CenterPoint)
233 fX(i+60,0) = CenterPoint->GetX()*100;
234 fX(i+60,1) = CenterPoint->GetY()*100;
235 fX(i+60,2) = CenterPoint->GetZ()*100;
237 fX(i,0) = OuterPoint->GetX()*100;
238 fX(i,1) = OuterPoint->GetY()*100;
239 fX(i,2) = OuterPoint->GetZ()*100;
263 void AliACORDEAlign::ComputePosition()
267 //Residuals for rotations
273 for (Int_t imod=0; imod<60; imod++)
275 if(TMath::Abs(fX(imod+60,0)-fX(imod,0))>=0.000001)
277 theta = (fX(imod+60,1)-fX(imod,1))/(fX(imod+60,0)-fX(imod,0));
278 resiphi = TMath::ATan(theta)*(180.0/TMath::Pi());
279 // calculate the residuals special modules
280 if(imod==0 || imod==9 || imod==50 || imod==59 )
282 resphi[imod] = 0.0-resiphi;
285 // for module with no measurements
292 if(imod>0 && imod <20)
294 resphi[imod] = resiphi + 45.0;
297 if(imod>=20 && imod <40)
299 resphi[imod] = -resiphi;
302 if(imod>=40 && imod <60)
304 resphi[imod] = resiphi - 45.0;
312 //Get the residuals for translations
314 AliCDBManager* cdb = AliCDBManager::Instance();
315 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
318 //AliCDBStorage* storage;
319 AliGeomManager::LoadGeometry();
323 TString basename = "ACORDE/Array";
326 // Get the ideal directly from the geometry
329 for (Int_t imod=0; imod<60; imod++)
333 cout<< symname << endl;
334 matrix = AliGeomManager::GetMatrix(symname);
335 tr=matrix->GetTranslation();
348 fX(imod+60,0)=fX(imod+60,0)- tr[0];
349 fX(imod+60,1)=fX(imod+60,1)- tr[1]- 4.0;
350 fX(imod+60,2)=fX(imod+60,2)- tr[2];
352 fX(imod,0) = resphi[imod];
363 //______________________________________________________________________
364 void AliACORDEAlign::Run(){
366 // runs the full chain
369 //if(!LoadSurveyFromAlienFile("ACORDE",999999,1))
371 // cout<<"Missing points"<<endl;
376 //LoadSurveyfromLocalFile("ACORDE",99999,1);
382 //CreateACORDEAlignObjs();
387 //_________________________________________________________________________
389 void AliACORDEAlign::StoreAlignObj()
392 // Storing ACORDE alignment objects
395 AliCDBManager* cdb = AliCDBManager::Instance();
396 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT");
398 TClonesArray *array = new TClonesArray("AliAlignObjParams",60);
400 // storing either in the OCDB or local file
404 TString basename = "ACORDE/Array";
407 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
408 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
410 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.0;
412 for (Int_t imod=0; imod<60; imod++)
423 new((*array)[imod]) AliAlignObjParams(symname,volid,dx,dy,dz,dpsi,dtheta,dphi,kFALSE);
427 if( TString(gSystem->Getenv("TOCDB"))!= TString("kTRUE") )
433 const char* filename = "ACORDESurveyMisalignment.root";
438 snprintf(fullname,80,"%s",filename);
441 TFile *f = new TFile(fullname,"RECREATE");
446 AliError("cannot open file for output\n");
449 AliInfo(Form("Saving alignment objects to the file %s", filename));
451 f->WriteObject(array,"ACORDEAlignObjs","kSingleKey");
456 // save in CDB storage
457 AliCDBStorage* storage;
459 TString Storage = gSystem->Getenv("STORAGE");
460 if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://"))
462 AliError(Form("STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
465 storage = cdb->GetStorage(Storage.Data());
468 AliError(Form("Unable to open storage %s\n",Storage.Data()));
472 AliCDBMetaData* md = new AliCDBMetaData();
473 md->SetResponsible("Pedro Podesta");
474 md->SetComment("Full misalignment of ACORDE from surveyors");
475 AliCDBId id("ACORDE/Align/Data",0,AliCDBRunRange::Infinity());
476 storage->Put(fAlignACORDEObjArray,id,md);