void SurveyToAlignmentExample(){ // Macro to show an example of conversion of survey data into alignment // data. The position of four fiducial marks, sticked above one surface // of a box is converted into the global position of the box. // gSystem->Load("libGeom"); TGeoManager *mgr = new TGeoManager("Geom","survey to alignment toy"); TGeoMedium *medium = 0; TGeoVolume *top = mgr->MakeBox("TOP",medium,250,250,250); mgr->SetTopVolume(top); // make shape components // ******** red outermost box *************** TGeoBBox *sbox0 = new TGeoBBox(200,200,50); TGeoVolume* box0 = new TGeoVolume("B0",sbox0); box0->SetVisDaughters(); box0->SetLineColor(2); //red top->AddNode(box0,1); // ******** green middle box *************** TGeoBBox *sbox1 = new TGeoBBox(180,180,40); TGeoVolume* box1 = new TGeoVolume("B1",sbox1); box1->SetLineColor(3);//green TGeoTranslation* tr = new TGeoTranslation("tr",10,0,0); box0->AddNode(box1,1,tr); // ******** bleu inner box *************** TGeoBBox *sbox2 = new TGeoBBox(160,160,30); TGeoVolume* box2 = new TGeoVolume("B2",sbox2); box2->SetLineColor(4);//bleu box1->AddNode(box2,1,tr); // ******** violet innermost box *************** Double_t zsize = 20.; TGeoBBox *sbox3 = new TGeoBBox(140,140,zsize); TGeoVolume* box3 = new TGeoVolume("B3",sbox3); box3->SetLineColor(6);//violet box2->AddNode(box3,1,tr); // Four fiducial marks on the box3, expressed in local coordinates // We imagine they are at 2mm above the upper surface of the volume // at the corners of a square of 200 cm side const Double_t xside = 100; const Double_t yside = 100; const Double_t zoffset = 0.2; const Double_t zdepth = zsize+zoffset; Double_t A[3]={-xside,-yside,zdepth}; Double_t B[3]={xside,-yside,zdepth}; Double_t C[3]={xside,yside,zdepth}; Double_t D[3]={-xside,yside,zdepth}; TGeoBBox *fmbox = new TGeoBBox(1,1,1); TGeoVolume* fm = new TGeoVolume("FM",fmbox); fm->SetLineColor(7);//color TGeoTranslation* Atr = new TGeoTranslation("Atr",-xside,-yside,zdepth); TGeoTranslation* Btr = new TGeoTranslation("Btr",xside,-yside,zdepth); TGeoTranslation* Ctr = new TGeoTranslation("Ctr",xside,yside,zdepth); TGeoTranslation* Dtr = new TGeoTranslation("Dtr",-xside,yside,zdepth); box3->AddNode(fm,1,Atr); box3->AddNode(fm,2,Btr); box3->AddNode(fm,3,Ctr); box3->AddNode(fm,4,Dtr); // ^ local y // | // D-------------|-------------C // | | | // | | | // | | | // | | | // | | | // | | | // ------------------|------------------> local x // | | | // | | | // | | | // | | | // | | | // | | | // A-------------|-------------B // // local z exiting the plane of the screen mgr->CloseGeometry(); mgr->GetTopVolume()->Draw(); mgr->SetVisOption(0); mgr->SetVisLevel(6); Int_t i; // ************* get ideal global matrix ******************* mgr->cd("TOP_1/B0_1/B1_1/B2_1/B3_1"); TGeoHMatrix g3 = *mgr->GetCurrentMatrix(); // !!don't declare g3 // as a pointer to mgr->GetCurrentMatrix(), mgr->cd("...") // would eventually change the content pointed by g3 behind your back // ************* get ideal local matrix ******************* TGeoNode* n3 = mgr->GetCurrentNode(); TGeoMatrix* l3 = n3->GetMatrix(); Double_t gA[3], gB[3], gC[3], gD[3]; // point coordinates in the global RS g3.LocalToMaster(A,gA); g3.LocalToMaster(B,gB); g3.LocalToMaster(C,gC); g3.LocalToMaster(D,gD); cout<MakePhysicalNode("TOP_1/B0_1/B1_1/B2_1/B3_1"); Double_t dphi = 3; // tilt by 3 degrees around z Double_t dz = 5; // shift by 5 cm along z TGeoRotation* rrot = new TGeoRotation("rot",dphi,0.,0.); TGeoCombiTrans localdelta = *(new TGeoCombiTrans(0.,0.,dz, rrot)); // new local matrix, representing real position TGeoHMatrix nlocal = *l3 * localdelta; TGeoHMatrix* nl3 = new TGeoHMatrix(nlocal); pn3->Align(nl3); //Let's get the global matrix for later comparison TGeoHMatrix* ng3 = pn3->GetMatrix(); //"real" global matrix, what survey sees printf("\n\n************ real global matrix **************\n"); ng3->Print(); Double_t ngA[3], ngB[3], ngC[3], ngD[3]; ng3->LocalToMaster(A,ngA); ng3->LocalToMaster(B,ngB); ng3->LocalToMaster(C,ngC); ng3->LocalToMaster(D,ngD); cout<1.e-8){ s = Double_t(1.)/sizen ; //normalization factor }else{ return 0; } // plane expressed in the hessian normal form, see: // http://mathworld.wolfram.com/HessianNormalForm.html // the first three are the coordinates of the orthonormal vector // the fourth coordinate is equal to the distance from the origin for(i=0;i<3;i++){ plane[i] = n[i] * s; } plane[3] = -( plane[0] * ngA[0] + plane[1] * ngA[1] + plane[2] * ngA[2] ); cout<1.e-8){ for(i=0;i<3;i++){ ab[i] /= sx; } cout<1.e-8){ for(i=0;i<3;i++){ bc[i] /= sy; } cout<Inverse(); //now equal to the inverse of g3 // gdelta.MultiplyLeft(&ng); // Int_t index = 0; // // if the volume is in the look-up table use something like this instead: // // AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,i); // AliAlignObjMatrix* mobj = new AliAlignObjMatrix("symname",index,gdelta,kTRUE); }