]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGeometry.cxx
Use Riostream.h to resolve the std namespace (Alpha, HP)
[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//
710f859a 27//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC "KI" & 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"
710f859a 45#include "AliPHOSRecPoint.h"
d15a28e7 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 ;
fa0bc588 61 if (fPHOSAngle ) delete[] fPHOSAngle ;
52a36ffd 62}
52a36ffd 63//____________________________________________________________________________
64
65void AliPHOSGeometry::Init(void)
66{
a4e98857 67 // Initializes the PHOS parameters :
68 // IHEP is the Protvino CPV (cathode pad chambers)
69 // GPS2 is the Subatech Pre-Shower (two micromegas sandwiching a passive lead converter)
809cd394 70 // MIXT 4 PHOS modules withe the IHEP CPV and one PHOS module with the Subatech Pre-Shower
710f859a 71
809cd394 72 TString test(GetName()) ;
73 if (test != "IHEP" && test != "GPS2" && test != "MIXT") {
74 cerr << "ERROR: " << ClassName() << "::Init -> " << test.Data()
75 << " is not a known geometry (choose among IHEP, GPS2 and MIXT)" << endl ;
76 abort() ;
77 }
78
710f859a 79 fgInit = kTRUE ;
80
81 fNModules = 5;
82 fAngle = 20;
83
84 fGeometryEMCA = new AliPHOSEMCAGeometry();
85
86 fGeometryCPV = new AliPHOSCPVGeometry ();
87
88 fGeometrySUPP = new AliPHOSSupportGeometry();
89
90 fPHOSAngle = new Float_t[fNModules] ;
91
92 Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
93
581e32d4 94 fPHOSParams[0] = TMath::Max((Double_t)fGeometryCPV->GetCPVBoxSize(0)/2.,
95 (Double_t)(emcParams[0]*(fGeometryCPV->GetCPVBoxSize(1)+emcParams[3]) -
710f859a 96 emcParams[1]* fGeometryCPV->GetCPVBoxSize(1))/emcParams[3] ) ;
97 fPHOSParams[1] = emcParams[1] ;
581e32d4 98 fPHOSParams[2] = TMath::Max((Double_t)emcParams[2], (Double_t)fGeometryCPV->GetCPVBoxSize(2)/2.);
710f859a 99 fPHOSParams[3] = emcParams[3] + fGeometryCPV->GetCPVBoxSize(1)/2. ;
100
101 fIPtoUpperCPVsurface = fGeometryEMCA->GetIPtoOuterCoverDistance() - fGeometryCPV->GetCPVBoxSize(1) ;
102
103 Int_t index ;
104 for ( index = 0; index < fNModules; index++ )
52a36ffd 105 fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
710f859a 106
107 this->SetPHOSAngles() ;
108 fRotMatrixArray = new TObjArray(fNModules) ;
109
52a36ffd 110}
111
112//____________________________________________________________________________
113AliPHOSGeometry * AliPHOSGeometry::GetInstance()
114{
a4e98857 115 // Returns the pointer of the unique instance; singleton specific
116
809cd394 117 return static_cast<AliPHOSGeometry *>( fgGeom ) ;
52a36ffd 118}
119
120//____________________________________________________________________________
121AliPHOSGeometry * AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title)
122{
123 // Returns the pointer of the unique instance
a4e98857 124 // Creates it with the specified options (name, title) if it does not exist yet
125
52a36ffd 126 AliPHOSGeometry * rv = 0 ;
127 if ( fgGeom == 0 ) {
128 if ( strcmp(name,"") == 0 )
129 rv = 0 ;
130 else {
131 fgGeom = new AliPHOSGeometry(name, title) ;
132 if ( fgInit )
133 rv = (AliPHOSGeometry * ) fgGeom ;
134 else {
135 rv = 0 ;
136 delete fgGeom ;
137 fgGeom = 0 ;
138 }
139 }
140 }
141 else {
142 if ( strcmp(fgGeom->GetName(), name) != 0 ) {
143 cout << "AliPHOSGeometry <E> : current geometry is " << fgGeom->GetName() << endl
144 << " you cannot call " << name << endl ;
145 }
146 else
147 rv = (AliPHOSGeometry *) fgGeom ;
148 }
149 return rv ;
150}
4697edca 151
52a36ffd 152//____________________________________________________________________________
153void AliPHOSGeometry::SetPHOSAngles()
154{
a4e98857 155 // Calculates the position of the PHOS modules in ALICE global coordinate system
52a36ffd 156
157 Double_t const kRADDEG = 180.0 / kPI ;
710f859a 158 Float_t pphi = 2 * TMath::ATan( GetOuterBoxSize(0) / ( 2.0 * GetIPtoUpperCPVsurface() ) ) ;
52a36ffd 159 pphi *= kRADDEG ;
710f859a 160 if (pphi > fAngle){
161 cout << "AliPHOSGeometry: PHOS modules overlap!\n";
162 cout << "pphi = " << pphi << " fAngle " << fAngle << endl ;
163
164 }
ed4205d8 165 pphi = fAngle;
52a36ffd 166
167 for( Int_t i = 1; i <= fNModules ; i++ ) {
ed4205d8 168 Float_t angle = pphi * ( i - fNModules / 2.0 - 0.5 ) ;
52a36ffd 169 fPHOSAngle[i-1] = - angle ;
170 }
d15a28e7 171}
172
173//____________________________________________________________________________
7b7c1533 174Bool_t AliPHOSGeometry::AbsToRelNumbering(const Int_t AbsId, Int_t * relid) const
d15a28e7 175{
b2a60966 176 // Converts the absolute numbering into the following array/
177 // relid[0] = PHOS Module number 1:fNModules
178 // relid[1] = 0 if PbW04
710f859a 179 // = -1 if CPV
180 // relid[2] = Row number inside a PHOS module
181 // relid[3] = Column number inside a PHOS module
d15a28e7 182
183 Bool_t rv = kTRUE ;
92862013 184 Float_t id = AbsId ;
d15a28e7 185
710f859a 186 Int_t phosmodulenumber = (Int_t)TMath:: Ceil( id / GetNCristalsInModule() ) ;
d15a28e7 187
710f859a 188 if ( phosmodulenumber > GetNModules() ) { // it is a CPV pad
189
190 id -= GetNPhi() * GetNZ() * GetNModules() ;
191 Float_t nCPV = GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() ;
192 relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
193 relid[1] = -1 ;
194 id -= ( relid[0] - 1 ) * nCPV ;
195 relid[2] = (Int_t) TMath::Ceil( id / GetNumberOfCPVPadsZ() ) ;
196 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() ) ;
d15a28e7 197 }
710f859a 198 else { // it is a PW04 crystal
d15a28e7 199
92862013 200 relid[0] = phosmodulenumber ;
201 relid[1] = 0 ;
202 id -= ( phosmodulenumber - 1 ) * GetNPhi() * GetNZ() ;
710f859a 203 relid[2] = (Int_t)TMath::Ceil( id / GetNZ() ) ;
204 relid[3] = (Int_t)( id - ( relid[2] - 1 ) * GetNZ() ) ;
d15a28e7 205 }
206 return rv ;
207}
52a36ffd 208
9f616d61 209//____________________________________________________________________________
7b7c1533 210void AliPHOSGeometry::EmcModuleCoverage(const Int_t mod, Double_t & tm, Double_t & tM, Double_t & pm, Double_t & pM, Option_t * opt) const
9f616d61 211{
a4e98857 212 // calculates the angular coverage in theta and phi of one EMC (=PHOS) module
9f616d61 213
214 Double_t conv ;
cf0c2bc1 215 if ( opt == Radian() )
9f616d61 216 conv = 1. ;
cf0c2bc1 217 else if ( opt == Degre() )
9f616d61 218 conv = 180. / TMath::Pi() ;
219 else {
220 cout << "<I> AliPHOSGeometry::EmcXtalCoverage : " << opt << " unknown option; result in radian " << endl ;
221 conv = 1. ;
222 }
223
710f859a 224 Float_t phi = GetPHOSAngle(mod) * (TMath::Pi() / 180.) ;
225 Float_t y0 = GetIPtoCrystalSurface() ;
226 Float_t * strip = fGeometryEMCA->GetStripHalfSize() ;
227 Float_t x0 = fGeometryEMCA->GetNStripX()*strip[0] ;
228 Float_t z0 = fGeometryEMCA->GetNStripZ()*strip[2] ;
229 Double_t angle = TMath::ATan( x0 / y0 ) ;
230 phi = phi + 1.5 * TMath::Pi() ; // to follow the convention of the particle generator(PHOS is between 220 and 320 deg.)
92862013 231 Double_t max = phi - angle ;
232 Double_t min = phi + angle ;
233 pM = TMath::Max(max, min) * conv ;
234 pm = TMath::Min(max, min) * conv ;
9f616d61 235
710f859a 236 angle = TMath::ATan( z0 / y0 ) ;
92862013 237 max = TMath::Pi() / 2. + angle ; // to follow the convention of the particle generator(PHOS is at 90 deg.)
238 min = TMath::Pi() / 2. - angle ;
239 tM = TMath::Max(max, min) * conv ;
240 tm = TMath::Min(max, min) * conv ;
9f616d61 241
242}
243
244//____________________________________________________________________________
7b7c1533 245void AliPHOSGeometry::EmcXtalCoverage(Double_t & theta, Double_t & phi, Option_t * opt) const
9f616d61 246{
a4e98857 247 // calculates the angular coverage in theta and phi of a single crystal in a EMC(=PHOS) module
9f616d61 248
249 Double_t conv ;
cf0c2bc1 250 if ( opt == Radian() )
9f616d61 251 conv = 1. ;
cf0c2bc1 252 else if ( opt == Degre() )
9f616d61 253 conv = 180. / TMath::Pi() ;
254 else {
255 cout << "<I> AliPHOSGeometry::EmcXtalCoverage : " << opt << " unknown option; result in radian " << endl ;
256 conv = 1. ;
257 }
258
710f859a 259 Float_t y0 = GetIPtoCrystalSurface() ;
92862013 260 theta = 2 * TMath::ATan( GetCrystalSize(2) / (2 * y0) ) * conv ;
261 phi = 2 * TMath::ATan( GetCrystalSize(0) / (2 * y0) ) * conv ;
9f616d61 262}
263
264
265//____________________________________________________________________________
52a36ffd 266void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos, TMatrix & gmat) const
d15a28e7 267{
a4e98857 268 // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
b2a60966 269
d15a28e7 270 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
92862013 271 TVector3 localposition ;
d15a28e7 272
273 tmpPHOS->GetLocalPosition(gpos) ;
274
275
276 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
710f859a 277 { gpos.SetY( - GetIPtoCrystalSurface()) ;
d15a28e7 278
279 }
280 else
710f859a 281 { // it is a CPV
282 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
d15a28e7 283 }
284
92862013 285 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
286 Double_t const kRADDEG = 180.0 / kPI ;
287 Float_t rphi = phi / kRADDEG ;
d15a28e7 288
92862013 289 TRotation rot ;
290 rot.RotateZ(-rphi) ; // a rotation around Z by angle
d15a28e7 291
92862013 292 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
293 gpos.Transform(rot) ; // rotate the baby
6ad0bfa0 294
d15a28e7 295}
296
297//____________________________________________________________________________
5cda30f6 298void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos) const
d15a28e7 299{
a4e98857 300 // Calculates the coordinates of a RecPoint in the ALICE global coordinate system
b2a60966 301
d15a28e7 302 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
92862013 303 TVector3 localposition ;
d15a28e7 304 tmpPHOS->GetLocalPosition(gpos) ;
305
306
307 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
710f859a 308 { gpos.SetY( - GetIPtoCrystalSurface() ) ;
d15a28e7 309 }
310 else
710f859a 311 { // it is a CPV
312 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
d15a28e7 313 }
314
92862013 315 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
316 Double_t const kRADDEG = 180.0 / kPI ;
317 Float_t rphi = phi / kRADDEG ;
d15a28e7 318
92862013 319 TRotation rot ;
320 rot.RotateZ(-rphi) ; // a rotation around Z by angle
d15a28e7 321
92862013 322 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
323 gpos.Transform(rot) ; // rotate the baby
d15a28e7 324}
325
326//____________________________________________________________________________
7b7c1533 327void AliPHOSGeometry::ImpactOnEmc(const Double_t theta, const Double_t phi, Int_t & ModuleNumber, Double_t & z, Double_t & x) const
d15a28e7 328{
a4e98857 329 // calculates the impact coordinates on PHOS of a neutral particle
330 // emitted in the direction theta and phi in the ALICE global coordinate system
d15a28e7 331
52a36ffd 332 // searches for the PHOS EMC module
333 ModuleNumber = 0 ;
334 Double_t tm, tM, pm, pM ;
335 Int_t index = 1 ;
336 while ( ModuleNumber == 0 && index <= GetNModules() ) {
337 EmcModuleCoverage(index, tm, tM, pm, pM) ;
338 if ( (theta >= tm && theta <= tM) && (phi >= pm && phi <= pM ) )
339 ModuleNumber = index ;
340 index++ ;
d15a28e7 341 }
52a36ffd 342 if ( ModuleNumber != 0 ) {
343 Float_t phi0 = GetPHOSAngle(ModuleNumber) * (TMath::Pi() / 180.) + 1.5 * TMath::Pi() ;
710f859a 344 Float_t y0 = GetIPtoCrystalSurface() ;
52a36ffd 345 Double_t angle = phi - phi0;
346 x = y0 * TMath::Tan(angle) ;
347 angle = theta - TMath::Pi() / 2 ;
348 z = y0 * TMath::Tan(angle) ;
d15a28e7 349 }
d15a28e7 350}
351
1c9d8212 352Bool_t AliPHOSGeometry::Impact(const TParticle * particle) const
353{
354 Bool_t In=kFALSE;
355 Int_t ModuleNumber=0;
356 Double_t z,x;
357 ImpactOnEmc(particle->Theta(),particle->Phi(),ModuleNumber,z,x);
358 if(ModuleNumber) In=kTRUE;
359 else In=kFALSE;
360 return In;
361}
362
d15a28e7 363//____________________________________________________________________________
7b7c1533 364Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t & AbsId) const
d15a28e7 365{
b2a60966 366 // Converts the relative numbering into the absolute numbering
ed4205d8 367 // EMCA crystals:
368 // AbsId = from 1 to fNModules * fNPhi * fNZ
ed4205d8 369 // CPV pad:
370 // AbsId = from N(total PHOS crystals) + 1
371 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
d15a28e7 372
373 Bool_t rv = kTRUE ;
710f859a 374
375 if ( relid[1] == 0 ) { // it is a Phos crystal
52a36ffd 376 AbsId =
710f859a 377 ( relid[0] - 1 ) * GetNPhi() * GetNZ() // the offset of PHOS modules
378 + ( relid[2] - 1 ) * GetNZ() // the offset along phi
379 + relid[3] ; // the offset along z
d15a28e7 380 }
710f859a 381 else { // it is a CPV pad
382 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from CPV pads
383 + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() // the pads offset of PHOS modules
384 + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() // the pads offset of a CPV row
52a36ffd 385 + relid[3] ; // the column number
386 }
387
d15a28e7 388 return rv ;
389}
390
391//____________________________________________________________________________
392
7b7c1533 393void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
d15a28e7 394{
a4e98857 395 // Converts the absolute numbering into the global ALICE coordinate system
b2a60966 396
ed4205d8 397
398 Int_t relid[4] ;
399
400 AbsToRelNumbering(id , relid) ;
401
402 Int_t phosmodule = relid[0] ;
403
404 Float_t y0 = 0 ;
405
710f859a 406 if ( relid[1] == 0 ) // it is a PbW04 crystal
407 y0 = - GetIPtoCrystalSurface() ;
408 else
409 y0 = - GetIPtoUpperCPVsurface() ;
410
ed4205d8 411 Float_t x, z ;
412 RelPosInModule(relid, x, z) ;
413
414 pos.SetX(x) ;
415 pos.SetZ(z) ;
710f859a 416 pos.SetY(y0) ;
ed4205d8 417
418 Float_t phi = GetPHOSAngle( phosmodule) ;
419 Double_t const kRADDEG = 180.0 / kPI ;
420 Float_t rphi = phi / kRADDEG ;
421
422 TRotation rot ;
423 rot.RotateZ(-rphi) ; // a rotation around Z by angle
424
425 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
426
427 pos.Transform(rot) ; // rotate the baby
d15a28e7 428}
429
430//____________________________________________________________________________
7b7c1533 431void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const
d15a28e7 432{
b2a60966 433 // Converts the relative numbering into the local PHOS-module (x, z) coordinates
52a36ffd 434 // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
b2a60966 435
786222b3 436 Int_t row = relid[2] ; //offset along x axis
437 Int_t column = relid[3] ; //offset along z axis
d15a28e7 438
ed4205d8 439
66c3e8ff 440 if ( relid[1] == 0 ) { // its a PbW04 crystal
441 x = - ( GetNPhi()/2. - row + 0.5 ) * GetCellStep() ; // position of Xtal with respect
442 z = ( GetNZ() /2. - column + 0.5 ) * GetCellStep() ; // of center of PHOS module
52a36ffd 443 }
444 else {
710f859a 445 x = - ( GetNumberOfCPVPadsPhi()/2. - row - 0.5 ) * GetPadSizePhi() ; // position of pad with respect
446 z = ( GetNumberOfCPVPadsZ() /2. - column - 0.5 ) * GetPadSizeZ() ; // of center of PHOS module
52a36ffd 447 }
2f3366b6 448}