]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSSurvey.cxx
Bug in choise of RawFitter version corrected
[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
6ba1dd81 106 for (Int_t i = 0; i < fStrNum * 2; ++i) {
107 xReal[i] = 0.;
108 zReal[i] = 0.;
109 }
110
56afa9a8 111 for (Int_t i = 0; i < fStrNum * 2; ++i) {
3c759505 112 if (!inputFile) {
113 AliError("Error while reading input file.");
56afa9a8 114 delete [] xReal;
115 delete [] zReal;
3c759505 116 return;
117 }
118 inputFile>>dummyInt>>xReal[i]>>dummyY>>zReal[i];
119 xReal[i] *= 0.1;
120 zReal[i] *= 0.1;
121 }
122
42c5218a 123 InitStripData(xReal, zReal);
56afa9a8 124
56afa9a8 125 delete [] zReal;
126 delete [] xReal;
56afa9a8 127}
128
129//____________________________________________________________________________
130AliPHOSSurvey::~AliPHOSSurvey()
131{
132 delete [] fStripData;
3c759505 133}
134
135//____________________________________________________________________________
90dbf5fb 136void AliPHOSSurvey::CreateAliAlignObjParams(TClonesArray &array)
3c759505 137{
90dbf5fb 138 //Create AliAlignObjParams.
3c759505 139 const AliPHOSGeometry * phosGeom = AliPHOSGeometry::GetInstance("IHEP", "IHEP");
140 if (!phosGeom) {
141 AliError("Cannot obtain AliPHOSGeometry instance.");
142 return;
143 }
144
145 if (!gGeoManager) {
146 AliWarning("Cannot create local transformations for strip units - gGeoManager does not exist.");
147 AliInfo("Null shifts and rotations will be created instead.");
148 return CreateNullObjects(array, phosGeom);
149 }
150
151 AliPHOSEMCAGeometry * emcaGeom = phosGeom->GetEMCAGeometry();
152 Int_t arrayInd = array.GetEntries(), iIndex = 0;
afb6e026 153 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
154 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
3c759505 155
156 for (Int_t module = 1; module <= phosGeom->GetNModules(); ++module) {
157 for (Int_t i = 0, stripNum = 0; i < emcaGeom->GetNStripX(); ++i) {
158 for (Int_t j = 0; j < emcaGeom->GetNStripZ(); ++j) {
159 TString stripName(TString::Format("PHOS/Module%d/Strip_%d_%d", module, i, j));
56afa9a8 160 AliPHOSStripDelta t(GetStripTransformation(stripNum++, module));
3c759505 161 new(array[arrayInd])
90dbf5fb 162 AliAlignObjParams(
3c759505 163 stripName.Data(), volid,
164 t.fXShift, t.fYShift, t.fZShift,
165 -t.fPsi, -t.fTheta, -t.fPhi,
56afa9a8 166 false
3c759505 167 );
168 ++arrayInd;
169 }
170 }
171 }
172}
173
174//____________________________________________________________________________
175void AliPHOSSurvey::CreateNullObjects(TClonesArray &array, const AliPHOSGeometry *phosGeom)const
176{
177 //Create null shifts and rotations.
178 const AliPHOSEMCAGeometry * emcaGeom = phosGeom->GetEMCAGeometry();
179 Int_t arrayInd = array.GetEntries(), iIndex = 0;
afb6e026 180 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
181 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
3c759505 182
183 for (Int_t module = 1; module <= phosGeom->GetNModules(); ++module)
184 for (Int_t i = 0; i < emcaGeom->GetNStripX(); ++i)
185 for (Int_t j = 0; j < emcaGeom->GetNStripZ(); ++j) {
186 TString stripName(TString::Format("PHOS/Module%d/Strip_%d_%d", module, i, j));
90dbf5fb 187 new(array[arrayInd]) AliAlignObjParams(stripName.Data(), volid, 0., 0., 0., 0., 0., 0., true);
3c759505 188 ++arrayInd;
189 }
190}
191
192//____________________________________________________________________________
56afa9a8 193AliPHOSSurvey::AliPHOSStripDelta AliPHOSSurvey::GetStripTransformation(Int_t stripIndex, Int_t module)const
3c759505 194{
195 //Strip 'stripIndex' transformation.
56afa9a8 196 AliPHOSStripDelta t = {0., 0., 0., 0., 0., 0.};
197 if (module != 3 || !fStripData)
3c759505 198 return t;
199 return fStripData[stripIndex];
200}
42c5218a 201
202//____________________________________________________________________________
203void AliPHOSSurvey::InitStripData(const Double_t *xReal, const Double_t *zReal)
204{
205 const AliPHOSGeometry *phosGeom = AliPHOSGeometry::GetInstance("IHEP", "IHEP");
206 AliPHOSEMCAGeometry * emcaGeom = phosGeom->GetEMCAGeometry();
207 const Float_t *strip = emcaGeom->GetStripHalfSize();
07ca2d72 208 const Float_t *cell = emcaGeom->GetAirCellHalfSize();
42c5218a 209
210 AliPHOSStripCoords *idealStrips = new AliPHOSStripCoords[fStrNum];//1
211 for (Int_t ix = 0, stripNumber = 0; ix < emcaGeom->GetNStripX(); ++ix) {
212 for (Int_t iz = 0; iz < emcaGeom->GetNStripZ(); ++iz) {
213 AliPHOSStripCoords &str = idealStrips[stripNumber++];
214 str.fX1 = ix * 2 * strip[0];
215 str.fX2 = str.fX1 + 14 * cell[0];
216 str.fZ1 = iz * 2 * strip[2];
217 str.fZ2 = str.fZ1 + 2 * cell[2];
218 }
219 }
220
221 AliPHOSStripCoords *realStrips = new AliPHOSStripCoords[fStrNum];//4
222 for (Int_t j = 0, stripNumber = 0; j < emcaGeom->GetNStripX() * 2; j += 2) {
223 for (Int_t i = 0; i < emcaGeom->GetNStripZ(); ++i) {
224 AliPHOSStripCoords &str = realStrips[stripNumber++];
225 str.fX1 = xReal[i + j * emcaGeom->GetNStripZ()];
226 str.fZ1 = zReal[i + j * emcaGeom->GetNStripZ()];
227 str.fX2 = xReal[i + (j + 1) * emcaGeom->GetNStripZ()];
228 str.fZ2 = zReal[i + (j + 1) * emcaGeom->GetNStripZ()];
229 }
230 }
231
232 fStripData = new AliPHOSStripDelta[fStrNum];
233
234 for (Int_t i = 0; i < fStrNum; ++i) {
235 const AliPHOSStripCoords &real = realStrips[i];
236 const AliPHOSStripCoords &ideal = idealStrips[i];
237 AliPHOSStripDelta &t = fStripData[i];
238 t.fTheta = TMath::ATan((real.fZ2 - real.fZ1) / (real.fX2 - real.fX1)) -
239 TMath::ATan((ideal.fZ2 - ideal.fZ1) / (ideal.fX2 - ideal.fX1));
240 t.fTheta *= TMath::RadToDeg();
241 t.fXShift = (real.fX1 + real.fX2) / 2 - (ideal.fX1 + ideal.fX2) / 2;
242 t.fZShift = (real.fZ1 + real.fZ2) / 2 - (ideal.fZ1 + ideal.fZ2) / 2;
243 t.fYShift = 0., t.fPsi = 0., t.fPhi = 0.;
244 }
245
246 delete [] realStrips;
247 delete [] idealStrips;
248}