1 #include "STEER/AliCDBManager.h"
2 #include "STEER/AliCDBStorage.h"
3 #include "STEER/AliCDBEntry.h"
4 #include "VZERO/AliVZEROSurveyData.h"
6 void VZEROSurveyToAlignment(){
8 // Macro to convert survey data into alignment data.
9 // The position of four fiducial marks, sticked on the
10 // entrance face of the V0C box is converted into the
11 // global position of the box. Positions given by surveyers
12 // are extracted from Survey Data Base.
14 if(!gGeoManager) TGeoManager::Import("geometry.root");
16 TClonesArray *array = new TClonesArray("AliAlignObjMatrix",10);
17 TClonesArray &mobj = *array;
19 Double_t l_vect[3]={0.,0.,0.}; // a local vector (the origin)
20 Double_t g_vect[3]; // vector corresp. to it in global RS
21 Double_t m_vect[3]; // vector corresp. to it in mother RS
23 gGeoManager->cd("/ALIC_1/VZERO_1/V0RI_1");
25 // ************* get global matrix *******************
26 TGeoHMatrix* g3 = gGeoManager->GetCurrentMatrix();
27 // this is used below as the ideal global matrix
29 // ************* get local matrix *******************
30 TGeoNode* n3 = gGeoManager->GetCurrentNode();
31 TGeoHMatrix* l3 = n3->GetMatrix();
33 // point coordinates in the global RS
34 g3->LocalToMaster(l_vect,g_vect);
35 cout<<endl<<"Point coordinates in the global RS: "<<
36 g_vect[0]<<" "<<g_vect[1]<<" "<<g_vect[2];
38 // point coordinates in the mother volume RS
39 l3->LocalToMaster(l_vect,m_vect);
40 cout<<endl<<"Point coordinates in the mother's volume RS: "<<
41 m_vect[0]<<" "<<m_vect[1]<<" "<<m_vect[2]<<" "<<endl;
43 // Hereafter are the four ideal fiducial marks on the V0C box,
44 // expressed in local coordinates and in cms - hard coded.
46 const Double_t xside = 22.627;
47 const Double_t yside = 22.627;
48 const Double_t zsize = 2.35;
49 const Double_t zoffset = 0.001;
51 const Double_t zdepth = zsize+zoffset;
52 Double_t A[3]={-xside,-yside,zdepth};
53 Double_t B[3]={xside,-yside,zdepth};
54 Double_t C[3]={xside,yside,zdepth};
55 Double_t D[3]={-xside,yside,zdepth};
57 TGeoTranslation* Atr = new TGeoTranslation("Atr",-xside,-yside,zdepth);
58 TGeoTranslation* Btr = new TGeoTranslation("Btr",xside,-yside,zdepth);
59 TGeoTranslation* Ctr = new TGeoTranslation("Ctr",xside,yside,zdepth);
60 TGeoTranslation* Dtr = new TGeoTranslation("Dtr",-xside,yside,zdepth);
64 // D-------------|-------------C
71 // ------------------|------------------> local x
78 // A-------------|-------------B
80 // local z exiting the plane of the screen
82 Double_t gA[3], gB[3], gC[3], gD[3];
83 g3->LocalToMaster(A,gA);
84 g3->LocalToMaster(B,gB);
85 g3->LocalToMaster(C,gC);
86 g3->LocalToMaster(D,gD);
87 cout<<endl<<"Ideal fiducial marks coordinates in the global RS:\n"<<
88 "A "<<gA[0]<<" "<<gA[1]<<" "<<gA[2]<<" "<<endl<<
89 "B "<<gB[0]<<" "<<gB[1]<<" "<<gB[2]<<" "<<endl<<
90 "C "<<gC[0]<<" "<<gC[1]<<" "<<gC[2]<<" "<<endl<<
91 "D "<<gD[0]<<" "<<gD[1]<<" "<<gD[2]<<" "<<endl;
93 // Retrieval of real survey data from CDB :
95 AliCDBManager *man = AliCDBManager::Instance();
96 AliCDBStorage *storLoc;
97 storLoc = man->GetStorage("local://$ALICE_ROOT");
100 entry = storLoc->Get("VZERO/Survey/Data", 0);
102 AliVZEROSurveyData * surveyda = 0;
103 if (entry) surveyda = (AliVZEROSurveyData*) entry->GetObject();
104 if (!surveyda) AliError("No survey data from survey database !");
106 Double_t ngA[3], ngB[3], ngC[3], ngD[3];
108 for(Int_t i=0; i<3; i++)
109 { ngA[i] = surveyda->GetPointA(i) ;
110 ngB[i] = surveyda->GetPointB(i) ;
111 ngC[i] = surveyda->GetPointC(i) ;
112 ngD[i] = surveyda->GetPointD(i) ; }
114 cout<<endl<<"Fiducial marks coordinates in the global RS given by survey:\n"<<
115 "A "<<ngA[0]<<" "<<ngA[1]<<" "<<ngA[2]<<" "<<endl<<
116 "B "<<ngB[0]<<" "<<ngB[1]<<" "<<ngB[2]<<" "<<endl<<
117 "C "<<ngC[0]<<" "<<ngC[1]<<" "<<ngC[2]<<" "<<endl<<
118 "D "<<ngD[0]<<" "<<ngD[1]<<" "<<ngD[2]<<" "<<endl;
122 // From the new fiducial marks coordinates derive back the new global position
123 // of the surveyed volume
124 //*** What follows is the actual survey-to-alignment procedure which assumes,
125 //*** as is the case of the present example, 4 fiducial marks
126 //*** at the corners of a square lying on a plane parallel to a surface
127 //*** of the surveyed box at a certain offset and with
128 //*** x and y sides parallel to the box's x and y axes.
129 //*** If the code below is placed in a separate class or method, it needs
130 //*** as input the four points and the offset from the origin (zdepth)
131 //*** The algorithm can be easily modified for different placement
132 //*** and/or cardinality of the fiducial marks.
134 Double_t ab[3], bc[3], n[3];
135 Double_t plane[4], s;
137 // first vector on the plane of the fiducial marks
139 ab[i] = ngB[i] - ngA[i];
142 // second vector on the plane of the fiducial marks
144 bc[i] = ngC[i] - ngB[i];
147 // vector normal to the plane of the fiducial marks obtained
148 // as cross product of the two vectors on the plane d0^d1
149 n[0] = ab[1] * bc[2] - ab[2] * bc[1];
150 n[1] = ab[2] * bc[0] - ab[0] * bc[2];
151 n[2] = ab[0] * bc[1] - ab[1] * bc[0];
153 Double_t sizen = TMath::Sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] );
155 s = Double_t(1.)/sizen ; //normalization factor
160 // plane expressed in the hessian normal form, see:
161 // http://mathworld.wolfram.com/HessianNormalForm.html
162 // the first three are the coordinates of the orthonormal vector
163 // the fourth coordinate is equal to the distance from the origin
167 plane[3] = -( plane[0] * ngA[0] + plane[1] * ngA[1] + plane[2] * ngA[2] );
168 // cout<<plane[0]<<" "<<plane[1]<<" "<<plane[2]<<" "<<plane[3]<<" "<<endl;
170 // The center of the square with fiducial marks as corners
171 // as the middle point of one diagonal - md
172 // Used below to get the center - orig - of the surveyed box
174 Double_t orig[3], md[3];
176 md[i] = (ngA[i] + ngC[i]) * 0.5;
181 orig[i] = md[i] - plane[i]*zdepth;
183 orig[1] = md[1] - plane[1]*zdepth;
184 orig[2] = md[2] - plane[2]*zdepth;
185 cout<<endl<<"Center of the box: "<<orig[0]<<" "<<orig[1]<<" "<<orig[2]<<endl;
187 // get x,y local directions needed to write the global rotation matrix
188 // for the surveyed volume by normalising vectors ab and bc
190 Double_t sx = TMath::Sqrt(ab[0]*ab[0] + ab[1]*ab[1] + ab[2]*ab[2]);
195 cout<<endl<<"x direction "<<ab[0]<<" "<<ab[1]<<" "<<ab[2]<<endl;
197 Double_t sy = TMath::Sqrt(bc[0]*bc[0] + bc[1]*bc[1] + bc[2]*bc[2]);
202 cout<<endl<<"y direction "<<bc[0]<<" "<<bc[1]<<" "<<bc[2]<<endl;
205 // the global matrix for the surveyed volume - ng
206 Double_t rot[9] = {ab[0],bc[0],plane[0],ab[1],bc[1],plane[1],ab[2],bc[2],plane[2]};
208 ng.SetTranslation(orig);
211 cout<<"\n********* global matrix inferred from surveyed fiducial marks ***********\n";
214 // To produce the alignment object for the given volume you would
215 // then do something like this:
216 // Calculate the global delta transformation as ng * g3^-1
218 TGeoHMatrix gdelta = g3->Inverse(); //now equal to the inverse of g3
219 gdelta.MultiplyLeft(&ng);
222 // if the volume is in the look-up table use something like this instead:
223 // AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,i);
225 //AliAlignObjMatrix* mobj[0] = new AliAlignObjMatrix("VZERO/V0C",index,gdelta,kTRUE);
227 new(mobj[0]) AliAlignObjMatrix("VZERO/V0C",index,gdelta,kTRUE);
229 if(!gSystem->Getenv("$TOCDB")){
231 TFile f("V0Survey.root","RECREATE");
232 if(!f) cerr<<"cannot open file for output\n";
234 f.WriteObject(array,"V0SurveyObjs ","kSingleKey");
237 // save in CDB storage
238 const char* Storage = gSystem->Getenv("$STORAGE");
239 AliCDBManager* cdb = AliCDBManager::Instance();
240 AliCDBStorage* storage = cdb->GetStorage(Storage);
241 AliCDBMetaData* md = new AliCDBMetaData();
242 md->SetResponsible("Brigitte Cheynis");
243 md->SetComment("Alignment objects for V0 survey");
244 md->SetAliRootVersion(gSystem->Getenv("$ARVERSION"));
245 AliCDBId id("VZERO/Align/Data",0,9999999);
246 storage->Put(array,id,md);