ROOT logo
#ifndef ALIMUONSURVEYOBJ_H
#define ALIMUONSURVEYOBJ_H
/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

/// \ingroup geometry
/// \class AliMUONSurveyObj
/// \brief Base class for survey of muon spectrometer
//
// Author: Javier Castillo

#include <TObject.h>

class TObjArray;
class TGeoCombiTrans;
class TVector3;
class TH2;
class TF2;
class TFitter;
class TArrayD;

class AliSurveyPoint;

class AliMUONSurveyObj:public TObject
{

 public:
  AliMUONSurveyObj();
  virtual ~AliMUONSurveyObj();
 
  virtual Int_t AddStickerTargets(TObjArray *pArray, TString stBaseName, Int_t lTargetMax = 9);
  virtual Int_t AddGButtonTargets(TObjArray *pArray, TString btBaseName, Int_t lTargetMax = 9);
  virtual Int_t AddLButtonTargets(TObjArray *pArray, TString btBaseName, Int_t lTargetMax = 9);

  /// To be implemented in a concrete Chamber or DetElem class
  virtual Int_t AddStickerTargets(TString stBaseName, Int_t lTargetMax = 9) = 0;
  /// To be implemented in a concrete Chamber or DetElem class
  virtual Int_t AddGButtonTargets(TString btBaseName, Int_t lTargetMax = 9) = 0;

  void AddStickerTarget(AliSurveyPoint *stPoint);
  void AddGButtonTarget(AliSurveyPoint *btPoint);
  void AddLButtonTarget(AliSurveyPoint *btPoint);
  void AddLButtonTarget(TVector3 *btVector);

  Int_t GetNStickerTargets();
  AliSurveyPoint *GetStickerTarget(Int_t stIndex);
  Int_t GetNGButtonTargets();
  AliSurveyPoint *GetGButtonTarget(Int_t btIndex);
  Int_t GetNLButtonTargets();
  AliSurveyPoint *GetLButtonTarget(Int_t btIndex);
  /// Set transformation of geoemtrical element
  void SetBaseTransformation(TGeoCombiTrans *baseTrf, Bool_t ownerBaseTrf = kFALSE) {
    fBaseTrf = baseTrf;
    fOwnerBaseTrf=ownerBaseTrf;
  }
  /// Set local transformation of geometrical element
  virtual void SetLocalTransformation(TGeoCombiTrans *localTrf, Bool_t ownerLocalTrf = kFALSE) {
    fLocalTrf=localTrf;
    fOwnerLocalTrf=ownerLocalTrf;
  }

  /// Returns the local transformation
  TGeoCombiTrans* GetLocalTrf() const {return fLocalTrf;} 
  /// Returns the base (global) transformation
  TGeoCombiTrans* GetBaseTrf() const {return fBaseTrf;}
  /// Returns the alignment transformation
  TGeoCombiTrans* GetAlignTrf()const {return fAlignTrf;}

  /// Define wether to work in mm (survey units) or cm (alice units)
  void SetUseCM(Bool_t bUseCM = kTRUE) {fUseCM = bUseCM;}
  /// Indicates if working in mm (survey units) or cm (alice units)
  Bool_t GetUseCM() const {return fUseCM;}

  void SetPlane(TString pName, Double_t xMin=-2000., Double_t xMax=+2000., Double_t yMin=-2000., Double_t yMax=2000.);
  void SetPlaneParameters(Double_t p0, Double_t p1, Double_t p2);

  void DrawSTargets();
  Double_t FitPlane();

  /// Returns the plane (TF2) representing the object
  TF2* GetPlane() const {return fPlane;}

  /// Returns the TFitter used for the best local to global transformation determination
  TFitter* GetFitter() const {return fFitter;}

  Int_t SurveyToAlign(TGeoCombiTrans &quadTransf, Double_t *parErr, Double_t psi=0., Double_t tht=0., Double_t epsi=0., Double_t etht=0.);
  Int_t SurveyToAlign(Double_t psi=0., Double_t tht=0., Double_t epsi=0., Double_t etht=0.);
  Double_t SurveyChi2(Double_t *par);

  Double_t EvalFunction(const TF2 *lFunction, Int_t iP1, Int_t iP2, const Char_t *lCoord);

  void CalculateTranslation(TF2 *xFunc, TF2 *yFunc, TF2 *zFunc, Int_t iP1, Int_t iP2, Double_t *lCenTemp);
  //  TGeoCombiTrans *CalculateTransformation(TF2 *xFunc, TF2 *yFunc, TF2 *zFunc, TF2 *pFunc, Int_t iP1, Int_t iP2);

  Double_t CalculateGlobalDiff(TGeoCombiTrans &lTransf, Int_t nPoints, TArrayD &lDiff);

  Int_t CalculateBestTransf(Int_t iP1, Int_t iP2, Double_t *lXYZ, Double_t *lPTP);

  void CalculateMeanTransf(Double_t *lXYZ, Double_t *lPTP);
  
