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