Add AliTRDalignment by Dariusz
[u/mrichter/AliRoot.git] / TRD / AliTRDalignment.h
1 #ifndef ALITRDALIGNMENT_H
2 #define ALITRDALIGNMENT_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 ////////////////////////////////////////////////////////////////////////////
9 //                                                                        //
10 // AliTRDalignment class is an instrument for reading, writing, and       //
11 // manipulating of the TRD alignment data.                                //
12 // D.Miskowiec, November 2006                                             //
13 //                                                                        //
14 ////////////////////////////////////////////////////////////////////////////
15
16 #include <TObject.h>
17 #include <TRandom.h>
18
19 #include <AliAlignObj.h>
20
21 class AliTRDalignment : public TObject {
22   
23  public:
24
25   AliTRDalignment();
26   AliTRDalignment(const AliTRDalignment& source);
27   AliTRDalignment& operator=(const AliTRDalignment& source);  
28   AliTRDalignment& operator+=(const AliTRDalignment& source);  
29   AliTRDalignment& operator-=(const AliTRDalignment& source);  
30   Bool_t operator==(const AliTRDalignment& source) const;  
31   virtual ~AliTRDalignment() {};                     // destructor
32
33   // setting 
34
35   void SetSmZero();                                  // reset to zero supermodule data
36   void SetChZero();                                  // reset to zero chamber data
37   void SetZero() {SetSmZero(); SetChZero();}         // reset to zero both
38   void SetSm(Int_t sm, const Double_t a[6])          { for (int i = 0; i < 6; i++) fSm[sm][i] = a[i]; }
39   void SetCh(Int_t ch, const Double_t a[6])          { for (int i = 0; i < 6; i++) fCh[ch][i] = a[i]; }
40   void SetSmRandom(Double_t a[6]);                   // generate random gaussians with sigmas a
41   void SetChRandom(Double_t a[6]);                   // generate random gaussians with sigmas a
42   void SetSmFull();                                  // set supermodule data to initial aka full 
43   void SetChFull();                                  // set chamber data to initial aka full 
44   void SetSmResidual();                              // set supermodule data to final aka residual
45   void SetChResidual();                              // set chamber data to final aka residual
46   void SetFull() {SetSmFull(); SetChFull();}
47   void SetResidual() {SetSmResidual(); SetChResidual();}
48
49   // dumping on screen
50
51   void PrintSm(Int_t sm, FILE *fp = stdout) const;   // print data of a supermodule
52   void PrintCh(Int_t sm, FILE *fp = stdout) const;   // print data of a chamber
53   void PrintSm(FILE *fp = stdout) const              { for (int i = 0; i <  18; i++)  PrintSm(i,fp);  }
54   void PrintCh(FILE *fp = stdout) const              { for (int i = 0; i < 540; i++)  PrintCh(i,fp);  }
55   void Print(FILE *fp = stdout) const                { PrintSm(fp); PrintCh(fp);                      }
56   void Print(Option_t *) const                       { Print();                                       } 
57
58   // reading-in from file
59
60   void ReadAscii(char *filename);                    // read from ascii file
61   void ReadRoot(char *filename);                     // read from root file
62   void ReadDB(char *filename);                       // read from DB file
63   void ReadDB(char *db, char *path, Int_t run, Int_t version=-1, Int_t subversion=-1);
64   void ReadGeo(char *misaligned);                    // read from misaligned_geometry.root
65   void ReadSurveyReport(char *filename);             // read from survey report
66   void ReadAny(char *filename);                      // read from any kind of file
67
68   // writing on file
69
70   void WriteAscii(char *filename) const;             // store data on ascii file
71   void WriteRoot(char *filename);                    // store data on root file
72   void WriteDB(char *filename, char *comment, Int_t run0, Int_t run1);
73                                                      // store data on a local DB-like file
74   void WriteDB(char *db, char *path, char *comment, Int_t run0, Int_t run1); 
75                                                      // store data on DB file
76   void WriteGeo(char *filename);                     // apply misalignment and store geometry 
77
78   // geometry and symbolic names getters
79
80   // phi-sector number of chamber ch, 0-17
81   Int_t    GetSec(Int_t ch) const                    { return ch/30;   }
82   // stack number, 0-4
83   Int_t    GetSta(Int_t ch) const                    { return ch%30/6; }
84   // plane number, 0-5
85   Int_t    GetPla(Int_t ch) const                    { return ch%30%6; }
86   // module number, 0-89
87   Int_t    GetMod(Int_t ch) const                    { return 5*GetSec(ch)+GetSta(ch);                           } 
88   // layer number, 9-14
89   Int_t    GetLay(Int_t ch) const                    { return AliAlignObj::kTRD1+GetPla(ch);                     }
90   // volume id
91   UShort_t GetVoi(Int_t ch) const                    { return AliAlignObj::LayerToVolUID(GetLay(ch),GetMod(ch)); }
92   char    *GetSmName(Int_t sm) const                 { return Form("TRD/sm%02d",sm);                             }
93   char    *GetChName(Int_t ch) const                 { return Form("TRD/sm%02d/st%d/pl%d",GetSec(ch),GetSta(ch),GetPla(ch)); }
94
95   // data analysis
96
97   Double_t GetSmRMS(Int_t xyz) const;                // calculate rms fSm[*][xyz]
98   Double_t GetChRMS(Int_t xyz) const;                // calculate rms fCh[*][xyz]
99   void     PrintSmRMS() const;                       // print rms of fSm
100   void     PrintChRMS() const;                       // print rms of fCh
101   void     PrintRMS() const                          { PrintSmRMS(); PrintChRMS();}
102
103  protected:
104
105   void ArToNumbers(TClonesArray *ar);                // read ar and fill fSm and fCh
106   void NumbersToAr(TClonesArray *ar);                // build ar using fSm and fCh data
107   void LoadIdealGeometry(char *filename);            // load ideal geometry from file
108   void LoadIdealGeometry() {LoadIdealGeometry("geometry.root");} 
109
110  protected:
111
112   Double_t fSm[18][6];                               // supermodule data
113   Double_t fCh[540][6];                              // chamber data 
114   TRandom  fRan;                                     // random generator for fake alignment data
115
116   ClassDef(AliTRDalignment,1)    
117
118 };
119     
120 #endif