]>
Commit | Line | Data |
---|---|---|
d0c548dc | 1 | void VZEROSurveyToAlignment(){ |
2 | ||
3 | // Macro to convert survey data into alignment data. | |
4 | // The position of four fiducial marks, sticked on the | |
5 | // entrance face of the V0C box is converted into the | |
6 | // global position of the box. Positions given by surveyers | |
7 | // are extracted from Survey Data Base. | |
8 | ||
9 | if(!gGeoManager) TGeoManager::Import("geometry.root"); | |
10 | ||
86880713 | 11 | // TClonesArray *array = new TClonesArray("AliAlignObjMatrix",10); |
12 | TClonesArray *array = new TClonesArray("AliAlignObjParams",10); | |
d0c548dc | 13 | TClonesArray &mobj = *array; |
14 | ||
86880713 | 15 | Double_t l_vect[3]={0.,0.,0.}; // local vector (the origin) |
d0c548dc | 16 | Double_t g_vect[3]; // vector corresp. to it in global RS |
17 | Double_t m_vect[3]; // vector corresp. to it in mother RS | |
b2586b5f | 18 | |
86880713 | 19 | // ************* get global matrix g3 ******************* |
20 | // TGeoHMatrix *g3 = AliGeomManager::GetMatrix("VZERO/V0C"); | |
21 | TGeoHMatrix *g3 = gGeoManager->GetCurrentMatrix(); | |
22 | // this is used below as the IDEAL global matrix | |
d0c548dc | 23 | |
86880713 | 24 | // ************* get local matrix l3 ******************* |
d0c548dc | 25 | TGeoNode* n3 = gGeoManager->GetCurrentNode(); |
86880713 | 26 | TGeoHMatrix *l3 = n3->GetMatrix(); |
27 | ||
d0c548dc | 28 | // point coordinates in the global RS |
29 | g3->LocalToMaster(l_vect,g_vect); | |
86880713 | 30 | cout<<endl<<"Point coordinates in the global RS: " |
31 | <<g_vect[0]<<" "<<g_vect[1]<<" "<<g_vect[2]; | |
d0c548dc | 32 | |
33 | // point coordinates in the mother volume RS | |
34 | l3->LocalToMaster(l_vect,m_vect); | |
86880713 | 35 | cout<<endl<<"Point coordinates in the mother's volume RS: \n" |
36 | <<m_vect[0]<<" "<<m_vect[1]<<" "<<m_vect[2]<<" "<<endl; | |
d0c548dc | 37 | |
38 | // Hereafter are the four ideal fiducial marks on the V0C box, | |
39 | // expressed in local coordinates and in cms - hard coded. | |
40 | ||
41 | const Double_t xside = 22.627; | |
42 | const Double_t yside = 22.627; | |
43 | const Double_t zsize = 2.35; | |
44 | const Double_t zoffset = 0.001; | |
45 | ||
46 | const Double_t zdepth = zsize+zoffset; | |
47 | Double_t A[3]={-xside,-yside,zdepth}; | |
48 | Double_t B[3]={xside,-yside,zdepth}; | |
49 | Double_t C[3]={xside,yside,zdepth}; | |
50 | Double_t D[3]={-xside,yside,zdepth}; | |
51 | ||
52 | TGeoTranslation* Atr = new TGeoTranslation("Atr",-xside,-yside,zdepth); | |
53 | TGeoTranslation* Btr = new TGeoTranslation("Btr",xside,-yside,zdepth); | |
54 | TGeoTranslation* Ctr = new TGeoTranslation("Ctr",xside,yside,zdepth); | |
55 | TGeoTranslation* Dtr = new TGeoTranslation("Dtr",-xside,yside,zdepth); | |
56 | ||
57 | // ^ local y | |
58 | // | | |
59 | // D-------------|-------------C | |
60 | // | | | | |
61 | // | | | | |
62 | // | | | | |
63 | // | | | | |
64 | // | | | | |
65 | // | | | | |
66 | // ------------------|------------------> local x | |
67 | // | | | | |
68 | // | | | | |
69 | // | | | | |
70 | // | | | | |
71 | // | | | | |
72 | // | | | | |
73 | // A-------------|-------------B | |
74 | // | |
75 | // local z exiting the plane of the screen | |
76 | ||
77 | Double_t gA[3], gB[3], gC[3], gD[3]; | |
78 | g3->LocalToMaster(A,gA); | |
79 | g3->LocalToMaster(B,gB); | |
80 | g3->LocalToMaster(C,gC); | |
81 | g3->LocalToMaster(D,gD); | |
86880713 | 82 | cout<<endl<<"Ideal fiducial marks coordinates in the global RS: \n" |
83 | <<"A "<<gA[0]<<" "<<gA[1]<<" "<<gA[2]<<" "<<endl | |
84 | <<"B "<<gB[0]<<" "<<gB[1]<<" "<<gB[2]<<" "<<endl | |
85 | <<"C "<<gC[0]<<" "<<gC[1]<<" "<<gC[2]<<" "<<endl | |
86 | <<"D "<<gD[0]<<" "<<gD[1]<<" "<<gD[2]<<" "<<endl; | |
87 | cout<<endl; | |
d0c548dc | 88 | |
86880713 | 89 | // Retrieval of REAL survey data from ALICE Survey Data Depot : |
d0c548dc | 90 | |
b2586b5f | 91 | AliSurveyObj *so = new AliSurveyObj(); |
d0c548dc | 92 | |
b2586b5f | 93 | so->FillFromLocalFile("Survey_835615_V0.txt"); |
86880713 | 94 | Int_t size = so->GetEntries(); |
b2586b5f | 95 | |
96 | Printf("Title: \"%s\"", so->GetReportTitle().Data()); | |
97 | Printf("Date: \"%s\"", so->GetReportDate().Data()); | |
98 | Printf("Detector: \"%s\"", so->GetDetector().Data()); | |
99 | Printf("URL: \"%s\"", so->GetURL().Data()); | |
100 | Printf("Number: \"%d\"", so->GetReportNumber()); | |
101 | Printf("Version: \"%d\"", so->GetReportVersion()); | |
102 | Printf("Observations: \"%s\"", so->GetObservations().Data()); | |
103 | Printf("Coordinate System: \"%s\"", so->GetCoordSys().Data()); | |
104 | Printf("Measurement Units: \"%s\"", so->GetUnits().Data()); | |
105 | Printf("Nr Columns: \"%d\" \n", so->GetNrColumns()); | |
106 | ||
107 | TObjArray *colNames = so->GetColumnNames(); | |
108 | ||
109 | TObjArray *points = so->GetData(); | |
110 | const char namePoint[4] = "6001"; | |
111 | Double_t coordinates[4][3]; | |
112 | // Printf(" ******* %c ******* \n\n ", namePoint[0]); | |
113 | Printf("Relevant points to be used for alignment procedure (in mm):"); | |
114 | for (Int_t i = 0; i < points->GetEntries(); ++i) { | |
115 | if(((AliSurveyPoint *) points->At(i))->GetPointName()[0] == namePoint[0]) { | |
116 | Printf("Point %d --> \"%s\" %f %f %f ", i, | |
117 | ((AliSurveyPoint *) points->At(i))->GetPointName().Data(), | |
118 | ((AliSurveyPoint *) points->At(i))->GetX(), | |
119 | ((AliSurveyPoint *) points->At(i))->GetY(), | |
120 | ((AliSurveyPoint *) points->At(i))->GetZ() ); | |
121 | if(i > 10){ | |
122 | coordinates[i-11][0] = (AliSurveyPoint *) points->At(i))->GetX(); | |
123 | coordinates[i-11][1] = (AliSurveyPoint *) points->At(i))->GetY(); | |
124 | coordinates[i-11][2] = (AliSurveyPoint *) points->At(i))->GetZ(); } | |
125 | } | |
126 | } | |
127 | ||
d0c548dc | 128 | Double_t ngA[3], ngB[3], ngC[3], ngD[3]; |
129 | ||
86880713 | 130 | for(Int_t i=0; i<3; i++) |
b2586b5f | 131 | { ngA[i] = coordinates[0][i] / 10.0 ; |
bd20663b | 132 | ngD[i] = coordinates[1][i] / 10.0 ; |
133 | ngB[i] = coordinates[2][i] / 10.0 ; | |
134 | ngC[i] = coordinates[3][i] / 10.0 ; } | |
d0c548dc | 135 | |
86880713 | 136 | cout<<endl<<"Fiducial marks coordinates in the global RS given by surveyers: \n" |
137 | <<"A "<<ngA[0]<<" "<<ngA[1]<<" "<<ngA[2]<<" "<<endl | |
138 | <<"B "<<ngB[0]<<" "<<ngB[1]<<" "<<ngB[2]<<" "<<endl | |
139 | <<"C "<<ngC[0]<<" "<<ngC[1]<<" "<<ngC[2]<<" "<<endl | |
140 | <<"D "<<ngD[0]<<" "<<ngD[1]<<" "<<ngD[2]<<" "<<endl; | |
d0c548dc | 141 | |
d0c548dc | 142 | // From the new fiducial marks coordinates derive back the new global position |
143 | // of the surveyed volume | |
144 | //*** What follows is the actual survey-to-alignment procedure which assumes, | |
145 | //*** as is the case of the present example, 4 fiducial marks | |
146 | //*** at the corners of a square lying on a plane parallel to a surface | |
147 | //*** of the surveyed box at a certain offset and with | |
148 | //*** x and y sides parallel to the box's x and y axes. | |
149 | //*** If the code below is placed in a separate class or method, it needs | |
150 | //*** as input the four points and the offset from the origin (zdepth) | |
151 | //*** The algorithm can be easily modified for different placement | |
152 | //*** and/or cardinality of the fiducial marks. | |
153 | ||
154 | Double_t ab[3], bc[3], n[3]; | |
155 | Double_t plane[4], s; | |
156 | ||
157 | // first vector on the plane of the fiducial marks | |
158 | for(i=0;i<3;i++){ | |
159 | ab[i] = ngB[i] - ngA[i]; | |
160 | } | |
161 | ||
162 | // second vector on the plane of the fiducial marks | |
163 | for(i=0;i<3;i++){ | |
164 | bc[i] = ngC[i] - ngB[i]; | |
165 | } | |
166 | ||
167 | // vector normal to the plane of the fiducial marks obtained | |
168 | // as cross product of the two vectors on the plane d0^d1 | |
169 | n[0] = ab[1] * bc[2] - ab[2] * bc[1]; | |
170 | n[1] = ab[2] * bc[0] - ab[0] * bc[2]; | |
171 | n[2] = ab[0] * bc[1] - ab[1] * bc[0]; | |
172 | ||
173 | Double_t sizen = TMath::Sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] ); | |
174 | if(sizen>1.e-8){ | |
175 | s = Double_t(1.)/sizen ; //normalization factor | |
176 | }else{ | |
177 | return 0; | |
178 | } | |
179 | ||
180 | // plane expressed in the hessian normal form, see: | |
181 | // http://mathworld.wolfram.com/HessianNormalForm.html | |
182 | // the first three are the coordinates of the orthonormal vector | |
183 | // the fourth coordinate is equal to the distance from the origin | |
184 | for(i=0;i<3;i++){ | |
185 | plane[i] = n[i] * s; | |
186 | } | |
187 | plane[3] = -( plane[0] * ngA[0] + plane[1] * ngA[1] + plane[2] * ngA[2] ); | |
bd20663b | 188 | // cout<<plane[0]<<" "<<plane[1]<<" "<<plane[2]<<" "<<plane[3]<<" "<<endl; |
d0c548dc | 189 | |
190 | // The center of the square with fiducial marks as corners | |
191 | // as the middle point of one diagonal - md | |
192 | // Used below to get the center - orig - of the surveyed box | |
193 | ||
194 | Double_t orig[3], md[3]; | |
195 | for(i=0;i<3;i++){ | |
196 | md[i] = (ngA[i] + ngC[i]) * 0.5; | |
197 | } | |
198 | ||
199 | // center of the box | |
200 | for(i=0;i<3;i++){ | |
201 | orig[i] = md[i] - plane[i]*zdepth; | |
202 | } | |
bd20663b | 203 | |
d0c548dc | 204 | cout<<endl<<"Center of the box: "<<orig[0]<<" "<<orig[1]<<" "<<orig[2]<<endl; |
205 | ||
206 | // get x,y local directions needed to write the global rotation matrix | |
207 | // for the surveyed volume by normalising vectors ab and bc | |
208 | ||
209 | Double_t sx = TMath::Sqrt(ab[0]*ab[0] + ab[1]*ab[1] + ab[2]*ab[2]); | |
210 | if(sx>1.e-8){ | |
211 | for(i=0;i<3;i++){ | |
212 | ab[i] /= sx; | |
213 | } | |
b2586b5f | 214 | cout<<"x direction "<<ab[0]<<" "<<ab[1]<<" "<<ab[2]<<endl; |
d0c548dc | 215 | } |
216 | Double_t sy = TMath::Sqrt(bc[0]*bc[0] + bc[1]*bc[1] + bc[2]*bc[2]); | |
217 | if(sy>1.e-8){ | |
218 | for(i=0;i<3;i++){ | |
219 | bc[i] /= sy; | |
220 | } | |
b2586b5f | 221 | cout<<"y direction "<<bc[0]<<" "<<bc[1]<<" "<<bc[2]<<endl; |
d0c548dc | 222 | } |
223 | ||
224 | // the global matrix for the surveyed volume - ng | |
225 | Double_t rot[9] = {ab[0],bc[0],plane[0],ab[1],bc[1],plane[1],ab[2],bc[2],plane[2]}; | |
226 | TGeoHMatrix ng; | |
227 | ng.SetTranslation(orig); | |
228 | ng.SetRotation(rot); | |
229 | ||
86880713 | 230 | // cout<<"\n********* global matrix inferred from surveyed fiducial marks ***********\n"; |
231 | // ng.Print(); | |
d0c548dc | 232 | |
233 | // To produce the alignment object for the given volume you would | |
234 | // then do something like this: | |
235 | // Calculate the global delta transformation as ng * g3^-1 | |
236 | ||
237 | TGeoHMatrix gdelta = g3->Inverse(); //now equal to the inverse of g3 | |
238 | gdelta.MultiplyLeft(&ng); | |
239 | Int_t index = 0; | |
240 | ||
241 | // if the volume is in the look-up table use something like this instead: | |
ae079791 | 242 | // AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,i); |
d0c548dc | 243 | |
244 | //AliAlignObjMatrix* mobj[0] = new AliAlignObjMatrix("VZERO/V0C",index,gdelta,kTRUE); | |
86880713 | 245 | // new(mobj[0]) AliAlignObjMatrix("VZERO/V0C",index,gdelta,kTRUE); |
246 | ||
247 | new(mobj[0]) AliAlignObjParams("VZERO/V0C",index,gdelta,kTRUE); | |
d0c548dc | 248 | |
249 | if(!gSystem->Getenv("$TOCDB")){ | |
250 | // save on file | |
bd20663b | 251 | TFile f("V0Survey.root","RECREATE"); |
252 | if(!f) cerr<<"cannot open file for output\n"; | |
253 | f.cd(); | |
254 | f.WriteObject(array,"V0SurveyObjs ","kSingleKey"); | |
255 | f.Close(); | |
d0c548dc | 256 | }else{ |
257 | // save in CDB storage | |
bd20663b | 258 | AliCDBManager* cdb = AliCDBManager::Instance(); |
162637e4 | 259 | AliCDBStorage* storage = cdb->GetStorage("local://$ALICE_ROOT/OCDB"); |
bd20663b | 260 | AliCDBMetaData* mda = new AliCDBMetaData(); |
261 | mda->SetResponsible("Brigitte Cheynis"); | |
262 | mda->SetComment("Alignment objects for V0 survey"); | |
263 | mda->SetAliRootVersion(gSystem->Getenv("$ARVERSION")); | |
264 | AliCDBId id("VZERO/Align/Data",0,9999999); | |
265 | storage->Put(array,id,mda); | |
d0c548dc | 266 | } |
86880713 | 267 | |
268 | cout<<"\n********* Alignment constants contained in alignment object ***********\n"; | |
269 | cout<<"*************** deduced from surveyed fiducial marks : ****************\n"; | |
270 | array->Print(); | |
271 | ||
272 | AliAlignObjParams* itsalobj = (AliAlignObjParams*) mobj.UncheckedAt(0); | |
273 | itsalobj->ApplyToGeometry(); | |
274 | ||
d0c548dc | 275 | array->Delete(); |
276 | ||
277 | } |