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)
57 // must be kept public for root persistency purposes,
58 // but should never be called by the outside world
66 //____________________________________________________________________________
67 AliPHOSGeometry::~AliPHOSGeometry(void)
71 if (fRotMatrixArray) fRotMatrixArray->Delete() ;
72 if (fRotMatrixArray) delete fRotMatrixArray ;
73 if (fPHOSAngle ) delete[] fPHOSAngle ;
75 //____________________________________________________________________________
77 void AliPHOSGeometry::Init(void)
79 // Initializes the PHOS parameters :
80 // IHEP is the Protvino CPV (cathode pad chambers)
81 // GPS2 is the Subatech Pre-Shower (two micromegas sandwiching a passive lead converter)
82 // MIXT 4 PHOS modules withe the IHEP CPV and one PHOS module with the Subatech Pre-Shower
84 TString test(GetName()) ;
85 if (test != "IHEP" && test != "GPS2" && test != "MIXT") {
86 Fatal("Init", "%s is not a known geometry (choose among IHEP, GPS2 and MIXT)", test.Data() ) ;
94 fGeometryEMCA = new AliPHOSEMCAGeometry();
96 fGeometryCPV = new AliPHOSCPVGeometry ();
98 fGeometrySUPP = new AliPHOSSupportGeometry();
100 fPHOSAngle = new Float_t[fNModules] ;
102 Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
104 fPHOSParams[0] = TMath::Max((Double_t)fGeometryCPV->GetCPVBoxSize(0)/2.,
105 (Double_t)(emcParams[0]*(fGeometryCPV->GetCPVBoxSize(1)+emcParams[3]) -
106 emcParams[1]* fGeometryCPV->GetCPVBoxSize(1))/emcParams[3] ) ;
107 fPHOSParams[1] = emcParams[1] ;
108 fPHOSParams[2] = TMath::Max((Double_t)emcParams[2], (Double_t)fGeometryCPV->GetCPVBoxSize(2)/2.);
109 fPHOSParams[3] = emcParams[3] + fGeometryCPV->GetCPVBoxSize(1)/2. ;
111 fIPtoUpperCPVsurface = fGeometryEMCA->GetIPtoOuterCoverDistance() - fGeometryCPV->GetCPVBoxSize(1) ;
114 for ( index = 0; index < fNModules; index++ )
115 fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
117 this->SetPHOSAngles() ;
118 fRotMatrixArray = new TObjArray(fNModules) ;
122 //____________________________________________________________________________
123 AliPHOSGeometry * AliPHOSGeometry::GetInstance()
125 // Returns the pointer of the unique instance; singleton specific
127 return static_cast<AliPHOSGeometry *>( fgGeom ) ;
130 //____________________________________________________________________________
131 AliPHOSGeometry * AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title)
133 // Returns the pointer of the unique instance
134 // Creates it with the specified options (name, title) if it does not exist yet
136 AliPHOSGeometry * rv = 0 ;
138 if ( strcmp(name,"") == 0 )
141 fgGeom = new AliPHOSGeometry(name, title) ;
143 rv = (AliPHOSGeometry * ) fgGeom ;
152 if ( strcmp(fgGeom->GetName(), name) != 0 )
153 ::Error("GetInstance", "Current geometry is %s. You cannot call %s", fgGeom->GetName(), name) ;
155 rv = (AliPHOSGeometry *) fgGeom ;
160 //____________________________________________________________________________
161 void AliPHOSGeometry::SetPHOSAngles()
163 // Calculates the position of the PHOS modules in ALICE global coordinate system
165 Double_t const kRADDEG = 180.0 / kPI ;
166 Float_t pphi = 2 * TMath::ATan( GetOuterBoxSize(0) / ( 2.0 * GetIPtoUpperCPVsurface() ) ) ;
169 Error("SetPHOSAngles", "PHOS modules overlap!\n pphi = %f fAngle = %f", pphi, fAngle);
174 for( Int_t i = 1; i <= fNModules ; i++ ) {
175 Float_t angle = pphi * ( i - fNModules / 2.0 - 0.5 ) ;
176 fPHOSAngle[i-1] = - angle ;
180 //____________________________________________________________________________
181 Bool_t AliPHOSGeometry::AbsToRelNumbering(const Int_t AbsId, Int_t * relid) const
183 // Converts the absolute numbering into the following array/
184 // relid[0] = PHOS Module number 1:fNModules
185 // relid[1] = 0 if PbW04
187 // relid[2] = Row number inside a PHOS module
188 // relid[3] = Column number inside a PHOS module
193 Int_t phosmodulenumber = (Int_t)TMath:: Ceil( id / GetNCristalsInModule() ) ;
195 if ( phosmodulenumber > GetNModules() ) { // it is a CPV pad
197 id -= GetNPhi() * GetNZ() * GetNModules() ;
198 Float_t nCPV = GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() ;
199 relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
201 id -= ( relid[0] - 1 ) * nCPV ;
202 relid[2] = (Int_t) TMath::Ceil( id / GetNumberOfCPVPadsZ() ) ;
203 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() ) ;
205 else { // it is a PW04 crystal
207 relid[0] = phosmodulenumber ;
209 id -= ( phosmodulenumber - 1 ) * GetNPhi() * GetNZ() ;
210 relid[2] = (Int_t)TMath::Ceil( id / GetNZ() ) ;
211 relid[3] = (Int_t)( id - ( relid[2] - 1 ) * GetNZ() ) ;
216 //____________________________________________________________________________
217 void AliPHOSGeometry::EmcModuleCoverage(const Int_t mod, Double_t & tm, Double_t & tM, Double_t & pm, Double_t & pM, Option_t * opt) const
219 // calculates the angular coverage in theta and phi of one EMC (=PHOS) module
222 if ( opt == Radian() )
224 else if ( opt == Degre() )
225 conv = 180. / TMath::Pi() ;
227 Warning("EmcModuleCoverage", "%s unknown option; result in radian", opt) ;
231 Float_t phi = GetPHOSAngle(mod) * (TMath::Pi() / 180.) ;
232 Float_t y0 = GetIPtoCrystalSurface() ;
233 Float_t x0 = GetCellStep()*GetNPhi() ;
234 Float_t z0 = GetCellStep()*GetNZ();
235 Double_t angle = TMath::ATan( x0 / y0 / 2 ) ;
236 phi = phi + 1.5 * TMath::Pi() ; // to follow the convention of the particle generator(PHOS is between 220 and 320 deg.)
237 Double_t max = phi - angle ;
238 Double_t min = phi + angle ;
239 pM = TMath::Max(max, min) * conv ;
240 pm = TMath::Min(max, min) * conv ;
242 angle = TMath::ATan( z0 / y0 / 2 ) ;
243 max = TMath::Pi() / 2. + angle ; // to follow the convention of the particle generator(PHOS is at 90 deg.)
244 min = TMath::Pi() / 2. - angle ;
245 tM = TMath::Max(max, min) * conv ;
246 tm = TMath::Min(max, min) * conv ;
250 //____________________________________________________________________________
251 void AliPHOSGeometry::EmcXtalCoverage(Double_t & theta, Double_t & phi, Option_t * opt) const
253 // calculates the angular coverage in theta and phi of a single crystal in a EMC(=PHOS) module
256 if ( opt == Radian() )
258 else if ( opt == Degre() )
259 conv = 180. / TMath::Pi() ;
261 Warning("EmcXtalCoverage", "%s unknown option; result in radian", opt) ;
265 Float_t y0 = GetIPtoCrystalSurface() ;
266 theta = 2 * TMath::ATan( GetCrystalSize(2) / (2 * y0) ) * conv ;
267 phi = 2 * TMath::ATan( GetCrystalSize(0) / (2 * y0) ) * conv ;
271 //____________________________________________________________________________
272 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos, TMatrix & gmat) const
274 // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
276 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
277 TVector3 localposition ;
279 tmpPHOS->GetLocalPosition(gpos) ;
282 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
283 { gpos.SetY( - GetIPtoCrystalSurface()) ;
288 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
291 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
292 Double_t const kRADDEG = 180.0 / kPI ;
293 Float_t rphi = phi / kRADDEG ;
296 rot.RotateZ(-rphi) ; // a rotation around Z by angle
298 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
299 gpos.Transform(rot) ; // rotate the baby
303 //____________________________________________________________________________
304 void AliPHOSGeometry::GetGlobal(const AliRecPoint* RecPoint, TVector3 & gpos) const
306 // Calculates the coordinates of a RecPoint in the ALICE global coordinate system
308 AliPHOSRecPoint * tmpPHOS = (AliPHOSRecPoint *) RecPoint ;
309 TVector3 localposition ;
310 tmpPHOS->GetLocalPosition(gpos) ;
313 if ( tmpPHOS->IsEmc() ) // it is a EMC crystal
314 { gpos.SetY( - GetIPtoCrystalSurface() ) ;
318 gpos.SetY(- GetIPtoUpperCPVsurface() ) ;
321 Float_t phi = GetPHOSAngle( tmpPHOS->GetPHOSMod()) ;
322 Double_t const kRADDEG = 180.0 / kPI ;
323 Float_t rphi = phi / kRADDEG ;
326 rot.RotateZ(-rphi) ; // a rotation around Z by angle
328 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
329 gpos.Transform(rot) ; // rotate the baby
332 //____________________________________________________________________________
333 void AliPHOSGeometry::ImpactOnEmc(const Double_t theta, const Double_t phi, Int_t & ModuleNumber, Double_t & z, Double_t & x) const
335 // calculates the impact coordinates on PHOS of a neutral particle
336 // emitted in the direction theta and phi in the ALICE global coordinate system
338 //Convert phi to range 0-2pi if nesassary
339 Double_t phiin2pi = phi ;
341 phiin2pi+=6.2831853072 ;
343 // searches for the PHOS EMC module
345 Double_t tm, tM, pm, pM ;
347 while ( ModuleNumber == 0 && index <= GetNModules() ) {
348 EmcModuleCoverage(index, tm, tM, pm, pM) ;
349 if ( (theta >= tm && theta <= tM) && (phiin2pi >= pm && phiin2pi <= pM ) )
350 ModuleNumber = index ;
353 if ( ModuleNumber != 0 ) {
354 Float_t phi0 = GetPHOSAngle(ModuleNumber) * (TMath::Pi() / 180.) + 1.5 * TMath::Pi() ;
355 Float_t y0 = GetIPtoCrystalSurface() ;
356 Double_t angle = phiin2pi - phi0;
357 x = y0 * TMath::Tan(angle) ;
358 angle = theta - TMath::Pi() / 2 ;
359 z = y0 * TMath::Tan(angle) ;
363 //____________________________________________________________________________
364 Bool_t AliPHOSGeometry::Impact(const TParticle * particle) const
366 // Check if a particle being propagates from IP along the straight line impacts EMC
369 Int_t moduleNumber=0;
371 ImpactOnEmc(particle->Theta(),particle->Phi(),moduleNumber,z,x);
372 if(moduleNumber) in=kTRUE;
377 //____________________________________________________________________________
378 Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t & AbsId) const
380 // Converts the relative numbering into the absolute numbering
382 // AbsId = from 1 to fNModules * fNPhi * fNZ
384 // AbsId = from N(total PHOS crystals) + 1
385 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
389 if ( relid[1] == 0 ) { // it is a Phos crystal
391 ( relid[0] - 1 ) * GetNPhi() * GetNZ() // the offset of PHOS modules
392 + ( relid[2] - 1 ) * GetNZ() // the offset along phi
393 + relid[3] ; // the offset along z
395 else { // it is a CPV pad
396 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from CPV pads
397 + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() // the pads offset of PHOS modules
398 + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() // the pads offset of a CPV row
399 + relid[3] ; // the column number
405 //____________________________________________________________________________
406 void AliPHOSGeometry::RelPosToAbsId(const Int_t module , const Double_t x, const Double_t z, Int_t & AbsId)const{
407 // Converts local PHOS-module (x, z) coordinates to absId
417 relid[2] = static_cast<Int_t>(TMath::Ceil(GetNPhi()/2.+ x/GetCellStep()));
418 relid[3] = static_cast<Int_t>(TMath::Ceil(GetNZ()/2. - z/GetCellStep())) ;
420 RelToAbsNumbering(relid,AbsId) ;
423 //____________________________________________________________________________
424 void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
426 // Converts the absolute numbering into the global ALICE coordinate system
431 AbsToRelNumbering(id , relid) ;
433 Int_t phosmodule = relid[0] ;
437 if ( relid[1] == 0 ) // it is a PbW04 crystal
438 y0 = - GetIPtoCrystalSurface() ;
440 y0 = - GetIPtoUpperCPVsurface() ;
443 RelPosInModule(relid, x, z) ;
449 Float_t phi = GetPHOSAngle( phosmodule) ;
450 Double_t const kRADDEG = 180.0 / kPI ;
451 Float_t rphi = phi / kRADDEG ;
454 rot.RotateZ(-rphi) ; // a rotation around Z by angle
456 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
458 pos.Transform(rot) ; // rotate the baby
461 //____________________________________________________________________________
462 void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const
464 // Converts the relative numbering into the local PHOS-module (x, z) coordinates
465 // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
467 Int_t row = relid[2] ; //offset along x axis
468 Int_t column = relid[3] ; //offset along z axis
471 if ( relid[1] == 0 ) { // its a PbW04 crystal
472 x = - ( GetNPhi()/2. - row + 0.5 ) * GetCellStep() ; // position of Xtal with respect
473 z = ( GetNZ() /2. - column + 0.5 ) * GetCellStep() ; // of center of PHOS module
476 x = - ( GetNumberOfCPVPadsPhi()/2. - row - 0.5 ) * GetPadSizePhi() ; // position of pad with respect
477 z = ( GetNumberOfCPVPadsZ() /2. - column - 0.5 ) * GetPadSizeZ() ; // of center of PHOS module