]>
Commit | Line | Data |
---|---|---|
d0c548dc | 1 | #include "STEER/AliCDBManager.h" |
2 | #include "STEER/AliCDBStorage.h" | |
3 | #include "STEER/AliCDBEntry.h" | |
4 | #include "VZERO/AliVZEROSurveyData.h" | |
5 | ||
6 | void VZEROSurveyToAlignment(){ | |
7 | ||
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. | |
13 | ||
14 | if(!gGeoManager) TGeoManager::Import("geometry.root"); | |
15 | ||
16 | TClonesArray *array = new TClonesArray("AliAlignObjMatrix",10); | |
17 | TClonesArray &mobj = *array; | |
18 | ||
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 | |
22 | ||
23 | gGeoManager->cd("/ALIC_1/VZERO_1/V0RI_1"); | |
24 | ||
25 | // ************* get global matrix ******************* | |
26 | TGeoHMatrix* g3 = gGeoManager->GetCurrentMatrix(); | |
27 | // this is used below as the ideal global matrix | |
28 | ||
29 | // ************* get local matrix ******************* | |
30 | TGeoNode* n3 = gGeoManager->GetCurrentNode(); | |
31 | TGeoHMatrix* l3 = n3->GetMatrix(); | |
32 | ||
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]; | |
37 | ||
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; | |
42 | ||
43 | // Hereafter are the four ideal fiducial marks on the V0C box, | |
44 | // expressed in local coordinates and in cms - hard coded. | |
45 | ||
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; | |
50 | ||
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}; | |
56 | ||
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); | |
61 | ||
62 | // ^ local y | |
63 | // | | |
64 | // D-------------|-------------C | |
65 | // | | | | |
66 | // | | | | |
67 | // | | | | |
68 | // | | | | |
69 | // | | | | |
70 | // | | | | |
71 | // ------------------|------------------> local x | |
72 | // | | | | |
73 | // | | | | |
74 | // | | | | |
75 | // | | | | |
76 | // | | | | |
77 | // | | | | |
78 | // A-------------|-------------B | |
79 | // | |
80 | // local z exiting the plane of the screen | |
81 | ||
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; | |
92 | ||
93 | // Retrieval of real survey data from CDB : | |
94 | ||
95 | AliCDBManager *man = AliCDBManager::Instance(); | |
96 | AliCDBStorage *storLoc; | |
97 | storLoc = man->GetStorage("local://$ALICE_ROOT"); | |
98 | ||
99 | AliCDBEntry *entry=0; | |
100 | entry = storLoc->Get("VZERO/Survey/Data", 0); | |
101 | ||
102 | AliVZEROSurveyData * surveyda = 0; | |
103 | if (entry) surveyda = (AliVZEROSurveyData*) entry->GetObject(); | |
104 | if (!surveyda) AliError("No survey data from survey database !"); | |
105 | ||
106 | Double_t ngA[3], ngB[3], ngC[3], ngD[3]; | |
107 | ||
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) ; } | |
113 | ||
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; | |
119 | ||
120 | delete entry; | |
121 | ||
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. | |
133 | ||
134 | Double_t ab[3], bc[3], n[3]; | |
135 | Double_t plane[4], s; | |
136 | ||
137 | // first vector on the plane of the fiducial marks | |
138 | for(i=0;i<3;i++){ | |
139 | ab[i] = ngB[i] - ngA[i]; | |
140 | } | |
141 | ||
142 | // second vector on the plane of the fiducial marks | |
143 | for(i=0;i<3;i++){ | |
144 | bc[i] = ngC[i] - ngB[i]; | |
145 | } | |
146 | ||
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]; | |
152 | ||
153 | Double_t sizen = TMath::Sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] ); | |
154 | if(sizen>1.e-8){ | |
155 | s = Double_t(1.)/sizen ; //normalization factor | |
156 | }else{ | |
157 | return 0; | |
158 | } | |
159 | ||
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 | |
164 | for(i=0;i<3;i++){ | |
165 | plane[i] = n[i] * s; | |
166 | } | |
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; | |
169 | ||
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 | |
173 | ||
174 | Double_t orig[3], md[3]; | |
175 | for(i=0;i<3;i++){ | |
176 | md[i] = (ngA[i] + ngC[i]) * 0.5; | |
177 | } | |
178 | ||
179 | // center of the box | |
180 | for(i=0;i<3;i++){ | |
181 | orig[i] = md[i] - plane[i]*zdepth; | |
182 | } | |
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; | |
186 | ||
187 | // get x,y local directions needed to write the global rotation matrix | |
188 | // for the surveyed volume by normalising vectors ab and bc | |
189 | ||
190 | Double_t sx = TMath::Sqrt(ab[0]*ab[0] + ab[1]*ab[1] + ab[2]*ab[2]); | |
191 | if(sx>1.e-8){ | |
192 | for(i=0;i<3;i++){ | |
193 | ab[i] /= sx; | |
194 | } | |
195 | cout<<endl<<"x direction "<<ab[0]<<" "<<ab[1]<<" "<<ab[2]<<endl; | |
196 | } | |
197 | Double_t sy = TMath::Sqrt(bc[0]*bc[0] + bc[1]*bc[1] + bc[2]*bc[2]); | |
198 | if(sy>1.e-8){ | |
199 | for(i=0;i<3;i++){ | |
200 | bc[i] /= sy; | |
201 | } | |
202 | cout<<endl<<"y direction "<<bc[0]<<" "<<bc[1]<<" "<<bc[2]<<endl; | |
203 | } | |
204 | ||
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]}; | |
207 | TGeoHMatrix ng; | |
208 | ng.SetTranslation(orig); | |
209 | ng.SetRotation(rot); | |
210 | ||
211 | cout<<"\n********* global matrix inferred from surveyed fiducial marks ***********\n"; | |
212 | ng.Print(); | |
213 | ||
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 | |
217 | ||
218 | TGeoHMatrix gdelta = g3->Inverse(); //now equal to the inverse of g3 | |
219 | gdelta.MultiplyLeft(&ng); | |
220 | Int_t index = 0; | |
221 | ||
222 | // if the volume is in the look-up table use something like this instead: | |
223 | // AliAlignObj::LayerToVolUID(AliAlignObj::kTOF,i); | |
224 | ||
225 | //AliAlignObjMatrix* mobj[0] = new AliAlignObjMatrix("VZERO/V0C",index,gdelta,kTRUE); | |
226 | ||
227 | new(mobj[0]) AliAlignObjMatrix("VZERO/V0C",index,gdelta,kTRUE); | |
228 | ||
229 | if(!gSystem->Getenv("$TOCDB")){ | |
230 | // save on file | |
231 | TFile f("V0Survey.root","RECREATE"); | |
232 | if(!f) cerr<<"cannot open file for output\n"; | |
233 | f.cd(); | |
234 | f.WriteObject(array,"V0SurveyObjs ","kSingleKey"); | |
235 | f.Close(); | |
236 | }else{ | |
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); | |
247 | } | |
248 | ||
249 | array->Delete(); | |
250 | ||
251 | } |