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