]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGeoUtils.cxx
Update from Alberica. Addition of VZERO equalized signals and ZNC.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGeoUtils.cxx
CommitLineData
70a0fabe 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
16/* $Id: AliPHOSGeometry.cxx 25590 2008-05-06 07:09:11Z prsnko $ */
17
18//_________________________________________________________________________
bb5c37a5 19// Geometry class for PHOS
70a0fabe 20// PHOS consists of the electromagnetic calorimeter (EMCA)
bb5c37a5 21// and a charged particle veto (CPV)
22// The EMCA/CPV modules are parametrized so that any configuration
70a0fabe 23// can be easily implemented
24// The title is used to identify the version of CPV used.
25//
26// -- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC "KI" & SUBATECH)
27
28// --- ROOT system ---
29
bb5c37a5 30#include "TClonesArray.h"
70a0fabe 31#include "TVector3.h"
32#include "TParticle.h"
33#include <TGeoManager.h>
34#include <TGeoMatrix.h>
35
36// --- Standard library ---
37
38// --- AliRoot header files ---
478420eb 39#include "AliLog.h"
70a0fabe 40#include "AliPHOSEMCAGeometry.h"
41#include "AliPHOSCPVGeometry.h"
bcc9e89e 42#include "AliPHOSSupportGeometry.h"
70a0fabe 43#include "AliPHOSGeoUtils.h"
44
45ClassImp(AliPHOSGeoUtils)
46
47//____________________________________________________________________________
48AliPHOSGeoUtils::AliPHOSGeoUtils():
bcc9e89e 49 fGeometryEMCA(0x0),fGeometryCPV(0x0),fGeometrySUPP(0x0),
70a0fabe 50 fNModules(0),fNCristalsInModule(0),fNPhi(0),fNZ(0),
51 fNumberOfCPVPadsPhi(0),fNumberOfCPVPadsZ(0),
52 fNCellsXInStrip(0),fNCellsZInStrip(0),fNStripZ(0),
bb5c37a5 53 fCrystalShift(0.),fCryCellShift(0.),fCryStripShift(0.),fCellStep(0.),
54 fPadSizePhi(0.),fPadSizeZ(0.),fCPVBoxSizeY(0.),fMisalArray(0x0)
70a0fabe 55
56{
57 // default ctor
58 // must be kept public for root persistency purposes, but should never be called by the outside world
6ba1dd81 59
60 fXtlArrSize[0]=0.;
61 fXtlArrSize[1]=0.;
62 fXtlArrSize[2]=0.;
63
64 for(Int_t mod=0; mod<5; mod++){
65 fEMCMatrix[mod]=0 ;
66 for(Int_t istrip=0; istrip<224; istrip++)
67 fStripMatrix[mod][istrip]=0 ;
68 fCPVMatrix[mod]=0;
69 fPHOSMatrix[mod]=0 ;
70 }
71
70a0fabe 72}
73
74//____________________________________________________________________________
75AliPHOSGeoUtils::AliPHOSGeoUtils(const AliPHOSGeoUtils & rhs)
76 : TNamed(rhs),
bcc9e89e 77 fGeometryEMCA(0x0),fGeometryCPV(0x0),fGeometrySUPP(0x0),
70a0fabe 78 fNModules(0),fNCristalsInModule(0),fNPhi(0),fNZ(0),
79 fNumberOfCPVPadsPhi(0),fNumberOfCPVPadsZ(0),
80 fNCellsXInStrip(0),fNCellsZInStrip(0),fNStripZ(0),
bb5c37a5 81 fCrystalShift(0.),fCryCellShift(0.),fCryStripShift(0.),fCellStep(0.),
82 fPadSizePhi(0.),fPadSizeZ(0.),fCPVBoxSizeY(0.),fMisalArray(0x0)
70a0fabe 83{
84 Fatal("cpy ctor", "not implemented") ;
85}
86
87//____________________________________________________________________________
88AliPHOSGeoUtils::AliPHOSGeoUtils(const Text_t* name, const Text_t* title)
89 : TNamed(name, title),
bcc9e89e 90 fGeometryEMCA(0x0),fGeometryCPV(0x0),fGeometrySUPP(0x0),
70a0fabe 91 fNModules(0),fNCristalsInModule(0),fNPhi(0),fNZ(0),
92 fNumberOfCPVPadsPhi(0),fNumberOfCPVPadsZ(0),
93 fNCellsXInStrip(0),fNCellsZInStrip(0),fNStripZ(0),
bb5c37a5 94 fCrystalShift(0.),fCryCellShift(0.),fCryStripShift(0.),fCellStep(0.),
95 fPadSizePhi(0.),fPadSizeZ(0.),fCPVBoxSizeY(0.),fMisalArray(0x0)
70a0fabe 96{
97 // ctor only for normal usage
bcc9e89e 98
99 fGeometryEMCA = new AliPHOSEMCAGeometry() ;
100 fGeometryCPV = new AliPHOSCPVGeometry() ;
101 fGeometrySUPP = new AliPHOSSupportGeometry() ;
102
103 fNModules = 5;
104 fNPhi = fGeometryEMCA->GetNPhi() ;
105 fNZ = fGeometryEMCA->GetNZ() ;
106 fNCristalsInModule = fNPhi*fNZ ;
107 fNCellsXInStrip= fGeometryEMCA->GetNCellsXInStrip() ;
108 fNCellsZInStrip= fGeometryEMCA->GetNCellsZInStrip() ;
109 fNStripZ = fGeometryEMCA->GetNStripZ() ;
110 fXtlArrSize[0]=fGeometryEMCA->GetInnerThermoHalfSize()[0] ; //Wery close to the zise of the Xtl set
111 fXtlArrSize[1]=fGeometryEMCA->GetInnerThermoHalfSize()[1] ; //Wery close to the zise of the Xtl set
112 fXtlArrSize[2]=fGeometryEMCA->GetInnerThermoHalfSize()[2] ; //Wery close to the zise of the Xtl set
113
114 //calculate offset to crystal surface
a2bb6de5 115 const Float_t * inthermo = fGeometryEMCA->GetInnerThermoHalfSize() ;
116 const Float_t * strip = fGeometryEMCA->GetStripHalfSize() ;
117 const Float_t * splate = fGeometryEMCA->GetSupportPlateHalfSize();
118 const Float_t * crystal = fGeometryEMCA->GetCrystalHalfSize() ;
119 const Float_t * pin = fGeometryEMCA->GetAPDHalfSize() ;
120 const Float_t * preamp = fGeometryEMCA->GetPreampHalfSize() ;
bcc9e89e 121 fCrystalShift=-inthermo[1]+strip[1]+splate[1]+crystal[1]-fGeometryEMCA->GetAirGapLed()/2.+pin[1]+preamp[1] ;
122 fCryCellShift=crystal[1]-(fGeometryEMCA->GetAirGapLed()-2*pin[1]-2*preamp[1])/2;
bb5c37a5 123 fCryStripShift=fCryCellShift+splate[1] ;
bcc9e89e 124 fCellStep = 2.*fGeometryEMCA->GetAirCellHalfSize()[0] ;
125
bcc9e89e 126 fNumberOfCPVPadsPhi = fGeometryCPV->GetNumberOfCPVPadsPhi() ;
127 fNumberOfCPVPadsZ = fGeometryCPV->GetNumberOfCPVPadsZ() ;
128 fPadSizePhi = fGeometryCPV->GetCPVPadSizePhi() ;
129 fPadSizeZ = fGeometryCPV->GetCPVPadSizeZ() ;
130 fCPVBoxSizeY= fGeometryCPV->GetCPVBoxSize(1) ;
bb5c37a5 131
132 for(Int_t mod=0; mod<5; mod++){
133 fEMCMatrix[mod]=0 ;
134 for(Int_t istrip=0; istrip<224; istrip++)
135 fStripMatrix[mod][istrip]=0 ;
136 fCPVMatrix[mod]=0;
137 fPHOSMatrix[mod]=0 ;
138 }
139
70a0fabe 140}
141
142//____________________________________________________________________________
143AliPHOSGeoUtils & AliPHOSGeoUtils::operator = (const AliPHOSGeoUtils & /*rvalue*/) {
bcc9e89e 144
145 Fatal("assignment operator", "not implemented") ;
70a0fabe 146 return *this ;
147}
148
149//____________________________________________________________________________
150AliPHOSGeoUtils::~AliPHOSGeoUtils(void)
151{
152 // dtor
bcc9e89e 153 if(fGeometryEMCA){
154 delete fGeometryEMCA; fGeometryEMCA = 0 ;
155 }
156 if(fGeometryCPV){
157 delete fGeometryCPV; fGeometryCPV=0 ;
158 }
159 if(fGeometrySUPP){
160 delete fGeometrySUPP ; fGeometrySUPP=0 ;
161 }
bb5c37a5 162 if(fMisalArray){
163 delete fMisalArray; fMisalArray=0 ;
164 }
3eef419b 165
ea98ab56 166 for(Int_t mod=0; mod<5; mod++){
167 delete fEMCMatrix[mod] ;
168 for(Int_t istrip=0; istrip<224; istrip++)
169 delete fStripMatrix[mod][istrip];
170 delete fCPVMatrix[mod];
79b175e1 171 delete fPHOSMatrix[mod];
ea98ab56 172 }
70a0fabe 173}
174//____________________________________________________________________________
175Bool_t AliPHOSGeoUtils::AbsToRelNumbering(Int_t absId, Int_t * relid) const
176{
177 // Converts the absolute numbering into the following array
178 // relid[0] = PHOS Module number 1:fNModules
179 // relid[1] = 0 if PbW04
180 // = -1 if CPV
181 // relid[2] = Row number inside a PHOS module
182 // relid[3] = Column number inside a PHOS module
183
184 Float_t id = absId ;
185
186 Int_t phosmodulenumber = (Int_t)TMath:: Ceil( id / fNCristalsInModule ) ;
187
188 if ( phosmodulenumber > fNModules ) { // it is a CPV pad
189
190 id -= fNPhi * fNZ * fNModules ;
191 Float_t nCPV = fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ ;
192 relid[0] = (Int_t) TMath::Ceil( id / nCPV ) ;
193 relid[1] = -1 ;
194 id -= ( relid[0] - 1 ) * nCPV ;
195 relid[2] = (Int_t) TMath::Ceil( id / fNumberOfCPVPadsZ ) ;
196 relid[3] = (Int_t) ( id - ( relid[2] - 1 ) * fNumberOfCPVPadsZ ) ;
197 }
198 else { // it is a PW04 crystal
199
200 relid[0] = phosmodulenumber ;
201 relid[1] = 0 ;
202 id -= ( phosmodulenumber - 1 ) * fNPhi * fNZ ;
203 relid[2] = (Int_t)TMath::Ceil( id / fNZ ) ;
204 relid[3] = (Int_t)( id - ( relid[2] - 1 ) * fNZ ) ;
205 }
206 return kTRUE ;
207}
208//____________________________________________________________________________
209Bool_t AliPHOSGeoUtils::RelToAbsNumbering(const Int_t * relid, Int_t & absId) const
210{
211 // Converts the relative numbering into the absolute numbering
212 // EMCA crystals:
213 // absId = from 1 to fNModules * fNPhi * fNZ
214 // CPV pad:
215 // absId = from N(total PHOS crystals) + 1
216 // to NCPVModules * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ
217
218 if ( relid[1] == 0 ) { // it is a Phos crystal
219 absId =
220 ( relid[0] - 1 ) * fNPhi * fNZ // the offset of PHOS modules
221 + ( relid[2] - 1 ) * fNZ // the offset along phi
222 + relid[3] ; // the offset along z
223 }
224 else { // it is a CPV pad
225 absId = fNPhi * fNZ * fNModules // the offset to separate EMCA crystals from CPV pads
226 + ( relid[0] - 1 ) * fNumberOfCPVPadsPhi * fNumberOfCPVPadsZ // the pads offset of PHOS modules
227 + ( relid[2] - 1 ) * fNumberOfCPVPadsZ // the pads offset of a CPV row
228 + relid[3] ; // the column number
229 }
230
231 return kTRUE ;
232}
233
234//____________________________________________________________________________
235void AliPHOSGeoUtils::RelPosInModule(const Int_t * relid, Float_t & x, Float_t & z) const
236{
237 // Converts the relative numbering into the local PHOS-module (x, z) coordinates
238
70a0fabe 239 if(relid[1]==0){ //this is PHOS
240
241 Double_t pos[3]= {0.0,-fCryCellShift,0.}; //Position incide the crystal
242 Double_t posC[3]={0.0,0.0,0.}; //Global position
243
244 //Shift and possibly apply misalignment corrections
245 Int_t strip=1+((Int_t) TMath::Ceil((Double_t)relid[2]/fNCellsXInStrip))*fNStripZ-
246 (Int_t) TMath::Ceil((Double_t)relid[3]/fNCellsZInStrip) ;
bb5c37a5 247 pos[0]=((relid[2]-1)%fNCellsXInStrip-fNCellsXInStrip/2+0.5)*fCellStep ;
248 pos[2]=(-(relid[3]-1)%fNCellsZInStrip+fNCellsZInStrip/2-0.5)*fCellStep ;
249
250 Int_t mod = relid[0] ;
98082233 251 const TGeoHMatrix * m2 = GetMatrixForStrip(mod, strip) ;
bb5c37a5 252 m2->LocalToMaster(pos,posC);
253
70a0fabe 254 //Return to PHOS local system
bb5c37a5 255 Double_t posL2[3]={posC[0],posC[1],posC[2]};
98082233 256 const TGeoHMatrix *mPHOS2 = GetMatrixForModule(mod) ;
bb5c37a5 257 mPHOS2->MasterToLocal(posC,posL2);
258 x=posL2[0] ;
259 z=-posL2[2];
70a0fabe 260 return ;
261 }
262 else{//CPV
263 //first calculate position with respect to CPV plain
264 Int_t row = relid[2] ; //offset along x axis
265 Int_t column = relid[3] ; //offset along z axis
266 Double_t pos[3]= {0.0,0.0,0.}; //Position incide the CPV printed circuit
267 Double_t posC[3]={0.0,0.0,0.}; //Global position
268 pos[0] = - ( fNumberOfCPVPadsPhi/2. - row - 0.5 ) * fPadSizePhi ; // position of pad with respect
269 pos[2] = - ( fNumberOfCPVPadsZ /2. - column - 0.5 ) * fPadSizeZ ; // of center of PHOS module
270
271 //now apply possible shifts and rotations
98082233 272 const TGeoHMatrix *m = GetMatrixForCPV(relid[0]) ;
bb5c37a5 273 m->LocalToMaster(pos,posC);
70a0fabe 274 //Return to PHOS local system
275 Double_t posL[3]={0.,0.,0.,} ;
98082233 276 const TGeoHMatrix *mPHOS = GetMatrixForPHOS(relid[0]) ;
bb5c37a5 277 mPHOS->MasterToLocal(posC,posL);
70a0fabe 278 x=posL[0] ;
279 z=posL[1];
280 return ;
281
282 }
283
284}
285//____________________________________________________________________________
286void AliPHOSGeoUtils::RelPosToAbsId(Int_t module, Double_t x, Double_t z, Int_t & absId) const
287{
288 // converts local PHOS-module (x, z) coordinates to absId
289
bb5c37a5 290 //Calculate AbsId using ideal geometry. Should be sufficient for primary particles calculation
291 //(the only place where this method used currently)
292 Int_t relid[4]={module,0,1,1} ;
293 relid[2] = static_cast<Int_t>(TMath::Ceil( x/ fCellStep + fNPhi / 2.) );
478420eb 294 relid[3] = fNZ+1-static_cast<Int_t>(TMath::Ceil(-z/ fCellStep + fNZ / 2.) ) ;
bb5c37a5 295 if(relid[2]<1)relid[2]=1 ;
296 if(relid[3]<1)relid[3]=1 ;
297 if(relid[2]>fNPhi)relid[2]=fNPhi ;
298 if(relid[3]>fNZ)relid[3]=fNZ ;
299 RelToAbsNumbering(relid,absId) ;
300
301/*
70a0fabe 302 //find Global position
303 if (!gGeoManager){
304 printf("Geo manager not initialized\n");
305 abort() ;
306 }
307 Double_t posL[3]={x,-fCrystalShift,-z} ; //Only for EMC!!!
308 Double_t posG[3] ;
309 char path[100] ;
310 sprintf(path,"/ALIC_1/PHOS_%d/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1",module) ;
311 if (!gGeoManager->cd(path)){
312 printf("Geo manager can not find path \n");
313 abort() ;
314 }
315 TGeoHMatrix *mPHOS = gGeoManager->GetCurrentMatrix();
316 if (mPHOS){
317 mPHOS->LocalToMaster(posL,posG);
318 }
319 else{
320 printf("Geo matrixes are not loaded \n") ;
321 abort() ;
322 }
323
324 Int_t relid[4] ;
325 gGeoManager->FindNode(posG[0],posG[1],posG[2]) ;
326 //Check that path contains PSTR and extract strip number
327 TString cpath(gGeoManager->GetPath()) ;
328 Int_t indx = cpath.Index("PCEL") ;
329 if(indx==-1){ //for the few events when particle hits between srips use ideal geometry
330 relid[0] = module ;
331 relid[1] = 0 ;
332 relid[2] = static_cast<Int_t>(TMath::Ceil( x/ fCellStep + fNPhi / 2.) );
333 relid[3] = static_cast<Int_t>(TMath::Ceil(-z/ fCellStep + fNZ / 2.) ) ;
334 if(relid[2]<1)relid[2]=1 ;
335 if(relid[3]<1)relid[3]=1 ;
336 if(relid[2]>fNPhi)relid[2]=fNPhi ;
337 if(relid[3]>fNZ)relid[3]=fNZ ;
338 RelToAbsNumbering(relid,absId) ;
339 }
340 else{
341 Int_t indx2 = cpath.Index("/",indx) ;
342 if(indx2==-1)
343 indx2=cpath.Length() ;
344 TString cell=cpath(indx+5,indx2-indx-5) ;
345 Int_t icell=cell.Atoi() ;
346 indx = cpath.Index("PSTR") ;
347 indx2 = cpath.Index("/",indx) ;
348 TString strip=cpath(indx+5,indx2-indx-5) ;
349 Int_t iStrip = strip.Atoi() ;
350
351 Int_t row = fNStripZ - (iStrip - 1) % (fNStripZ) ;
352 Int_t col = (Int_t) TMath::Ceil((Double_t) iStrip/(fNStripZ)) -1 ;
353
354 // Absid for 8x2-strips. Looks nice :)
355 absId = (module-1)*fNCristalsInModule +
356 row * 2 + (col*fNCellsXInStrip + (icell - 1) / 2)*fNZ - (icell & 1 ? 1 : 0);
357
358 }
bb5c37a5 359*/
70a0fabe 360
361}
362
363//____________________________________________________________________________
364void AliPHOSGeoUtils::RelPosToRelId(Int_t module, Double_t x, Double_t z, Int_t * relId) const
365{
366 //Evaluates RelId of the crystall with given coordinates
367
368 Int_t absId ;
369 RelPosToAbsId(module, x,z,absId) ;
370 AbsToRelNumbering(absId,relId) ;
371}
372
373//____________________________________________________________________________
374void AliPHOSGeoUtils::RelPosInAlice(Int_t id, TVector3 & pos ) const
375{
376 // Converts the absolute numbering into the global ALICE coordinate system
377
378 if (!gGeoManager){
379 printf("Geo manager not initialized\n");
380 abort();
381 }
382
383 Int_t relid[4] ;
384
385 AbsToRelNumbering(id , relid) ;
386
387 //construct module name
70a0fabe 388 if(relid[1]==0){ //this is EMC
389
bb5c37a5 390 Double_t ps[3]= {0.0,-fCryStripShift,0.}; //Position incide the crystal
70a0fabe 391 Double_t psC[3]={0.0,0.0,0.}; //Global position
392
393 //Shift and possibly apply misalignment corrections
394 Int_t strip=1+((Int_t) TMath::Ceil((Double_t)relid[2]/fNCellsXInStrip))*fNStripZ-
395 (Int_t) TMath::Ceil((Double_t)relid[3]/fNCellsZInStrip) ;
bb5c37a5 396 ps[0]=((relid[2]-1)%fNCellsXInStrip-fNCellsXInStrip/2+0.5)*fCellStep ;
397 ps[2]=(-(relid[3]-1)%fNCellsZInStrip+fNCellsZInStrip/2-0.5)*fCellStep ;
398
399 Int_t mod = relid[0] ;
98082233 400 const TGeoHMatrix * m2 = GetMatrixForStrip(mod, strip) ;
bb5c37a5 401 m2->LocalToMaster(ps,psC);
70a0fabe 402 pos.SetXYZ(psC[0],psC[1],psC[2]) ;
bb5c37a5 403
70a0fabe 404 }
405 else{
406 //first calculate position with respect to CPV plain
407 Int_t row = relid[2] ; //offset along x axis
408 Int_t column = relid[3] ; //offset along z axis
409 Double_t ps[3]= {0.0,fCPVBoxSizeY/2.,0.}; //Position on top of CPV
410 Double_t psC[3]={0.0,0.0,0.}; //Global position
411 pos[0] = - ( fNumberOfCPVPadsPhi/2. - row - 0.5 ) * fPadSizePhi ; // position of pad with respect
412 pos[2] = - ( fNumberOfCPVPadsZ /2. - column - 0.5 ) * fPadSizeZ ; // of center of PHOS module
413
414 //now apply possible shifts and rotations
98082233 415 const TGeoHMatrix *m = GetMatrixForCPV(relid[0]) ;
bb5c37a5 416 m->LocalToMaster(ps,psC);
70a0fabe 417 pos.SetXYZ(psC[0],psC[1],-psC[2]) ;
418 }
419}
420
421//____________________________________________________________________________
422void AliPHOSGeoUtils::Local2Global(Int_t mod, Float_t x, Float_t z,
423 TVector3& globalPosition) const
424{
70a0fabe 425 Double_t posL[3]={x,-fCrystalShift,-z} ; //Only for EMC!!!
426 Double_t posG[3] ;
98082233 427 const TGeoHMatrix *mPHOS = GetMatrixForModule(mod) ;
bb5c37a5 428 mPHOS->LocalToMaster(posL,posG);
70a0fabe 429 globalPosition.SetXYZ(posG[0],posG[1],posG[2]) ;
430}
431//____________________________________________________________________________
432void AliPHOSGeoUtils::Global2Local(TVector3& localPosition,
433 const TVector3& globalPosition,
434 Int_t module) const
435{
436 // Transforms a global position to the local coordinate system
437 // of the module
438 //Return to PHOS local system
439 Double_t posG[3]={globalPosition.X(),globalPosition.Y(),globalPosition.Z()} ;
440 Double_t posL[3]={0.,0.,0.} ;
98082233 441 const TGeoHMatrix *mPHOS = GetMatrixForModule(module) ;
478420eb 442 if(mPHOS){
443 mPHOS->MasterToLocal(posG,posL);
444 localPosition.SetXYZ(posL[0],posL[1]+fCrystalShift,-posL[2]) ;
445 }
446 else{
447 localPosition.SetXYZ(999.,999.,999.) ; //module does not exist in given configuration
448 }
70a0fabe 449
f4aea312 450}
451//____________________________________________________________________________
452Bool_t AliPHOSGeoUtils::GlobalPos2RelId(TVector3 & global, Int_t * relId){
453 //Converts position in global ALICE coordinates to relId
454 //returns false if x,z coordinates are beyond PHOS
455 //distande to PHOS surface is NOT calculated
456 TVector3 loc ;
478420eb 457 for(Int_t mod=1; mod<=fNModules; mod++){
f4aea312 458 Global2Local(loc,global,mod) ;
459 //If in Acceptance
460 if((TMath::Abs(loc.Z())<fXtlArrSize[2]) && (TMath::Abs(loc.X())<fXtlArrSize[0])){
461 RelPosToRelId(mod,loc.X(),loc.Z(),relId);
462 return kTRUE ;
463 }
464 }
465 return kFALSE ;
466
70a0fabe 467}
468//____________________________________________________________________________
469Bool_t AliPHOSGeoUtils::ImpactOnEmc(const TParticle * particle,
470 Int_t & moduleNumber, Double_t & z, Double_t & x) const
471{
472 // Tells if a particle enters PHOS and evaluates hit position
473 Double_t vtx[3]={particle->Vx(),particle->Vy(),particle->Vz()} ;
474 return ImpactOnEmc(vtx,particle->Theta(),particle->Phi(),moduleNumber,z,x);
475}
476
477//____________________________________________________________________________
478Bool_t AliPHOSGeoUtils::ImpactOnEmc(const Double_t * vtx, Double_t theta, Double_t phi,
479 Int_t & moduleNumber, Double_t & z, Double_t & x) const
480{
481 // calculates the impact coordinates on PHOS of a neutral particle
482 // emitted in the vertex vtx[3] with direction vec(p) in the ALICE global coordinate system
483 TVector3 p(TMath::Sin(theta)*TMath::Cos(phi),TMath::Sin(theta)*TMath::Sin(phi),TMath::Cos(theta)) ;
484 return ImpactOnEmc(vtx,p,moduleNumber,z,x) ;
485
486}
487//____________________________________________________________________________
488Bool_t AliPHOSGeoUtils::ImpactOnEmc(const Double_t * vtx, const TVector3 &p,
489 Int_t & moduleNumber, Double_t & z, Double_t & x) const
490{
491 // calculates the impact coordinates on PHOS of a neutral particle
492 // emitted in the vertex vtx[3] with direction theta and phi in the ALICE global coordinate system
493 TVector3 v(vtx[0],vtx[1],vtx[2]) ;
494
70a0fabe 495 for(Int_t imod=1; imod<=fNModules ; imod++){
496 //create vector from (0,0,0) to center of crystal surface of imod module
497 Double_t tmp[3]={0.,-fCrystalShift,0.} ;
498
98082233 499 const TGeoHMatrix *m = GetMatrixForModule(imod) ;
478420eb 500 if(!m) //module does not exist in given configuration
501 continue ;
70a0fabe 502 Double_t posG[3]={0.,0.,0.} ;
bb5c37a5 503 m->LocalToMaster(tmp,posG);
70a0fabe 504 TVector3 n(posG[0],posG[1],posG[2]) ;
505 Double_t direction=n.Dot(p) ;
506 if(direction<=0.)
507 continue ; //momentum directed FROM module
508 Double_t fr = (n.Mag2()-n.Dot(v))/direction ;
509 //Calculate direction in module plain
510 n-=v+fr*p ;
511 n*=-1. ;
512 if(TMath::Abs(TMath::Abs(n.Z())<fXtlArrSize[2]) && n.Pt()<fXtlArrSize[0]){
513 moduleNumber = imod ;
514 z=n.Z() ;
515 x=TMath::Sign(n.Pt(),n.X()) ;
516 //no need to return to local system since we calcilated distance from module center
517 //and tilts can not be significant.
518 return kTRUE ;
519 }
520 }
521 //Not in acceptance
522 x=0; z=0 ;
523 moduleNumber=0 ;
524 return kFALSE ;
525
526}
70a0fabe 527//____________________________________________________________________________
bcc9e89e 528void AliPHOSGeoUtils::GetIncidentVector(const TVector3 &vtx, Int_t module, Float_t x,Float_t z, TVector3 &vInc) const {
529 //Calculates vector pointing from vertex to current poisition in module local frame
530 //Note that PHOS local system and ALICE global have opposite z directions
70a0fabe 531
bcc9e89e 532 Global2Local(vInc,vtx,module) ;
533 vInc.SetXYZ(vInc.X()+x,vInc.Y(),vInc.Z()+z) ;
70a0fabe 534}
bb5c37a5 535//____________________________________________________________________________
98082233 536const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForModule(Int_t mod)const {
bb5c37a5 537 //Provides shift-rotation matrix for module mod
bcc9e89e 538
bb5c37a5 539 //If GeoManager exists, take matrixes from it
540 if(gGeoManager){
541 char path[255] ;
14895588 542 snprintf(path,255,"/ALIC_1/PHOS_%d/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1",mod) ;
bb5c37a5 543 // sprintf(path,"/ALIC_1/PHOS_%d",relid[0]) ;
544 if (!gGeoManager->cd(path)){
478420eb 545 AliWarning(Form("Geo manager can not find path %s \n",path));
546 return 0;
bb5c37a5 547 }
548 return gGeoManager->GetCurrentMatrix();
549 }
550 if(fEMCMatrix[mod-1]){
551 return fEMCMatrix[mod-1] ;
552 }
553 else{
478420eb 554 AliWarning("Can not find PHOS misalignment matrixes\n") ;
555 AliWarning("Either import TGeoManager from geometry.root or \n");
556 AliWarning("read stored matrixes from AliESD Header: \n") ;
557 AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
558 return 0 ;
bb5c37a5 559 }
560 return 0 ;
561}
562//____________________________________________________________________________
98082233 563const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForStrip(Int_t mod, Int_t strip)const {
bb5c37a5 564 //Provides shift-rotation matrix for strip unit of the module mod
565
566 //If GeoManager exists, take matrixes from it
567 if(gGeoManager){
568 char path[255] ;
14895588 569 snprintf(path,255,"/ALIC_1/PHOS_%d/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1/PSTR_%d",mod,strip) ;
bb5c37a5 570 if (!gGeoManager->cd(path)){
478420eb 571 AliWarning(Form("Geo manager can not find path %s \n",path));
572 return 0 ;
bb5c37a5 573 }
574 return gGeoManager->GetCurrentMatrix();
575 }
576 if(fStripMatrix[mod-1][strip-1]){
577 return fStripMatrix[mod-1][strip-1] ;
578 }
579 else{
478420eb 580 AliWarning("Can not find PHOS misalignment matrixes\n") ;
581 AliWarning("Either import TGeoManager from geometry.root or \n");
582 AliWarning("read stored matrixes from AliESD Header: \n") ;
583 AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
584 return 0 ;
bb5c37a5 585 }
586 return 0 ;
587}
588//____________________________________________________________________________
98082233 589const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForCPV(Int_t mod)const {
bb5c37a5 590 //Provides shift-rotation matrix for CPV of the module mod
591
592 //If GeoManager exists, take matrixes from it
593 if(gGeoManager){
594 char path[255] ;
595 //now apply possible shifts and rotations
14895588 596 snprintf(path,255,"/ALIC_1/PHOS_%d/PCPV_1",mod) ;
bb5c37a5 597 if (!gGeoManager->cd(path)){
478420eb 598 AliWarning(Form("Geo manager can not find path %s \n",path));
599 return 0 ;
bb5c37a5 600 }
601 return gGeoManager->GetCurrentMatrix();
602 }
603 if(fCPVMatrix[mod-1]){
604 return fCPVMatrix[mod-1] ;
605 }
606 else{
478420eb 607 AliWarning("Can not find PHOS misalignment matrixes\n") ;
608 AliWarning("Either import TGeoManager from geometry.root or \n");
609 AliWarning("read stored matrixes from AliESD Header: \n") ;
610 AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
611 return 0 ;
bb5c37a5 612 }
613 return 0 ;
614}
615//____________________________________________________________________________
98082233 616const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForPHOS(Int_t mod)const {
bb5c37a5 617 //Provides shift-rotation matrix for PHOS (EMC+CPV)
618
619 //If GeoManager exists, take matrixes from it
620 if(gGeoManager){
6ba1dd81 621
bb5c37a5 622 char path[255] ;
14895588 623 snprintf(path,255,"/ALIC_1/PHOS_%d",mod) ;
624
bb5c37a5 625 if (!gGeoManager->cd(path)){
478420eb 626 AliWarning(Form("Geo manager can not find path %s \n",path));
627 return 0 ;
bb5c37a5 628 }
629 return gGeoManager->GetCurrentMatrix();
630 }
631 if(fPHOSMatrix[mod-1]){
632 return fPHOSMatrix[mod-1] ;
633 }
634 else{
478420eb 635 AliWarning("Can not find PHOS misalignment matrixes\n") ;
636 AliWarning("Either import TGeoManager from geometry.root or \n");
637 AliWarning("read stored matrixes from AliESD Header: \n") ;
638 AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
639 return 0 ;
bb5c37a5 640 }
641 return 0 ;
642}
643//____________________________________________________________________________
98082233 644void AliPHOSGeoUtils::SetMisalMatrix(const TGeoHMatrix * m, Int_t mod){
bb5c37a5 645 //Fills pointers to geo matrixes
646
79b175e1 647 if(fPHOSMatrix[mod]){ //have been set already. Can not be changed any more
648 return ;
649 }
0e1c4f91 650 if(m==NULL) //Matrix for non-existing modules? Remain zero, no need to re-set
651 return ;
79b175e1 652 fPHOSMatrix[mod]= new TGeoHMatrix(*m) ;
d3506595 653
3eef419b 654 //Calculate maxtrices for PTII
bb5c37a5 655 if(!fMisalArray)
656 fMisalArray = new TClonesArray("TGeoHMatrix",1120+10) ;
657 Int_t nr = fMisalArray->GetEntriesFast() ;
658 Double_t rotEMC[9]={1.,0.,0.,0.,0.,-1.,0.,1.,0.} ;
659 const Float_t * inthermo = fGeometryEMCA->GetInnerThermoHalfSize() ;
660 const Float_t * strip = fGeometryEMCA->GetStripHalfSize() ;
661 const Float_t * covparams = fGeometryEMCA->GetAlCoverParams() ;
662 const Float_t * warmcov = fGeometryEMCA->GetWarmAlCoverHalfSize() ;
663 Float_t z = fGeometryCPV->GetCPVBoxSize(1) / 2. - warmcov[2] + covparams[3]-inthermo[1] ;
664 Double_t locTII[3]={0.,0.,z} ;
665 Double_t globTII[3] ;
666
3eef419b 667 if (fEMCMatrix[mod] == NULL)
668 fEMCMatrix[mod] = new((*fMisalArray)[nr])TGeoHMatrix() ;
98082233 669 nr++ ;
3eef419b 670 fEMCMatrix[mod]->SetRotation(rotEMC) ;
671 fEMCMatrix[mod]->MultiplyLeft(fPHOSMatrix[mod]) ;
bb5c37a5 672 fPHOSMatrix[mod]->LocalToMaster(locTII,globTII) ;
3eef419b 673 fEMCMatrix[mod]->SetTranslation(globTII) ;
bb5c37a5 674
675 //Now calculate ideal matrixes for strip misalignment.
676 //For the moment we can not store them in ESDHeader
677
678 Double_t loc[3]={0.,inthermo[1] - strip[1],0.} ;
679 Double_t glob[3] ;
680
681 Int_t istrip=0 ;
682 for(Int_t irow = 0; irow < fGeometryEMCA->GetNStripX(); irow ++){
683 loc[0] = (2*irow + 1 - fGeometryEMCA->GetNStripX())* strip[0] ;
684 for(Int_t icol = 0; icol < fGeometryEMCA->GetNStripZ(); icol ++){
685 loc[2] = (2*icol + 1 - fGeometryEMCA->GetNStripZ()) * strip[2] ;
686 fEMCMatrix[mod]->LocalToMaster(loc,glob) ;
3eef419b 687 if (fStripMatrix[mod][istrip] == NULL)
688 fStripMatrix[mod][istrip] = new((*fMisalArray)[nr])TGeoHMatrix(*(fEMCMatrix[mod])) ; //Use same rotation as PHOS module
98082233 689 nr++ ;
3eef419b 690 fStripMatrix[mod][istrip]->SetTranslation(glob) ;
bb5c37a5 691 istrip++;
692 }
693 }
694
695 //Now calculate CPV matrixes
696 const Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
697 Double_t globCPV[3] ;
698 Double_t locCPV[3]={0.,0.,- emcParams[3]} ;
699 Double_t rot[9]={1.,0.,0.,0.,0.,1.,0.,-1.,0.} ;
700
3eef419b 701 if (fCPVMatrix[mod] == NULL)
702 fCPVMatrix[mod] = new((*fMisalArray)[nr])TGeoHMatrix() ;
98082233 703 nr++ ;
3eef419b 704 fCPVMatrix[mod]->SetRotation(rot) ;
705 fCPVMatrix[mod]->MultiplyLeft(fPHOSMatrix[mod]) ;
706 fCPVMatrix[mod]->ReflectY(kFALSE) ;
bb5c37a5 707 fPHOSMatrix[mod]->LocalToMaster(locCPV,globCPV) ;
3eef419b 708 fCPVMatrix[mod]->SetTranslation(globCPV) ;
bb5c37a5 709
710}
711