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

/* $Id$ */

////////////////////////////////////////////////////////////////////////////
//                                                                        //
// AliTRDalignment class is an instrument for reading, writing, and       //
// manipulating of the TRD alignment data.                                //
// D.Miskowiec, November 2006                                             //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

#include <TObject.h>
#include <TRandom.h>
#include <TObjString.h>
#include <AliGeomManager.h>
class AliSurveyObj;

class AliTRDalignment : public TObject {
  
 public:

  AliTRDalignment();
  AliTRDalignment(const AliTRDalignment& source);
  AliTRDalignment& operator=(const AliTRDalignment& source);  
  AliTRDalignment& operator*=(double fac);  
  AliTRDalignment& operator+=(const AliTRDalignment& source);  
  AliTRDalignment& operator-=(const AliTRDalignment& source);  
  Bool_t operator==(const AliTRDalignment& source) const;  
  virtual ~AliTRDalignment() {};

  // setters 

  void SetSmZero();                                  // reset to zero supermodule data
  void SetChZero();                                  // reset to zero chamber data
  void SetSm(int sm, const double a[6])              {for (int i = 0; i < 6; i++) fSm[sm][i] = a[i];}
  void SetCh(int ch, const double a[6])              {for (int i = 0; i < 6; i++) fCh[ch][i] = a[i];}
  void SetSmRandom(double a[6]);                     // generate random gaussians with sigmas a
  void SetChRandom(double a[6]);                     // generate random gaussians with sigmas a
  void SetSmFull();                                  // set supermodule data to initial aka full 
  void SetChFull();                                  // set chamber data to initial aka full 
  void SetSmResidual();                              // set supermodule data to final aka residual
  void SetChResidual();                              // set chamber data to final aka residual
  void SetZero()                                     {SetSmZero(); SetChZero();}
  void SetIdeal()                                    {SetZero();}
  void SetFull()                                     {SetSmFull(); SetChFull();}
  void SetResidual()                                 {SetSmResidual(); SetChResidual();}
  void SetComment(char *s)                           {fComment.SetString(s);} 

  // simple getters (for other getters see below)

  void GetSm(int sm, double * const a) const         {for (int i = 0; i < 6; i++) a[i] = fSm[sm][i];}
  void GetCh(int ch, double * const a) const         {for (int i = 0; i < 6; i++) a[i] = fCh[ch][i];}
  
  // dumping on screen

  void PrintSm(int sm, FILE * const fp = stdout) const;   // print data of a supermodule
  void PrintCh(int ch, FILE * const fp = stdout) const;   // print data of a chamber
  void PrintSm(FILE * const fp = stdout) const       {for (int i = 0; i <  18; i++)  PrintSm(i,fp);}
  void PrintCh(FILE * const fp = stdout) const       {for (int i = 0; i < 540; i++)  PrintCh(i,fp);}
  void Print(FILE * const fp = stdout) const         {PrintSm(fp); PrintCh(fp);                    }
  void Print(Option_t *) const                       {Print();                                     } 

  // reading-in from file

  void ReadAscii(const char * const filename);           // read from ascii file
  void ReadCurrentGeo();                                 // read from currently loaded geometry
  void ReadRoot(const char * const filename);            // read from root file
  void ReadDB(const char * const filename);              // read from DB file
  void ReadDB(const char * const db, const char * const path, int run, int version=-1, int subversion=-1);
  Bool_t DecodeSurveyPointName(TString pna, Int_t &sm, Int_t &iz,Int_t &ir, Int_t &iphi);
  void ReadSurveyReport(const char * const filename);    // read from survey report
  void ReadSurveyReport(const AliSurveyObj * const so);  // read from survey object 
  void ReadAny(const char * const  filename);            // read from any kind of file

  // writing on file

  void WriteAscii(const char * const filename) const;                    // store data on ascii file
  void WriteRoot(const char * const filename);                           // store data on root file
  void WriteDB(const char * const fina, int r0, int r1, int v, int s);   // store data on a local DB-like file
  void WriteDB(char * const db, const char * const pa, int r0, int r1);  // store data on DB file
  void WriteGeo(char *filename);                                         // apply misalignment and store geometry 

