1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 // Geometry class for PHOS : singleton
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.
27 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC "KI" & SUBATECH)
29 // --- ROOT system ---
32 #include "TRotation.h"
36 // --- Standard library ---
40 // --- AliRoot header files ---
42 #include "AliPHOSGeometry.h"
43 #include "AliPHOSEMCAGeometry.h"
44 #include "AliPHOSRecPoint.h"
47 ClassImp(AliPHOSGeometry) ;
49 // these initialisations are needed for a singleton
50 AliPHOSGeometry * AliPHOSGeometry::fgGeom = 0 ;
51 Bool_t AliPHOSGeometry::fgInit = kFALSE ;
53 //____________________________________________________________________________
54 AliPHOSGeometry::~AliPHOSGeometry(void)
58 if (fRotMatrixArray) fRotMatrixArray->Delete() ;
59 if (fRotMatrixArray) delete fRotMatrixArray ;
60 if (fPHOSAngle ) delete[] fPHOSAngle ;
62 //____________________________________________________________________________
64 void AliPHOSGeometry::Init(void)
66 // Initializes the PHOS parameters :
67 // IHEP is the Protvino CPV (cathode pad chambers)
69 TString test(GetName()) ;
70 if (test != "IHEP" ) {
71 Fatal("Init", "%s is not a known geometry (choose among IHEP)", test.Data() ) ;
79 fGeometryEMCA = new AliPHOSEMCAGeometry();
81 fGeometryCPV = new AliPHOSCPVGeometry ();
83 fGeometrySUPP = new AliPHOSSupportGeometry();
85 fPHOSAngle = new Float_t[fNModules] ;
87 Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
89 fPHOSParams[0] = TMath::Max((Double_t)fGeometryCPV->GetCPVBoxSize(0)/2.,
90 (Double_t)(emcParams[0]*(fGeometryCPV->GetCPVBoxSize(1)+emcParams[3]) -
91 emcParams[1]* fGeometryCPV->GetCPVBoxSize(1))/emcParams[3] ) ;
92 fPHOSParams[1] = emcParams[1] ;
93 fPHOSParams[2] = TMath::Max((Double_t)emcParams[2], (Double_t)fGeometryCPV->GetCPVBoxSize(2)/2.);
94 fPHOSParams[3] = emcParams[3] + fGeometryCPV->GetCPVBoxSize(1)/2. ;
96 fIPtoUpperCPVsurface = fGeometryEMCA->GetIPtoOuterCoverDistance() - fGeometryCPV->GetCPVBoxSize(1) ;
99 for ( index = 0; index < fNModules; index++ )
100 fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
102 this->SetPHOSAngles() ;
103 fRotMatrixArray = new TObjArray(fNModules) ;
107 //____________________________________________________________________________
108 AliPHOSGeometry * AliPHOSGeometry::GetInstance()
110 // Returns the pointer of the unique instance; singleton specific
112 return static_cast<AliPHOSGeometry *>( fgGeom ) ;
115 //____________________________________________________________________________
116 AliPHOSGeometry * AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title)
118 // Returns the pointer of the unique instance
119 // Creates it with the specified options (name, title) if it does not exist yet
121 AliPHOSGeometry * rv = 0 ;
123 if ( strcmp(name,"") == 0 )
126 fgGeom = new AliPHOSGeometry(name, title) ;
128 rv = (AliPHOSGeometry * ) fgGeom ;
137 if ( strcmp(fgGeom->GetName(), name) != 0 )
138 ::Error("GetInstance", "Current geometry is %s. You cannot call %s", fgGeom->GetName(), name) ;
140 rv = (AliPHOSGeometry *) fgGeom ;
145 //____________________________________________________________________________
146 void AliPHOSGeometry::SetPHOSAngles()
148 // Calculates the position of the PHOS modules in ALICE global coordinate system
150 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
151 Float_t pphi = 2 * TMath::ATan( GetOuterBoxSize(0) / ( 2.0 * GetIPtoUpperCPVsurface() ) ) ;
154 Error("SetPHOSAngles", "PHOS modules overlap!\n pphi = %f fAngle = %f", pphi, fAngle);
159 for( Int_t i = 1; i <= fNModules ; i++ ) {
160 Float_t angle = pphi * ( i - fNModules / 2.0 - 0.5 ) ;
161 fPHOSAngle[i-1] = - angle ;
165 //____________________________________________________________________________
166 Bool_t AliPHOSGeometry::AbsToRelNumbering(const Int_t AbsId, Int_t * relid) const
168 // Converts the absolute numbering into the following array/
169 // relid[0] = PHOS Module number 1:fNModules
170 // relid[1] = 0 if PbW04
172 // relid[2] = Row number inside a PHOS module
173 // relid[3] = Column number inside a PHOS module
178 Int_t phosmodulenumber = (Int_t)TMath:: Ceil( id / GetNCristalsInModule() ) ;
180 if ( phosmodulenumber > GetNModules() ) { // it is a CPV pad
182 id -= GetNPhi() * GetNZ() * GetNModules() ;
183 Float_t nCPV = GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() ;
184 relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
186 id -= ( relid[0] - 1 ) * nCPV ;
187 relid[2] = (Int_t) TMath::Ceil( id / GetNumberOfCPVPadsZ() ) ;
188 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() ) ;
190 else { // it is a PW04 crystal
192 relid[0] = phosmodulenumber ;
194 id -= ( phosmodulenumber - 1 ) * GetNPhi() * GetNZ() ;
195 relid[2] = (Int_t)TMath::Ceil( id / GetNZ() ) ;
196 relid[3] = (Int_t)( id - ( relid[2] - 1 ) * GetNZ() ) ;
201 //____________________________________________________________________________
202 void AliPHOSGeometry::EmcModuleCoverage(const Int_t mod, Double_t & tm, Double_t & tM, Double_t & pm, Double_t & pM, Option_t * opt) const
204 // calculates the angular coverage in theta and phi of one EMC (=PHOS) module
207 if ( opt == Radian() )
209 else if ( opt == Degre() )
210 conv = 180. / TMath::Pi() ;
212 Warning("EmcModuleCoverage", "%s unknown option; result in radian", opt) ;
216 Float_t phi = GetPHOSAngle(mod) * (TMath::Pi() / 180.) ;
217 Float_t y0 = GetIPtoCrystalSurface() ;
218 Float_t * strip = fGeometryEMCA->GetStripHalfSize() ;
219 Float_t x0 = fGeometryEMCA->GetNStripX()*strip[0] ;
220 Float_t z0 = fGeometryEMCA->GetNStripZ()*strip[2] ;
221 Double_t angle = TMath::ATan( x0 / y0 ) ;
222 phi = phi + 1.5 * TMath::Pi() ; // to follow the convention of the particle generator(PHOS is between 220 and 320 deg.)
223 Double_t max = phi - angle ;
224 Double_t min = phi + angle ;
225 pM = TMath::Max(max, min) * conv ;
226 pm = TMath::Min(max, min) * conv ;
228 angle = TMath::ATan( z0 / y0 ) ;
229 max = TMath::Pi() / 2. + angle ; // to follow the convention of the particle generator(PHOS is at 90 deg.)
230 min = TMath::Pi() / 2. - angle ;
231 tM = TMath::Max(max, min) * conv ;
232 tm = TMath::Min(max, min) * conv ;
236 //____________________________________________________________________________
237 void AliPHOSGeometry::EmcXtalCoverage(Double_t & theta, Double_t & phi, Option_t * opt) const
239 // calculates the angular coverage in theta and phi of a single crystal in a EMC(=PHOS) module
242 if ( opt == Radian() )
244 else if ( opt == Degre() )
245 conv = 180. / TMath::Pi() ;
247 Warning("EmcXtalCoverage", "%s unknown option; result in radian", opt) ;
251 Float_t y0 = GetIPtoCrystalSurface() ;
252 theta = 2 * TMath::ATan( GetCrystalSize(2) / (2 * y0) ) * conv ;
253 phi = 2 * TMath::ATan( GetCrystalSize(0) / (2 * y0) ) * conv ;
257 //____________________________________________________________________________
258 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos, TMatrix & gmat) const
260 // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
262 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
263 TVector3 localposition ;
265 tmpPHOS->GetLocalPosition(gpos) ;
268 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
269 { gpos.SetY( - GetIPtoCrystalSurface()) ;
274 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
277 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
278 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
279 Float_t rphi = phi / kRADDEG ;
282 rot.RotateZ(-rphi) ; // a rotation around Z by angle
284 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
285 gpos.Transform(rot) ; // rotate the baby
286 gmat = 0; // Not implemented yet
290 //____________________________________________________________________________
291 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos) const
293 // Calculates the coordinates of a RecPoint in the ALICE global coordinate system
295 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
296 TVector3 localposition ;
297 tmpPHOS->GetLocalPosition(gpos) ;
300 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
301 { gpos.SetY( - GetIPtoCrystalSurface() ) ;
305 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
308 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
309 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
310 Float_t rphi = phi / kRADDEG ;
313 rot.RotateZ(-rphi) ; // a rotation around Z by angle
315 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
316 gpos.Transform(rot) ; // rotate the baby
319 //____________________________________________________________________________
320 void AliPHOSGeometry::ImpactOnEmc(const Double_t theta, const Double_t phi, Int_t & ModuleNumber, Double_t & z, Double_t & x) const
322 // calculates the impact coordinates on PHOS of a neutral particle
323 // emitted in the direction theta and phi in the ALICE global coordinate system
325 // searches for the PHOS EMC module
327 Double_t tm, tM, pm, pM ;
329 while ( ModuleNumber == 0 && index <= GetNModules() ) {
330 EmcModuleCoverage(index, tm, tM, pm, pM) ;
331 if ( (theta >= tm && theta <= tM) && (phi >= pm && phi <= pM ) )
332 ModuleNumber = index ;
335 if ( ModuleNumber != 0 ) {
336 Float_t phi0 = GetPHOSAngle(ModuleNumber) * (TMath::Pi() / 180.) + 1.5 * TMath::Pi() ;
337 Float_t y0 = GetIPtoCrystalSurface() ;
338 Double_t angle = phi - phi0;
339 x = y0 * TMath::Tan(angle) ;
340 angle = theta - TMath::Pi() / 2 ;
341 z = y0 * TMath::Tan(angle) ;
345 Bool_t AliPHOSGeometry::Impact(const TParticle * particle) const
348 Int_t ModuleNumber=0;
350 ImpactOnEmc(particle->Theta(),particle->Phi(),ModuleNumber,z,x);
351 if(ModuleNumber) In=kTRUE;
356 //____________________________________________________________________________
357 Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t & AbsId) const
359 // Converts the relative numbering into the absolute numbering
361 // AbsId = from 1 to fNModules * fNPhi * fNZ
363 // AbsId = from N(total PHOS crystals) + 1
364 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
368 if ( relid[1] == 0 ) { // it is a Phos crystal
370 ( relid[0] - 1 ) * GetNPhi() * GetNZ() // the offset of PHOS modules
371 + ( relid[2] - 1 ) * GetNZ() // the offset along phi
372 + relid[3] ; // the offset along z
374 else { // it is a CPV pad
375 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from CPV pads
376 + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() // the pads offset of PHOS modules
377 + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() // the pads offset of a CPV row
378 + relid[3] ; // the column number
384 //____________________________________________________________________________
386 void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
388 // Converts the absolute numbering into the global ALICE coordinate system
393 AbsToRelNumbering(id , relid) ;
395 Int_t phosmodule = relid[0] ;
399 if ( relid[1] == 0 ) // it is a PbW04 crystal
400 y0 = - GetIPtoCrystalSurface() ;
402 y0 = - GetIPtoUpperCPVsurface() ;
405 RelPosInModule(relid, x, z) ;
411 Float_t phi = GetPHOSAngle( phosmodule) ;
412 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
413 Float_t rphi = phi / kRADDEG ;
416 rot.RotateZ(-rphi) ; // a rotation around Z by angle
418 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
420 pos.Transform(rot) ; // rotate the baby
423 //____________________________________________________________________________
424 void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const
426 // Converts the relative numbering into the local PHOS-module (x, z) coordinates
427 // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
429 Int_t row = relid[2] ; //offset along x axis
430 Int_t column = relid[3] ; //offset along z axis
433 if ( relid[1] == 0 ) { // its a PbW04 crystal
434 x = - ( GetNPhi()/2. - row + 0.5 ) * GetCellStep() ; // position of Xtal with respect
435 z = ( GetNZ() /2. - column + 0.5 ) * GetCellStep() ; // of center of PHOS module
438 x = - ( GetNumberOfCPVPadsPhi()/2. - row - 0.5 ) * GetPadSizePhi() ; // position of pad with respect
439 z = ( GetNumberOfCPVPadsZ() /2. - column - 0.5 ) * GetPadSizeZ() ; // of center of PHOS module