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 // searches for the PHOS EMC module
340 Double_t tm, tM, pm, pM ;
342 while ( ModuleNumber == 0 && index <= GetNModules() ) {
343 EmcModuleCoverage(index, tm, tM, pm, pM) ;
344 if ( (theta >= tm && theta <= tM) && (phi >= pm && phi <= pM ) )
345 ModuleNumber = index ;
348 if ( ModuleNumber != 0 ) {
349 Float_t phi0 = GetPHOSAngle(ModuleNumber) * (TMath::Pi() / 180.) + 1.5 * TMath::Pi() ;
350 Float_t y0 = GetIPtoCrystalSurface() ;
351 Double_t angle = phi - phi0;
352 x = y0 * TMath::Tan(angle) ;
353 angle = theta - TMath::Pi() / 2 ;
354 z = y0 * TMath::Tan(angle) ;
358 //____________________________________________________________________________
359 Bool_t AliPHOSGeometry::Impact(const TParticle * particle) const
361 // Check if a particle being propagates from IP along the straight line impacts EMC
364 Int_t moduleNumber=0;
366 ImpactOnEmc(particle->Theta(),particle->Phi(),moduleNumber,z,x);
367 if(moduleNumber) in=kTRUE;
372 //____________________________________________________________________________
373 Bool_t AliPHOSGeometry::RelToAbsNumbering(const Int_t * relid, Int_t & AbsId) const
375 // Converts the relative numbering into the absolute numbering
377 // AbsId = from 1 to fNModules * fNPhi * fNZ
379 // AbsId = from N(total PHOS crystals) + 1
380 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
384 if ( relid[1] == 0 ) { // it is a Phos crystal
386 ( relid[0] - 1 ) * GetNPhi() * GetNZ() // the offset of PHOS modules
387 + ( relid[2] - 1 ) * GetNZ() // the offset along phi
388 + relid[3] ; // the offset along z
390 else { // it is a CPV pad
391 AbsId = GetNPhi() * GetNZ() * GetNModules() // the offset to separate EMCA crystals from CPV pads
392 + ( relid[0] - 1 ) * GetNumberOfCPVPadsPhi() * GetNumberOfCPVPadsZ() // the pads offset of PHOS modules
393 + ( relid[2] - 1 ) * GetNumberOfCPVPadsZ() // the pads offset of a CPV row
394 + relid[3] ; // the column number
400 //____________________________________________________________________________
401 void AliPHOSGeometry::RelPosToAbsId(const Int_t module , const Double_t x, const Double_t z, Int_t & AbsId)const{
402 // Converts local PHOS-module (x, z) coordinates to absId
412 relid[2] = static_cast<Int_t>(TMath::Ceil(GetNPhi()/2.+ x/GetCellStep()));
413 relid[3] = static_cast<Int_t>(TMath::Ceil(GetNZ()/2. - z/GetCellStep())) ;
415 RelToAbsNumbering(relid,AbsId) ;
418 //____________________________________________________________________________
419 void AliPHOSGeometry::RelPosInAlice(const Int_t id, TVector3 & pos ) const
421 // Converts the absolute numbering into the global ALICE coordinate system
426 AbsToRelNumbering(id , relid) ;
428 Int_t phosmodule = relid[0] ;
432 if ( relid[1] == 0 ) // it is a PbW04 crystal
433 y0 = - GetIPtoCrystalSurface() ;
435 y0 = - GetIPtoUpperCPVsurface() ;
438 RelPosInModule(relid, x, z) ;
444 Float_t phi = GetPHOSAngle( phosmodule) ;
445 Double_t const kRADDEG = 180.0 / kPI ;
446 Float_t rphi = phi / kRADDEG ;
449 rot.RotateZ(-rphi) ; // a rotation around Z by angle
451 TRotation dummy = rot.Invert() ; // to transform from original frame to rotate frame
453 pos.Transform(rot) ; // rotate the baby
456 //____________________________________________________________________________
457 void AliPHOSGeometry::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const
459 // Converts the relative numbering into the local PHOS-module (x, z) coordinates
460 // Note: sign of z differs from that in the previous version (Yu.Kharlov, 12 Oct 2000)
462 Int_t row = relid[2] ; //offset along x axis
463 Int_t column = relid[3] ; //offset along z axis
466 if ( relid[1] == 0 ) { // its a PbW04 crystal
467 x = - ( GetNPhi()/2. - row + 0.5 ) * GetCellStep() ; // position of Xtal with respect
468 z = ( GetNZ() /2. - column + 0.5 ) * GetCellStep() ; // of center of PHOS module
471 x = - ( GetNumberOfCPVPadsPhi()/2. - row - 0.5 ) * GetPadSizePhi() ; // position of pad with respect
472 z = ( GetNumberOfCPVPadsZ() /2. - column - 0.5 ) * GetPadSizeZ() ; // of center of PHOS module