Rename of version v4
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGeometry.cxx
CommitLineData
d15a28e7 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
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
b2a60966 19// Geometry class for PHOS : singleton
a3dfe79c 20// PHOS consists of the electromagnetic calorimeter (EMCA)
21// and a charged particle veto either in the Subatech's version (PPSD)
22// or in the IHEP's one (CPV).
23// The EMCA/PPSD/CPV modules are parametrized so that any configuration
24// can be easily implemented
25// The title is used to identify the version of CPV used.
b2a60966 26//
27//*-- Author: Yves Schutz (SUBATECH)
d15a28e7 28
29// --- ROOT system ---
30
31#include "TVector3.h"
32#include "TRotation.h"
fa7cce36 33#include "TFolder.h"
34#include "TROOT.h"
d15a28e7 35
36// --- Standard library ---
37
de9ec31b 38#include <iostream.h>
4410223b 39#include <stdlib.h>
d15a28e7 40
41// --- AliRoot header files ---
42
43#include "AliPHOSGeometry.h"
468794ea 44#include "AliPHOSEMCAGeometry.h"
d15a28e7 45#include "AliPHOSPpsdRecPoint.h"
46#include "AliConst.h"
47
9ec91567 48ClassImp(AliPHOSGeometry) ;
d15a28e7 49
a4e98857 50// these initialisations are needed for a singleton
9ec91567 51AliPHOSGeometry * AliPHOSGeometry::fgGeom = 0 ;
282c5906 52Bool_t AliPHOSGeometry::fgInit = kFALSE ;
9ec91567 53
d15a28e7 54//____________________________________________________________________________
55AliPHOSGeometry::~AliPHOSGeometry(void)
56{
b2a60966 57 // dtor
58
52a36ffd 59 if (fRotMatrixArray) fRotMatrixArray->Delete() ;
60 if (fRotMatrixArray) delete fRotMatrixArray ;
61 if (fPHOSAngle ) delete fPHOSAngle ;
62}
63
64//____________________________________________________________________________
65
66void AliPHOSGeometry::Init(void)
67{
a4e98857 68 // Initializes the PHOS parameters :
69 // IHEP is the Protvino CPV (cathode pad chambers)
70 // GPS2 is the Subatech Pre-Shower (two micromegas sandwiching a passive lead converter)
71 // MIXT 4 PHOS modules withe the IHEP CPV qnd one PHOS module with the Subatche Pre-Shower
52a36ffd 72
a4e98857 73 if ( ((strcmp( fName, "GPS2" )) == 0) ||
ed4205d8 74 ((strcmp( fName, "IHEP" )) == 0) ||
75 ((strcmp( fName, "MIXT" )) == 0) ) {
52a36ffd 76 fgInit = kTRUE ;
ed4205d8 77
78 fNModules = 5;
79 fNPPSDModules = 0;
80 fAngle = 20;
81
82 fGeometryEMCA = new AliPHOSEMCAGeometry();
83 if ( ((strcmp( fName, "GPS2" )) == 0) ) {
84 fGeometryPPSD = new AliPHOSPPSDGeometry();
85 fGeometryCPV = 0;
86 fNPPSDModules = fNModules;
87 }
88 else if ( ((strcmp( fName, "IHEP" )) == 0) ) {
89 fGeometryCPV = new AliPHOSCPVGeometry ();
90 fGeometryPPSD = 0;
91 fNPPSDModules = 0;
92 }
93 else if ( ((strcmp( fName, "MIXT" )) == 0) ) {
94 fGeometryCPV = new AliPHOSCPVGeometry ();
95 fGeometryPPSD = new AliPHOSPPSDGeometry();
96 fNPPSDModules = 1;
97 }
98 fGeometrySUPP = new AliPHOSSupportGeometry();
99
52a36ffd 100 fPHOSAngle = new Float_t[fNModules] ;
101 Int_t index ;
102 for ( index = 0; index < fNModules; index++ )
103 fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
104
105 this->SetPHOSAngles() ;
106 fRotMatrixArray = new TObjArray(fNModules) ;
fa7cce36 107
108 // post the geometry into the appropriate folder
7b7c1533 109 TFolder * folder = (TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/Geometry/PHOS");
110 if ( !folder ) {
111 cerr << "ERROR: AliPHOSGeometry::Init -> No WhiteBoard/Geometry/PHOS found !" << endl ;
112 abort();
113 } else {
fa7cce36 114 folder->SetOwner() ;
115 folder->Add(this) ;
7b7c1533 116 }
52a36ffd 117 }
ed4205d8 118 else {
119 fgInit = kFALSE ;
120 cout << "PHOS Geometry setup: option not defined " << fName << endl ;
d0f1c6bb 121 abort() ;
ed4205d8 122 }
52a36ffd 123}
124
5ccb0008 125
126//____________________________________________________________________________
127Bool_t AliPHOSGeometry::IsInEMC(const Int_t id) const {
128 Int_t relid[4] ;
129 AbsToRelNumbering(id, relid) ;
130 if ( relid[1] == 0 )
131 return kTRUE ;
132 else
133 return kFALSE ;
134 }
135
52a36ffd 136//____________________________________________________________________________
a4e98857 137Float_t AliPHOSGeometry::GetCPVBoxSize(Int_t index) const
138{
139 // returns the coarse dimension CPV depending on the CPV option set
140
2f04ed65 141 if (strcmp(fName,"GPS2") ==0 )
142 return fGeometryPPSD->GetCPVBoxSize(index);
143 else if (strcmp(fName,"IHEP")==0)
144 return fGeometryCPV ->GetCPVBoxSize(index);
145 else if (strcmp(fName,"MIXT")==0)
146 return TMath::Max(fGeometryCPV ->GetCPVBoxSize(index), fGeometryPPSD->GetCPVBoxSize(index));
147 else
148 return 0;
149}
150
151//____________________________________________________________________________
52a36ffd 152AliPHOSGeometry * AliPHOSGeometry::GetInstance()
153{
a4e98857 154 // Returns the pointer of the unique instance; singleton specific
155
52a36ffd 156 return (AliPHOSGeometry *) fgGeom ;
157}
158
159//____________________________________________________________________________
160AliPHOSGeometry * AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title)
161{
162 // Returns the pointer of the unique instance
a4e98857 163 // Creates it with the specified options (name, title) if it does not exist yet
164
52a36ffd 165 AliPHOSGeometry * rv = 0 ;
166 if ( fgGeom == 0 ) {
167 if ( strcmp(name,"") == 0 )
168 rv = 0 ;
169 else {
170 fgGeom = new AliPHOSGeometry(name, title) ;
171 if ( fgInit )
172 rv = (AliPHOSGeometry * ) fgGeom ;
173 else {
174 rv = 0 ;
175 delete fgGeom ;
176 fgGeom = 0 ;
177 }
178 }
179 }
180 else {
181 if ( strcmp(fgGeom->GetName(), name) != 0 ) {
182 cout << "AliPHOSGeometry <E> : current geometry is " << fgGeom->GetName() << endl
183 << " you cannot call " << name << endl ;
184 }
185 else
186 rv = (AliPHOSGeometry *) fgGeom ;
187 }
188 return rv ;
189}
4697edca 190
52a36ffd 191//____________________________________________________________________________
192void AliPHOSGeometry::SetPHOSAngles()
193{
a4e98857 194 // Calculates the position of the PHOS modules in ALICE global coordinate system
52a36ffd 195
196 Double_t const kRADDEG = 180.0 / kPI ;
ed4205d8 197 Float_t pphi = 2 * TMath::ATan( GetOuterBoxSize(0) / ( 2.0 * GetIPtoOuterCoverDistance() ) ) ;
52a36ffd 198 pphi *= kRADDEG ;
ed4205d8 199 if (pphi > fAngle) cout << "AliPHOSGeometry: PHOS modules overlap!\n";
200 pphi = fAngle;
52a36ffd 201
202 for( Int_t i = 1; i <= fNModules ; i++ ) {
ed4205d8 203 Float_t angle = pphi * ( i - fNModules / 2.0 - 0.5 ) ;
52a36ffd 204 fPHOSAngle[i-1] = - angle ;
205 }
d15a28e7 206}
207
208//____________________________________________________________________________
7b7c1533 209Bool_t AliPHOSGeometry::AbsToRelNumbering(const Int_t AbsId, Int_t * relid) const
d15a28e7 210{
b2a60966 211 // Converts the absolute numbering into the following array/
212 // relid[0] = PHOS Module number 1:fNModules
213 // relid[1] = 0 if PbW04
214 // = PPSD Module number 1:fNumberOfModulesPhi*fNumberOfModulesZ*2 (2->up and bottom level)
215 // relid[2] = Row number inside a PHOS or PPSD module
216 // relid[3] = Column number inside a PHOS or PPSD module
d15a28e7 217
218 Bool_t rv = kTRUE ;
92862013 219 Float_t id = AbsId ;
d15a28e7 220
92862013 221 Int_t phosmodulenumber = (Int_t)TMath:: Ceil( id / ( GetNPhi() * GetNZ() ) ) ;
d15a28e7 222
52a36ffd 223 if ( phosmodulenumber > GetNModules() ) { // it is a PPSD or CPV pad
224
225 if ( strcmp(fName,"GPS2") == 0 ) {
226 id -= GetNPhi() * GetNZ() * GetNModules() ;
227 Float_t tempo = 2 * GetNumberOfModulesPhi() * GetNumberOfModulesZ() * GetNumberOfPadsPhi() * GetNumberOfPadsZ() ;
228 relid[0] = (Int_t)TMath::Ceil( id / tempo ) ;
229 id -= ( relid[0] - 1 ) * tempo ;
230 relid[1] = (Int_t)TMath::Ceil( id / ( GetNumberOfPadsPhi() * GetNumberOfPadsZ() ) ) ;
231 id -= ( relid[1] - 1 ) * GetNumberOfPadsPhi() * GetNumberOfPadsZ() ;
232 relid[2] = (Int_t)TMath::Ceil( id / GetNumberOfPadsPhi() ) ;
233 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfPadsPhi() ) ;
234 }
235 else if ( strcmp(fName,"IHEP") == 0 ) {
236 id -= GetNPhi() * GetNZ() * GetNModules() ;
ed4205d8 237 Float_t nCPV = GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() ;
238 relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
52a36ffd 239 relid[1] = 1 ;
ed4205d8 240 id -= ( relid[0] - 1 ) * nCPV ;
241 relid[2] = (Int_t) TMath::Ceil( id / GetNumberOfCPVPadsZ() ) ;
242 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() ) ;
243 }
244 else if ( strcmp(fName,"MIXT") == 0 ) {
245 id -= GetNPhi() * GetNZ() * GetNModules() ;
246 Float_t nPPSD = 2 * GetNumberOfModulesPhi() * GetNumberOfModulesZ() * GetNumberOfPadsPhi() * GetNumberOfPadsZ() ;
247 Float_t nCPV = GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() ;
248 if (id <= nCPV*GetNCPVModules()) { // this pad belons to CPV
249 relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
250 relid[1] = 1 ;
251 id -= ( relid[0] - 1 ) * nCPV ;
252 relid[2] = (Int_t) TMath::Ceil( id / GetNumberOfCPVPadsZ() ) ;
253 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() ) ;
254 }
255 else { // this pad belons to PPSD
256 id -= nCPV*GetNCPVModules();
257 relid[0] = (Int_t)TMath::Ceil( id / nPPSD );
258 id -= ( relid[0] - 1 ) * nPPSD ;
259 relid[0] += GetNCPVModules();
260 relid[1] = (Int_t)TMath::Ceil( id / ( GetNumberOfPadsPhi() * GetNumberOfPadsZ() ) ) ;
261 id -= ( relid[1] - 1 ) * GetNumberOfPadsPhi() * GetNumberOfPadsZ() ;
262 relid[2] = (Int_t)TMath::Ceil( id / GetNumberOfPadsPhi() ) ;
263 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfPadsPhi() ) ;
264 }
52a36ffd 265 }
d15a28e7 266 }
267 else { // its a PW04 crystal
268
92862013 269 relid[0] = phosmodulenumber ;
270 relid[1] = 0 ;
271 id -= ( phosmodulenumber - 1 ) * GetNPhi() * GetNZ() ;
272 relid[2] = (Int_t)TMath::Ceil( id / GetNPhi() ) ;
273 relid[3] = (Int_t)( id - ( relid[2] - 1 ) * GetNPhi() ) ;
d15a28e7 274 }
275 return rv ;
276}
52a36ffd 277
9f616d61 278//____________________________________________________________________________
7b7c1533 279void AliPHOSGeometry::EmcModuleCoverage(const Int_t mod, Double_t & tm, Double_t & tM, Double_t & pm, Double_t & pM, Option_t * opt) const
9f616d61 280{
a4e98857 281 // calculates the angular coverage in theta and phi of one EMC (=PHOS) module
9f616d61 282
283 Double_t conv ;
cf0c2bc1 284 if ( opt == Radian() )
9f616d61 285 conv = 1. ;
cf0c2bc1 286 else if ( opt == Degre() )
9f616d61 287 conv = 180. / TMath::Pi() ;
288 else {
289 cout << "<I> AliPHOSGeometry::EmcXtalCoverage : " << opt << " unknown option; result in radian " << endl ;
290 conv = 1. ;
291 }
292
293 Float_t phi = GetPHOSAngle(mod) * (TMath::Pi() / 180.) ;
92862013 294 Float_t y0 = GetIPtoOuterCoverDistance() + GetUpperPlateThickness()
9f616d61 295 + GetSecondUpperPlateThickness() + GetUpperCoolingPlateThickness() ;
296
92862013 297 Double_t angle = TMath::ATan( GetCrystalSize(0)*GetNPhi() / (2 * y0) ) ;
9f616d61 298 phi = phi + 1.5 * TMath::Pi() ; // to follow the convention of the particle generator(PHOS is between 230 and 310 deg.)
92862013 299 Double_t max = phi - angle ;
300 Double_t min = phi + angle ;
301 pM = TMath::Max(max, min) * conv ;
302 pm = TMath::Min(max, min) * conv ;
9f616d61 303
92862013 304 angle = TMath::ATan( GetCrystalSize(2)*GetNZ() / (2 * y0) ) ;
305 max = TMath::Pi() / 2. + angle ; // to follow the convention of the particle generator(PHOS is at 90 deg.)
306 min = TMath::Pi() / 2. - angle ;
307 tM = TMath::Max(max, min) * conv ;
308 tm = TMath::Min(max, min) * conv ;
9f616d61 309
310}
311
312//____________________________________________________________________________
7b7c1533 313void AliPHOSGeometry::EmcXtalCoverage(Double_t & theta, Double_t & phi, Option_t * opt) const
9f616d61 314{
a4e98857 315 // calculates the angular coverage in theta and phi of a single crystal in a EMC(=PHOS) module
9f616d61 316
317 Double_t conv ;
cf0c2bc1 318 if ( opt == Radian() )
9f616d61 319 conv = 1. ;
cf0c2bc1 320 else if ( opt == Degre() )
9f616d61 321 conv = 180. / TMath::Pi() ;
322 else {
323 cout << "<I> AliPHOSGeometry::EmcXtalCoverage : " << opt << " unknown option; result in radian " << endl ;
324 conv = 1. ;
325 }
326
92862013 327 Float_t y0 = GetIPtoOuterCoverDistance() + GetUpperPlateThickness()
9f616d61 328 + GetSecondUpperPlateThickness() + GetUpperCoolingPlateThickness() ;
92862013 329 theta = 2 * TMath::ATan( GetCrystalSize(2) / (2 * y0) ) * conv ;
330 phi = 2 * TMath::ATan( GetCrystalSize(0) / (2 * y0) ) * conv ;
9f616d61 331}
332
333
334//____________________________________________________________________________
52a36ffd 335void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos, TMatrix & gmat) const
d15a28e7 336{
a4e98857 337 // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
b2a60966 338
d15a28e7 339 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
92862013 340 TVector3 localposition ;
d15a28e7 341
342 tmpPHOS->GetLocalPosition(gpos) ;
343
344
345 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
346 { gpos.SetY( -(GetIPtoOuterCoverDistance() + GetUpperPlateThickness() +
347 GetSecondUpperPlateThickness() + GetUpperCoolingPlateThickness()) ) ;
348
349 }
350 else
351 { // it is a PPSD pad
352 AliPHOSPpsdRecPoint * tmpPpsd = (AliPHOSPpsdRecPoint *) RecPoint ;
353 if (tmpPpsd->GetUp() ) // it is an upper module
354 {
355 gpos.SetY(-( GetIPtoOuterCoverDistance() - GetMicromegas2Thickness() -
356 GetLeadToMicro2Gap() - GetLeadConverterThickness() -
357 GetMicro1ToLeadGap() - GetMicromegas1Thickness() / 2.0 ) ) ;
358 }
359 else // it is a lower module
360 gpos.SetY(-( GetIPtoOuterCoverDistance() - GetMicromegas2Thickness() / 2.0) ) ;
361 }
362
92862013 363 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
364 Double_t const kRADDEG = 180.0 / kPI ;
365 Float_t rphi = phi / kRADDEG ;
d15a28e7 366
92862013 367 TRotation rot ;
368 rot.RotateZ(-rphi) ; // a rotation around Z by angle
d15a28e7 369
92862013 370 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
371 gpos.Transform(rot) ; // rotate the baby
6ad0bfa0 372
d15a28e7 373}
374
375//____________________________________________________________________________
5cda30f6 376void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos) const
d15a28e7 377{
a4e98857 378 // Calculates the coordinates of a RecPoint in the ALICE global coordinate system
b2a60966 379
d15a28e7 380 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
92862013 381 TVector3 localposition ;
d15a28e7 382 tmpPHOS->GetLocalPosition(gpos) ;
383
384
385 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
386 { gpos.SetY( -(GetIPtoOuterCoverDistance() + GetUpperPlateThickness() +
387 GetSecondUpperPlateThickness() + GetUpperCoolingPlateThickness()) ) ;
388 }
389 else
390 { // it is a PPSD pad
391 AliPHOSPpsdRecPoint * tmpPpsd = (AliPHOSPpsdRecPoint *) RecPoint ;
392 if (tmpPpsd->GetUp() ) // it is an upper module
393 {
394 gpos.SetY(-( GetIPtoOuterCoverDistance() - GetMicromegas2Thickness() -
395 GetLeadToMicro2Gap() - GetLeadConverterThickness() -
396 GetMicro1ToLeadGap() - GetMicromegas1Thickness() / 2.0 ) ) ;
397 }
398 else // it is a lower module
399 gpos.SetY(-( GetIPtoOuterCoverDistance() - GetMicromegas2Thickness() / 2.0) ) ;
400 }
401
92862013 402 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
403 Double_t const kRADDEG = 180.0 / kPI ;
404 Float_t rphi = phi / kRADDEG ;
d15a28e7 405
92862013 406 TRotation rot ;
407 rot.RotateZ(-rphi) ; // a rotation around Z by angle
d15a28e7 408
92862013 409 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
410 gpos.Transform(rot) ; // rotate the baby
d15a28e7 411}
412
413//____________________________________________________________________________
7b7c1533 414void AliPHOSGeometry::ImpactOnEmc(const Double_t theta, const Double_t phi, Int_t & ModuleNumber, Double_t & z, Double_t & x) const
d15a28e7 415{
a4e98857 416 // calculates the impact coordinates on PHOS of a neutral particle
417 // emitted in the direction theta and phi in the ALICE global coordinate system
d15a28e7 418
52a36ffd 419 // searches for the PHOS EMC module
420 ModuleNumber = 0 ;
421 Double_t tm, tM, pm, pM ;
422 Int_t index = 1 ;
423 while ( ModuleNumber == 0 && index <= GetNModules() ) {
424 EmcModuleCoverage(index, tm, tM, pm, pM) ;
425 if ( (theta >= tm && theta <= tM) && (phi >= pm && phi <= pM ) )
426 ModuleNumber = index ;
427 index++ ;
d15a28e7 428 }
52a36ffd 429 if ( ModuleNumber != 0 ) {
430 Float_t phi0 = GetPHOSAngle(ModuleNumber) * (TMath::Pi() / 180.) + 1.5 * TMath::Pi() ;
431 Float_t y0 = GetIPtoOuterCoverDistance() + GetUpperPlateThickness()
432 + GetSecondUpperPlateThickness() + GetUpperCoolingPlateThickness() ;
433 Double_t angle = phi - phi0;
434 x = y0 * TMath::Tan(angle) ;
435 angle = theta - TMath::Pi() / 2 ;
436 z = y0 * TMath::Tan(angle) ;
d15a28e7 437 }
d15a28e7 438}
439
440//____________________________________________________________________________
7b7c1533 441Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t & AbsId) const
d15a28e7 442{
b2a60966 443 // Converts the relative numbering into the absolute numbering
ed4205d8 444 // EMCA crystals:
445 // AbsId = from 1 to fNModules * fNPhi * fNZ
446 // PPSD gas cell:
447 // AbsId = from N(total EMCA crystals) + 1
448 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ +
449 // fNModules * 2 * (fNumberOfModulesPhi * fNumberOfModulesZ) * fNumberOfPadsPhi * fNumberOfPadsZ
450 // CPV pad:
451 // AbsId = from N(total PHOS crystals) + 1
452 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
d15a28e7 453
454 Bool_t rv = kTRUE ;
455
ed4205d8 456 if ( relid[1] > 0 && strcmp(fName,"GPS2")==0) { // it is a PPSD pad
457 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from PPSD pads
458 + ( relid[0] - 1 ) * GetNumberOfModulesPhi() * GetNumberOfModulesZ() // the pads offset of PPSD modules
d15a28e7 459 * GetNumberOfPadsPhi() * GetNumberOfPadsZ() * 2
ed4205d8 460 + ( relid[1] - 1 ) * GetNumberOfPadsPhi() * GetNumberOfPadsZ() // the pads offset of PPSD modules
461 + ( relid[2] - 1 ) * GetNumberOfPadsPhi() // the pads offset of a PPSD row
462 + relid[3] ; // the column number
463 }
464
465 else if ( relid[1] > 0 && strcmp(fName,"MIXT")==0) { // it is a PPSD pad
466 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from PPSD pads
467 + GetNCPVModules() * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() // the pads offset of CPV modules if any
468 + ( relid[0] - 1 - GetNCPVModules())
469 * GetNumberOfModulesPhi() * GetNumberOfModulesZ() // the pads offset of PPSD modules
470 * GetNumberOfPadsPhi() * GetNumberOfPadsZ() * 2
471 + ( relid[1] - 1 ) * GetNumberOfPadsPhi() * GetNumberOfPadsZ() // the pads offset of PPSD modules
472 + ( relid[2] - 1 ) * GetNumberOfPadsPhi() // the pads offset of a PPSD row
473 + relid[3] ; // the column number
d15a28e7 474 }
52a36ffd 475
476 else if ( relid[1] == 0 ) { // it is a Phos crystal
477 AbsId =
478 ( relid[0] - 1 ) * GetNPhi() * GetNZ() // the offset of PHOS modules
479 + ( relid[2] - 1 ) * GetNPhi() // the offset of a xtal row
480 + relid[3] ; // the column number
d15a28e7 481 }
482
52a36ffd 483 else if ( relid[1] == -1 ) { // it is a CPV pad
484 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from CPV pads
ed4205d8 485 + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() // the pads offset of PHOS modules
486 + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() // the pads offset of a CPV row
52a36ffd 487 + relid[3] ; // the column number
488 }
489
d15a28e7 490 return rv ;
491}
492
493//____________________________________________________________________________
494
7b7c1533 495void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
d15a28e7 496{
a4e98857 497 // Converts the absolute numbering into the global ALICE coordinate system
ed4205d8 498 // It works only for the GPS2 geometry
b2a60966 499
ed4205d8 500 if (id > 0 && strcmp(fName,"GPS2")==0) {
501
502 Int_t relid[4] ;
503
504 AbsToRelNumbering(id , relid) ;
505
506 Int_t phosmodule = relid[0] ;
507
508 Float_t y0 = 0 ;
509
510 if ( relid[1] == 0 ) { // it is a PbW04 crystal
511 y0 = -(GetIPtoOuterCoverDistance() + GetUpperPlateThickness()
512 + GetSecondUpperPlateThickness() + GetUpperCoolingPlateThickness()) ;
513 }
514 if ( relid[1] > 0 ) { // its a PPSD pad
515 if ( relid[1] > GetNumberOfModulesPhi() * GetNumberOfModulesZ() ) { // its an bottom module
516 y0 = -( GetIPtoOuterCoverDistance() - GetMicromegas2Thickness() / 2.0) ;
517 }
518 else // its an upper module
519 y0 = -( GetIPtoOuterCoverDistance() - GetMicromegas2Thickness() - GetLeadToMicro2Gap()
520 - GetLeadConverterThickness() - GetMicro1ToLeadGap() - GetMicromegas1Thickness() / 2.0) ;
521 }
522
523 Float_t x, z ;
524 RelPosInModule(relid, x, z) ;
525
526 pos.SetX(x) ;
527 pos.SetZ(z) ;
9cc0fcba 528 pos.SetY(- TMath::Sqrt(x*x + z*z + y0*y0) ) ;
ed4205d8 529
530
531
532 Float_t phi = GetPHOSAngle( phosmodule) ;
533 Double_t const kRADDEG = 180.0 / kPI ;
534 Float_t rphi = phi / kRADDEG ;
535
536 TRotation rot ;
537 rot.RotateZ(-rphi) ; // a rotation around Z by angle
538
539 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
540
9cc0fcba 541 cout << "before X,Y,Z " << pos.X() << endl << pos.Y() << endl << pos.Z() << endl;
ed4205d8 542 pos.Transform(rot) ; // rotate the baby
9cc0fcba 543 cout << "X,Y,Z " << pos.X() << endl << pos.Y() << endl << pos.Z() << endl;
d15a28e7 544 }
545 else {
ed4205d8 546 pos.SetX(0.);
547 pos.SetY(0.);
548 pos.SetZ(0.);
549 }
d15a28e7 550}
551
552//____________________________________________________________________________
7b7c1533 553void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const
d15a28e7 554{
b2a60966 555 // Converts the relative numbering into the local PHOS-module (x, z) coordinates
52a36ffd 556 // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
ed4205d8 557
558 Bool_t padOfCPV = (strcmp(fName,"IHEP")==0) ||
559 ((strcmp(fName,"MIXT")==0) && relid[0]<=GetNCPVModules()) ;
560 Bool_t padOfPPSD = (strcmp(fName,"GPS2")==0) ||
561 ((strcmp(fName,"MIXT")==0) && relid[0]> GetNCPVModules()) ;
b2a60966 562
92862013 563 Int_t ppsdmodule ;
a3dfe79c 564 Float_t x0,z0;
52a36ffd 565 Int_t row = relid[2] ; //offset along x axiz
566 Int_t column = relid[3] ; //offset along z axiz
d15a28e7 567
ed4205d8 568 Float_t padsizeZ = 0;
569 Float_t padsizeX = 0;
570 Int_t nOfPadsPhi = 0;
571 Int_t nOfPadsZ = 0;
572 if ( padOfPPSD ) {
573 padsizeZ = GetPPSDModuleSize(2) / GetNumberOfPadsZ();
574 padsizeX = GetPPSDModuleSize(0) / GetNumberOfPadsPhi();
575 nOfPadsPhi = GetNumberOfPadsPhi();
576 nOfPadsZ = GetNumberOfPadsZ();
577 }
578 else if ( padOfCPV ) {
579 padsizeZ = GetPadSizeZ();
580 padsizeX = GetPadSizePhi();
581 nOfPadsPhi = GetNumberOfCPVPadsPhi();
582 nOfPadsZ = GetNumberOfCPVPadsZ();
583 }
584
92862013 585 if ( relid[1] == 0 ) { // its a PbW04 crystal
52a36ffd 586 x = - ( GetNPhi()/2. - row + 0.5 ) * GetCrystalSize(0) ; // position ox Xtal with respect
587 z = ( GetNZ() /2. - column + 0.5 ) * GetCrystalSize(2) ; // of center of PHOS module
588 }
589 else {
ed4205d8 590 if ( padOfPPSD ) {
591 if ( relid[1] > GetNumberOfModulesPhi() * GetNumberOfModulesZ() )
592 ppsdmodule = relid[1]-GetNumberOfModulesPhi() * GetNumberOfModulesZ();
593 else
594 ppsdmodule = relid[1] ;
595 Int_t modrow = 1+(Int_t)TMath::Ceil( (Float_t)ppsdmodule / GetNumberOfModulesPhi()-1. ) ;
596 Int_t modcol = ppsdmodule - ( modrow - 1 ) * GetNumberOfModulesPhi() ;
a3dfe79c 597 x0 = ( GetNumberOfModulesPhi() / 2. - modrow + 0.5 ) * GetPPSDModuleSize(0) ;
598 z0 = ( GetNumberOfModulesZ() / 2. - modcol + 0.5 ) * GetPPSDModuleSize(2) ;
599 } else {
600 x0 = 0;
601 z0 = 0;
602 }
ed4205d8 603 x = - ( nOfPadsPhi/2. - row - 0.5 ) * padsizeX + x0 ; // position of pad with respect
604 z = ( nOfPadsZ /2. - column - 0.5 ) * padsizeZ - z0 ; // of center of PHOS module
52a36ffd 605 }
2f3366b6 606}