Using the right AliITSRecPoint constructor for the correct initialization of the...
[u/mrichter/AliRoot.git] / ITS / AliITSInitGeometry.cxx
CommitLineData
023ae34b 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/*
17$Id$
18*/
6b0f3880 19////////////////////////////////////////////////////////////////
20// This class initializes the class AliITSgeom
21// The initialization is done starting from
22// a geometry coded by means of the ROOT geometrical modeler
23// This initialization can be used both for simulation and reconstruction
24///////////////////////////////////////////////////////////////
25
023ae34b 26#include <TArrayD.h>
27#include <TArrayF.h>
28#include <TStopwatch.h>
023ae34b 29#include <TGeoManager.h>
30#include <TGeoVolume.h>
31#include <TGeoShape.h>
32#include <TGeoBBox.h>
33#include <TGeoTrd1.h>
34#include <TGeoTrd2.h>
35#include <TGeoArb8.h>
36#include <TGeoTube.h>
37#include <TGeoCone.h>
38#include <TGeoSphere.h>
39#include <TGeoPara.h>
40#include <TGeoPgon.h>
41#include <TGeoPcon.h>
42#include <TGeoEltu.h>
43#include <TGeoHype.h>
3010c308 44#include <TMath.h>
023ae34b 45
6def2bd2 46#include "AliLog.h"
47#include "AliITSgeomSPD.h"
48#include "AliITSgeomSDD.h"
49#include "AliITSgeomSSD.h"
50#include "AliITSsegmentationSPD.h"
51#include "AliITSsegmentationSDD.h"
52#include "AliITSsegmentationSSD.h"
023ae34b 53#include "AliITSgeom.h"
54#include "AliITSInitGeometry.h"
55
56ClassImp(AliITSInitGeometry)
57//______________________________________________________________________
58AliITSInitGeometry::AliITSInitGeometry():
59TObject(),
60fName(),
61fMinorVersion(0),
62fMajorVersion(0),
63fTiming(kFALSE),
64fSegGeom(kFALSE),
65fDecode(kFALSE){
66 // Default Creator
67 // Inputs:
68 // none.
69 // Outputs:
70 // none.
71 // Return:
72 // A default inilized AliITSInitGeometry object
73}
74//______________________________________________________________________
75AliITSInitGeometry::AliITSInitGeometry(const Char_t *name,Int_t minorversion):
76TObject(),
77fName(name),
78fMinorVersion(minorversion),
79fMajorVersion(0),
80fTiming(kFALSE),
81fSegGeom(kFALSE),
82fDecode(kFALSE){
83 // Default Creator
84 // Inputs:
85 // none.
86 // Outputs:
87 // none.
88 // Return:
89 // A default inilized AliITSInitGeometry object
90
91 if(fName.CompareTo("AliITSvPPRasymmFMD")==0)if(fMinorVersion==1||
92 fMinorVersion==2){
93 fMajorVersion=10;
94 return;
95 } // end if
96 // if not defined geometry error
97 Error("AliITSInitGeometry(name,version)"," Name must be AliITSvPPRasymmFMD"
98 " and version must be 1 or 2 for now.");
99 fMinorVersion = 0;
100 fName = "";
101 return;
102}
103//______________________________________________________________________
104AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(){
105 // Creates and Initilizes the geometry transformation class AliITSgeom
106 // to values appropreate to this specific geometry. Now that
107 // the segmentation is part of AliITSgeom, the detector
108 // segmentations are also defined here.
109 // Inputs:
110 // none.
111 // Outputs:
112 // none.
113 // Return:
114 // A pointer to a new properly inilized AliITSgeom class. If
115 // pointer = 0 then failed to init.
116
117 AliITSgeom *geom = new AliITSgeom();
118 if(!InitAliITSgeom(geom)){ // Error initilization failed
119 delete geom;
120 geom = 0;
121 } // end if
122 return geom;
123}
124//______________________________________________________________________
125Bool_t AliITSInitGeometry::InitAliITSgeom(AliITSgeom *geom){
6def2bd2 126 // Initilizes the geometry transformation class AliITSgeom
127 // to values appropreate to this specific geometry. Now that
128 // the segmentation is part of AliITSgeom, the detector
129 // segmentations are also defined here.
130 // Inputs:
131 // AliITSgeom *geom A pointer to the AliITSgeom class
132 // Outputs:
133 // AliITSgeom *geom This pointer recreated and properly inilized.
134 // Return:
135 // none.
023ae34b 136
6def2bd2 137 if(!gGeoManager){
138 AliFatal("The geometry manager has not been initialized (e.g. TGeoManager::Import(\"geometry.root\")should be called in advance) - exit forced");
139 return kFALSE;
140 }
141 switch(fMajorVersion){
142 case 10:{ // only case defined so far
143 return InitAliITSgeomPPRasymmFMD(geom);
144 }break; // end case
145 default:{
146 Error("InitAliITSgeom","Undefined geomtery");
023ae34b 147 return kFALSE;
6def2bd2 148 } break; // end case
149 } // end switch
150 return kFALSE;
023ae34b 151}
152//______________________________________________________________________
153Bool_t AliITSInitGeometry::InitAliITSgeomPPRasymmFMD(AliITSgeom *geom){
154 // Initilizes the geometry transformation class AliITSgeom
155 // to values appropreate to this specific geometry. Now that
156 // the segmentation is part of AliITSgeom, the detector
157 // segmentations are also defined here.
158 // Inputs:
159 // AliITSgeom *geom A pointer to the AliITSgeom class
160 // Outputs:
161 // AliITSgeom *geom This pointer recreated and properly inilized.
162 // Return:
163 // none.
164 // const Double_t kcm2micron = 1.0E4;
165 const Int_t kItype=0; // Type of transormation defined 0=> Geant
166 const Int_t klayers = 6; // number of layers in the ITS
167 const Int_t kladders[klayers] = {20,40,14,22,34,38}; // Number of ladders
168 const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
6b0f3880 169 const AliITSDetector kIdet[6] = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
170 const TString kPathbase = "/ALIC_1/ITSV_1/ITSD_1/";
171 const TString kNames[2][klayers] = {
023ae34b 172 {"%sIT12_1/I12A_%d/I10A_%d/I103_%d/I101_1/ITS1_1", // lay=1
173 "%sIT12_1/I12A_%d/I20A_%d/I1D3_%d/I1D1_1/ITS2_1", // lay=2
174 "%sIT34_1/I004_%d/I302_%d/ITS3_%d/", // lay=3
175 "%sIT34_1/I005_%d/I402_%d/ITS4_%d/", // lay=4
176 "%sIT56_1/I565_%d/I562_%d/ITS5_%d/", // lay=5
177 "%sIT56_1/I569_%d/I566_%d/ITS6_%d/"},// lay=6
178 {"%sIT12_1/I12B_%d/I10B_%d/I107_%d/I101_1/ITS1_1", // lay=1
179 "%sIT12_1/I12B_%d/I20B_%d/I1D7_%d/I1D1_1/ITS2_1", // lay=2
180 "%sIT34_1/I004_%d/I302_%d/ITS3_%d", // lay=3
181 "%sIT34_1/I005_%d/I402_%d/ITS4_%d", // lay=4
182 "%sIT56_1/I565_%d/I562_%d/ITS5_%d", // lay=5
183 "%sIT56_1/I569_%d/I566_%d/ITS6_%d"}};// Lay=6
184 /*
185 Int_t itsGeomTreeCopys[knlayers][3]= {{10, 2, 4},// lay=1
186 {10, 4, 4},// lay=2
187 {14, 6, 1},// lay=3
188 {22, 8, 1},// lay=4
189 {34,22, 1},// lay=5
190 {38,25, 1}};//lay=6
191 */
192 Int_t mod,nmods=0,lay,lad,det,cpn0,cpn1,cpn2;
193 Double_t tran[3]={0.0,0.0,0.0},rot[10]={9*0.0,1.0};
194 TArrayD shapePar;
195 TString path,shapeName;
196 TGeoHMatrix materix;
197 Bool_t initSeg[3]={kFALSE,kFALSE,kFALSE};
24e270ad 198 TStopwatch *time = 0x0;if(fTiming) time=new TStopwatch();
023ae34b 199
200 if(fTiming) time->Start();
201 for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
202 geom->Init(kItype,klayers,kladders,kdetectors,nmods);
203 for(mod=0;mod<nmods;mod++){
204 DecodeDetectorLayers(mod,lay,lad,det); // Write
6b0f3880 205 geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
023ae34b 206 RecodeDetector(mod,cpn0,cpn1,cpn2); // Write reusing lay,lad,det.
6b0f3880 207 path.Form(kNames[fMinorVersion-1][lay-1].Data(),
208 kPathbase.Data(),cpn0,cpn1,cpn2);
023ae34b 209 geom->GetGeomMatrix(mod)->SetPath(path);
210 GetTransformation(path.Data(),materix);
211 geom->SetTrans(mod,materix.GetTranslation());
212 geom->SetRotMatrix(mod,materix.GetRotationMatrix());
6b0f3880 213 if(initSeg[kIdet[lay-1]]) continue;
023ae34b 214 GetShape(path,shapeName,shapePar);
215 if(shapeName.CompareTo("BOX")){
216 Error("InitITSgeom","Geometry changed without proper code update"
217 "or error in reading geometry. Shape is not BOX.");
218 return kFALSE;
219 } // end if
6b0f3880 220 InitGeomShapePPRasymmFMD(kIdet[lay-1],initSeg,shapePar,geom);
023ae34b 221 } // end for module
222 if(fTiming){
223 time->Stop();
224 time->Print();
225 delete time;
226 } // end if
227 return kTRUE;
228}
229//______________________________________________________________________
230Bool_t AliITSInitGeometry::InitGeomShapePPRasymmFMD(AliITSDetector idet,
231 Bool_t *initSeg,
232 TArrayD &shapePar,
233 AliITSgeom *geom){
234 // Initilizes the geometry segmentation class AliITSgeomS?D, or
235 // AliITSsegmentationS?D depending on the vaule of fSegGeom,
236 // to values appropreate to this specific geometry. Now that
237 // the segmentation is part of AliITSgeom, the detector
238 // segmentations are also defined here.
239 // Inputs:
240 // Int_t lay The layer number/name.
241 // AliITSgeom *geom A pointer to the AliITSgeom class
242 // Outputs:
243 // AliITSgeom *geom This pointer recreated and properly inilized.
244 // Return:
245 // none.
246 // const Double_t kcm2micron = 1.0E4;
247 const Double_t kmicron2cm = 1.0E-4;
248 Int_t i;
249 TArrayF shapeParF;
250
251 shapeParF.Set(shapePar.GetSize());
252 for(i=0;i<shapePar.GetSize();i++) shapeParF[i]=shapePar[i];
253 switch (idet){
254 case kSPD:{
255 initSeg[idet] = kTRUE;
256 AliITSgeomSPD *geomSPD = new AliITSgeomSPD425Short();
257 Float_t bx[256],bz[280];
258 for(i=000;i<256;i++) bx[i] = 50.0*kmicron2cm; // in x all are 50 microns.
259 for(i=000;i<160;i++) bz[i] = 425.0*kmicron2cm; // most are 425 microns
260 // except below
261 for(i=160;i<280;i++) bz[i] = 0.0*kmicron2cm; // Outside of detector.
262 bz[ 31] = bz[ 32] = 625.0*kmicron2cm; // first chip boundry
263 bz[ 63] = bz[ 64] = 625.0*kmicron2cm; // first chip boundry
264 bz[ 95] = bz[ 96] = 625.0*kmicron2cm; // first chip boundry
265 bz[127] = bz[128] = 625.0*kmicron2cm; // first chip boundry
266 bz[160] = 425.0*kmicron2cm;// Set so that there is no zero pixel size for fNz.
267 geomSPD->ReSetBins(shapeParF[1],256,bx,160,bz);
268 geom->ReSetShape(idet,geomSPD);
269 }break;
270 case kSDD:{
271 initSeg[idet] = kTRUE;
272 AliITSgeomSDD *geomSDD = new AliITSgeomSDD256(shapeParF.GetSize(),
273 shapeParF.GetArray());
274 geom->ReSetShape(idet,geomSDD);
275 }break;
276 case kSSD:{
277 initSeg[idet] = kTRUE;
278 AliITSgeomSSD *geomSSD = new AliITSgeomSSD275and75(
279 shapeParF.GetSize(),shapeParF.GetArray());
280 geom->ReSetShape(idet,geomSSD);
281 }break;
282 default:{// Others, Note no kSDDp or kSSDp in this geometry.
283 geom->ReSetShape(idet,0);
284 Info("InitGeomShapePPRasymmFMD",
285 "default Dx=%f Dy=%f Dz=%f default=%d",
286 shapePar[0],shapePar[1],shapePar[2],idet);
287 }break;
288 } // end switch
289 return kTRUE;
290}
291//______________________________________________________________________
292Bool_t AliITSInitGeometry::InitSegmentationPPRasymmFMD(AliITSDetector idet,
293 Bool_t *initSeg,
294 TArrayD &shapePar,
295 AliITSgeom *geom){
296 // Initilizes the geometry segmentation class AliITSgeomS?D, or
297 // AliITSsegmentationS?D depending on the vaule of fSegGeom,
298 // to values appropreate to this specific geometry. Now that
299 // the segmentation is part of AliITSgeom, the detector
300 // segmentations are also defined here.
301 // Inputs:
302 // Int_t lay The layer number/name.
303 // AliITSgeom *geom A pointer to the AliITSgeom class
304 // Outputs:
305 // AliITSgeom *geom This pointer recreated and properly inilized.
306 // Return:
307 // none.
308 const Double_t kcm2micron = 1.0E4;
309 Int_t i;
310
311 switch (idet){
312 case kSPD:{
313 initSeg[idet] = kTRUE;
314 AliITSsegmentationSPD *segSPD = new AliITSsegmentationSPD();
315 segSPD->SetDetSize(2.*shapePar[0]*kcm2micron, // X
316 2.*shapePar[2]*kcm2micron, // Z
317 2.*shapePar[1]*kcm2micron);// Y Microns
318 segSPD->SetNPads(256,160);// Number of Bins in x and z
319 Float_t bx[256],bz[280];
320 for(i=000;i<256;i++) bx[i] = 50.0; // in x all are 50 microns.
321 for(i=000;i<160;i++) bz[i] = 425.0; // most are 425 microns
322 // except below
323 for(i=160;i<280;i++) bz[i] = 0.0; // Outside of detector.
324 bz[ 31] = bz[ 32] = 625.0; // first chip boundry
325 bz[ 63] = bz[ 64] = 625.0; // first chip boundry
326 bz[ 95] = bz[ 96] = 625.0; // first chip boundry
327 bz[127] = bz[128] = 625.0; // first chip boundry
328 bz[160] = 425.0;// Set so that there is no zero pixel size for fNz.
329 segSPD->SetBinSize(bx,bz); // Based on AliITSgeomSPD for now.
330 geom->ReSetShape(idet,segSPD);
331 }break;
332 case kSDD:{
333 initSeg[idet] = kTRUE;
334 AliITSsegmentationSDD *segSDD = new AliITSsegmentationSDD();
335 segSDD->SetDetSize(shapePar[0]*kcm2micron, // X
336 2.*shapePar[2]*kcm2micron, // Z
337 2.*shapePar[1]*kcm2micron);// Y Microns
338 segSDD->SetNPads(256,256);// Anodes, Samples
339 geom->ReSetShape(idet,segSDD);
340 }break;
341 case kSSD:{
342 initSeg[idet] = kTRUE;
343 AliITSsegmentationSSD *segSSD = new AliITSsegmentationSSD();
344 segSSD->SetDetSize(2.*shapePar[0]*kcm2micron, // X
345 2.*shapePar[2]*kcm2micron, // Z
346 2.*shapePar[1]*kcm2micron);// Y Microns.
347 segSSD->SetPadSize(95.,0.); // strip x pitch in microns
348 segSSD->SetNPads(768,2); // number of strips on each side, sides.
349 segSSD->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
350 segSSD->SetAnglesLay5(0.0075,0.0275);//strip angels rad P and N
351 segSSD->SetAnglesLay6(0.0275,0.0075);//strip angels rad P and N
352 geom->ReSetShape(idet,segSSD);
353 }break;
354 default:{// Others, Note no kSDDp or kSSDp in this geometry.
355 geom->ReSetShape(idet,0);
356 Info("InitSegmentationPPRasymmFMD",
357 "default segmentation Dx=%f Dy=%f Dz=%f default=%d",
358 shapePar[0],shapePar[1],shapePar[2],idet);
359 }break;
360 } // end switch
361 return kTRUE;
362}
363//______________________________________________________________________
364Bool_t AliITSInitGeometry::GetTransformation(const TString &volumePath,
365 TGeoHMatrix &mat){
366 // Returns the Transformation matrix between the volume specified
367 // by the path volumePath and the Top or mater volume. The format
368 // of the path volumePath is as follows (assuming ALIC is the Top volume)
369 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
370 // or master volume which has only 1 instance of. Of all of the daughter
371 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
372 // the daughter volume of DDIP is S05I copy #2 and so on.
373 // Inputs:
374 // TString& volumePath The volume path to the specific volume
375 // for which you want the matrix. Volume name
376 // hierarchy is separated by "/" while the
377 // copy number is appended using a "_".
378 // Outputs:
379 // TGeoHMatrix &mat A matrix with its values set to those
380 // appropriate to the Local to Master transformation
381 // Return:
382 // A logical value if kFALSE then an error occurred and no change to
383 // mat was made.
384
385 // We have to preserve the modeler state
386
387 // Preserve the modeler state.
388 gGeoManager->PushPath();
389 if (!gGeoManager->cd(volumePath.Data())) {
390 gGeoManager->PopPath();
391 Error("GetTransformation","Error in cd-ing to ",volumePath.Data());
392 return kFALSE;
393 } // end if !gGeoManager
394 mat = *gGeoManager->GetCurrentMatrix();
395 // Retstore the modeler state.
396 gGeoManager->PopPath();
397 return kTRUE;
398}
399//______________________________________________________________________
400Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
401 TString &shapeType,TArrayD &par){
402 // Returns the shape and its parameters for the volume specified
403 // by volumeName.
404 // Inputs:
405 // TString& volumeName The volume name
406 // Outputs:
407 // TString &shapeType Shape type
408 // TArrayD &par A TArrayD of parameters with all of the
409 // parameters of the specified shape.
410 // Return:
411 // A logical indicating whether there was an error in getting this
412 // information
413 Int_t npar;
414 gGeoManager->PushPath();
415 if (!gGeoManager->cd(volumePath.Data())) {
416 gGeoManager->PopPath();
417 return kFALSE;
418 }
419 TGeoVolume * vol = gGeoManager->GetCurrentVolume();
420 gGeoManager->PopPath();
421 if (!vol) return kFALSE;
422 TGeoShape *shape = vol->GetShape();
6b0f3880 423 TClass *classType = shape->IsA();
424 if (classType==TGeoBBox::Class()) {
023ae34b 425 shapeType = "BOX";
426 npar = 3;
427 par.Set(npar);
428 TGeoBBox *box = (TGeoBBox*)shape;
429 par.AddAt(box->GetDX(),0);
430 par.AddAt(box->GetDY(),1);
431 par.AddAt(box->GetDZ(),2);
432 return kTRUE;
433 }
6b0f3880 434 if (classType==TGeoTrd1::Class()) {
023ae34b 435 shapeType = "TRD1";
436 npar = 4;
437 par.Set(npar);
438 TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
439 par.AddAt(trd1->GetDx1(),0);
440 par.AddAt(trd1->GetDx2(),1);
441 par.AddAt(trd1->GetDy(), 2);
442 par.AddAt(trd1->GetDz(), 3);
443 return kTRUE;
444 }
6b0f3880 445 if (classType==TGeoTrd2::Class()) {
023ae34b 446 shapeType = "TRD2";
447 npar = 5;
448 par.Set(npar);
449 TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
450 par.AddAt(trd2->GetDx1(),0);
451 par.AddAt(trd2->GetDx2(),1);
452 par.AddAt(trd2->GetDy1(),2);
453 par.AddAt(trd2->GetDy2(),3);
454 par.AddAt(trd2->GetDz(), 4);
455 return kTRUE;
456 }
6b0f3880 457 if (classType==TGeoTrap::Class()) {
023ae34b 458 shapeType = "TRAP";
459 npar = 11;
460 par.Set(npar);
461 TGeoTrap *trap = (TGeoTrap*)shape;
462 Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
463 par.AddAt(trap->GetDz(),0);
464 par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
465 par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
466 par.AddAt(trap->GetH1(),3);
467 par.AddAt(trap->GetBl1(),4);
468 par.AddAt(trap->GetTl1(),5);
469 par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
470 par.AddAt(trap->GetH2(),7);
471 par.AddAt(trap->GetBl2(),8);
472 par.AddAt(trap->GetTl2(),9);
473 par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
474 return kTRUE;
475 }
6b0f3880 476 if (classType==TGeoTube::Class()) {
023ae34b 477 shapeType = "TUBE";
478 npar = 3;
479 par.Set(npar);
480 TGeoTube *tube = (TGeoTube*)shape;
481 par.AddAt(tube->GetRmin(),0);
482 par.AddAt(tube->GetRmax(),1);
483 par.AddAt(tube->GetDz(),2);
484 return kTRUE;
485 }
6b0f3880 486 if (classType==TGeoTubeSeg::Class()) {
023ae34b 487 shapeType = "TUBS";
488 npar = 5;
489 par.Set(npar);
490 TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
491 par.AddAt(tubs->GetRmin(),0);
492 par.AddAt(tubs->GetRmax(),1);
493 par.AddAt(tubs->GetDz(),2);
494 par.AddAt(tubs->GetPhi1(),3);
495 par.AddAt(tubs->GetPhi2(),4);
496 return kTRUE;
497 }
6b0f3880 498 if (classType==TGeoCone::Class()) {
023ae34b 499 shapeType = "CONE";
500 npar = 5;
501 par.Set(npar);
502 TGeoCone *cone = (TGeoCone*)shape;
503 par.AddAt(cone->GetDz(),0);
504 par.AddAt(cone->GetRmin1(),1);
505 par.AddAt(cone->GetRmax1(),2);
506 par.AddAt(cone->GetRmin2(),3);
507 par.AddAt(cone->GetRmax2(),4);
508 return kTRUE;
509 }
6b0f3880 510 if (classType==TGeoConeSeg::Class()) {
023ae34b 511 shapeType = "CONS";
512 npar = 7;
513 par.Set(npar);
514 TGeoConeSeg *cons = (TGeoConeSeg*)shape;
515 par.AddAt(cons->GetDz(),0);
516 par.AddAt(cons->GetRmin1(),1);
517 par.AddAt(cons->GetRmax1(),2);
518 par.AddAt(cons->GetRmin2(),3);
519 par.AddAt(cons->GetRmax2(),4);
520 par.AddAt(cons->GetPhi1(),5);
521 par.AddAt(cons->GetPhi2(),6);
522 return kTRUE;
523 }
6b0f3880 524 if (classType==TGeoSphere::Class()) {
023ae34b 525 shapeType = "SPHE";
526 npar = 6;
527 par.Set(npar);
528
529 TGeoSphere *sphe = (TGeoSphere*)shape;
530 par.AddAt(sphe->GetRmin(),0);
531 par.AddAt(sphe->GetRmax(),1);
532 par.AddAt(sphe->GetTheta1(),2);
533 par.AddAt(sphe->GetTheta2(),3);
534 par.AddAt(sphe->GetPhi1(),4);
535 par.AddAt(sphe->GetPhi2(),5);
536 return kTRUE;
537 }
6b0f3880 538 if (classType==TGeoPara::Class()) {
023ae34b 539 shapeType = "PARA";
540 npar = 6;
541 par.Set(npar);
542 TGeoPara *para = (TGeoPara*)shape;
543 par.AddAt(para->GetX(),0);
544 par.AddAt(para->GetY(),1);
545 par.AddAt(para->GetZ(),2);
546 par.AddAt(para->GetTxy(),3);
547 par.AddAt(para->GetTxz(),4);
548 par.AddAt(para->GetTyz(),5);
549 return kTRUE;
550 }
6b0f3880 551 if (classType==TGeoPgon::Class()) {
023ae34b 552 shapeType = "PGON";
553 TGeoPgon *pgon = (TGeoPgon*)shape;
554 Int_t nz = pgon->GetNz();
555 const Double_t *rmin = pgon->GetRmin();
556 const Double_t *rmax = pgon->GetRmax();
557 const Double_t *z = pgon->GetZ();
558 npar = 4 + 3*nz;
559 par.Set(npar);
560 par.AddAt(pgon->GetPhi1(),0);
561 par.AddAt(pgon->GetDphi(),1);
562 par.AddAt(pgon->GetNedges(),2);
563 par.AddAt(pgon->GetNz(),3);
564 for (Int_t i=0; i<nz; i++) {
565 par.AddAt(z[i], 4+3*i);
566 par.AddAt(rmin[i], 4+3*i+1);
567 par.AddAt(rmax[i], 4+3*i+2);
568 }
569 return kTRUE;
570 }
6b0f3880 571 if (classType==TGeoPcon::Class()) {
023ae34b 572 shapeType = "PCON";
573 TGeoPcon *pcon = (TGeoPcon*)shape;
574 Int_t nz = pcon->GetNz();
575 const Double_t *rmin = pcon->GetRmin();
576 const Double_t *rmax = pcon->GetRmax();
577 const Double_t *z = pcon->GetZ();
578 npar = 3 + 3*nz;
579 par.Set(npar);
580 par.AddAt(pcon->GetPhi1(),0);
581 par.AddAt(pcon->GetDphi(),1);
582 par.AddAt(pcon->GetNz(),2);
583 for (Int_t i=0; i<nz; i++) {
584 par.AddAt(z[i], 3+3*i);
585
586 par.AddAt(rmin[i], 3+3*i+1);
587 par.AddAt(rmax[i], 3+3*i+2);
588 }
589 return kTRUE;
590 }
6b0f3880 591 if (classType==TGeoEltu::Class()) {
023ae34b 592 shapeType = "ELTU";
593 npar = 3;
594 par.Set(npar);
595 TGeoEltu *eltu = (TGeoEltu*)shape;
596 par.AddAt(eltu->GetA(),0);
597 par.AddAt(eltu->GetB(),1);
598 par.AddAt(eltu->GetDz(),2);
599 return kTRUE;
600 }
6b0f3880 601 if (classType==TGeoHype::Class()) {
023ae34b 602 shapeType = "HYPE";
603 npar = 5;
604 par.Set(npar);
605 TGeoHype *hype = (TGeoHype*)shape;
606 par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
607 par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
608 par.AddAt(hype->GetDZ(),2);
609 par.AddAt(hype->GetStIn(),3);
610 par.AddAt(hype->GetStOut(),4);
611 return kTRUE;
612 }
6b0f3880 613 if (classType==TGeoGtra::Class()) {
023ae34b 614 shapeType = "GTRA";
615 npar = 12;
616 par.Set(npar);
617 TGeoGtra *trap = (TGeoGtra*)shape;
618 Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
619 par.AddAt(trap->GetDz(),0);
620 par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
621 par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
622 par.AddAt(trap->GetH1(),3);
623 par.AddAt(trap->GetBl1(),4);
624 par.AddAt(trap->GetTl1(),5);
625 par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
626 par.AddAt(trap->GetH2(),7);
627 par.AddAt(trap->GetBl2(),8);
628 par.AddAt(trap->GetTl2(),9);
629 par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
630 par.AddAt(trap->GetTwistAngle(),11);
631 return kTRUE;
632 }
6b0f3880 633 if (classType==TGeoCtub::Class()) {
023ae34b 634 shapeType = "CTUB";
635 npar = 11;
636 par.Set(npar);
637 TGeoCtub *ctub = (TGeoCtub*)shape;
638 const Double_t *lx = ctub->GetNlow();
639 const Double_t *tx = ctub->GetNhigh();
640 par.AddAt(ctub->GetRmin(),0);
641 par.AddAt(ctub->GetRmax(),1);
642 par.AddAt(ctub->GetDz(),2);
643 par.AddAt(ctub->GetPhi1(),3);
644 par.AddAt(ctub->GetPhi2(),4);
645 par.AddAt(lx[0],5);
646 par.AddAt(lx[1],6);
647 par.AddAt(lx[2],7);
648 par.AddAt(tx[0],8);
649 par.AddAt(tx[1],9);
650 par.AddAt(tx[2],10);
651 return kTRUE;
652 }
653 Error("GetShape","Getting shape parameters for shape %s not implemented",
654 shape->ClassName());
655 return kFALSE;
656}
657//______________________________________________________________________
658void AliITSInitGeometry::DecodeDetector(Int_t &mod,Int_t layer,Int_t cpn0,
6b0f3880 659 Int_t cpn1,Int_t cpn2) const {
023ae34b 660 // decode geometry into detector module number. There are two decoding
661 // Scheams. Old which does not follow the ALICE coordinate system
662 // requirements, and New which dose.
663 // Inputs:
664 // Int_t layer The ITS layer
665 // Int_t cpn0 The lowest copy number
666 // Int_t cpn1 The middle copy number
667 // Int_t cpn2 the highest copy number
668 // Output:
669 // Int_t &mod The module number assoicated with this set
670 // of copy numbers.
671 // Return:
672 // none.
6b0f3880 673 const Int_t kDetPerLadderSPD[2]={2,4};
674 const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
675 const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
24e270ad 676 Int_t lay=-1,lad=-1,det=-1,i;
023ae34b 677
678 if(fDecode){ // New decoding scheam
679 switch (layer){
680 case 1:{
681 lay = layer;
682 det = 5-cpn2;
683 if(cpn0==4&&cpn1==1) lad=1;
684 else if(cpn0==4&&cpn1==2) lad=20;
685 else if(cpn0<4){
6b0f3880 686 lad = 8-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
023ae34b 687 }else{ // cpn0>4
6b0f3880 688 lad = 28-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
023ae34b 689 } // end if
690 } break;
691 case 2:{
692 lay = layer;
693 det = 5-cpn2;
694 if(cpn0==4&&cpn1==1) lad=1;
695 else if(cpn0<4){
6b0f3880 696 lad = 14-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
023ae34b 697 }else{ // cpn0>4
6b0f3880 698 lad = 54-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
023ae34b 699 } // end if
700 } break;
701 case 3:{
702 lay = layer;
703 if(cpn0<5) lad = 5-cpn0;
704 else lad = 19-cpn0;
705 det = 7-cpn1;
706 } break;
707 case 4:{
708 lay = layer;
709 if(cpn0<7) lad = 7-cpn0;
710 else lad = 29-cpn0;
711 det = 9-cpn1;
712 } break;
713 case 5:{
714 lay = layer;
715 if(cpn0<10) lad = 10-cpn0;
716 else lad = 44-cpn0;
717 det = 23-cpn1;
718 } break;
719 case 6:{
720 lay = layer;
721 if(cpn0<9) lad = 9-cpn0;
722 else lad = 47-cpn0;
723 det = 26-cpn1;
724 } break;
725 } // end switch
726 mod = 0;
6b0f3880 727 for(i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
728 mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
023ae34b 729 return;
730 } // end if
731 // Old decoding scheam
732 switch(layer){
733 case 1: case 2:{
734 lay = layer;
6b0f3880 735 lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
023ae34b 736 det = cpn2;
737 }break;
738 case 3: case 4:{
739 lay = layer;
740 lad = cpn0;
741 det = cpn1;
742 }break;
743 case 5: case 6:{
744 lay = layer;
745 lad = cpn0;
746 det = cpn1;
747 }break;
748 default:{
749 }break;
750 } // end switch
751 mod = 0;
6b0f3880 752 for(i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
753 mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
023ae34b 754 return;
755}
756//______________________________________________________________________
757void AliITSInitGeometry::RecodeDetector(Int_t mod,Int_t &cpn0,
758 Int_t &cpn1,Int_t &cpn2){
759 // decode geometry into detector module number. There are two decoding
760 // Scheams. Old which does not follow the ALICE coordinate system
761 // requirements, and New which dose.
762 // Inputs:
763 // Int_t mod The module number assoicated with this set
764 // of copy numbers.
765 // Output:
766 // Int_t cpn0 The lowest copy number
767 // Int_t cpn1 The middle copy number
768 // Int_t cpn2 the highest copy number
769 // Return:
770 // none.
6b0f3880 771 const Int_t kITSgeoTreeCopys[6][3]= {{10, 2, 4},// lay=1
023ae34b 772 {10, 4, 4},// lay=2
773 {14, 6, 1},// lay=3
774 {22, 8, 1},// lay=4
775 {34,22, 1},// lay=5
776 {38,25, 1}};//lay=6
6b0f3880 777 const Int_t kDetPerLadderSPD[2]={2,4};
778 // const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
779 // const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
023ae34b 780 Int_t lay,lad,det;
781
782 cpn0 = cpn1 = cpn2 = 0;
783 DecodeDetectorLayers(mod,lay,lad,det);
784 if(fDecode){ // New decoding scheam
785 switch (lay){
786 case 1:{
787 cpn2 = 5-det; // Detector 1-4
6b0f3880 788 cpn1 = 1+(lad-1)%kDetPerLadderSPD[lay-1];
789 cpn0 = 5-(lad+kDetPerLadderSPD[lay-1])/kDetPerLadderSPD[lay-1];
790 if(mod>27) cpn0 = 15-(lad+kDetPerLadderSPD[lay-1])/
791 kDetPerLadderSPD[lay-1];
023ae34b 792 } break;
793 case 2:{
794 cpn2 = 5-det; // Detector 1-4
6b0f3880 795 cpn1 = 4-(lad+2)%kDetPerLadderSPD[lay-1];
796 cpn0 = 1+(14-cpn1-lad)/kDetPerLadderSPD[lay-1];
797 if(mod>131) cpn0 = 1+(54-lad-cpn1)/kDetPerLadderSPD[lay-1];
023ae34b 798 } break;
799 case 3:{
800 cpn2 = 1;
801 if(lad<5) cpn0 = 5-lad;
802 else cpn0 = 19-lad;
803 cpn1 = 7-det;
804 } break;
805 case 4:{
806 cpn2 = 1;
807 if(lad<7) cpn0 = 7-lad;
808 else cpn0 = 29-lad;
809 cpn1 = 9-det;
810 } break;
811 case 5:{
812 cpn2 = 1;
813 if(lad<10) cpn0 = 10-lad;
814 else cpn0 = 44-lad;
815 cpn1 = 23-det;
816 } break;
817 case 6:{
818 cpn2 = 1;
819 if(lad<9) cpn0 = 9-lad;
820 else cpn0 = 47-lad;
821 cpn1 = 26-det;
822 } break;
823 default:{
824 Error("RecodeDetector","New: mod=%d lay=%d not 1-6.");
825 return;
826 } break;
827 } // end switch
828 if(cpn0<1||cpn1<1||cpn2<1||
6b0f3880 829 cpn0>kITSgeoTreeCopys[lay-1][0]||
830 cpn1>kITSgeoTreeCopys[lay-1][1]||
831 cpn2>kITSgeoTreeCopys[lay-1][2])
023ae34b 832 Error("RecodeDetector",
833 "cpn0=%d cpn1=%d cpn2=%d mod=%d lay=%d lad=%d det=%d",
834 cpn0,cpn1,cpn2,mod,lay,lad,det);
835 return;
836 } // end if
837 // Old encoding
838 switch (lay){
839 case 1: case 2:{
840 cpn2 = det; // Detector 1-4
6b0f3880 841 cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
842 cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
023ae34b 843 } break;
844 case 3: case 4: case 5 : case 6:{
845 cpn2 = 1;
846 cpn1 = det;
847 cpn0 = lad;
848 } break;
849 default:{
850 Error("RecodeDetector","Old: mod=%d lay=%d not 1-6.");
851 return;
852 } break;
853 } // end switch
854 if(cpn0<1||cpn1<1||cpn2<1||
6b0f3880 855 cpn0>kITSgeoTreeCopys[lay-1][0]||
856 cpn1>kITSgeoTreeCopys[lay-1][1]||
857 cpn2>kITSgeoTreeCopys[lay-1][2])
023ae34b 858 Error("RecodeDetector",
859 "cpn0=%d cpn1=%d cpn2=%d mod=%d lay=%d lad=%d det=%d",
860 cpn0,cpn1,cpn2,mod,lay,lad,det);
861 return;
862}
863//______________________________________________________________________
864void AliITSInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &lay,
865 Int_t &lad,Int_t &det){
866 // decode geometry into detector module number. There are two decoding
867 // Scheams. Old which does not follow the ALICE coordinate system
868 // requirements, and New which dose. Note, this use of layer ladder
869 // and detector numbers are strictly for internal use of this
870 // specific code. They do not represent the "standard" layer ladder
871 // or detector numbering except in a very old and obsoleate sence.
872 // Inputs:
873 // Int_t mod The module number assoicated with this set
874 // of copy numbers.
875 // Output:
876 // Int_t lay The layer number
877 // Int_t lad The ladder number
878 // Int_t det the dettector number
879 // Return:
880 // none.
6b0f3880 881 // const Int_t kDetPerLadderSPD[2]={2,4};
882 const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
883 const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
023ae34b 884 Int_t mod2;
885
886 det = 0;
887 lad = 0;
888 lay = 0;
889 mod2 = 0;
890 do{
6b0f3880 891 mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
023ae34b 892 lay++;
893 }while(mod2<=mod); // end while
894 if(lay>6||lay<1) Error("DecodeDetectorLayers","0<lay=%d>6",lay);
6b0f3880 895 mod2 -= kLadPerLayer[lay-1]*kDetPerLadder[lay-1];
023ae34b 896 do{
897 lad++;
6b0f3880 898 mod2 += kDetPerLadder[lay-1];
023ae34b 899 }while(mod2<=mod); // end while
6b0f3880 900 if(lad>kLadPerLayer[lay-1]||lad<1) Error("DecodeDetectorLayera",
901 "lad=%d>kLadPerLayer[lay-1=%d]=%d mod=%d mod2=%d",lad,lay-1,
902 kLadPerLayer[lay-1],mod,mod2);
903 mod2 -= kDetPerLadder[lay-1];
023ae34b 904 det = mod-mod2+1;
6b0f3880 905 if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
023ae34b 906 "det=%d>detPerLayer[lay-1=%d]=%d mod=%d mod2=%d lad=%d",det,
6b0f3880 907 lay-1,kDetPerLadder[lay-1],mod,mod2,lad);
023ae34b 908 return;
909}
910