]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGeometry.cxx
Input number added to Print
[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//
05d33a3d 27// -- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC "KI" & SUBATECH)
d15a28e7 28
29// --- ROOT system ---
30
31#include "TVector3.h"
32#include "TRotation.h"
e957fea8 33#include "TParticle.h"
91daaf24 34#include <TGeoManager.h>
268f57b1 35#include <TGeoMatrix.h>
d15a28e7 36
37// --- Standard library ---
38
d15a28e7 39// --- AliRoot header files ---
351dd634 40#include "AliLog.h"
d15a28e7 41#include "AliPHOSGeometry.h"
468794ea 42#include "AliPHOSEMCAGeometry.h"
710f859a 43#include "AliPHOSRecPoint.h"
d15a28e7 44
925e6570 45ClassImp(AliPHOSGeometry)
d15a28e7 46
a4e98857 47// these initialisations are needed for a singleton
05d33a3d 48AliPHOSGeometry * AliPHOSGeometry::fgGeom = 0 ;
49Bool_t AliPHOSGeometry::fgInit = kFALSE ;
9ec91567 50
e957fea8 51//____________________________________________________________________________
3663622c 52AliPHOSGeometry::AliPHOSGeometry() :
bcc9e89e 53 AliPHOSGeoUtils(),
3663622c 54 fAngle(0.f),
55 fPHOSAngle(0),
56 fIPtoUpperCPVsurface(0),
308fb942 57 fCrystalShift(0),
58 fCryCellShift(0),
bcc9e89e 59 fRotMatrixArray(0)
3663622c 60{
e957fea8 61 // default ctor
62 // must be kept public for root persistency purposes, but should never be called by the outside world
e957fea8 63 fgGeom = 0 ;
6ba1dd81 64
65 fPHOSParams[0] = 0.;
66 fPHOSParams[1] = 0.;
67 fPHOSParams[2] = 0.;
68 fPHOSParams[3] = 0.;
e957fea8 69}
70
3663622c 71//____________________________________________________________________________
72AliPHOSGeometry::AliPHOSGeometry(const AliPHOSGeometry & rhs)
bcc9e89e 73 : AliPHOSGeoUtils(rhs),
3663622c 74 fAngle(rhs.fAngle),
75 fPHOSAngle(0),
76 fIPtoUpperCPVsurface(rhs.fIPtoUpperCPVsurface),
308fb942 77 fCrystalShift(rhs.fCrystalShift),
78 fCryCellShift(rhs.fCryCellShift),
bcc9e89e 79 fRotMatrixArray(0)
3663622c 80{
81 Fatal("cpy ctor", "not implemented") ;
82}
83
91daaf24 84//____________________________________________________________________________
3663622c 85AliPHOSGeometry::AliPHOSGeometry(const Text_t* name, const Text_t* title)
bcc9e89e 86 : AliPHOSGeoUtils(name, title),
3663622c 87 fAngle(0.f),
88 fPHOSAngle(0),
89 fIPtoUpperCPVsurface(0),
308fb942 90 fCrystalShift(0),
91 fCryCellShift(0),
bcc9e89e 92 fRotMatrixArray(0)
3663622c 93{
94 // ctor only for internal usage (singleton)
95 Init() ;
9a2cdbdf 96 fgGeom = this;
3663622c 97}
98
d15a28e7 99//____________________________________________________________________________
100AliPHOSGeometry::~AliPHOSGeometry(void)
101{
b2a60966 102 // dtor
103
52a36ffd 104 if (fRotMatrixArray) fRotMatrixArray->Delete() ;
105 if (fRotMatrixArray) delete fRotMatrixArray ;
fa0bc588 106 if (fPHOSAngle ) delete[] fPHOSAngle ;
52a36ffd 107}
52a36ffd 108
91daaf24 109//____________________________________________________________________________
52a36ffd 110void AliPHOSGeometry::Init(void)
111{
a4e98857 112 // Initializes the PHOS parameters :
113 // IHEP is the Protvino CPV (cathode pad chambers)
710f859a 114
115 fgInit = kTRUE ;
05d33a3d 116
85698486 117 fAngle = 20;
05d33a3d 118
710f859a 119
120 fPHOSAngle = new Float_t[fNModules] ;
121
a2bb6de5 122 const Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
710f859a 123
581e32d4 124 fPHOSParams[0] = TMath::Max((Double_t)fGeometryCPV->GetCPVBoxSize(0)/2.,
a83b6179 125 (Double_t)(emcParams[0] - (emcParams[1]-emcParams[0])*
126 fGeometryCPV->GetCPVBoxSize(1)/2/emcParams[3]));
710f859a 127 fPHOSParams[1] = emcParams[1] ;
581e32d4 128 fPHOSParams[2] = TMath::Max((Double_t)emcParams[2], (Double_t)fGeometryCPV->GetCPVBoxSize(2)/2.);
710f859a 129 fPHOSParams[3] = emcParams[3] + fGeometryCPV->GetCPVBoxSize(1)/2. ;
130
131 fIPtoUpperCPVsurface = fGeometryEMCA->GetIPtoOuterCoverDistance() - fGeometryCPV->GetCPVBoxSize(1) ;
8e20650f 132
133 //calculate offset to crystal surface
a2bb6de5 134 const Float_t * inthermo = fGeometryEMCA->GetInnerThermoHalfSize() ;
135 const Float_t * strip = fGeometryEMCA->GetStripHalfSize() ;
136 const Float_t * splate = fGeometryEMCA->GetSupportPlateHalfSize();
137 const Float_t * crystal = fGeometryEMCA->GetCrystalHalfSize() ;
138 const Float_t * pin = fGeometryEMCA->GetAPDHalfSize() ;
139 const Float_t * preamp = fGeometryEMCA->GetPreampHalfSize() ;
8e20650f 140 fCrystalShift=-inthermo[1]+strip[1]+splate[1]+crystal[1]-fGeometryEMCA->GetAirGapLed()/2.+pin[1]+preamp[1] ;
141 fCryCellShift=crystal[1]-(fGeometryEMCA->GetAirGapLed()-2*pin[1]-2*preamp[1])/2;
142
710f859a 143 Int_t index ;
144 for ( index = 0; index < fNModules; index++ )
52a36ffd 145 fPHOSAngle[index] = 0.0 ; // Module position angles are set in CreateGeometry()
710f859a 146
710f859a 147 fRotMatrixArray = new TObjArray(fNModules) ;
05d33a3d 148
85698486 149 // Geometry parameters are calculated
150
151 SetPHOSAngles();
152 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
153 Float_t r = GetIPtoOuterCoverDistance() + fPHOSParams[3] - GetCPVBoxSize(1) ;
154 for (Int_t iModule=0; iModule<fNModules; iModule++) {
155 fModuleCenter[iModule][0] = r * TMath::Sin(fPHOSAngle[iModule] / kRADDEG );
156 fModuleCenter[iModule][1] =-r * TMath::Cos(fPHOSAngle[iModule] / kRADDEG );
157 fModuleCenter[iModule][2] = 0.;
158
159 fModuleAngle[iModule][0][0] = 90;
160 fModuleAngle[iModule][0][1] = fPHOSAngle[iModule];
161 fModuleAngle[iModule][1][0] = 0;
162 fModuleAngle[iModule][1][1] = 0;
163 fModuleAngle[iModule][2][0] = 90;
164 fModuleAngle[iModule][2][1] = 270 + fPHOSAngle[iModule];
05d33a3d 165 }
166
52a36ffd 167}
168
169//____________________________________________________________________________
170AliPHOSGeometry * AliPHOSGeometry::GetInstance()
171{
a4e98857 172 // Returns the pointer of the unique instance; singleton specific
173
809cd394 174 return static_cast<AliPHOSGeometry *>( fgGeom ) ;
52a36ffd 175}
176
177//____________________________________________________________________________
178AliPHOSGeometry * AliPHOSGeometry::GetInstance(const Text_t* name, const Text_t* title)
179{
180 // Returns the pointer of the unique instance
a4e98857 181 // Creates it with the specified options (name, title) if it does not exist yet
182
52a36ffd 183 AliPHOSGeometry * rv = 0 ;
184 if ( fgGeom == 0 ) {
185 if ( strcmp(name,"") == 0 )
186 rv = 0 ;
187 else {
188 fgGeom = new AliPHOSGeometry(name, title) ;
189 if ( fgInit )
190 rv = (AliPHOSGeometry * ) fgGeom ;
191 else {
192 rv = 0 ;
193 delete fgGeom ;
194 fgGeom = 0 ;
195 }
196 }
197 }
198 else {
21cd0c07 199 if ( strcmp(fgGeom->GetName(), name) != 0 )
351dd634 200 ::Error("GetInstance", "Current geometry is %s. You cannot call %s",
201 fgGeom->GetName(), name) ;
52a36ffd 202 else
203 rv = (AliPHOSGeometry *) fgGeom ;
204 }
205 return rv ;
206}
4697edca 207
52a36ffd 208//____________________________________________________________________________
209void AliPHOSGeometry::SetPHOSAngles()
210{
a4e98857 211 // Calculates the position of the PHOS modules in ALICE global coordinate system
91daaf24 212 // in ideal geometry
52a36ffd 213
a8c47ab6 214 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
710f859a 215 Float_t pphi = 2 * TMath::ATan( GetOuterBoxSize(0) / ( 2.0 * GetIPtoUpperCPVsurface() ) ) ;
52a36ffd 216 pphi *= kRADDEG ;
710f859a 217 if (pphi > fAngle){
351dd634 218 AliError(Form("PHOS modules overlap!\n pphi = %f fAngle = %f",
219 pphi, fAngle));
710f859a 220
221 }
ed4205d8 222 pphi = fAngle;
52a36ffd 223
224 for( Int_t i = 1; i <= fNModules ; i++ ) {
ed4205d8 225 Float_t angle = pphi * ( i - fNModules / 2.0 - 0.5 ) ;
52a36ffd 226 fPHOSAngle[i-1] = - angle ;
227 }
d15a28e7 228}
9f616d61 229//____________________________________________________________________________
308fb942 230void AliPHOSGeometry::GetGlobal(const AliRecPoint* , TVector3 & ) const
9ee9f78d 231{
232 AliFatal(Form("Please use GetGlobalPHOS(recPoint,gpos) instead of GetGlobal!"));
233}
234
235//____________________________________________________________________________
236void AliPHOSGeometry::GetGlobalPHOS(const AliPHOSRecPoint* recPoint, TVector3 & gpos) const
d15a28e7 237{
a4e98857 238 // Calculates the coordinates of a RecPoint and the error matrix in the ALICE global coordinate system
b2a60966 239
9ee9f78d 240 const AliPHOSRecPoint * tmpPHOS = recPoint ;
92862013 241 TVector3 localposition ;
d15a28e7 242
243 tmpPHOS->GetLocalPosition(gpos) ;
244
91daaf24 245 if (!gGeoManager){
246 AliFatal("Geo manager not initialized\n");
d15a28e7 247 }
91daaf24 248 //construct module name
249 char path[100] ;
250 Double_t dy ;
251 if(tmpPHOS->IsEmc()){
6ba1dd81 252 TString spath="/ALIC_1/PHOS_%d/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1";
253 snprintf(path,spath.Length(),spath.Data(),tmpPHOS->GetPHOSMod()) ;
8e20650f 254// sprintf(path,"/ALIC_1/PHOS_%d",tmpPHOS->GetPHOSMod()) ;
255 dy=fCrystalShift ;
d15a28e7 256 }
91daaf24 257 else{
6ba1dd81 258 TString spath="/ALIC_1/PHOS_%d/PCPV_1";
259 snprintf(path,spath.Length(),spath.Data(),tmpPHOS->GetPHOSMod()) ;
91daaf24 260 dy= GetCPVBoxSize(1)/2. ; //center of CPV module
261 }
262 Double_t pos[3]={gpos.X(),gpos.Y()-dy,gpos.Z()} ;
8e20650f 263 if(tmpPHOS->IsEmc())
264 pos[2]=-pos[2] ; //Opposite z directions in EMC matrix and local frame!!!
6ba1dd81 265 Double_t posC[3] = {};
91daaf24 266 //now apply possible shifts and rotations
267 if (!gGeoManager->cd(path)){
268 AliFatal("Geo manager can not find path \n");
269 }
270 TGeoHMatrix *m = gGeoManager->GetCurrentMatrix();
8e20650f 271 if (m){
272 m->LocalToMaster(pos,posC);
273 }
91daaf24 274 else{
275 AliFatal("Geo matrixes are not loaded \n") ;
276 }
8e20650f 277 gpos.SetXYZ(posC[0],posC[1],posC[2]) ;
7b51037f 278
aa35fc01 279}
aa0b9641 280//____________________________________________________________________________
281
7b51037f 282void AliPHOSGeometry::GetModuleCenter(TVector3& center,
283 const char *det,
284 Int_t module) const
aa0b9641 285{
bfc17d18 286 // Returns a position of the center of the CPV or EMC module
91daaf24 287 // in ideal (not misaligned) geometry
1504ac47 288 Float_t rDet = 0.;
e77bb310 289 if (strcmp(det,"CPV") == 0) rDet = GetIPtoCPVDistance ();
290 else if (strcmp(det,"EMC") == 0) rDet = GetIPtoCrystalSurface();
351dd634 291 else
292 AliFatal(Form("Wrong detector name %s",det));
bfc17d18 293
395f4eea 294 Float_t angle = GetPHOSAngle(module); // (40,20,0,-20,-40) degrees
295 angle *= TMath::Pi()/180;
296 angle += 3*TMath::Pi()/2.;
7b51037f 297 center.SetXYZ(rDet*TMath::Cos(angle), rDet*TMath::Sin(angle), 0.);
aa0b9641 298}
299