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