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"
33 #include "TParticle.h"
35 // --- Standard library ---
37 // --- AliRoot header files ---
39 #include "AliPHOSGeometry.h"
40 #include "AliPHOSEMCAGeometry.h"
41 #include "AliPHOSRecPoint.h"
43 ClassImp(AliPHOSGeometry) ;
45 // these initialisations are needed for a singleton
46 AliPHOSGeometry * AliPHOSGeometry::fgGeom = 0 ;
47 Bool_t AliPHOSGeometry::fgInit = kFALSE ;
49 //____________________________________________________________________________
50 AliPHOSGeometry::AliPHOSGeometry() {
52 // must be kept public for root persistency purposes, but should never be called by the outside world
61 //____________________________________________________________________________
62 AliPHOSGeometry::~AliPHOSGeometry(void)
66 if (fRotMatrixArray) fRotMatrixArray->Delete() ;
67 if (fRotMatrixArray) delete fRotMatrixArray ;
68 if (fPHOSAngle ) delete[] fPHOSAngle ;
70 //____________________________________________________________________________
72 void AliPHOSGeometry::Init(void)
74 // Initializes the PHOS parameters :
75 // IHEP is the Protvino CPV (cathode pad chambers)
77 TString test(GetName()) ;
78 if (test != "IHEP" ) {
79 Fatal("Init", "%s is not a known geometry (choose among IHEP)", test.Data() ) ;
87 fGeometryEMCA = new AliPHOSEMCAGeometry();
89 fGeometryCPV = new AliPHOSCPVGeometry ();
91 fGeometrySUPP = new AliPHOSSupportGeometry();
93 fPHOSAngle = new Float_t[fNModules] ;
95 Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
97 fPHOSParams[0] = TMath::Max((Double_t)fGeometryCPV->GetCPVBoxSize(0)/2.,
98 (Double_t)(emcParams[0]*(fGeometryCPV->GetCPVBoxSize(1)+emcParams[3]) -
99 emcParams[1]* fGeometryCPV->GetCPVBoxSize(1))/emcParams[3] ) ;
100 fPHOSParams[1] = emcParams[1] ;
101 fPHOSParams[2] = TMath::Max((Double_t)emcParams[2], (Double_t)fGeometryCPV->GetCPVBoxSize(2)/2.);
102 fPHOSParams[3] = emcParams[3] + fGeometryCPV->GetCPVBoxSize(1)/2. ;
104 fIPtoUpperCPVsurface = fGeometryEMCA->GetIPtoOuterCoverDistance() - fGeometryCPV->GetCPVBoxSize(1) ;
107 for ( index = 0; index < fNModules; index++ )
108 fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
110 this->SetPHOSAngles() ;
111 fRotMatrixArray = new TObjArray(fNModules) ;
115 //____________________________________________________________________________
116 AliPHOSGeometry * AliPHOSGeometry::GetInstance()
118 // Returns the pointer of the unique instance; singleton specific
120 return static_cast<AliPHOSGeometry *>( fgGeom ) ;
123 //____________________________________________________________________________
124 AliPHOSGeometry * AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title)
126 // Returns the pointer of the unique instance
127 // Creates it with the specified options (name, title) if it does not exist yet
129 AliPHOSGeometry * rv = 0 ;
131 if ( strcmp(name,"") == 0 )
134 fgGeom = new AliPHOSGeometry(name, title) ;
136 rv = (AliPHOSGeometry * ) fgGeom ;
145 if ( strcmp(fgGeom->GetName(), name) != 0 )
146 ::Error("GetInstance", "Current geometry is %s. You cannot call %s", fgGeom->GetName(), name) ;
148 rv = (AliPHOSGeometry *) fgGeom ;
153 //____________________________________________________________________________
154 void AliPHOSGeometry::SetPHOSAngles()
156 // Calculates the position of the PHOS modules in ALICE global coordinate system
158 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
159 Float_t pphi = 2 * TMath::ATan( GetOuterBoxSize(0) / ( 2.0 * GetIPtoUpperCPVsurface() ) ) ;
162 Error("SetPHOSAngles", "PHOS modules overlap!\n pphi = %f fAngle = %f", pphi, fAngle);
167 for( Int_t i = 1; i <= fNModules ; i++ ) {
168 Float_t angle = pphi * ( i - fNModules / 2.0 - 0.5 ) ;
169 fPHOSAngle[i-1] = - angle ;
173 //____________________________________________________________________________
174 Bool_t AliPHOSGeometry::AbsToRelNumbering(const Int_t AbsId, Int_t * relid) const
176 // Converts the absolute numbering into the following array/
177 // relid[0] = PHOS Module number 1:fNModules
178 // relid[1] = 0 if PbW04
180 // relid[2] = Row number inside a PHOS module
181 // relid[3] = Column number inside a PHOS module
186 Int_t phosmodulenumber = (Int_t)TMath:: Ceil( id / GetNCristalsInModule() ) ;
188 if ( phosmodulenumber > GetNModules() ) { // it is a CPV pad
190 id -= GetNPhi() * GetNZ() * GetNModules() ;
191 Float_t nCPV = GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() ;
192 relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
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() ) ;
198 else { // it is a PW04 crystal
200 relid[0] = phosmodulenumber ;
202 id -= ( phosmodulenumber - 1 ) * GetNPhi() * GetNZ() ;
203 relid[2] = (Int_t)TMath::Ceil( id / GetNZ() ) ;
204 relid[3] = (Int_t)( id - ( relid[2] - 1 ) * GetNZ() ) ;
209 //____________________________________________________________________________
210 void AliPHOSGeometry::EmcModuleCoverage(const Int_t mod, Double_t & tm, Double_t & tM, Double_t & pm, Double_t & pM, Option_t * opt) const
212 // calculates the angular coverage in theta and phi of one EMC (=PHOS) module
215 if ( opt == Radian() )
217 else if ( opt == Degre() )
218 conv = 180. / TMath::Pi() ;
220 Warning("EmcModuleCoverage", "%s unknown option; result in radian", opt) ;
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.)
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 ;
236 angle = TMath::ATan( z0 / y0 ) ;
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 ;
244 //____________________________________________________________________________
245 void AliPHOSGeometry::EmcXtalCoverage(Double_t & theta, Double_t & phi, Option_t * opt) const
247 // calculates the angular coverage in theta and phi of a single crystal in a EMC(=PHOS) module
250 if ( opt == Radian() )
252 else if ( opt == Degre() )
253 conv = 180. / TMath::Pi() ;
255 Warning("EmcXtalCoverage", "%s unknown option; result in radian", opt) ;
259 Float_t y0 = GetIPtoCrystalSurface() ;
260 theta = 2 * TMath::ATan( GetCrystalSize(2) / (2 * y0) ) * conv ;
261 phi = 2 * TMath::ATan( GetCrystalSize(0) / (2 * y0) ) * conv ;
265 //____________________________________________________________________________
266 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos, TMatrix & gmat) const
268 // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
270 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
271 TVector3 localposition ;
273 tmpPHOS->GetLocalPosition(gpos) ;
276 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
277 { gpos.SetY( - GetIPtoCrystalSurface()) ;
282 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
285 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
286 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
287 Float_t rphi = phi / kRADDEG ;
290 rot.RotateZ(-rphi) ; // a rotation around Z by angle
292 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
293 gpos.Transform(rot) ; // rotate the baby
294 gmat = 0; // Not implemented yet
298 //____________________________________________________________________________
299 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos) const
301 // Calculates the coordinates of a RecPoint in the ALICE global coordinate system
303 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
304 TVector3 localposition ;
305 tmpPHOS->GetLocalPosition(gpos) ;
308 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
309 { gpos.SetY( - GetIPtoCrystalSurface() ) ;
313 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
316 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
317 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
318 Float_t rphi = phi / kRADDEG ;
321 rot.RotateZ(-rphi) ; // a rotation around Z by angle
323 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
324 gpos.Transform(rot) ; // rotate the baby
327 //____________________________________________________________________________
328 void AliPHOSGeometry::ImpactOnEmc(const Double_t theta, const Double_t phi, Int_t & ModuleNumber, Double_t & z, Double_t & x) const
330 // calculates the impact coordinates on PHOS of a neutral particle
331 // emitted in the direction theta and phi in the ALICE global coordinate system
333 // searches for the PHOS EMC module
335 Double_t tm, tM, pm, pM ;
337 while ( ModuleNumber == 0 && index <= GetNModules() ) {
338 EmcModuleCoverage(index, tm, tM, pm, pM) ;
339 if ( (theta >= tm && theta <= tM) && (phi >= pm && phi <= pM ) )
340 ModuleNumber = index ;
343 if ( ModuleNumber != 0 ) {
344 Float_t phi0 = GetPHOSAngle(ModuleNumber) * (TMath::Pi() / 180.) + 1.5 * TMath::Pi() ;
345 Float_t y0 = GetIPtoCrystalSurface() ;
346 Double_t angle = phi - phi0;
347 x = y0 * TMath::Tan(angle) ;
348 angle = theta - TMath::Pi() / 2 ;
349 z = y0 * TMath::Tan(angle) ;
353 //____________________________________________________________________________
354 Bool_t AliPHOSGeometry::Impact(const TParticle * particle) const
356 // Tells if a particle enters PHOS
358 Int_t moduleNumber=0;
360 ImpactOnEmc(particle->Theta(),particle->Phi(),moduleNumber,z,x);
368 //____________________________________________________________________________
369 Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t & AbsId) const
371 // Converts the relative numbering into the absolute numbering
373 // AbsId = from 1 to fNModules * fNPhi * fNZ
375 // AbsId = from N(total PHOS crystals) + 1
376 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
380 if ( relid[1] == 0 ) { // it is a Phos crystal
382 ( relid[0] - 1 ) * GetNPhi() * GetNZ() // the offset of PHOS modules
383 + ( relid[2] - 1 ) * GetNZ() // the offset along phi
384 + relid[3] ; // the offset along z
386 else { // it is a CPV pad
387 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from CPV pads
388 + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() // the pads offset of PHOS modules
389 + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() // the pads offset of a CPV row
390 + relid[3] ; // the column number
396 //____________________________________________________________________________
398 void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
400 // Converts the absolute numbering into the global ALICE coordinate system
405 AbsToRelNumbering(id , relid) ;
407 Int_t phosmodule = relid[0] ;
411 if ( relid[1] == 0 ) // it is a PbW04 crystal
412 y0 = - GetIPtoCrystalSurface() ;
414 y0 = - GetIPtoUpperCPVsurface() ;
417 RelPosInModule(relid, x, z) ;
423 Float_t phi = GetPHOSAngle( phosmodule) ;
424 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
425 Float_t rphi = phi / kRADDEG ;
428 rot.RotateZ(-rphi) ; // a rotation around Z by angle
430 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
432 pos.Transform(rot) ; // rotate the baby
435 //____________________________________________________________________________
436 void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const
438 // Converts the relative numbering into the local PHOS-module (x, z) coordinates
439 // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
441 Int_t row = relid[2] ; //offset along x axis
442 Int_t column = relid[3] ; //offset along z axis
445 if ( relid[1] == 0 ) { // its a PbW04 crystal
446 x = - ( GetNPhi()/2. - row + 0.5 ) * GetCellStep() ; // position of Xtal with respect
447 z = ( GetNZ() /2. - column + 0.5 ) * GetCellStep() ; // of center of PHOS module
450 x = - ( GetNumberOfCPVPadsPhi()/2. - row - 0.5 ) * GetPadSizePhi() ; // position of pad with respect
451 z = ( GetNumberOfCPVPadsZ() /2. - column - 0.5 ) * GetPadSizeZ() ; // of center of PHOS module