  // geometry and symbolic names getters

  // phi-sector number of chamber ch, 0-17
  int GetSec(int ch) const           {return ch/30;}
  // stack number, 0-4
  int GetSta(int ch) const           {return ch%30/6;}
  // plane number, 0-5 
  int GetPla(int ch) const           {return ch%30%6;}
  // module number, 0-89
  int GetMod(int ch) const           {return 5*GetSec(ch)+GetSta(ch);} 
  // layer number, 9-14
  int GetLay(int ch) const           {return AliGeomManager::kTRD1+GetPla(ch);}
  // volume id
  UShort_t GetVoi(int ch) const      {return AliGeomManager::LayerToVolUID(GetLay(ch),GetMod(ch));}
  // symbolic name of a supermodule
  char *GetSmName(int sm) const      {return Form("TRD/sm%02d",sm);}
  // symbolic name of a chamber
  char *GetChName(int ch) const      {return Form("TRD/sm%02d/st%d/pl%d",GetSec(ch),GetSta(ch),GetPla(ch));}
  // index of a supermodule 
  int GetSmIndex(const char *name)   {for (int i=0; i<18; i++) if (strcmp(name,GetSmName(i))==0) return i; return -1;}
  // index of a chamber
  int GetChIndex(const char *name)   {for (int i=0; i<540; i++) if (strcmp(name,GetChName(i))==0) return i; return -1;}

  // data analysis

  double GetSmRMS(int xyz) const;                    // calculate rms fSm[*][xyz]
  double GetChRMS(int xyz) const;                    // calculate rms fCh[*][xyz]
  void   PrintSmRMS() const;                         // print rms of fSm
  void   PrintChRMS() const;                         // print rms of fCh
  void   PrintRMS() const                            {PrintSmRMS(); PrintChRMS();}

  double SurveyChi2(int i, const double * const a);  // compare survey with ideal, return chi2
  double SurveyChi2(const double * const a)          {return SurveyChi2(fIbuffer[0],a);}
  void   SurveyToAlignment(int i, const char * const flag);  // determine alignment of supermodule i based on survey
  void   SurveyToAlignment(const char * const flag)  {for (int i=0; i<18; i++) SurveyToAlignment(i,flag);}

 protected:

  void   ArToNumbers(TClonesArray * const ar);       // read ar and fill fSm and fCh
  void   NumbersToAr(TClonesArray * const ar);       // build ar using fSm and fCh data
  int    IsGeoLoaded();                              // check if geometry is loaded

 protected:

  double     fSm[18][6];                             // supermodule data
  double     fCh[540][6];                            // chamber data 
  TObjString fComment;                               // info concerning origin of the data etc.
  TRandom    fRan;                                   // random generator for fake alignment data

  // Temporary storage for ideal position of the survey points and the survey data.
  // The survey data are in master frame and in cm. Each supermodule has 8 survey marks. 
  // The indices are sm number, z-end, radius, phi. 
  // The ideal positions of survey points are in local frame of supermodule and in cm. 
  // The indices are z-end, radius, phi. 
  // The processed survey results are stored in fSm.
  double fSurveyX[18][2][2][2];                      // supermodule survey point X
  double fSurveyY[18][2][2][2];                      // supermodule survey point Y
  double fSurveyZ[18][2][2][2];                      // supermodule survey point Z
  double fSurveyEX[18][2][2][2];                     // supermodule survey point X error
  double fSurveyEY[18][2][2][2];                     // supermodule survey point Y error
  double fSurveyEZ[18][2][2][2];                     // supermodule survey point Z error
  double fSurveyX0[2][2][2];                         // ideal X position of the survey marks
  double fSurveyY0[2][2][2];                         // ideal Y position of the survey marks
  double fSurveyZ0[2][2][2];                         // ideal Z position of the survey marks
  int    fIbuffer[1000];                             // generic buffer for misc. operations
  double fDbuffer[1000];                             // generic buffer for misc. operations

  ClassDef(AliTRDalignment,1)    

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