]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGeoUtils.cxx
Adding Tasks to create NuclexAOD from MC productions and first Task to read Nuclex AOD
[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){
b8bec44f 379 AliFatal("Geo manager not initialized\n");
70a0fabe 380 }
381
382 Int_t relid[4] ;
383
384 AbsToRelNumbering(id , relid) ;
385
386 //construct module name
70a0fabe 387 if(relid[1]==0){ //this is EMC
388
bb5c37a5 389 Double_t ps[3]= {0.0,-fCryStripShift,0.}; //Position incide the crystal
70a0fabe 390 Double_t psC[3]={0.0,0.0,0.}; //Global position
391
392 //Shift and possibly apply misalignment corrections
393 Int_t strip=1+((Int_t) TMath::Ceil((Double_t)relid[2]/fNCellsXInStrip))*fNStripZ-
394 (Int_t) TMath::Ceil((Double_t)relid[3]/fNCellsZInStrip) ;
bb5c37a5 395 ps[0]=((relid[2]-1)%fNCellsXInStrip-fNCellsXInStrip/2+0.5)*fCellStep ;
396 ps[2]=(-(relid[3]-1)%fNCellsZInStrip+fNCellsZInStrip/2-0.5)*fCellStep ;
397
398 Int_t mod = relid[0] ;
98082233 399 const TGeoHMatrix * m2 = GetMatrixForStrip(mod, strip) ;
bb5c37a5 400 m2->LocalToMaster(ps,psC);
70a0fabe 401 pos.SetXYZ(psC[0],psC[1],psC[2]) ;
bb5c37a5 402
70a0fabe 403 }
404 else{
405 //first calculate position with respect to CPV plain
406 Int_t row = relid[2] ; //offset along x axis
407 Int_t column = relid[3] ; //offset along z axis
408 Double_t ps[3]= {0.0,fCPVBoxSizeY/2.,0.}; //Position on top of CPV
409 Double_t psC[3]={0.0,0.0,0.}; //Global position
410 pos[0] = - ( fNumberOfCPVPadsPhi/2. - row - 0.5 ) * fPadSizePhi ; // position of pad with respect
411 pos[2] = - ( fNumberOfCPVPadsZ /2. - column - 0.5 ) * fPadSizeZ ; // of center of PHOS module
412
413 //now apply possible shifts and rotations
98082233 414 const TGeoHMatrix *m = GetMatrixForCPV(relid[0]) ;
bb5c37a5 415 m->LocalToMaster(ps,psC);
70a0fabe 416 pos.SetXYZ(psC[0],psC[1],-psC[2]) ;
417 }
418}
419
420//____________________________________________________________________________
421void AliPHOSGeoUtils::Local2Global(Int_t mod, Float_t x, Float_t z,
422 TVector3& globalPosition) const
423{
70a0fabe 424 Double_t posL[3]={x,-fCrystalShift,-z} ; //Only for EMC!!!
425 Double_t posG[3] ;
98082233 426 const TGeoHMatrix *mPHOS = GetMatrixForModule(mod) ;
bb5c37a5 427 mPHOS->LocalToMaster(posL,posG);
70a0fabe 428 globalPosition.SetXYZ(posG[0],posG[1],posG[2]) ;
429}
430//____________________________________________________________________________
431void AliPHOSGeoUtils::Global2Local(TVector3& localPosition,
432 const TVector3& globalPosition,
433 Int_t module) const
434{
435 // Transforms a global position to the local coordinate system
436 // of the module
437 //Return to PHOS local system
438 Double_t posG[3]={globalPosition.X(),globalPosition.Y(),globalPosition.Z()} ;
439 Double_t posL[3]={0.,0.,0.} ;
98082233 440 const TGeoHMatrix *mPHOS = GetMatrixForModule(module) ;
478420eb 441 if(mPHOS){
442 mPHOS->MasterToLocal(posG,posL);
443 localPosition.SetXYZ(posL[0],posL[1]+fCrystalShift,-posL[2]) ;
444 }
445 else{
446 localPosition.SetXYZ(999.,999.,999.) ; //module does not exist in given configuration
447 }
70a0fabe 448
f4aea312 449}
450//____________________________________________________________________________
451Bool_t AliPHOSGeoUtils::GlobalPos2RelId(TVector3 & global, Int_t * relId){
452 //Converts position in global ALICE coordinates to relId
453 //returns false if x,z coordinates are beyond PHOS
454 //distande to PHOS surface is NOT calculated
455 TVector3 loc ;
478420eb 456 for(Int_t mod=1; mod<=fNModules; mod++){
f4aea312 457 Global2Local(loc,global,mod) ;
458 //If in Acceptance
459 if((TMath::Abs(loc.Z())<fXtlArrSize[2]) && (TMath::Abs(loc.X())<fXtlArrSize[0])){
460 RelPosToRelId(mod,loc.X(),loc.Z(),relId);
461 return kTRUE ;
462 }
463 }
464 return kFALSE ;
465
70a0fabe 466}
467//____________________________________________________________________________
468Bool_t AliPHOSGeoUtils::ImpactOnEmc(const TParticle * particle,
469 Int_t & moduleNumber, Double_t & z, Double_t & x) const
470{
471 // Tells if a particle enters PHOS and evaluates hit position
472 Double_t vtx[3]={particle->Vx(),particle->Vy(),particle->Vz()} ;
473 return ImpactOnEmc(vtx,particle->Theta(),particle->Phi(),moduleNumber,z,x);
474}
475
476//____________________________________________________________________________
477Bool_t AliPHOSGeoUtils::ImpactOnEmc(const Double_t * vtx, Double_t theta, Double_t phi,
478 Int_t & moduleNumber, Double_t & z, Double_t & x) const
479{
480 // calculates the impact coordinates on PHOS of a neutral particle
481 // emitted in the vertex vtx[3] with direction vec(p) in the ALICE global coordinate system
482 TVector3 p(TMath::Sin(theta)*TMath::Cos(phi),TMath::Sin(theta)*TMath::Sin(phi),TMath::Cos(theta)) ;
483 return ImpactOnEmc(vtx,p,moduleNumber,z,x) ;
484
485}
486//____________________________________________________________________________
487Bool_t AliPHOSGeoUtils::ImpactOnEmc(const Double_t * vtx, const TVector3 &p,
488 Int_t & moduleNumber, Double_t & z, Double_t & x) const
489{
490 // calculates the impact coordinates on PHOS of a neutral particle
491 // emitted in the vertex vtx[3] with direction theta and phi in the ALICE global coordinate system
492 TVector3 v(vtx[0],vtx[1],vtx[2]) ;
493
70a0fabe 494 for(Int_t imod=1; imod<=fNModules ; imod++){
495 //create vector from (0,0,0) to center of crystal surface of imod module
496 Double_t tmp[3]={0.,-fCrystalShift,0.} ;
497
98082233 498 const TGeoHMatrix *m = GetMatrixForModule(imod) ;
478420eb 499 if(!m) //module does not exist in given configuration
500 continue ;
70a0fabe 501 Double_t posG[3]={0.,0.,0.} ;
bb5c37a5 502 m->LocalToMaster(tmp,posG);
70a0fabe 503 TVector3 n(posG[0],posG[1],posG[2]) ;
504 Double_t direction=n.Dot(p) ;
505 if(direction<=0.)
506 continue ; //momentum directed FROM module
507 Double_t fr = (n.Mag2()-n.Dot(v))/direction ;
508 //Calculate direction in module plain
509 n-=v+fr*p ;
510 n*=-1. ;
511 if(TMath::Abs(TMath::Abs(n.Z())<fXtlArrSize[2]) && n.Pt()<fXtlArrSize[0]){
512 moduleNumber = imod ;
513 z=n.Z() ;
514 x=TMath::Sign(n.Pt(),n.X()) ;
515 //no need to return to local system since we calcilated distance from module center
516 //and tilts can not be significant.
517 return kTRUE ;
518 }
519 }
520 //Not in acceptance
521 x=0; z=0 ;
522 moduleNumber=0 ;
523 return kFALSE ;
524
525}
70a0fabe 526//____________________________________________________________________________
bcc9e89e 527void AliPHOSGeoUtils::GetIncidentVector(const TVector3 &vtx, Int_t module, Float_t x,Float_t z, TVector3 &vInc) const {
528 //Calculates vector pointing from vertex to current poisition in module local frame
529 //Note that PHOS local system and ALICE global have opposite z directions
70a0fabe 530
bcc9e89e 531 Global2Local(vInc,vtx,module) ;
532 vInc.SetXYZ(vInc.X()+x,vInc.Y(),vInc.Z()+z) ;
70a0fabe 533}
bb5c37a5 534//____________________________________________________________________________
98082233 535const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForModule(Int_t mod)const {
bb5c37a5 536 //Provides shift-rotation matrix for module mod
bcc9e89e 537
bb5c37a5 538 //If GeoManager exists, take matrixes from it
539 if(gGeoManager){
540 char path[255] ;
14895588 541 snprintf(path,255,"/ALIC_1/PHOS_%d/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1",mod) ;
bb5c37a5 542 // sprintf(path,"/ALIC_1/PHOS_%d",relid[0]) ;
543 if (!gGeoManager->cd(path)){
478420eb 544 AliWarning(Form("Geo manager can not find path %s \n",path));
545 return 0;
bb5c37a5 546 }
547 return gGeoManager->GetCurrentMatrix();
548 }
549 if(fEMCMatrix[mod-1]){
550 return fEMCMatrix[mod-1] ;
551 }
552 else{
bd8f520e 553 // AliWarning("Can not find PHOS misalignment matrixes\n") ;
554 // AliWarning("Either import TGeoManager from geometry.root or \n");
555 // AliWarning("read stored matrixes from AliESD Header: \n") ;
556 // AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
478420eb 557 return 0 ;
bb5c37a5 558 }
559 return 0 ;
560}
561//____________________________________________________________________________
98082233 562const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForStrip(Int_t mod, Int_t strip)const {
bb5c37a5 563 //Provides shift-rotation matrix for strip unit of the module mod
564
565 //If GeoManager exists, take matrixes from it
566 if(gGeoManager){
567 char path[255] ;
14895588 568 snprintf(path,255,"/ALIC_1/PHOS_%d/PEMC_1/PCOL_1/PTIO_1/PCOR_1/PAGA_1/PTII_1/PSTR_%d",mod,strip) ;
bb5c37a5 569 if (!gGeoManager->cd(path)){
478420eb 570 AliWarning(Form("Geo manager can not find path %s \n",path));
571 return 0 ;
bb5c37a5 572 }
573 return gGeoManager->GetCurrentMatrix();
574 }
575 if(fStripMatrix[mod-1][strip-1]){
576 return fStripMatrix[mod-1][strip-1] ;
577 }
578 else{
478420eb 579 AliWarning("Can not find PHOS misalignment matrixes\n") ;
580 AliWarning("Either import TGeoManager from geometry.root or \n");
581 AliWarning("read stored matrixes from AliESD Header: \n") ;
582 AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
583 return 0 ;
bb5c37a5 584 }
585 return 0 ;
586}
587//____________________________________________________________________________
98082233 588const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForCPV(Int_t mod)const {
bb5c37a5 589 //Provides shift-rotation matrix for CPV of the module mod
590
591 //If GeoManager exists, take matrixes from it
592 if(gGeoManager){
593 char path[255] ;
594 //now apply possible shifts and rotations
14895588 595 snprintf(path,255,"/ALIC_1/PHOS_%d/PCPV_1",mod) ;
bb5c37a5 596 if (!gGeoManager->cd(path)){
478420eb 597 AliWarning(Form("Geo manager can not find path %s \n",path));
598 return 0 ;
bb5c37a5 599 }
600 return gGeoManager->GetCurrentMatrix();
601 }
602 if(fCPVMatrix[mod-1]){
603 return fCPVMatrix[mod-1] ;
604 }
605 else{
478420eb 606 AliWarning("Can not find PHOS misalignment matrixes\n") ;
607 AliWarning("Either import TGeoManager from geometry.root or \n");
608 AliWarning("read stored matrixes from AliESD Header: \n") ;
609 AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
610 return 0 ;
bb5c37a5 611 }
612 return 0 ;
613}
614//____________________________________________________________________________
98082233 615const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForPHOS(Int_t mod)const {
bb5c37a5 616 //Provides shift-rotation matrix for PHOS (EMC+CPV)
617
618 //If GeoManager exists, take matrixes from it
619 if(gGeoManager){
6ba1dd81 620
bb5c37a5 621 char path[255] ;
14895588 622 snprintf(path,255,"/ALIC_1/PHOS_%d",mod) ;
623
bb5c37a5 624 if (!gGeoManager->cd(path)){
478420eb 625 AliWarning(Form("Geo manager can not find path %s \n",path));
626 return 0 ;
bb5c37a5 627 }
628 return gGeoManager->GetCurrentMatrix();
629 }
630 if(fPHOSMatrix[mod-1]){
631 return fPHOSMatrix[mod-1] ;
632 }
633 else{
478420eb 634 AliWarning("Can not find PHOS misalignment matrixes\n") ;
635 AliWarning("Either import TGeoManager from geometry.root or \n");
636 AliWarning("read stored matrixes from AliESD Header: \n") ;
637 AliWarning("AliPHOSGeoUtils::SetMisalMatrixes(header->GetPHOSMisalMatrix()) \n") ;
638 return 0 ;
bb5c37a5 639 }
640 return 0 ;
641}
642//____________________________________________________________________________
98082233 643void AliPHOSGeoUtils::SetMisalMatrix(const TGeoHMatrix * m, Int_t mod){
bb5c37a5 644 //Fills pointers to geo matrixes
645
79b175e1 646 if(fPHOSMatrix[mod]){ //have been set already. Can not be changed any more
647 return ;
648 }
0e1c4f91 649 if(m==NULL) //Matrix for non-existing modules? Remain zero, no need to re-set
650 return ;
79b175e1 651 fPHOSMatrix[mod]= new TGeoHMatrix(*m) ;
d3506595 652
3eef419b 653 //Calculate maxtrices for PTII
bb5c37a5 654 if(!fMisalArray)
655 fMisalArray = new TClonesArray("TGeoHMatrix",1120+10) ;
656 Int_t nr = fMisalArray->GetEntriesFast() ;
657 Double_t rotEMC[9]={1.,0.,0.,0.,0.,-1.,0.,1.,0.} ;
658 const Float_t * inthermo = fGeometryEMCA->GetInnerThermoHalfSize() ;
659 const Float_t * strip = fGeometryEMCA->GetStripHalfSize() ;
660 const Float_t * covparams = fGeometryEMCA->GetAlCoverParams() ;
661 const Float_t * warmcov = fGeometryEMCA->GetWarmAlCoverHalfSize() ;
662 Float_t z = fGeometryCPV->GetCPVBoxSize(1) / 2. - warmcov[2] + covparams[3]-inthermo[1] ;
663 Double_t locTII[3]={0.,0.,z} ;
664 Double_t globTII[3] ;
665
3eef419b 666 if (fEMCMatrix[mod] == NULL)
667 fEMCMatrix[mod] = new((*fMisalArray)[nr])TGeoHMatrix() ;
98082233 668 nr++ ;
3eef419b 669 fEMCMatrix[mod]->SetRotation(rotEMC) ;
670 fEMCMatrix[mod]->MultiplyLeft(fPHOSMatrix[mod]) ;
bb5c37a5 671 fPHOSMatrix[mod]->LocalToMaster(locTII,globTII) ;
3eef419b 672 fEMCMatrix[mod]->SetTranslation(globTII) ;
bb5c37a5 673
674 //Now calculate ideal matrixes for strip misalignment.
675 //For the moment we can not store them in ESDHeader
676
677 Double_t loc[3]={0.,inthermo[1] - strip[1],0.} ;
678 Double_t glob[3] ;
679
680 Int_t istrip=0 ;
681 for(Int_t irow = 0; irow < fGeometryEMCA->GetNStripX(); irow ++){
682 loc[0] = (2*irow + 1 - fGeometryEMCA->GetNStripX())* strip[0] ;
683 for(Int_t icol = 0; icol < fGeometryEMCA->GetNStripZ(); icol ++){
684 loc[2] = (2*icol + 1 - fGeometryEMCA->GetNStripZ()) * strip[2] ;
685 fEMCMatrix[mod]->LocalToMaster(loc,glob) ;
3eef419b 686 if (fStripMatrix[mod][istrip] == NULL)
687 fStripMatrix[mod][istrip] = new((*fMisalArray)[nr])TGeoHMatrix(*(fEMCMatrix[mod])) ; //Use same rotation as PHOS module
98082233 688 nr++ ;
3eef419b 689 fStripMatrix[mod][istrip]->SetTranslation(glob) ;
bb5c37a5 690 istrip++;
691 }
692 }
693
694 //Now calculate CPV matrixes
695 const Float_t * emcParams = fGeometryEMCA->GetEMCParams() ;
696 Double_t globCPV[3] ;
697 Double_t locCPV[3]={0.,0.,- emcParams[3]} ;
698 Double_t rot[9]={1.,0.,0.,0.,0.,1.,0.,-1.,0.} ;
699
3eef419b 700 if (fCPVMatrix[mod] == NULL)
701 fCPVMatrix[mod] = new((*fMisalArray)[nr])TGeoHMatrix() ;
98082233 702 nr++ ;
3eef419b 703 fCPVMatrix[mod]->SetRotation(rot) ;
704 fCPVMatrix[mod]->MultiplyLeft(fPHOSMatrix[mod]) ;
705 fCPVMatrix[mod]->ReflectY(kFALSE) ;
bb5c37a5 706 fPHOSMatrix[mod]->LocalToMaster(locCPV,globCPV) ;
3eef419b 707 fCPVMatrix[mod]->SetTranslation(globCPV) ;
bb5c37a5 708
709}
710