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