  /// Set xMin for functions fitting
  void SetXMin(Double_t xMin) {fXMin = xMin;}
  /// Set xMax for functions fitting
  void SetXMax(Double_t xMax) {fXMax = xMax;}
  /// Set yMin for functions fitting
  void SetYMin(Double_t yMin) {fYMin = yMin;}
  /// Set yMax for functions fitting
  void SetYMax(Double_t yMax) {fYMax = yMax;}
  /// Set zMin for functions fitting
  void SetZMin(Double_t zMin) {fZMin = zMin;}
  /// Set zMax for functions fitting
  void SetZMax(Double_t zMax) {fZMax = zMax;}

  virtual void PrintLocalTrf();
  virtual void PrintAlignTrf();

  void FillSTHistograms(TString baseNameC, TH2 *hSTc, TString baseNameA="", TH2 *hSTa = 0);

  Double_t GetAlignResX();
  Double_t GetAlignResY();

  AliSurveyPoint* ConvertPointUnits(AliSurveyPoint *stPoint, Float_t lFactor = 0.1);

 private:
  /// Not implemented
  AliMUONSurveyObj(const AliMUONSurveyObj& right);
  /// Not implemented
  AliMUONSurveyObj&  operator = (const AliMUONSurveyObj& right);

  Double_t EqPlane(const Double_t *x, const Double_t *par) const {
    /// Plane equation 
    return (-par[1]*x[0] +par[0]*x[1] -par[2]);  // then psi=ATan(par[0]) and tht=ATan(par[0])
    //    return (-par[0]*x[0] -par[1]*x[1] -par[2]); 
  }

  TObjArray *fSTargets;   ///< Array of AliSurveyPoint of Sticker Targets
  TObjArray *fGBTargets;  ///< Array of AliSurveyPoint of Button Targets
  TObjArray *fLBTargets;  ///< Array of TVector3 or AliSurveyPoint of local position of Button Targets
  TGeoCombiTrans *fLocalTrf; ///< Local transformation
  TGeoCombiTrans *fAlignTrf; ///< Local alignment transformation
  TGeoCombiTrans *fBaseTrf;  ///< Base Transformation

  Bool_t fOwnerLocalTrf;    ///< Flag for owner of fLocalTrf
  Bool_t fOwnerAlignTrf;    ///< Flag for owner of fAlignTrf
  Bool_t fOwnerBaseTrf;     ///< Flag for owner of fBaseTrf

  Bool_t fUseCM;            ///< Use centimeters, survey units are mm but aliroot uses cm

  TF2 *fPlane;  ///< TF2 for plane fitting

  TFitter *fFitter;  ///< Fitter for best local to global transformation

  Double_t fXMin;    ///< xMin for functions fitting
  Double_t fXMax;    ///< xMax for functions fitting
  Double_t fYMin;    ///< yMin for functions fitting
  Double_t fYMax;    ///< yMax for functions fitting
  Double_t fZMin;    ///< zMin for functions fitting
  Double_t fZMax;    ///< zMax for functions fitting


ClassDef(AliMUONSurveyObj, 0) //Class for alignment of muon spectrometer
};

