1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 //-----------------------------------------------------------------------------
17 /// \class AliMUONSurveyObj
18 /// Base class for the survey processing of the ALICE DiMuon spectrometer
20 /// This base object provides methods to process the survey+photogrammetry
21 /// data of the Chambers (frames) and Detection Elements of the DiMuon
22 /// Spectrometer and calculate their misalignments.
24 /// \author Javier Castillo
25 //-----------------------------------------------------------------------------
31 #include "TGeoMatrix.h"
37 #include "TGraph2DErrors.h"
41 #include "AliSurveyPoint.h"
43 #include "AliMUONSurveyObj.h"
44 #include "AliMUONSurveyUtil.h"
46 void SurveyFcn(int &npar, double *g, double &f, double *par, int iflag);
49 ClassImp(AliMUONSurveyObj)
52 AliMUONSurveyObj::AliMUONSurveyObj()
60 , fOwnerLocalTrf(kFALSE)
61 , fOwnerAlignTrf(kTRUE)
62 , fOwnerBaseTrf(kFALSE)
72 /// Default constructor
74 fSTargets = new TObjArray();
75 fSTargets->SetOwner(kFALSE);
76 fGBTargets = new TObjArray();
77 fGBTargets->SetOwner(kFALSE);
78 fLBTargets = new TObjArray();
79 fLBTargets->SetOwner(kFALSE);
81 fAlignTrf = new TGeoCombiTrans();
83 fFitter = new TFitter(100);
86 AliMUONSurveyObj::~AliMUONSurveyObj() {
104 if(fOwnerLocalTrf && fLocalTrf) {
108 if(fOwnerAlignTrf && fAlignTrf) {
112 if(fOwnerBaseTrf && fBaseTrf) {
122 void AliMUONSurveyObj::AddStickerTarget(AliSurveyPoint *stPoint){
123 fSTargets->Add(stPoint);
126 void AliMUONSurveyObj::AddGButtonTarget(AliSurveyPoint *btPoint){
127 fGBTargets->Add(btPoint);
130 void AliMUONSurveyObj::AddLButtonTarget(AliSurveyPoint *btPoint){
131 fLBTargets->Add(btPoint);
134 void AliMUONSurveyObj::AddLButtonTarget(TVector3 *btVector){
135 fLBTargets->Add(btVector);
138 Int_t AliMUONSurveyObj::AddStickerTargets(TObjArray *pArray, TString stBaseName, Int_t lTargetMax){
140 AliError(Form("Survey points array is empty %p!",pArray));
143 if (stBaseName.IsNull()) {
144 AliError(Form("Need base name for sticker targets %s!",stBaseName.Data()));
149 AliSurveyPoint *pointSST = 0x0;
153 for (int iPoint=0; iPoint<lTargetMax; iPoint++) {
154 TString stFullName(stBaseName);
155 stNumber = Form("%d",iPoint+1);
156 if(lTargetMax>9&&iPoint+1<10) {
159 stFullName+=stNumber;
161 pointSST = (AliSurveyPoint *)pArray->FindObject(stFullName.Data());
164 AddStickerTarget(pointSST);
165 AliInfo(Form("Added survey sticker target %s at index %d",pointSST->GetName(),stIndex));
170 AliInfo(Form("Found %d sticker targets with base name %s",fSTargets->GetEntries(),stBaseName.Data()));
174 Int_t AliMUONSurveyObj::AddGButtonTargets(TObjArray *pArray, TString btBaseName, Int_t lTargetMax){
175 printf("%s \n",btBaseName.Data());
177 AliError(Form("Survey points array is empty %p!",pArray));
180 if (btBaseName.IsNull()) {
181 AliError(Form("Need base name for button targets %s!",btBaseName.Data()));
186 AliSurveyPoint *pointSBT = 0x0;
190 for (int iPoint=0; iPoint<lTargetMax; iPoint++) {
191 TString btFullName(btBaseName);
192 btNumber = Form("%d",iPoint+1);
193 if(lTargetMax>9&&iPoint+1<10) {
196 btFullName+=btNumber;
197 printf("%s \n",btFullName.Data());
198 pointSBT = (AliSurveyPoint *)pArray->FindObject(btFullName.Data());
201 AddGButtonTarget(pointSBT);
202 AliInfo(Form("Added survey button target %s at index %d",pointSBT->GetName(),btIndex));
207 AliInfo(Form("Found %d button targets with base name %s",fGBTargets->GetEntries(),btBaseName.Data()));
211 Int_t AliMUONSurveyObj::AddLButtonTargets(TObjArray *pArray, TString btBaseName, Int_t lTargetMax){
212 printf("%s \n",btBaseName.Data());
214 AliError(Form("Local points array is empty %p!",pArray));
217 if (btBaseName.IsNull()) {
218 AliError(Form("Need base name for button targets %s!",btBaseName.Data()));
223 AliSurveyPoint *pointSBT = 0x0;
227 for (int iPoint=0; iPoint<lTargetMax; iPoint++) {
228 TString btFullName(btBaseName);
229 btNumber = Form("%d",iPoint+1);
230 if(lTargetMax>9&&iPoint+1<10) {
233 btFullName+=btNumber;
234 printf("%s \n",btFullName.Data());
235 pointSBT = (AliSurveyPoint *)pArray->FindObject(btFullName.Data());
238 AddLButtonTarget(pointSBT);
239 AliInfo(Form("Added local button target %s at index %d",pointSBT->GetName(),btIndex));
244 AliInfo(Form("Found %d local button targets with base name %s",fLBTargets->GetEntries(),btBaseName.Data()));
248 Int_t AliMUONSurveyObj::GetNStickerTargets() {
249 return fSTargets->GetEntriesFast();
252 AliSurveyPoint* AliMUONSurveyObj::GetStickerTarget(Int_t stIndex){
253 if (stIndex<0||stIndex>=fSTargets->GetEntriesFast()) {
254 AliError(Form("No sticker target at index %d",stIndex));
258 return (AliSurveyPoint*)fSTargets->At(stIndex);
262 Int_t AliMUONSurveyObj::GetNGButtonTargets() {
263 return fGBTargets->GetEntriesFast();
266 AliSurveyPoint* AliMUONSurveyObj::GetGButtonTarget(Int_t btIndex){
267 if (btIndex<0||btIndex>=fGBTargets->GetEntriesFast()) {
268 AliError(Form("No surveyed button target at index %d",btIndex));
272 return (AliSurveyPoint*)fGBTargets->At(btIndex);
276 Int_t AliMUONSurveyObj::GetNLButtonTargets() {
277 return fGBTargets->GetEntriesFast();
280 AliSurveyPoint* AliMUONSurveyObj::GetLButtonTarget(Int_t btIndex){
281 if (btIndex<0||btIndex>=fLBTargets->GetEntriesFast()) {
282 AliError(Form("No surveyed button target at index %d",btIndex));
286 if(fLBTargets->At(btIndex)->IsA()==TVector3::Class()){
287 TVector3 *lBT = (TVector3*)fLBTargets->At(btIndex);
289 return (new AliSurveyPoint(TString("local"),(float)lBT->X(),(float)lBT->Y(),(float)lBT->Z(),(float)0.,(float)0.,(float)0.,'B',kTRUE));
290 } else if(fLBTargets->At(btIndex)->IsA()==AliSurveyPoint::Class()) {
291 AliSurveyPoint *lBT = (AliSurveyPoint*)fLBTargets->At(btIndex);
294 AliError(Form("Unexpected class %s ! Valid classes are TVector3 or AliSurveyPoint",fLBTargets->At(btIndex)->ClassName()));
300 void AliMUONSurveyObj::SetPlane(TString pName, Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax){
305 fPlane = new TF2(pName,this,&AliMUONSurveyObj::eqPlane,xMin,xMax,yMin,yMax,3,"AliMUONSurveyObj","eqPlane");
308 void AliMUONSurveyObj::SetPlaneParameters(Double_t p0, Double_t p1, Double_t p2) {
310 AliError("Must use SetPlane before SetPlaneParameters!!!");
313 fPlane->SetParameter(0,p0);
314 fPlane->SetParameter(1,p1);
315 fPlane->SetParameter(2,p2);
319 void AliMUONSurveyObj::DrawSTargets() {
321 TGraph2DErrors *gST = new TGraph2DErrors(3);
322 AliSurveyPoint *pST = 0x0;
323 for (Int_t iPoint=0; iPoint<GetNStickerTargets(); iPoint++) {
324 pST = GetStickerTarget(iPoint);
325 // pST->PrintPoint();
326 gST->SetPoint(iPoint,pST->GetX(),pST->GetY(),pST->GetZ());
327 gST->SetPointError(iPoint,pST->GetPrecisionX(),pST->GetPrecisionY(),pST->GetPrecisionZ());
329 gST->DrawClone("P0");
331 if (gST) gST->Delete();
334 Double_t AliMUONSurveyObj::FitPlane() {
336 AliError("Must use SetPlane before FitPlane!!!");
339 if (fSTargets->GetEntriesFast()<3) {
340 AliError("Not enough sticker targets (%d) for plane fitting!!!");
344 Double_t pl[3] = {0};
345 Double_t pg[3] = {0};
347 TGraph2DErrors *gST = new TGraph2DErrors(3);
348 AliSurveyPoint *pST = 0x0;
349 for (Int_t iPoint=0; iPoint<GetNStickerTargets(); iPoint++) {
350 pST = GetStickerTarget(iPoint);
351 // pST->PrintPoint();
355 fBaseTrf->MasterToLocal(pg,pl);
356 gST->SetPoint(iPoint,pl[0],pl[1],pl[2]);
357 printf("%d %f %f %f\n",iPoint,pl[0],pl[1],pl[2]);
358 gST->SetPointError(iPoint,pST->GetPrecisionX(),pST->GetPrecisionY(),pST->GetPrecisionZ());
362 if (gST) gST->Delete();
364 return fPlane->GetChisquare();
367 Double_t AliMUONSurveyObj::SurveyChi2(Double_t *par){
369 TGeoTranslation transTemp;
370 TGeoRotation rotTemp;
371 TGeoCombiTrans trfTemp;
375 trfTemp.SetTranslation(transTemp);
376 trfTemp.SetRotation(rotTemp);
378 trfTemp.RotateZ(TMath::RadToDeg()*par[5]);
379 trfTemp.RotateY(TMath::RadToDeg()*par[4]);
380 trfTemp.RotateX(TMath::RadToDeg()*par[3]);
381 trfTemp.SetTranslation(par[0],par[1],par[2]);
383 TGeoHMatrix matGlo = (*fBaseTrf)*trfTemp;
384 TGeoCombiTrans trfGlo(matGlo);
386 Double_t pl[3] = {0};
387 Double_t pg[3] = {0};
389 for(Int_t iPoint=0; iPoint<fGBTargets->GetEntries(); iPoint++){
390 AliSurveyPoint *gBT = (AliSurveyPoint*)fGBTargets->At(iPoint);
391 if(fLBTargets->At(iPoint)->IsA()==TVector3::Class()){
392 TVector3 *lBT = (TVector3*)fLBTargets->At(iPoint);
396 } else if(fLBTargets->At(iPoint)->IsA()==AliSurveyPoint::Class()) {
397 AliSurveyPoint *lBT = (AliSurveyPoint*)fLBTargets->At(iPoint);
402 AliError(Form("Unexpected class %s ! Valid classes are TVector3 or AliSurveyPoint",fLBTargets->At(iPoint)->ClassName()));
406 trfGlo.LocalToMaster(pl, pg);
407 // printf("%d %f %f %f\n",iPoint,pg[0],pg[1],pg[2]);
408 if(fLBTargets->At(iPoint)->IsA()==TVector3::Class()){
409 lChi2 += (pg[0]-gBT->GetX())*(pg[0]-gBT->GetX())/(gBT->GetPrecisionX()*gBT->GetPrecisionX());
410 lChi2 += (pg[1]-gBT->GetY())*(pg[1]-gBT->GetY())/(gBT->GetPrecisionY()*gBT->GetPrecisionY());
411 lChi2 += (pg[2]-gBT->GetZ())*(pg[2]-gBT->GetZ())/(gBT->GetPrecisionZ()*gBT->GetPrecisionZ());
412 } else if(fLBTargets->At(iPoint)->IsA()==AliSurveyPoint::Class()) {
413 AliSurveyPoint *lBT = (AliSurveyPoint*)fLBTargets->At(iPoint);
414 lChi2 += (pg[0]-gBT->GetX())*(pg[0]-gBT->GetX())/(gBT->GetPrecisionX()*gBT->GetPrecisionX()+lBT->GetPrecisionX()*lBT->GetPrecisionX());
415 lChi2 += (pg[1]-gBT->GetY())*(pg[1]-gBT->GetY())/(gBT->GetPrecisionY()*gBT->GetPrecisionY()+lBT->GetPrecisionY()*lBT->GetPrecisionY());
416 lChi2 += (pg[2]-gBT->GetZ())*(pg[2]-gBT->GetZ())/(gBT->GetPrecisionZ()*gBT->GetPrecisionZ()+lBT->GetPrecisionZ()*lBT->GetPrecisionZ());
418 AliError(Form("Unexpected class %s ! Valid classes are TVector3 or AliSurveyPoint",fLBTargets->At(iPoint)->ClassName()));
426 //_____________________________________________________________________________
427 void SurveyFcn(int &npar, double *g, double &f, double *par, int iflag) {
430 // Standard function as needed by Minuit-like minimization procedures.
431 // For the set of parameters par calculates and returns chi-squared.
434 // smuggle a C++ object into a C function
435 AliMUONSurveyObj *aSurveyObj = (AliMUONSurveyObj*) gMinuit->GetObjectFit();
437 f = aSurveyObj->SurveyChi2(par);
440 if (g) {} // no warnings about unused stuff...
444 //_____________________________________________________________________________
445 Int_t AliMUONSurveyObj::SurveyToAlign(TGeoCombiTrans &quadTransf, Double_t *parErr, Double_t psi, Double_t tht, Double_t epsi, Double_t etht) {
447 if (fGBTargets->GetEntries()!=fLBTargets->GetEntries()){
448 AliError(Form("Different number of button targets: %d survey points and %d local coord!",
449 fGBTargets->GetEntries(),fLBTargets->GetEntries()));
454 gMinuit->SetObjectFit(this);
455 fitter.SetFCN(SurveyFcn);
456 fitter.SetParameter(0,"dx",0,0.1,-20,20);
457 fitter.SetParameter(1,"dy",0,0.1,-20,20);
458 fitter.SetParameter(2,"dz",0,0.1,0,0);
459 fitter.SetParameter(3,"rx",psi,0.0001,-0.05,0.05);
460 fitter.SetParameter(4,"ry",tht,0.0001,-0.05,0.05);
461 // fitter.SetParameter(3,"rx",psi,0.0001,psi-5*epsi,psi+5*epsi);
462 // fitter.SetParameter(4,"ry",tht,0.0001,tht-5*etht,tht+5*etht);
463 fitter.SetParameter(5,"rz",0,0.0001,0,0);
465 if(psi) fitter.FixParameter(3);
466 if(tht) fitter.FixParameter(4);
470 fitter.ExecuteCommand("SET PRINT", arglist, 1);
471 fitter.ExecuteCommand("SET ERR", arglist, 1);
473 //fitter.ExecuteCommand("SIMPLEX", arglist, 1);
474 // fitter.ExecuteCommand("MINIMIZE", arglist, 1);
475 fitter.ExecuteCommand("MIGRAD", arglist, 1);
476 fitter.ExecuteCommand("IMPROVE", arglist, 1);
477 // fitter.ExecuteCommand("MINOS", arglist, 1);
478 // fitter.ExecuteCommand("CALL 3", arglist,0);
480 for (int j=0; j<3; j++) printf("%10.3f ",fitter.GetParameter(j));
481 for (int j=3; j<6; j++) printf("%10.3f ",1000*fitter.GetParameter(j));
483 for (int j=0; j<3; j++) printf("%10.3f ",fitter.GetParError(j));
484 for (int j=3; j<6; j++) printf("%10.3f ",1000*fitter.GetParError(j));
488 quadTransf.RotateZ(TMath::RadToDeg()*fitter.GetParameter(5));
489 quadTransf.RotateY(TMath::RadToDeg()*fitter.GetParameter(4));
490 quadTransf.RotateX(TMath::RadToDeg()*fitter.GetParameter(3));
491 quadTransf.SetTranslation(fitter.GetParameter(0),fitter.GetParameter(1),fitter.GetParameter(2));
493 for(Int_t iPar=0; iPar<6; iPar++){
494 parErr[iPar] = fitter.GetParError(iPar);
496 if(epsi) parErr[3] = epsi;
497 if(etht) parErr[4] = etht;
503 //_____________________________________________________________________________
504 Int_t AliMUONSurveyObj::SurveyToAlign(Double_t psi, Double_t tht, Double_t epsi, Double_t etht) {
506 if (fGBTargets->GetEntries()!=fLBTargets->GetEntries()){
507 AliError(Form("Different number of button targets: %d survey points and %d local coord!",
508 fGBTargets->GetEntries(),fLBTargets->GetEntries()));
512 // TFitter fitter(100);
513 gMinuit->SetObjectFit(this);
514 fFitter->SetFCN(SurveyFcn);
515 fFitter->SetParameter(0,"dx",0,0.1,-20,20);
516 fFitter->SetParameter(1,"dy",0,0.1,-20,20);
517 fFitter->SetParameter(2,"dz",0,0.1,0,0);
519 fFitter->SetParameter(3,"rx",psi,epsi,psi-5*epsi,psi+5*epsi);
521 fFitter->SetParameter(3,"rx",psi,0.0001,-0.05,0.05);
523 fFitter->SetParameter(4,"ry",tht,etht,tht-5*etht,tht+5*etht);
525 fFitter->SetParameter(4,"ry",tht,0.0001,-0.05,0.05);
526 // fFitter->SetParameter(3,"rx",psi,0.0001,psi-5*epsi,psi+5*epsi);
527 // fFitter->SetParameter(4,"ry",tht,0.0001,tht-5*etht,tht+5*etht);
528 fFitter->SetParameter(5,"rz",0,0.0001,0,0);
530 if(psi) fFitter->FixParameter(3);
531 if(tht) fFitter->FixParameter(4);
535 fFitter->ExecuteCommand("SET PRINT", arglist, 1);
536 fFitter->ExecuteCommand("SET ERR", arglist, 1);
538 //fFitter->ExecuteCommand("SIMPLEX", arglist, 1);
539 // fFitter->ExecuteCommand("MINIMIZE", arglist, 1);
540 fFitter->ExecuteCommand("MIGRAD", arglist, 1);
541 fFitter->ExecuteCommand("IMPROVE", arglist, 1);
542 // fFitter->ExecuteCommand("MINOS", arglist, 1);
543 // fFitter->ExecuteCommand("CALL 3", arglist,0);
545 for (int j=0; j<3; j++) printf("%10.3f ",fFitter->GetParameter(j));
546 for (int j=3; j<6; j++) printf("%10.3f ",1000*fFitter->GetParameter(j));
548 for (int j=0; j<3; j++) printf("%10.3f ",fFitter->GetParError(j));
549 for (int j=3; j<6; j++) printf("%10.3f ",1000*fFitter->GetParError(j));
553 fAlignTrf->RotateZ(TMath::RadToDeg()*fFitter->GetParameter(5));
554 fAlignTrf->RotateY(TMath::RadToDeg()*fFitter->GetParameter(4));
555 fAlignTrf->RotateX(TMath::RadToDeg()*fFitter->GetParameter(3));
556 fAlignTrf->SetTranslation(fFitter->GetParameter(0),fFitter->GetParameter(1),fFitter->GetParameter(2));
558 if(epsi) fFitter->ReleaseParameter(3); // To get error
559 if(etht) fFitter->ReleaseParameter(4); // To get error
561 TGeoCombiTrans lGlobalTrf = TGeoCombiTrans((*fBaseTrf)*(*fAlignTrf));
562 AliSurveyPoint *pointGBT;
563 AliSurveyPoint *pointLBT;
564 Double_t pl[3] = {0};
565 Double_t pg[3] = {0};
566 for (int iPoint=0; iPoint<GetNGButtonTargets(); iPoint++){
567 pointGBT=GetGButtonTarget(iPoint);
568 pointLBT=GetLButtonTarget(iPoint);
569 pl[0] = pointLBT->GetX();
570 pl[1] = pointLBT->GetY();
571 pl[2] = pointLBT->GetZ();
572 lGlobalTrf.LocalToMaster(pl,pg);
573 printf("Point %d local: %.3f %.3f %.3f\n",iPoint,pl[0],pl[1],pl[2]);
574 printf("Point %d global: %.3f %.3f %.3f\n",iPoint,pg[0],pg[1],pg[2]);
575 printf("Point %d survey: %.3f %.3f %.3f\n",iPoint,pointGBT->GetX(),pointGBT->GetY(),pointGBT->GetZ());
582 Double_t AliMUONSurveyObj::EvalFunction(TF2 *lFunction, Int_t iP1, Int_t iP2, Char_t *lCoord) {
585 AliError("No function given!!!");
588 AliSurveyPoint *gP1 = GetGButtonTarget(iP1);
589 AliSurveyPoint *gP2 = GetGButtonTarget(iP2);
592 AliError("Missing global button target!!!");
596 // AliInfo(Form("Function %s parameters %f %f %f %f %f %f",lFunction->GetName(),lFunction->GetParameter(0),lFunction->GetParameter(1),lFunction->GetParameter(2),lFunction->GetParameter(3),lFunction->GetParameter(4),lFunction->GetParameter(5)));
597 Double_t pl1[3] = {0};
598 Double_t pl2[3] = {0};
599 Double_t pg1[3] = {0};
600 Double_t pg2[3] = {0};
602 pg1[0] = gP1->GetX();
603 pg1[1] = gP1->GetY();
604 pg1[2] = gP1->GetZ();
605 pg2[0] = gP2->GetX();
606 pg2[1] = gP2->GetY();
607 pg2[2] = gP2->GetZ();
609 fBaseTrf->MasterToLocal(pg1,pl1);
610 fBaseTrf->MasterToLocal(pg2,pl2);
616 lVal = lFunction->Eval(pl1[0],pl2[0]);
617 // lVal = lFunction->Eval(gP1->GetX(),gP2->GetX());
618 // AliInfo(Form("case X, lVal = %f",lVal));
623 lVal = lFunction->Eval(pl1[1],pl2[1]);
624 // lVal = lFunction->Eval(gP1->GetY(),gP2->GetY());
625 // AliInfo(Form("case Y, lVal = %f",lVal));
630 lVal = lFunction->Eval(pl1[2],pl2[2]);
631 // lVal = lFunction->Eval(gP1->GetZ(),gP2->GetZ());
632 // AliInfo(Form("case Z, lVal = %f",lVal));
637 AliError(Form("Coordinate %c is not valid, options are X Y Z",lCoord));
643 void AliMUONSurveyObj::CalculateTranslation(TF2 *xFunc, TF2 *yFunc, TF2 *zFunc, Int_t iP1, Int_t iP2, Double_t *lCenTemp) {
645 lCenTemp[0] = EvalFunction(xFunc,iP1,iP2,"X");
646 lCenTemp[1] = EvalFunction(yFunc,iP1,iP2,"Y");
647 lCenTemp[2] = EvalFunction(zFunc,iP1,iP2,"Z");
651 Double_t AliMUONSurveyObj::CalculateGlobalDiff(TGeoCombiTrans &lTransf, Int_t nPoints, TArrayD &lDiff){
653 if (nPoints > GetNGButtonTargets()) {
654 nPoints = GetNGButtonTargets();
657 for(Int_t iVal=0; iVal<nPoints*(3+1)+1; iVal++){
661 Double_t pl[3] = {0};
662 Double_t pg[3] = {0};
663 Double_t pml[3] = {0};
664 Double_t pmg[3] = {0};
665 AliSurveyPoint *gBT = 0x0;
666 for(Int_t iPoint=0; iPoint<nPoints; iPoint++){
667 gBT = GetGButtonTarget(iPoint);
668 if(!gBT||!fLBTargets->At(iPoint)){
669 AliError(Form("The local or global target %d is missing!",iPoint));
670 lDiff[nPoints*(3+1)] = 1.e7;
671 return lDiff[nPoints*(3+1)];
673 if(fLBTargets->At(iPoint)->IsA()==TVector3::Class()){
674 TVector3 *lBT = (TVector3*)fLBTargets->At(iPoint);
678 } else if(fLBTargets->At(iPoint)->IsA()==AliSurveyPoint::Class()) {
679 AliSurveyPoint *lBT = (AliSurveyPoint*)fLBTargets->At(iPoint);
684 AliError(Form("Unexpected class %s ! Valid classes are TVector3 or AliSurveyPoint",fLBTargets->At(iPoint)->ClassName()));
688 lTransf.LocalToMaster(pl,pg);
689 pmg[0] = gBT->GetX();
690 pmg[1] = gBT->GetY();
691 pmg[2] = gBT->GetZ();
692 fBaseTrf->MasterToLocal(pmg,pml);
693 // printf("l %d %f %f %f\n",iPoint,pl[0],pl[1],pl[2]);
694 // printf("g %d %f %f %f\n",iPoint,pg[0],pg[1],pg[2]);
695 // printf("ml %d %f %f %f\n",iPoint,pml[0],pml[1],pml[2]);
696 // printf("mg %d %f %f %f\n",iPoint,gBT->GetX(),gBT->GetY(),gBT->GetZ());
697 lDiff[iPoint*(3+1)+0] = (pml[0]-pg[0]);
698 lDiff[iPoint*(3+1)+1] = (pml[1]-pg[1]);
699 lDiff[iPoint*(3+1)+2] = (pml[2]-pg[2]);
701 lDiff[iPoint*(3+1)+3] = TMath::Sqrt(lDiff[iPoint*(3+1)+0]*lDiff[iPoint*(3+1)+0]+
702 lDiff[iPoint*(3+1)+1]*lDiff[iPoint*(3+1)+1]+
703 lDiff[iPoint*(3+1)+2]*lDiff[iPoint*(3+1)+2]);
705 lDiff[nPoints*(3+1)] += lDiff[iPoint*(3+1)+3]*lDiff[iPoint*(3+1)+3];
708 lDiff[nPoints*(3+1)] = TMath::Sqrt(lDiff[nPoints*(3+1)]);
709 return lDiff[nPoints*(3+1)];
712 Int_t AliMUONSurveyObj::CalculateBestTransf(Int_t iP1, Int_t iP2, Double_t *lXYZ, Double_t *lPTP) {
714 Double_t lPsi = lPTP[0];
715 Double_t lTht = lPTP[1];
717 Double_t pl1[3] = {0};
718 Double_t pl2[3] = {0};
720 if(!fLBTargets->At(iP1)||!fLBTargets->At(iP2)){
721 AliError(Form("Local target %d or %d is missing!",iP1,iP2));
725 if(fLBTargets->At(iP1)->IsA()==TVector3::Class()){
726 TVector3 *lBT1 = (TVector3*)fLBTargets->At(iP1);
730 } else if(fLBTargets->At(iP1)->IsA()==AliSurveyPoint::Class()) {
731 AliSurveyPoint *lBT1 = (AliSurveyPoint*)fLBTargets->At(iP1);
736 AliError(Form("Unexpected class %s ! Valid classes are TVector3 or AliSurveyPoint",fLBTargets->At(iP1)->ClassName()));
739 if(fLBTargets->At(iP2)->IsA()==TVector3::Class()){
740 TVector3 *lBT2 = (TVector3*)fLBTargets->At(iP2);
744 } else if(fLBTargets->At(iP2)->IsA()==AliSurveyPoint::Class()) {
745 AliSurveyPoint *lBT2 = (AliSurveyPoint*)fLBTargets->At(iP2);
750 AliError(Form("Unexpected class %s ! Valid classes are TVector3 or AliSurveyPoint",fLBTargets->At(iP2)->ClassName()));
755 AliMUONSurveyUtil *surveyUtil = AliMUONSurveyUtil::Instance();
758 char *fxcName = "fXcn00";
759 TF2 **fXc = new TF2*[2];
761 fXc[0] = new TF2(fxcName,surveyUtil,&AliMUONSurveyUtil::xnCenter,fXMin,fXMax,fYMin,fYMax,7,"AliMUONSurveyUtil","xnCenter");
763 fXc[1] = new TF2(fxcName,surveyUtil,&AliMUONSurveyUtil::xpCenter,fXMin,fXMax,fYMin,fYMax,7,"AliMUONSurveyUtil","xpCenter");
766 char *fycName = "fYcn00";
767 TF2 **fYc = new TF2*[2];
769 fYc[0] = new TF2(fycName,surveyUtil,&AliMUONSurveyUtil::ynCenter,fYMin,fYMax,fYMin,fYMax,8,"AliMUONSurveyUtil","ynCenter");
771 fYc[1] = new TF2(fycName,surveyUtil,&AliMUONSurveyUtil::ypCenter,fYMin,fYMax,fYMin,fYMax,8,"AliMUONSurveyUtil","ypCenter");
774 char *fzcName = "fZcn00";
775 TF2 **fZc = new TF2*[2];
777 fZc[0] = new TF2(fzcName,surveyUtil,&AliMUONSurveyUtil::znCenter,fZMin,fZMax,fZMin,fZMax,8,"AliMUONSurveyUtil","znCenter");
779 fZc[1] = new TF2(fzcName,surveyUtil,&AliMUONSurveyUtil::zpCenter,fZMin,fZMax,fZMin,fZMax,8,"AliMUONSurveyUtil","zpCenter");
781 // Phi rotation using xglobal coords functions
782 char *fphixName = "fPhiXnn00";
783 TF2 ***fPhiX = new TF2**[2];
784 for (Int_t iX =0; iX<2; iX++) {
785 fPhiX[iX] = new TF2*[2];
787 fphixName = "fPhiXnn";
788 fPhiX[0][0] = new TF2(fphixName,surveyUtil,&AliMUONSurveyUtil::phixnn,fXMin,fXMax,fXMin,fXMax,7,"AliMUONSurveyUtil","phixnn");
789 fphixName = "fPhiXnp";
790 fPhiX[0][1] = new TF2(fphixName,surveyUtil,&AliMUONSurveyUtil::phixnp,fXMin,fXMax,fXMin,fXMax,7,"AliMUONSurveyUtil","phixnp");
791 fphixName = "fPhiXpn";
792 fPhiX[1][0] = new TF2(fphixName,surveyUtil,&AliMUONSurveyUtil::phixpn,fXMin,fXMax,fXMin,fXMax,7,"AliMUONSurveyUtil","phixpn");
793 fphixName = "fPhiXpp";
794 fPhiX[1][1] = new TF2(fphixName,surveyUtil,&AliMUONSurveyUtil::phixpp,fXMin,fXMax,fXMin,fXMax,7,"AliMUONSurveyUtil","phixpp");
796 // Phi rotation using yglobal coords functions
797 char *fphiyName = "fPhiYnn00";
798 TF2 ***fPhiY = new TF2**[2];
799 for (Int_t iY =0; iY<2; iY++) {
800 fPhiY[iY] = new TF2*[2];
802 fphiyName = "fPhiYnn";
803 fPhiY[0][0] = new TF2(fphiyName,surveyUtil,&AliMUONSurveyUtil::phiynn,fYMin,fYMax,fYMin,fYMax,8,"AliMUONSurveyUtil","phiynn");
804 fphiyName = "fPhiYnp";
805 fPhiY[0][1] = new TF2(fphiyName,surveyUtil,&AliMUONSurveyUtil::phiynp,fYMin,fYMax,fYMin,fYMax,8,"AliMUONSurveyUtil","phiynp");
806 fphiyName = "fPhiYpn";
807 fPhiY[1][0] = new TF2(fphiyName,surveyUtil,&AliMUONSurveyUtil::phiypn,fYMin,fYMax,fYMin,fYMax,8,"AliMUONSurveyUtil","phiypn");
808 fphiyName = "fPhiYpp";
809 fPhiY[1][1] = new TF2(fphiyName,surveyUtil,&AliMUONSurveyUtil::phiypp,fYMin,fYMax,fYMin,fYMax,8,"AliMUONSurveyUtil","phiypp");
812 // Set Parameters of functions
813 for(Int_t iS=0; iS<2; iS++){
814 fXc[iS]->SetParameters(pl1[0],pl1[1],pl1[2],pl2[0],pl2[1],pl2[2],lTht);
815 fYc[iS]->SetParameters(pl1[0],pl1[1],pl1[2],pl2[0],pl2[1],pl2[2],lPsi,lTht);
816 fZc[iS]->SetParameters(pl1[0],pl1[1],pl1[2],pl2[0],pl2[1],pl2[2],lPsi,lTht);
817 // fXc[iS]->SetParameters(lBT1->X(),lBT1->Y(),lBT1->Z(),lBT2->X(),lBT2->Y(),lBT2->Z(),lTht);
818 // fYc[iS]->SetParameters(lBT1->X(),lBT1->Y(),lBT1->Z(),lBT2->X(),lBT2->Y(),lBT2->Z(),lPsi,lTht);
819 // fZc[iS]->SetParameters(lBT1->X(),lBT1->Y(),lBT1->Z(),lBT2->X(),lBT2->Y(),lBT2->Z(),lPsi,lTht);
820 for(Int_t jS=0; jS<2; jS++){
821 fPhiX[iS][jS]->SetParameters(pl1[0],pl1[1],pl1[2],pl2[0],pl2[1],pl2[2],lTht);
822 fPhiY[iS][jS]->SetParameters(pl1[0],pl1[1],pl1[2],pl2[0],pl2[1],pl2[2],lPsi,lTht);
823 // fPhiX[iS][jS]->SetParameters(lBT1->X(),lBT1->Y(),lBT1->Z(),lBT2->X(),lBT2->Y(),lBT2->Z(),lTht);
824 // fPhiY[iS][jS]->SetParameters(lBT1->X(),lBT1->Y(),lBT1->Z(),lBT2->X(),lBT2->Y(),lBT2->Z(),lPsi,lTht);
828 Double_t lCenTemp[3];
829 Double_t lRotTemp[3];
831 TGeoCombiTrans trfTemp;
833 Int_t nPoints = GetNGButtonTargets();
835 TArrayD lDiffTemp(nPoints*(3+1)+1);
836 TArrayD lDiffMin(nPoints*(3+1)+1);
838 for(Int_t i=0; i<nPoints*(3+1)+1; i++){
839 lDiffMin[i]=1000000.;
844 // Calculate Detection Element Center from button targets
847 // Trying 2x*2y*2z*(2phi+2phi) possibilities
848 for(Int_t iX=0; iX<2; iX++){
849 for(Int_t iY=0; iY<2; iY++){
850 for(Int_t iZ=0; iZ<2; iZ++){
851 CalculateTranslation(fXc[iX],fYc[iY],fZc[iZ],iP1,iP2,lCenTemp);
855 for(Int_t iP=0; iP<2; iP++){
856 lRotTemp[2] = EvalFunction(fPhiX[iX][iP],iP1,iP2,"X");
859 trfTemp.RotateZ(TMath::RadToDeg()*lRotTemp[2]);
860 trfTemp.RotateY(TMath::RadToDeg()*lRotTemp[1]);
861 trfTemp.RotateX(TMath::RadToDeg()*lRotTemp[0]);
862 trfTemp.SetTranslation(lCenTemp);
864 if(CalculateGlobalDiff(trfTemp,nPoints,lDiffTemp)<lDiffMin[nPoints*(3+1)]){
866 for(Int_t i=0; i<nPoints*(3+1)+1; i++){
867 printf(" %f",lDiffTemp[i]);
870 printf(" : mycenX%dY%dZ%d(%f,%f,%f); rotx%d(%f,%f,%f)\n",iX,iY,iZ,lCenTemp[0],lCenTemp[1],lCenTemp[2],iP,lRotTemp[0],lRotTemp[1],lRotTemp[2]);
871 printf("Transformation improved ...\n");
872 for (int i=0; i<3; i++) {
873 lXYZ[i] = lCenTemp[i];
875 lPTP[2] = lRotTemp[2];
876 for(Int_t i=0; i<nPoints*(3+1)+1; i++){
877 lDiffMin[i]=lDiffTemp[i];
881 for(Int_t iP=0; iP<2; iP++){
882 lRotTemp[2] = EvalFunction(fPhiY[iY][iP],iP1,iP2,"Y");
885 trfTemp.RotateZ(TMath::RadToDeg()*lRotTemp[2]);
886 trfTemp.RotateY(TMath::RadToDeg()*lRotTemp[1]);
887 trfTemp.RotateX(TMath::RadToDeg()*lRotTemp[0]);
888 trfTemp.SetTranslation(lCenTemp);
890 if(CalculateGlobalDiff(trfTemp,nPoints,lDiffTemp)<lDiffMin[nPoints*(3+1)]){
892 for(Int_t i=0; i<nPoints*(3+1)+1; i++){
893 printf(" %f",lDiffTemp[i]);
896 printf(" : mycenX%dY%dZ%d(%f,%f,%f); roty%d(%f,%f,%f)\n",iX,iY,iZ,lCenTemp[0],lCenTemp[1],lCenTemp[2],iP,lRotTemp[0],lRotTemp[1],lRotTemp[2]);
897 printf("Transformation improved ...\n");
898 for (int i=0; i<3; i++) {
899 lXYZ[i] = lCenTemp[i];
901 lPTP[2] = lRotTemp[2];
902 for(Int_t i=0; i<nPoints*(3+1)+1; i++){
903 lDiffMin[i]=lDiffTemp[i];
911 for (Int_t i=0; i<2; i++) {
915 for (Int_t j=0; j<2; j++) {
928 if (lDiffMin[nPoints*(3+1)]>20) return 0;
933 void AliMUONSurveyObj::CalculateMeanTransf(Double_t *lXYZ, Double_t *lPTP) {
941 Int_t nPoints = GetNGButtonTargets();
942 // Loop over all possible pairs of button tragets
943 for(Int_t iP1=0; iP1<nPoints; iP1++){
944 for(Int_t iP2=iP1+1; iP2<nPoints; iP2++){
945 printf("%d and %d\n",iP1,iP2);
947 if(CalculateBestTransf(iP1,iP2,lXYZ,lPTP)) {
966 void AliMUONSurveyObj::PrintLocalTrf() {
967 Double_t lRotTemp[3];
968 AliMUONSurveyUtil::MatrixToAngles(fLocalTrf->GetRotationMatrix(),lRotTemp);
969 printf("(%.3f %.3f %.3f), (%.6f %.6f %.6f)\n",fLocalTrf->GetTranslation()[0],fLocalTrf->GetTranslation()[1],fLocalTrf->GetTranslation()[2],lRotTemp[0],lRotTemp[1],lRotTemp[2]);
972 void AliMUONSurveyObj::PrintAlignTrf() {
973 Double_t lRotTemp[3];
974 AliMUONSurveyUtil::MatrixToAngles(fAlignTrf->GetRotationMatrix(),lRotTemp);
975 printf("(%.3f %.3f %.3f), (%.6f %.6f %.6f)\n",fAlignTrf->GetTranslation()[0],fAlignTrf->GetTranslation()[1],fAlignTrf->GetTranslation()[2],lRotTemp[0],lRotTemp[1],lRotTemp[2]);
978 void AliMUONSurveyObj::FillSTHistograms(TString baseNameC, TH2 *hSTc, TString baseNameA, TH2 *hSTa) {
979 if(baseNameC.IsNull()||!hSTc){
980 AliError("Need base name for points on side C and/or a histogram for them!");
983 AliSurveyPoint *pointST = 0x0;
984 for (Int_t iPoint=0; iPoint<GetNStickerTargets(); iPoint++) {
985 pointST = GetStickerTarget(iPoint);
986 if (!pointST) continue;
987 if (pointST->GetPointName().Contains(baseNameC)){
988 hSTc->Fill(pointST->GetX(),pointST->GetY(),-pointST->GetZ());
989 } else if ((!baseNameA.IsNull()) &&
990 (pointST->GetPointName().Contains(baseNameA))) {
992 AliError("Base name for points on side A provided but no histogram for them!");
995 hSTa->Fill(pointST->GetX(),pointST->GetY(),-pointST->GetZ());
1000 Double_t AliMUONSurveyObj::GetAlignResX() {
1002 AliError("There is no fitter for this object! X resolution will be 0.");
1005 return fFitter->GetParError(0);
1008 Double_t AliMUONSurveyObj::GetAlignResY() {
1010 AliError("There is no fitter for this object! Y resolution will be 0.");
1013 return fFitter->GetParError(1);