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