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