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