]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSSurvey.cxx
Coding convensions satisfied (T.Pocheptsov)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSSurvey.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 /* History of cvs commits:
19  *
20  * $Log$
21  * Revision 1.1  2007/04/19 15:47:20  kharlov
22  * Add misalignment of strip units with AliPHOSSurvey class
23  *
24  */
25
26 // Objects of this class read txt file with survey (photogrammetry) data
27 // and convert the data into AliAlignObjAngles of alignable PHOS volumes.
28 // It can be used as a base class, you need to override GetStripTransformation.
29 // AliPHOSSurvey inherits TObject only to use AliLog "functions".
30 // Author: Timur Pocheptsov (JINR)
31
32 #include <fstream>
33
34 #include <TClonesArray.h>
35 #include <TGeoManager.h>
36 #include <TString.h>
37 #include <TMath.h>
38
39 #include "AliPHOSEMCAGeometry.h"
40 #include "AliAlignObjAngles.h"
41 #include "AliPHOSGeometry.h"
42 #include "AliPHOSSurvey.h"
43 #include "AliLog.h"
44
45 ClassImp(AliPHOSSurvey)
46
47 //____________________________________________________________________________
48 AliPHOSSurvey::AliPHOSSurvey()
49                 : fStrNum(0),
50                   fStripData(0)
51 {
52   //Default constructor.
53 }
54
55 namespace {
56
57   struct AliPHOSStripCoords {
58     Double_t fX1; //x coordinate of the first strip point
59     Double_t fZ1; //z coordinate of the first strip point
60     Double_t fX2; //x coordinate of the second strip point
61     Double_t fZ2; //z coordinate of the second strip point
62   };
63
64 }
65
66 //____________________________________________________________________________
67 AliPHOSSurvey::AliPHOSSurvey(const TString &txtFileName)
68                 : fStrNum(0),
69                   fStripData(0)
70 {
71   //Read survey data from txt file.
72   const AliPHOSGeometry *phosGeom = AliPHOSGeometry::GetInstance("IHEP", "IHEP");
73   if (!phosGeom) {
74     AliError("Cannot obtain AliPHOSGeometry instance.");
75     return;
76   }
77
78   std::ifstream inputFile(txtFileName.Data());
79   if (!inputFile) {
80     AliError(("Cannot open the survey file " + txtFileName).Data());
81     return;
82   }
83
84   AliPHOSEMCAGeometry * emcaGeom = phosGeom->GetEMCAGeometry();
85   fStrNum = emcaGeom->GetNStripX() * emcaGeom->GetNStripZ();
86   const Float_t *strip = emcaGeom->GetStripHalfSize();
87   const Float_t *cell = emcaGeom->GetSteelCellHalfSize(); 
88
89   AliPHOSStripCoords *idealStrips = new AliPHOSStripCoords[fStrNum];//1
90   for (Int_t ix = 0, stripNumber = 0; ix < emcaGeom->GetNStripX(); ++ix) {
91     for (Int_t iz = 0; iz < emcaGeom->GetNStripZ(); ++iz) {
92       AliPHOSStripCoords &str = idealStrips[stripNumber++];
93       str.fX1 = ix * 2 * strip[0];
94       str.fX2 = str.fX1 + 14 * cell[0];
95       str.fZ1 = iz * 2 * strip[2];
96       str.fZ2 = str.fZ1 + 2 * cell[2];
97     }
98   }
99
100   Int_t dummyInt = 0;
101   Double_t dummyY = 0.;
102   Double_t *xReal = new Double_t[fStrNum * 2];//2
103   Double_t *zReal = new Double_t[fStrNum * 2];//3
104
105   for (Int_t i = 0; i < fStrNum * 2; ++i) {
106     if (!inputFile) {
107       AliError("Error while reading input file.");
108       delete [] idealStrips;
109       delete [] xReal;
110       delete [] zReal;
111       return;
112     }
113     inputFile>>dummyInt>>xReal[i]>>dummyY>>zReal[i];
114     xReal[i] *= 0.1;
115     zReal[i] *= 0.1;
116   }
117
118   AliPHOSStripCoords *realStrips = new AliPHOSStripCoords[fStrNum];//4
119
120   for (Int_t j = 0, stripNumber = 0; j < emcaGeom->GetNStripX() * 2; j += 2) {
121     for (Int_t i = 0; i < emcaGeom->GetNStripZ(); ++i) {
122       AliPHOSStripCoords &str = realStrips[stripNumber++];
123       str.fX1 = xReal[i + j * emcaGeom->GetNStripZ()];
124       str.fZ1 = zReal[i + j * emcaGeom->GetNStripZ()];
125       str.fX2 = xReal[i + (j + 1) * emcaGeom->GetNStripZ()];
126       str.fZ2 = zReal[i + (j + 1) * emcaGeom->GetNStripZ()];
127     }
128   }
129
130   fStripData = new AliPHOSStripDelta[fStrNum];
131   
132   for (Int_t i = 0; i < fStrNum; ++i) {
133     const AliPHOSStripCoords &real = realStrips[i];
134     const AliPHOSStripCoords &ideal = idealStrips[i];
135     AliPHOSStripDelta &t = fStripData[i];
136     t.fTheta = TMath::ATan((real.fZ2 - real.fZ1)  / (real.fX2 - real.fX1)) - 
137                TMath::ATan((ideal.fZ2 - ideal.fZ1) / (ideal.fX2 - ideal.fX1));
138     t.fTheta *= TMath::RadToDeg();
139     t.fXShift = (real.fX1 + real.fX2) / 2 - (ideal.fX1 + ideal.fX2) / 2;
140     t.fZShift = (real.fZ1 + real.fZ2) / 2 - (ideal.fZ1 + ideal.fZ2) / 2;
141     t.fYShift = 0., t.fPsi = 0., t.fPhi = 0.;
142   }
143   
144   delete [] realStrips;
145   delete [] zReal;
146   delete [] xReal;
147   delete [] idealStrips;
148 }
149
150 //____________________________________________________________________________
151 AliPHOSSurvey::~AliPHOSSurvey()
152 {
153   delete [] fStripData;
154 }
155
156 //____________________________________________________________________________
157 void AliPHOSSurvey::CreateAliAlignObjAngles(TClonesArray &array)
158 {
159   //Create AliAlignObjAngles.
160   const AliPHOSGeometry * phosGeom = AliPHOSGeometry::GetInstance("IHEP", "IHEP");
161   if (!phosGeom) {
162     AliError("Cannot obtain AliPHOSGeometry instance.");
163     return;
164   }
165
166   if (!gGeoManager) {
167     AliWarning("Cannot create local transformations for strip units - gGeoManager does not exist.");
168     AliInfo("Null shifts and rotations will be created instead.");
169     return CreateNullObjects(array, phosGeom);
170   }
171
172   AliPHOSEMCAGeometry * emcaGeom = phosGeom->GetEMCAGeometry();
173   Int_t arrayInd = array.GetEntries(), iIndex = 0;
174   AliAlignObj::ELayerID iLayer = AliAlignObj::kInvalidLayer;
175   UShort_t volid = AliAlignObj::LayerToVolUID(iLayer,iIndex);
176
177   for (Int_t module = 1; module <= phosGeom->GetNModules(); ++module) {
178     for (Int_t i = 0, stripNum = 0; i < emcaGeom->GetNStripX(); ++i) {
179       for (Int_t j = 0; j < emcaGeom->GetNStripZ(); ++j) {
180         TString stripName(TString::Format("PHOS/Module%d/Strip_%d_%d", module, i, j));
181         AliPHOSStripDelta t(GetStripTransformation(stripNum++, module));
182         new(array[arrayInd])
183           AliAlignObjAngles(
184                             stripName.Data(), volid, 
185                             t.fXShift, t.fYShift, t.fZShift, 
186                             -t.fPsi, -t.fTheta, -t.fPhi, 
187                             false
188                            );
189         ++arrayInd;
190       }
191     }
192   }
193 }
194
195 //____________________________________________________________________________
196 void AliPHOSSurvey::CreateNullObjects(TClonesArray &array, const AliPHOSGeometry *phosGeom)const
197 {
198   //Create null shifts and rotations.
199   const AliPHOSEMCAGeometry * emcaGeom = phosGeom->GetEMCAGeometry();
200   Int_t arrayInd = array.GetEntries(), iIndex = 0;
201   AliAlignObj::ELayerID iLayer = AliAlignObj::kInvalidLayer;
202   UShort_t volid = AliAlignObj::LayerToVolUID(iLayer,iIndex);
203
204   for (Int_t module = 1; module <= phosGeom->GetNModules(); ++module)
205     for (Int_t i = 0; i < emcaGeom->GetNStripX(); ++i)
206       for (Int_t j = 0; j < emcaGeom->GetNStripZ(); ++j) {
207         TString stripName(TString::Format("PHOS/Module%d/Strip_%d_%d", module, i, j));
208         new(array[arrayInd]) AliAlignObjAngles(stripName.Data(), volid, 0., 0., 0., 0., 0., 0., true);
209         ++arrayInd;
210       }
211 }
212
213 //____________________________________________________________________________
214 AliPHOSSurvey::AliPHOSStripDelta AliPHOSSurvey::GetStripTransformation(Int_t stripIndex, Int_t module)const
215 {
216   //Strip 'stripIndex' transformation.
217   AliPHOSStripDelta t = {0., 0., 0., 0., 0., 0.};
218   if (module != 3 || !fStripData)
219     return t;
220   return fStripData[stripIndex];
221 }