#endif
 AliMUONSurveyObj.h:1
 AliMUONSurveyObj.h:2
 AliMUONSurveyObj.h:3
 AliMUONSurveyObj.h:4
 AliMUONSurveyObj.h:5
 AliMUONSurveyObj.h:6
 AliMUONSurveyObj.h:7
 AliMUONSurveyObj.h:8
 AliMUONSurveyObj.h:9
 AliMUONSurveyObj.h:10
 AliMUONSurveyObj.h:11
 AliMUONSurveyObj.h:12
 AliMUONSurveyObj.h:13
 AliMUONSurveyObj.h:14
 AliMUONSurveyObj.h:15
 AliMUONSurveyObj.h:16
 AliMUONSurveyObj.h:17
 AliMUONSurveyObj.h:18
 AliMUONSurveyObj.h:19
 AliMUONSurveyObj.h:20
 AliMUONSurveyObj.h:21
 AliMUONSurveyObj.h:22
 AliMUONSurveyObj.h:23
 AliMUONSurveyObj.h:24
 AliMUONSurveyObj.h:25
 AliMUONSurveyObj.h:26
 AliMUONSurveyObj.h:27
 AliMUONSurveyObj.h:28
 AliMUONSurveyObj.h:29
 AliMUONSurveyObj.h:30
 AliMUONSurveyObj.h:31
 AliMUONSurveyObj.h:32
 AliMUONSurveyObj.h:33
 AliMUONSurveyObj.h:34
 AliMUONSurveyObj.h:35
 AliMUONSurveyObj.h:36
 AliMUONSurveyObj.h:37
 AliMUONSurveyObj.h:38
 AliMUONSurveyObj.h:39
 AliMUONSurveyObj.h:40
 AliMUONSurveyObj.h:41
 AliMUONSurveyObj.h:42
 AliMUONSurveyObj.h:43
 AliMUONSurveyObj.h:44
 AliMUONSurveyObj.h:45
 AliMUONSurveyObj.h:46
 AliMUONSurveyObj.h:47
 AliMUONSurveyObj.h:48
 AliMUONSurveyObj.h:49
 AliMUONSurveyObj.h:50
 AliMUONSurveyObj.h:51
 AliMUONSurveyObj.h:52
 AliMUONSurveyObj.h:53
 AliMUONSurveyObj.h:54
 AliMUONSurveyObj.h:55
 AliMUONSurveyObj.h:56
 AliMUONSurveyObj.h:57
 AliMUONSurveyObj.h:58
 AliMUONSurveyObj.h:59
 AliMUONSurveyObj.h:60
 AliMUONSurveyObj.h:61
 AliMUONSurveyObj.h:62
 AliMUONSurveyObj.h:63
 AliMUONSurveyObj.h:64
 AliMUONSurveyObj.h:65
 AliMUONSurveyObj.h:66
 AliMUONSurveyObj.h:67
 AliMUONSurveyObj.h:68
 AliMUONSurveyObj.h:69
 AliMUONSurveyObj.h:70
 AliMUONSurveyObj.h:71
 AliMUONSurveyObj.h:72
 AliMUONSurveyObj.h:73
 AliMUONSurveyObj.h:74
 AliMUONSurveyObj.h:75
 AliMUONSurveyObj.h:76
 AliMUONSurveyObj.h:77
 AliMUONSurveyObj.h:78
 AliMUONSurveyObj.h:79
 AliMUONSurveyObj.h:80
 AliMUONSurveyObj.h:81
 AliMUONSurveyObj.h:82
 AliMUONSurveyObj.h:83
 AliMUONSurveyObj.h:84
 AliMUONSurveyObj.h:85
 AliMUONSurveyObj.h:86
 AliMUONSurveyObj.h:87
 AliMUONSurveyObj.h:88
 AliMUONSurveyObj.h:89
 AliMUONSurveyObj.h:90
 AliMUONSurveyObj.h:91
 AliMUONSurveyObj.h:92
 AliMUONSurveyObj.h:93
 AliMUONSurveyObj.h:94
 AliMUONSurveyObj.h:95
 AliMUONSurveyObj.h:96
 AliMUONSurveyObj.h:97
 AliMUONSurveyObj.h:98
 AliMUONSurveyObj.h:99
 AliMUONSurveyObj.h:100
 AliMUONSurveyObj.h:101
 AliMUONSurveyObj.h:102
 AliMUONSurveyObj.h:103
 AliMUONSurveyObj.h:104
 AliMUONSurveyObj.h:105
 AliMUONSurveyObj.h:106
 AliMUONSurveyObj.h:107
 AliMUONSurveyObj.h:108
 AliMUONSurveyObj.h:109
 AliMUONSurveyObj.h:110
 AliMUONSurveyObj.h:111
 AliMUONSurveyObj.h:112
 AliMUONSurveyObj.h:113
 AliMUONSurveyObj.h:114
 AliMUONSurveyObj.h:115
 AliMUONSurveyObj.h:116
 AliMUONSurveyObj.h:117
 AliMUONSurveyObj.h:118
 AliMUONSurveyObj.h:119
 AliMUONSurveyObj.h:120
 AliMUONSurveyObj.h:121
 AliMUONSurveyObj.h:122
 AliMUONSurveyObj.h:123
 AliMUONSurveyObj.h:124
 AliMUONSurveyObj.h:125
 AliMUONSurveyObj.h:126
 AliMUONSurveyObj.h:127
 AliMUONSurveyObj.h:128
 AliMUONSurveyObj.h:129
 AliMUONSurveyObj.h:130
 AliMUONSurveyObj.h:131
 AliMUONSurveyObj.h:132
 AliMUONSurveyObj.h:133
 AliMUONSurveyObj.h:134
 AliMUONSurveyObj.h:135
 AliMUONSurveyObj.h:136
 AliMUONSurveyObj.h:137
 AliMUONSurveyObj.h:138
 AliMUONSurveyObj.h:139
 AliMUONSurveyObj.h:140
 AliMUONSurveyObj.h:141
 AliMUONSurveyObj.h:142
 AliMUONSurveyObj.h:143
 AliMUONSurveyObj.h:144
 AliMUONSurveyObj.h:145
 AliMUONSurveyObj.h:146
 AliMUONSurveyObj.h:147
 AliMUONSurveyObj.h:148
 AliMUONSurveyObj.h:149
 AliMUONSurveyObj.h:150
 AliMUONSurveyObj.h:151
 AliMUONSurveyObj.h:152
 AliMUONSurveyObj.h:153
 AliMUONSurveyObj.h:154
 AliMUONSurveyObj.h:155
 AliMUONSurveyObj.h:156
 AliMUONSurveyObj.h:157
 AliMUONSurveyObj.h:158
 AliMUONSurveyObj.h:159
 AliMUONSurveyObj.h:160
 AliMUONSurveyObj.h:161
 AliMUONSurveyObj.h:162
 AliMUONSurveyObj.h:163
 AliMUONSurveyObj.h:164