]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSgeom.cxx
No inline in the implementation file
[u/mrichter/AliRoot.git] / ITS / AliITSgeom.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
4c039060 17
58005f18 18///////////////////////////////////////////////////////////////////////
593e9459 19// ITS geometry manipulation routines. //
58005f18 20// Created April 15 1999. //
21// version: 0.0.0 //
22// By: Bjorn S. Nilsen //
23// version: 0.0.1 //
24// Updated May 27 1999. //
593e9459 25// Added Cylindrical random and global based changes. //
58005f18 26// Added function PrintComparison. //
27///////////////////////////////////////////////////////////////////////
593e9459 28
29
30////////////////////////////////////////////////////////////////////////
593e9459 31// The local coordinate system by, default, is show in the following
32// figures. Also shown are the ladder numbering scheme.
33//Begin_Html
34/*
269f57ed 35<img src="picts/ITS/AliITSgeomMatrix_L1.gif">
36</pre>
37<br clear=left>
38<font size=+2 color=blue>
39<p>This shows the relative geometry differences between the ALICE Global
40coordinate system and the local detector coordinate system.
41</font>
42<pre>
43
44<pre>
593e9459 45<img src="picts/ITS/its1+2_convention_front_5.gif">
46</pre>
47<br clear=left>
48<font size=+2 color=blue>
49<p>This shows the front view of the SPDs and the orientation of the local
50pixel coordinate system. Note that the inner pixel layer has its y coordinate
51in the opposite direction from all of the other layers.
52</font>
53<pre>
54
55<pre>
56<img src="picts/ITS/its3+4_convention_front_5.gif">
57</pre>
58<br clear=left>
59<font size=+2 color=blue>
60<p>This shows the front view of the SDDs and the orientation of the local
61pixel coordinate system.
62</font>
63<pre>
64
65<pre>
66<img src="picts/ITS/its5+6_convention_front_5.gif">
67</pre>
68<br clear=left>
69<font size=+2 color=blue>
70<p>This shows the front view of the SSDs and the orientation of the local
71pixel coordinate system.
72</font>
73<pre>
74*/
75//End_Html
269f57ed 76//
593e9459 77////////////////////////////////////////////////////////////////////////
78
79////////////////////////////////////////////////////////////////////////
80//
81// version: 0
82// Written by Bjorn S. Nilsen
83//
84// Data Members:
85//
86// Int_t fNlayers
87// The number of ITS layers for this geometry. By default this
88// is 6, but can be modified by the creator function if there are
89// more layers defined.
90//
91// Int_t *fNlad
92// A pointer to an array fNlayers long containing the number of
93// ladders for each layer. This array is typically created and filled
94// by the AliITSgeom creator function.
95//
96// Int_t *fNdet
97// A pointer to an array fNlayers long containing the number of
98// active detector volumes for each ladder. This array is typically
99// created and filled by the AliITSgeom creator function.
100//
269f57ed 101// AliITSgeomMatrix *fGm
102// A pointer to an array of AliITSgeomMatrix classes. One element
103// per module (detector) in the ITS. AliITSgeomMatrix basicly contains
104// all of the necessary information about the detector and it's coordinate
105// transformations.
593e9459 106//
107// TObjArray *fShape
108// A pointer to an array of TObjects containing the detailed shape
109// information for each type of detector used in the ITS. For example
110// I have created AliITSgeomSPD, AliITSgeomSDD, and AliITSgeomSSD as
111// example structures, derived from TObjects, to hold the detector
112// information. I would recommend that one element in each of these
113// structures, that which describes the shape of the active volume,
114// be one of the ROOT classes derived from TShape. In this way it would
115// be easy to have the display program display the correct active
116// ITS volumes. See the example classes AliITSgeomSPD, AliITSgeomSDD,
117// and AliITSgeomSSD for a more detailed example.
593e9459 118////////////////////////////////////////////////////////////////////////
4ae5bbc4 119#include <Riostream.h>
3f38f7af 120//#include <stdlib.h>
121//#include <stdio.h>
122//#include <string.h>
123//#include <ctype.h>
8253cd9a 124
125#include <TSystem.h>
269f57ed 126#include <TRandom.h>
e8189707 127
58005f18 128#include "AliITSgeom.h"
269f57ed 129#include "AliITSgeomSPD.h"
130#include "AliITSgeomSDD.h"
131#include "AliITSgeomSSD.h"
58005f18 132
133ClassImp(AliITSgeom)
134
85f1e34a 135//______________________________________________________________________
58005f18 136AliITSgeom::AliITSgeom(){
85f1e34a 137 // The default constructor for the AliITSgeom class. It, by default,
138 // sets fNlayers to zero and zeros all pointers.
139 // Do not allocate anything zero everything.
140
8253cd9a 141 fTrans = 0; // standard GEANT global/local coordinate system.
142 fNlayers = 0;
143 fNlad = 0;
144 fNdet = 0;
145 fGm = 0;
146 fShape = 0;
147 strcpy(fVersion,"test");
148 return;
149}
85f1e34a 150//______________________________________________________________________
8253cd9a 151AliITSgeom::AliITSgeom(Int_t itype,Int_t nlayers,Int_t *nlads,Int_t *ndets,
152 Int_t mods){
85f1e34a 153 // A simple constructor to set basic geometry class variables
154 // Inputs:
155 // Int_t itype the type of transformation kept.
156 // bit 0 => Standard GEANT
157 // bit 1 => ITS tracking
158 // bit 2 => A change in the coordinate system has been made.
159 // others are still to be defined as needed.
160 // Int_t nlayers The number of ITS layers also set the size of the arrays
161 // Int_t *nlads an array of the number of ladders for each layer. This
162 // array must be nlayers long.
163 // Int_t *ndets an array of the number of detectors per ladder for each
164 // layer. This array must be nlayers long.
165 // Int_t mods The number of modules. Typicaly the sum of all the
166 // detectors on every layer and ladder.
167 // Outputs:
168 // none
8253cd9a 169 Int_t i;
170
171 fTrans = itype;
172 fNlayers = nlayers;
173 fNlad = new Int_t[nlayers];
174 fNdet = new Int_t[nlayers];
175 for(i=0;i<nlayers;i++){fNlad[i] = nlads[i];fNdet[i] = ndets[i];}
176 fNmodules = mods;
177 fGm = new TObjArray(mods,0);
5c9c741e 178 fShape = new TObjArray(5); // default value
179 for(i=0;i<5;i++) fShape->AddAt(0,i);
8253cd9a 180 strcpy(fVersion,"test");
181 return;
58005f18 182}
8253cd9a 183//______________________________________________________________________
184void AliITSgeom::CreatMatrix(Int_t mod,Int_t lay,Int_t lad,Int_t det,
85f1e34a 185 AliITSDetector idet,const Double_t tran[3],
186 const Double_t rot[10]){
187 // Given the translation vector tran[3] and the rotation matrix rot[1],
188 // this function creates and adds to the TObject Array fGm the
189 // AliITSgeomMatrix object.
190 // Inputs are:
191 // Int_t mod The module number. The location in TObjArray
192 // Int_t lay The layer where this module is
193 // Int_t lad On which ladder this module is
194 // Int_t det Which detector on this ladder this module is
195 // AliITSDetector idet The type of detector see AliITSgeom.h
196 // Double_t tran[3] The translation vector
197 // Double_t rot[10] The rotation matrix.
198 // Outputs are:
199 // none
200 // The rot[10] matrix is set up like:
201 /* / rot[0] rot[1] rot[2] \
202 // | rot[3] rot[4] rot[5] |
203 // \ rot[6] rot[7] rot[8] / if(rot[9]!=0) then the Identity matrix
204 // is used regardless of the values in rot[0]-rot[8].
205 */
8253cd9a 206 Int_t id[3];
207 Double_t r[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
58005f18 208
8253cd9a 209 if(fGm->At(mod)!=0) delete fGm->At(mod);
210 id[0] = lay; id[1] = lad; id[2] = det;
211 if(rot[9]!=0.0) { // null rotation
212 r[0][0] = rot[0]; r[0][1] = rot[1]; r[0][2] = rot[2];
213 r[1][0] = rot[3]; r[1][1] = rot[4]; r[1][2] = rot[5];
214 r[2][0] = rot[6]; r[2][1] = rot[7]; r[2][2] = rot[8];
215 } // end if
216 fGm->AddAt(new AliITSgeomMatrix(idet,id,r,tran),mod);
217}
85f1e34a 218//______________________________________________________________________
58005f18 219AliITSgeom::~AliITSgeom(){
85f1e34a 220 // The destructor for the AliITSgeom class. If the arrays fNlad,
221 // fNdet, or fGm have had memory allocated to them, there pointer values
222 // are non zero, then this memory space is freed and they are set
223 // to zero. In addition, fNlayers is set to zero. The destruction of
224 // TObjArray fShape is, by default, handled by the TObjArray destructor.
225
085bb6ed 226 if(fGm!=0){
36583d28 227 //for(Int_t i=0;i<fNlayers;i++) delete fGm->At(i);
228 fGm->Delete();
8253cd9a 229 delete fGm;
085bb6ed 230 } // end if fGm!=0
58005f18 231 if(fNlad!=0) delete[] fNlad;
232 if(fNdet!=0) delete[] fNdet;
233 fNlayers = 0;
234 fNlad = 0;
235 fNdet = 0;
269f57ed 236 fGm = 0;
58005f18 237 return;
238}
269f57ed 239//______________________________________________________________________
240void AliITSgeom::ReadNewFile(const char *filename){
85f1e34a 241 // It is generaly preferred to define the geometry in AliITSgeom
242 // directly from the GEANT geometry, see AliITSvPPRasymm.cxx for
243 // and example. Under some circumstances this may not be possible.
244 // This function will read in a formatted file for all of the
245 // information needed to define the geometry in AliITSgeom.
246 // Unlike the older file format, this file may contain comments
247 // and the order of the data does not need to be completely
248 // respected. A file can be created using the function WriteNewFile
249 // defined below.
250 // Inputs are:
251 // const char *filename The file name of the file to be read in.
252 // Outputs are:
253 // none
8253cd9a 254 Int_t ncmd=9;
5c9c741e 255 const char *cmda[]={"Version" ,"fTrans" ,"fNmodules",
256 "fNlayers" ,"fNladers","fNdetectors",
257 "fNDetectorTypes","fShape" ,"Matrix"};
8253cd9a 258 Int_t i,j,lNdetTypes,ldet;
259 char cmd[20],c;
164da35c 260 AliITSgeomSPD *spd=0;
261 AliITSgeomSDD *sdd=0;
262 AliITSgeomSSD *ssd=0;
263 AliITSgeomMatrix *m=0;
264 ifstream *fp=0;
265 char *filtmp=0;
8253cd9a 266
267 filtmp = gSystem->ExpandPathName(filename);
5c9c741e 268 cout << "AliITSgeom, Reading New .det file " << filtmp << endl;
8253cd9a 269 fp = new ifstream(filtmp,ios::in); // open file to write
270 while(fp->get(c)!=NULL){ // for ever loop
271 if(c==' ') continue; // remove blanks
272 if(c=='\n') continue;
273 if(c=='#' || c=='!'){for(;fp->get(c)!=NULL,c!='\n';); continue;}
274 if(c=='/'){
275 fp->get(c);{
276 if(c=='/'){for(;fp->get(c)!=NULL,c!='\n';);continue;}
277 if(c=='*'){
278 NotYet:
279 for(;fp->get(c)!=NULL,c!='*';);
280 fp->get(c);{
281 if(c=='/') continue;
282 goto NotYet;
283 } //
284 } // end if c=='*'
285 } // end if second /
286 } // end if first /
5c9c741e 287 fp->putback(c);
8253cd9a 288 *fp >> cmd;
289 for(i=0;i<ncmd;i++) if(strcmp(cmd,cmda[i])==0) break;
290 switch (i){
291 case 0: // Version
292 *fp >> fVersion;
293 break;
294 case 1: // fTrans
295 *fp >> fTrans;
296 break;
297 case 2: // fNModules
298 *fp >> fNmodules;
299 if(fGm!=0){
300 for(j=0;j<fGm->GetEntriesFast();j++) delete fGm->At(j);
301 delete fGm;
302 } // end if
303 fGm = new TObjArray(fNmodules,0);
304 break;
305 case 3: // fNlayers
306 *fp >> fNlayers;
307 if(fNlad!=0) delete fNlad;
308 if(fNdet!=0) delete fNdet;
309 fNlad = new Int_t[fNlayers];
310 fNdet = new Int_t[fNlayers];
311 break;
312 case 4: // fNladers
313 for(j=0;j<fNlayers;j++) *fp >> fNlad[j];
314 break;
315 case 5: // fNdetectors
316 for(j=0;j<fNlayers;j++) *fp >> fNdet[j];
317 break;
318 case 6: // fNDetectorTypes
319 *fp >> lNdetTypes;
320 if(fShape!=0){
321 for(j=0;j<fShape->GetEntriesFast();j++) delete fShape->At(j);
322 delete fShape;
323 } // end if
324 fShape = new TObjArray(lNdetTypes,0);
325 break;
326 case 7: // fShape
327 *fp >> ldet;
5c9c741e 328 if(fShape==0) fShape = new TObjArray(5,0);
8253cd9a 329 switch (ldet){
330 case kSPD :
164da35c 331 spd = new AliITSgeomSPD();
8253cd9a 332 *fp >> *spd;
164da35c 333 ReSetShape(ldet,spd);
8253cd9a 334 spd = 0;
335 break;
164da35c 336 case kSDD : case kSDDp:
337 sdd = new AliITSgeomSDD();
8253cd9a 338 *fp >> *sdd;
164da35c 339 ReSetShape(ldet,sdd);
8253cd9a 340 sdd = 0;
341 break;
342 case kSSD : case kSSDp :
164da35c 343 ssd = new AliITSgeomSSD();
8253cd9a 344 *fp >> *ssd;
164da35c 345 ReSetShape(ldet,ssd);
8253cd9a 346 ssd = 0;
347 break;
348 default:
331329a2 349 Error("ReadNewFile","Unknown fShape type number=%d c=%c",ldet,c);
8253cd9a 350 for(;fp->get(c)==NULL,c!='\n';); // skip to end of line.
351 break;
352 } // end switch
353 break;
354 case 8: // Matrix
355 *fp >> ldet;
356 if(fGm==0) fGm = new TObjArray(2270,0);
357 if(fGm->At(ldet)!=0) delete (fGm->At(ldet));
358 fGm->AddAt((TObject*)new AliITSgeomMatrix(),ldet);
359 m = (AliITSgeomMatrix*) fGm->At(ldet);
360 *fp >> *m;
361 m = 0;
362 break;
363 default:
331329a2 364 Error("ReadNewFile","Data line i=%d c=%c",i,c);
8253cd9a 365 for(;fp->get(c)==NULL,c!='\n';); // skip this line
366 break;
367 } // end switch i
368 } // end while
369 delete fp;
370
371 return;
372}
373//______________________________________________________________________
374void AliITSgeom::WriteNewFile(const char *filename){
85f1e34a 375 // Writes AliITSgeom, AliITSgeomMatrix, and the defined AliITSgeomS*D
376 // classes to a file in a format that is more readable and commendable.
377 // Inputs are:
378 // const char *filename The file name of the file to be write to.
379 // Outputs are:
380 // none
8253cd9a 381 ofstream *fp;
382 Int_t i;
383 char *filtmp;
384
385 filtmp = gSystem->ExpandPathName(filename);
5c9c741e 386 cout << "AliITSgeom, Writing New .det file " << filtmp << endl;
8253cd9a 387 fp = new ofstream(filtmp,ios::out); // open file to write
388 *fp << "//Comment lines begin with two //, one #, or one !" << endl;
389 *fp << "#Blank lines are skipped including /* and */ sections." << endl;
390 *fp << "!and, in principle the order of the lines is not important" <<endl;
391 *fp << "/* In AliITSgeom.h are defined an enumerated type called" << endl;
392 *fp << " AliITSDetectors These are kSPD=" << (Int_t) kSPD ;
393 *fp << ", kSDD=" << (Int_t) kSDD << ", kSSD=" << (Int_t) kSSD;
5c9c741e 394 *fp << ", kSSDp=" << (Int_t) kSSDp << ", and kSDDp=" << (Int_t) kSDDp;
395 *fp << "*/" << endl;
85f1e34a 396 *fp << "Version " << fVersion << endl;//This should be consistent with the
8253cd9a 397 // geometry version.
398 *fp << "fTrans " << fTrans << endl;
399 *fp << "fNmodules " << fNmodules << endl;
400 *fp << "fNlayers " << fNlayers << endl;
401 *fp << "fNladers ";
402 for(i=0;i<fNlayers;i++) *fp << fNlad[i] << " ";
403 *fp << endl;
404 *fp << "fNdetectors ";
405 for(i=0;i<fNlayers;i++) *fp << fNdet[i] << " ";
406 *fp << endl;
407 *fp << "fNDetectorTypes " << fShape->GetEntriesFast() << endl;
408 for(i=0;i<fShape->GetEntriesFast();i++){
409 if(!IsShapeDefined(i)) continue; // only print out used shapes.
410 switch (i){
411 case kSPD :
412 *fp << "fShape " << (Int_t) kSPD << " ";
413 *fp << *((AliITSgeomSPD*)(fShape->At(i)));
414 break;
415 case kSDD :
416 *fp << "fShape " << (Int_t) kSDD << " ";
417 *fp << *((AliITSgeomSDD*)(fShape->At(i)));
418 break;
419 case kSSD : case kSSDp :
420 *fp << "fShape " << i << " ";
421 *fp << *((AliITSgeomSSD*)(fShape->At(i)));
422 break;
423 default:
424 Error("AliITSgeom::WriteNewFile","Unknown Shape value");
425 } // end switch (i)
426 } // end for i
427 for(i=0;i<fNmodules;i++){
428 *fp << "Matrix " << i << " ";
429 *fp << *GetGeomMatrix(i);
430 } // end for i
431 *fp << "//End of File" << endl;;
432
433 delete fp;
269f57ed 434 return;
435}
85f1e34a 436//______________________________________________________________________
58005f18 437AliITSgeom::AliITSgeom(const char *filename){
85f1e34a 438 // The constructor for the AliITSgeom class. All of the data to fill
439 // this structure is read in from the file given my the input filename.
440 // Inputs are:
441 // const char *filename The file name of the file to be read in.
442 // Outputs are:
443 // none
444 FILE *pf=0;
445 Int_t i,lm=0,id[3];
446 Int_t l,a,d;
447 Float_t x,y,z,o,p,q,r,s,t;
448 Double_t rot6[6],tran[3];
449 char buf[200],*buff=0; // input character buffer;
450 char *filtmp;
58005f18 451
85f1e34a 452 filtmp = gSystem->ExpandPathName(filename);
453 cout << "AliITSgeom reading old .det file " << filtmp << endl;
454 fShape = 0;
455 strcpy(fVersion,"DefauleV5");
456 pf = fopen(filtmp,"r");
457
458 fNlayers = 6; // set default number of ladders
459 TryAgain:
460 fNlad = new Int_t[fNlayers];
461 fNdet = new Int_t[fNlayers];
462 fNmodules = 0;
463 // find the number of ladders and detectors in this geometry.
464 for(i=0;i<fNlayers;i++){fNlad[i]=fNdet[i]=0;} // zero out arrays
465 while(fgets(buf,200,pf)!=NULL){ // for ever loop
466 for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces.
467 buff = &(buf[i]);
468 break;
469 } // end for i
470 // remove blank lines and comments.
471 if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'||
472 (buff[0]=='/'&&buff[1]=='/')) continue;
473 if(isalpha(buff[0])) { // must be the new file formated file.
269f57ed 474 fclose(pf);
475 delete[] fNlad;delete[] fNdet;
476 ReadNewFile(filename);
477 return;
85f1e34a 478 } // end if isalpha(buff[0])
479 sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f",
480 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
481 if(l>lm) lm = l;
482 if(l<1 || l>fNlayers) {
483 printf("error in file %s layer=%d min. is 1 max is %d\n",
484 filename,l,fNlayers);
485 continue;
486 }// end if l
487 fNmodules++;
488 if(l<=fNlayers&&fNlad[l-1]<a) fNlad[l-1] = a;
489 if(l<=fNlayers&&fNdet[l-1]<d) fNdet[l-1] = d;
490 } // end while ever loop
491 if(lm>fNlayers){
269f57ed 492 delete[] fNlad;
493 delete[] fNdet;
494 fNlayers = lm;
495 goto TryAgain;
85f1e34a 496 } // end if lm>fNlayers
497 // counted the number of ladders and detectors now allocate space.
498 fGm = new TObjArray(fNmodules,0);
58005f18 499
85f1e34a 500 // Set up Shapes for a default configuration of 6 layers.
501 fTrans = 0; // standard GEANT global/local coordinate system.
502 // prepare to read in transforms
503 lm = 0; // reuse lm as counter of modules.
504 rewind(pf); // start over reading file
505 while(fgets(buf,200,pf)!=NULL){ // for ever loop
506 for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces.
507 buff = &(buf[i]);
508 break;
509 } // end for i
510 // remove blank lines and comments.
511 if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'||
512 (buff[0]=='/'&&buff[1]=='/')) continue;
513 x = y = z = o = p = q = r = s = t = 0.0;
514 sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f",
515 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
516 if(l<1 || l>fNlayers) {
517 printf("error in file %s layer=%d min. is 1 max is %d/n",
518 filename,l,fNlayers);
519 continue;
520 }// end if l
521 id[0] = l;id[1] = a;id[2] = d;
522 tran[0] = tran[1] = tran[2] = 0.0;
523 tran[0] = (Double_t)x;tran[1] = (Double_t)y;tran[2] = (Double_t)z;
524 rot6[0] = rot6[1] = rot6[2] = rot6[3] = rot6[4] = rot6[5] =0.0;
525 rot6[0] = (Double_t)o;rot6[1] = (Double_t)p;rot6[2] = (Double_t)q;
526 rot6[3] = (Double_t)r;rot6[4] = (Double_t)s;rot6[5] = (Double_t)t;
527 switch (l){
528 case 1: case 2: // layer 1 or2 SPD
529 fGm->AddAt(new AliITSgeomMatrix(rot6,kSPD,id,tran),lm++);
530 break;
531 case 3: case 4: // layer 3 or 4 SDD
532 fGm->AddAt(new AliITSgeomMatrix(rot6,kSDD,id,tran),lm++);
533 break;
534 case 5: case 6: // layer 5 or 6 SSD
535 fGm->AddAt(new AliITSgeomMatrix(rot6,kSSD,id,tran),lm++);
536 break;
537 } // end switch
538 } // end while ever loop
539 fclose(pf);
58005f18 540}
85f1e34a 541//______________________________________________________________________
ac74f489 542AliITSgeom::AliITSgeom(AliITSgeom &source) : TObject(source){
85f1e34a 543 // The copy constructor for the AliITSgeom class. It calls the
544 // = operator function. See the = operator function for more details.
545 // Inputs are:
546 // AliITSgeom &source The AliITSgeom class with which to make this
547 // a copy of.
548 // Outputs are:
549 // none.
593e9459 550
551 *this = source; // Just use the = operator for now.
593e9459 552 return;
58005f18 553}
85f1e34a 554//______________________________________________________________________
555AliITSgeom& AliITSgeom::operator=(AliITSgeom &source){
556 // The = operator function for the AliITSgeom class. It makes an
557 // independent copy of the class in such a way that any changes made
558 // to the copied class will not affect the source class in any way.
559 // This is required for many ITS alignment studies where the copied
560 // class is then modified by introducing some misalignment.
561 // Inputs are:
562 // AliITSgeom &source The AliITSgeom class with which to make this
563 // a copy of.
564 // Outputs are:
565 // return *this The a new copy of source.
269f57ed 566 Int_t i;
58005f18 567
85f1e34a 568 if(this == &source) return *this; // don't assign to ones self.
58005f18 569
570 // if there is an old structure allocated delete it first.
269f57ed 571 if(this->fGm != 0){
8253cd9a 572 for(i=0;i<this->fNmodules;i++) delete this->fGm->At(i);
269f57ed 573 delete this->fGm;
085bb6ed 574 } // end if fGm != 0
575 if(fNlad != 0) delete[] fNlad;
576 if(fNdet != 0) delete[] fNdet;
577
269f57ed 578 this->fTrans = source.fTrans;
579 this->fNmodules = source.fNmodules;
580 this->fNlayers = source.fNlayers;
581 this->fNlad = new Int_t[fNlayers];
582 for(i=0;i<this->fNlayers;i++) this->fNlad[i] = source.fNlad[i];
583 this->fNdet = new Int_t[fNlayers];
584 for(i=0;i<this->fNlayers;i++) this->fNdet[i] = source.fNdet[i];
585 this->fShape = new TObjArray(*(source.fShape));//This does not make a proper copy.
8253cd9a 586 this->fGm = new TObjArray(this->fNmodules,0);
269f57ed 587 for(i=0;i<this->fNmodules;i++){
8253cd9a 588 this->fGm->AddAt(new AliITSgeomMatrix(*(
589 (AliITSgeomMatrix*)(source.fGm->At(i)))),i);
085bb6ed 590 } // end for i
85f1e34a 591 return *this;
592}
593//______________________________________________________________________
8746957a 594Int_t AliITSgeom::GetNdetectors(Int_t lay) const {
3f38f7af 595 // Return the number of detectors/ladder for the given layer
596 // Inputs:
597 // Int_t lay the layer number
598 // Outputs:
599 // none.
600 // Return:
601 // Int_t the number of detectors/ladders for the give layer
602 Int_t ndet;
603
604 ndet = fNdet[lay-1];
605 return ndet;
606}
607//______________________________________________________________________
8746957a 608Int_t AliITSgeom::GetNladders(Int_t lay) const {
3f38f7af 609 // Return the number of ladders for the given layer
610 // Inputs:
611 // Int_t lay the layer number
612 // Outputs:
613 // none.
614 // Return:
615 // Int_t the number of ladders for the give layer
616 Int_t nlad;
617
618 nlad = fNlad[lay-1];
619 return nlad;
620}
621//______________________________________________________________________
85f1e34a 622Int_t AliITSgeom::GetModuleIndex(Int_t lay,Int_t lad,Int_t det){
623 // This routine computes the module index number from the layer,
624 // ladder, and detector numbers. The number of ladders and detectors
625 // per layer is determined when this geometry package is constructed,
626 // see AliITSgeom(const char *filename) for specifics.
627 // Inputs are:
628 // Int_t lay The layer number. Starting from 1.
629 // Int_t lad The ladder number. Starting from 1.
630 // Int_t det The detector number. Starting from 1.
631 // Outputs are:
632 // return the module index number, starting from zero.
269f57ed 633 Int_t i,j,k,id[3];
593e9459 634
635 i = fNdet[lay-1] * (lad-1) + det - 1;
636 j = 0;
637 for(k=0;k<lay-1;k++) j += fNdet[k]*fNlad[k];
269f57ed 638 i = i+j;
8253cd9a 639 GetGeomMatrix(i)->GetIndex(id);
269f57ed 640 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
641 // Array of modules fGm is not in expected order. Search for this index
642 for(i=0;i<fNmodules;i++){
8253cd9a 643 GetGeomMatrix(i)->GetIndex(id);
269f57ed 644 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
645 } // end for i
646 // This layer ladder and detector combination does not exist return -1.
647 return -1;
593e9459 648}
269f57ed 649//______________________________________________________________________
85f1e34a 650void AliITSgeom::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det){
651 // This routine computes the layer, ladder and detector number
652 // given the module index number. The number of ladders and detectors
653 // per layer is determined when this geometry package is constructed,
654 // see AliITSgeom(const char *filename) for specifics.
655 // Inputs are:
656 // Int_t index The module index number, starting from zero.
657 // Outputs are:
658 // Int_t lay The layer number. Starting from 1.
659 // Int_t lad The ladder number. Starting from 1.
660 // Int_t det The detector number. Starting from 1.
269f57ed 661 Int_t id[3];
88cb7938 662 AliITSgeomMatrix *g = GetGeomMatrix(index);
663 if (g == 0x0)
664 {
665 Error("GetModuleId","Can not get GeoMatrix for index = %d",index);
666 lay = -1; lad = -1; det = -1;
667 }
668 else
669 {
670 g->GetIndex(id);
671 lay = id[0]; lad = id[1]; det = id[2];
672 }
269f57ed 673 return;
674
675 // The old way kept for posterity.
676/*
677 Int_t i,j,k;
593e9459 678 j = 0;
679 for(k=0;k<fNlayers;k++){
58005f18 680 j += fNdet[k]*fNlad[k];
aa6248e2 681 if(j>index)break;
58005f18 682 } // end for k
683 lay = k+1;
684 i = index -j + fNdet[k]*fNlad[k];
685 j = 0;
686 for(k=0;k<fNlad[lay-1];k++){
aa6248e2 687 j += fNdet[lay-1];
688 if(j>i)break;
58005f18 689 } // end for k
690 lad = k+1;
691 det = 1+i-fNdet[lay-1]*k;
692 return;
269f57ed 693*/
58005f18 694}
85f1e34a 695//______________________________________________________________________
696Int_t AliITSgeom::GetStartDet(Int_t dtype){
697 // returns the starting module index value for a give type of detector id.
698 // This assumes that the detector types are different on different layers
699 // and that they are not mixed up.
700 // Inputs are:
701 // Int_t dtype A detector type number. 0 for SPD, 1 for SDD, and 2 for SSD.
702 // outputs:
703 // return the module index for the first occurance of that detector type.
704
705 switch(dtype){
706 case 0:
707 return GetModuleIndex(1,1,1);
708 break;
709 case 1:
710 return GetModuleIndex(3,1,1);
711 break;
712 case 2:
713 return GetModuleIndex(5,1,1);
714 break;
715 default:
716 Warning("GetStartDet","undefined detector type %d",dtype);
717 return 0;
718 } // end switch
719
720 Warning("GetStartDet","undefined detector type %d",dtype);
721 return 0;
085bb6ed 722}
85f1e34a 723//______________________________________________________________________
724Int_t AliITSgeom::GetLastDet(Int_t dtype){
725 // returns the last module index value for a give type of detector id.
726 // This assumes that the detector types are different on different layers
727 // and that they are not mixed up.
728 // Inputs are:
729 // Int_t dtype A detector type number. 0 for SPD, 1 for SDD, and 2 for SSD.
730 // outputs are:
731 // return the module index for the last occurance of that detector type.
732
733 switch(dtype){
734 case 0:
735 return GetLastSPD();
736 break;
737 case 1:
738 return GetLastSDD();
739 break;
740 case 2:
741 return GetLastSSD();
742 break;
743 default:
744 Warning("GetLastDet","undefined detector type %d",dtype);
745 return 0;
746 } // end switch
747
748 Warning("GetLastDet","undefined detector type %d",dtype);
749 return 0;
085bb6ed 750}
85f1e34a 751//______________________________________________________________________
8746957a 752void AliITSgeom::GetCenterThetaPhi(Int_t lay,Int_t lad,Int_t det,
3f38f7af 753 TVector &x){
754 // This function returns the Cartesian translation [cm] and the
755 // 6 GEANT rotation angles [degrees]for a given layer ladder and
756 // detector number, in the TVector x (at least 9 elements large).
757 // Inputs:
758 // Int_t lay ITS Layer number
759 // Int_t lad ITS Ladder number
760 // Int_t det ITS Detector number
761 // Outputs:
762 // TVector &x The translation vector and the 6 rotaion angles
763 // Return:
764 // none.
765 Double_t t[3],ang[6];
766 Int_t index=GetModuleIndex(lay,lad,det);
767
768 GetTrans(index,t);
769 GetGeantAngles(index,ang);
770 x(0) = t[0];x(1) = t[1];x(2) = t[2];
771 x(3) = ang[0];x(4) = ang[1];x(5) = ang[2];
772 x(6) = ang[3];x(7) = ang[4];x(8) = ang[5];
773}
774//______________________________________________________________________
593e9459 775void AliITSgeom::PrintComparison(FILE *fp,AliITSgeom *other){
85f1e34a 776 // This function was primarily created for diagnostic reasons. It
777 // print to a file pointed to by the file pointer fp the difference
778 // between two AliITSgeom classes. The format of the file is basicly,
779 // define d? to be the difference between the same element of the two
780 // classes. For example dfrx = this->GetGeomMatrix(i)->frx
781 // - other->GetGeomMatrix(i)->frx.
782 // if(at least one of dfx0, dfy0, dfz0,dfrx,dfry,dfrz are non zero) then
783 // print layer ladder detector dfx0 dfy0 dfz0 dfrx dfry dfrz
784 // if(at least one of the 9 elements of dfr[] are non zero) then print
785 // layer ladder detector dfr[0] dfr[1] dfr[2]
786 // dfr[3] dfr[4] dfr[5]
787 // dfr[6] dfr[7] dfr[8]
788 // Only non zero values are printed to save space. The differences are
789 // typical written to a file because there are usually a lot of numbers
790 // printed out and it is usually easier to read them in some nice editor
791 // rather than zooming quickly past you on a screen. fprintf is used to
792 // do the printing. The fShapeIndex difference is not printed at this time.
793 // Inputs are:
794 // FILE *fp A file pointer to an opened file for writing in which
795 // the results of the comparison will be written.
796 // AliITSgeom *other The other AliITSgeom class to which this one is
797 // being compared.
798 // outputs are:
799 // none
800 Int_t i,j,idt[3],ido[3];
801 Double_t tt[3],to[3]; // translation
802 Double_t rt[3],ro[3]; // phi in radians
803 Double_t mt[3][3],mo[3][3]; // matrixes
804 AliITSgeomMatrix *gt,*go;
805 Bool_t t;
806
807 for(i=0;i<this->fNmodules;i++){
808 gt = this->GetGeomMatrix(i);
809 go = other->GetGeomMatrix(i);
810 gt->GetIndex(idt);
811 go->GetIndex(ido);
812 t = kFALSE;
813 for(i=0;i<3;i++) t = t&&idt[i]!=ido[i];
814 if(t) fprintf(fp,"%4.4d %1.1d %2.2d %2.2d %1.1d %2.2d %2.2d\n",i,
815 idt[0],idt[1],idt[2],ido[0],ido[1],ido[2]);
816 gt->GetTranslation(tt);
817 go->GetTranslation(to);
818 gt->GetAngles(rt);
819 go->GetAngles(ro);
820 t = kFALSE;
821 for(i=0;i<3;i++) t = t&&tt[i]!=to[i];
822 if(t) fprintf(fp,"%1.1d %2.2d %2.2d dTrans=%f %f %f drot=%f %f %f\n",
823 idt[0],idt[1],idt[2],
824 tt[0]-to[0],tt[1]-to[1],tt[2]-to[2],
825 rt[0]-ro[0],rt[1]-ro[1],rt[2]-ro[2]);
826 t = kFALSE;
827 gt->GetMatrix(mt);
828 go->GetMatrix(mo);
829 for(i=0;i<3;i++)for(j=0;j<3;j++) t = mt[i][j] != mo[i][j];
830 if(t){
831 fprintf(fp,"%1.1d %2.2d %2.2d dfr= %e %e %e\n",
832 idt[0],idt[1],idt[2],
833 mt[0][0]-mo[0][0],mt[0][1]-mo[0][1],mt[0][2]-mo[0][2]);
834 fprintf(fp," dfr= %e %e %e\n",
835 mt[1][0]-mo[1][0],mt[1][1]-mo[1][1],mt[1][2]-mo[1][2]);
836 fprintf(fp," dfr= %e %e %e\n",
837 mt[2][0]-mo[2][0],mt[2][1]-mo[2][1],mt[2][2]-mo[2][2]);
838 } // end if t
839 } // end for i
840 return;
58005f18 841}
85f1e34a 842//______________________________________________________________________
843void AliITSgeom::PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det){
844 // This function prints out the coordinate transformations for
845 // the particular detector defined by layer, ladder, and detector
846 // to the file pointed to by the File pointer fp. fprintf statements
847 // are used to print out the numbers. The format is
848 // layer ladder detector Trans= fx0 fy0 fz0 rot= frx fry frz
849 // Shape=fShapeIndex
850 // dfr= fr[0] fr[1] fr[2]
851 // dfr= fr[3] fr[4] fr[5]
852 // dfr= fr[6] fr[7] fr[8]
853 // By indicating which detector, some control over the information
854 // is given to the user. The output it written to the file pointed
855 // to by the file pointer fp. This can be set to stdout if you want.
856 // Inputs are:
857 // FILE *fp A file pointer to an opened file for writing in which
858 // the results of the comparison will be written.
859 // Int_t lay The layer number. Starting from 1.
860 // Int_t lad The ladder number. Starting from 1.
861 // Int_t det The detector number. Starting from 1.
862 // outputs are:
863 // none
864 AliITSgeomMatrix *gt;
865 Double_t t[3],r[3],m[3][3];
866
867 gt = this->GetGeomMatrix(GetModuleIndex(lay,lad,det));
868 gt->GetTranslation(t);
869 gt->GetAngles(r);
870 fprintf(fp,"%1.1d %2.2d %2.2d Trans=%f %f %f rot=%f %f %f Shape=%d\n",
871 lay,lad,det,t[0],t[1],t[2],r[0],r[1],r[2],
872 gt->GetDetectorIndex());
873 gt->GetMatrix(m);
874 fprintf(fp," dfr= %e %e %e\n",m[0][0],m[0][1],m[0][2]);
875 fprintf(fp," dfr= %e %e %e\n",m[1][0],m[1][1],m[1][2]);
876 fprintf(fp," dfr= %e %e %e\n",m[2][0],m[2][1],m[2][2]);
877 return;
58005f18 878}
85f1e34a 879//______________________________________________________________________
880ofstream & AliITSgeom::PrintGeom(ofstream &rb){
881 // Stream out an object of class AliITSgeom to standard output.
882 // Intputs are:
883 // ofstream &rb The output streaming buffer.
884 // Outputs are:
885 // ofstream &rb The output streaming buffer.
269f57ed 886 Int_t i;
593e9459 887
85f1e34a 888 rb.setf(ios::scientific);
889 rb << fTrans << " ";
890 rb << fNmodules << " ";
891 rb << fNlayers << " ";
892 for(i=0;i<fNlayers;i++) rb << fNlad[i] << " ";
893 for(i=0;i<fNlayers;i++) rb << fNdet[i] << "\n";
269f57ed 894 for(i=0;i<fNmodules;i++) {
85f1e34a 895 rb <<setprecision(16) << *(GetGeomMatrix(i)) << "\n";
269f57ed 896 } // end for i
164da35c 897 rb << fShape->GetEntries()<<endl;
898 for(i=0;i<fShape->GetEntries();i++) if(fShape->At(i)!=0) switch (i){
899 case kSPD:
900 rb << kSPD <<","<< (AliITSgeomSPD*)(fShape->At(kSPD));
901 break;
902 case kSDD:
903 rb << kSDD <<","<< (AliITSgeomSDD*)(fShape->At(kSDD));
904 break;
905 case kSSD:
906 rb << kSSD <<","<< (AliITSgeomSSD*)(fShape->At(kSSD));
907 break;
908 case kSSDp:
909 rb << kSSDp <<","<< (AliITSgeomSSD*)(fShape->At(kSSDp));
910 break;
911 case kSDDp:
912 rb << kSDDp <<","<< (AliITSgeomSDD*)(fShape->At(kSDDp));
913 break;
914 } // end for i / switch
85f1e34a 915 return rb;
593e9459 916}
85f1e34a 917//______________________________________________________________________
918ifstream & AliITSgeom::ReadGeom(ifstream &rb){
919 // Stream in an object of class AliITSgeom from standard input.
920 // Intputs are:
921 // ifstream &rb The input streaming buffer.
922 // Outputs are:
923 // ifstream &rb The input streaming buffer.
164da35c 924 Int_t i,j;
269f57ed 925
85f1e34a 926 fNlad = new Int_t[fNlayers];
927 fNdet = new Int_t[fNlayers];
928 if(fGm!=0){
929 for(i=0;i<fNmodules;i++) delete GetGeomMatrix(i);
930 delete fGm;
931 } // end if fGm!=0
932
933 rb >> fTrans >> fNmodules >> fNlayers;
934 fNlad = new Int_t[fNlayers];
935 fNdet = new Int_t[fNlayers];
936 for(i=0;i<fNlayers;i++) rb >> fNlad[i];
937 for(i=0;i<fNlayers;i++) rb >> fNdet[i];
938 fGm = new TObjArray(fNmodules,0);
939 for(i=0;i<fNmodules;i++){
940 fGm->AddAt(new AliITSgeomMatrix,i);
941 rb >> *(GetGeomMatrix(i));
942 } // end for i
164da35c 943 rb >> i;
944 fShape = new TObjArray(i);
945 for(i=0;i<fShape->GetEntries();i++) {
946 rb >> j;
947 switch (j){
948 case kSPD:{
949 AliITSgeomSPD *s = new AliITSgeomSPD();
950 rb >> *s;
951 fShape->AddAt(s,kSPD);}
952 break;
953 case kSDD:{
954 AliITSgeomSDD *s = new AliITSgeomSDD();
955 rb >> *s;
956 fShape->AddAt(s,kSDD);}
957 break;
958 case kSSD:{
959 AliITSgeomSSD *s = new AliITSgeomSSD();
960 rb >> *s;
961 fShape->AddAt(s,kSSD);}
962 break;
963 case kSSDp:{
964 AliITSgeomSSD *s = new AliITSgeomSSD();
965 rb >> *s;
966 fShape->AddAt(s,kSSDp);}
967 break;
968 case kSDDp:{
969 AliITSgeomSDD *s = new AliITSgeomSDD();
970 rb >> *s;
971 fShape->AddAt(s,kSDDp);}
972 break;
973 } // end switch
974 } // end for i
85f1e34a 975 return rb;
593e9459 976}
593e9459 977//______________________________________________________________________
269f57ed 978// The following routines modify the transformation of "this"
979// geometry transformations in a number of different ways.
593e9459 980//______________________________________________________________________
269f57ed 981void AliITSgeom::GlobalChange(const Float_t *tran,const Float_t *rot){
85f1e34a 982 // This function performs a Cartesian translation and rotation of
983 // the full ITS from its default position by an amount determined by
984 // the three element arrays tran and rot. If every element
985 // of tran and rot are zero then there is no change made
986 // the geometry. The change is global in that the exact same translation
987 // and rotation is done to every detector element in the exact same way.
988 // The units of the translation are those of the Monte Carlo, usually cm,
989 // and those of the rotation are in radians. The elements of tran
990 // are tran[0] = x, tran[1] = y, and tran[2] = z.
991 // The elements of rot are rot[0] = rx, rot[1] = ry, and
992 // rot[2] = rz. A change in x will move the hole ITS in the ALICE
993 // global x direction, the same for a change in y. A change in z will
994 // result in a translation of the ITS as a hole up or down the beam line.
995 // A change in the angles will result in the inclination of the ITS with
996 // respect to the beam line, except for an effective rotation about the
997 // beam axis which will just rotate the ITS as a hole about the beam axis.
998 // Intputs are:
999 // Float_t *tran A 3 element array representing the global translations.
1000 // the elements are x,y,z in cm.
1001 // Float_t *rot A 3 element array representing the global rotation
1002 // angles about the three axis x,y,z in radians
1003 // Outputs are:
1004 // none.
1005 Int_t i,j;
1006 Double_t t[3],r[3];
1007 AliITSgeomMatrix *g;
1008
1009 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
1010 for(i=0;i<fNmodules;i++){
1011 g = this->GetGeomMatrix(i);
1012 g->GetTranslation(t);
1013 g->GetAngles(r);
1014 for(j=0;j<3;j++){
1015 t[j] += tran[j];
1016 r[j] += rot[j];
1017 } // end for j
1018 g->SetTranslation(t);
1019 g->SetAngles(r);
1020 } // end for i
1021 return;
593e9459 1022}
85f1e34a 1023//______________________________________________________________________
1024void AliITSgeom::GlobalCylindericalChange(const Float_t *tran,
1025 const Float_t *rot){
1026 // This function performs a cylindrical translation and rotation of
1027 // each ITS element by a fixed about in radius, rphi, and z from its
1028 // default position by an amount determined by the three element arrays
1029 // tran and rot. If every element of tran and
1030 // rot are zero then there is no change made the geometry. The
1031 // change is global in that the exact same distance change in translation
1032 // and rotation is done to every detector element in the exact same way.
1033 // The units of the translation are those of the Monte Carlo, usually cm,
1034 // and those of the rotation are in radians. The elements of tran
1035 // are tran[0] = r, tran[1] = rphi, and tran[2] = z.
1036 // The elements of rot are rot[0] = rx, rot[1] = ry, and
1037 // rot[2] = rz. A change in r will results in the increase of the
1038 // radius of each layer by the same about. A change in rphi will results in
1039 // the rotation of each layer by a different angle but by the same
1040 // circumferential distance. A change in z will result in a translation
1041 // of the ITS as a hole up or down the beam line. A change in the angles
1042 // will result in the inclination of the ITS with respect to the beam
1043 // line, except for an effective rotation about the beam axis which will
1044 // just rotate the ITS as a hole about the beam axis.
1045 // Intputs are:
1046 // Float_t *tran A 3 element array representing the global translations.
1047 // the elements are r,theta,z in cm/radians.
1048 // Float_t *rot A 3 element array representing the global rotation
1049 // angles about the three axis x,y,z in radians
1050 // Outputs are:
1051 // none.
1052 Int_t i,j;
1053 Double_t t[3],ro[3],r,r0,phi,rphi;
1054 AliITSgeomMatrix *g;
1055
1056 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
1057 for(i=0;i<fNmodules;i++){
1058 g = this->GetGeomMatrix(i);
1059 g->GetTranslation(t);
1060 g->GetAngles(ro);
1061 r = r0= TMath::Hypot(t[1],t[0]);
1062 phi = TMath::ATan2(t[1],t[0]);
1063 rphi = r0*phi;
1064 r += tran[0];
1065 rphi += tran[1];
1066 phi = rphi/r0;
1067 t[0] = r*TMath::Cos(phi);
1068 t[1] = r*TMath::Sin(phi);
1069 t[2] += tran[2];
1070 for(j=0;j<3;j++){
1071 ro[j] += rot[j];
1072 } // end for j
1073 g->SetTranslation(t);
1074 g->SetAngles(ro);
1075 } // end for i
1076 return;
593e9459 1077}
85f1e34a 1078//______________________________________________________________________
269f57ed 1079void AliITSgeom::RandomChange(const Float_t *stran,const Float_t *srot){
85f1e34a 1080 // This function performs a Gaussian random displacement and/or
1081 // rotation about the present global position of each active
1082 // volume/detector of the ITS. The sigma of the random displacement
1083 // is determined by the three element array stran, for the
1084 // x y and z translations, and the three element array srot,
1085 // for the three rotation about the axis x y and z.
1086 // Intputs are:
1087 // Float_t *stran A 3 element array representing the global translations
1088 // variances. The elements are x,y,z in cm.
1089 // Float_t *srot A 3 element array representing the global rotation
1090 // angles variances about the three axis x,y,z in radians.
1091 // Outputs are:
1092 // none.
1093 Int_t i,j;
1094 Double_t t[3],r[3];
1095 AliITSgeomMatrix *g;
1096
1097 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
1098 for(i=0;i<fNmodules;i++){
1099 g = this->GetGeomMatrix(i);
1100 g->GetTranslation(t);
1101 g->GetAngles(r);
1102 for(j=0;j<3;j++){
1103 t[j] += gRandom->Gaus(0.0,stran[j]);
1104 r[j] += gRandom->Gaus(0.0, srot[j]);
1105 } // end for j
1106 g->SetTranslation(t);
1107 g->SetAngles(r);
1108 } // end for i
1109 return;
593e9459 1110}
85f1e34a 1111//______________________________________________________________________
269f57ed 1112void AliITSgeom::RandomCylindericalChange(const Float_t *stran,
1113 const Float_t *srot){
85f1e34a 1114 // This function performs a Gaussian random displacement and/or
1115 // rotation about the present global position of each active
1116 // volume/detector of the ITS. The sigma of the random displacement
1117 // is determined by the three element array stran, for the
1118 // r rphi and z translations, and the three element array srot,
1119 // for the three rotation about the axis x y and z. This random change
1120 // in detector position allow for the simulation of a random uncertainty
1121 // in the detector positions of the ITS.
1122 // Intputs are:
1123 // Float_t *stran A 3 element array representing the global translations
1124 // variances. The elements are r,theta,z in cm/readians.
1125 // Float_t *srot A 3 element array representing the global rotation
1126 // angles variances about the three axis x,y,z in radians.
1127 // Outputs are:
1128 // none.
1129 Int_t i,j;
1130 Double_t t[3],ro[3],r,r0,phi,rphi;
1131 TRandom ran;
1132 AliITSgeomMatrix *g;
1133
1134 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
1135 for(i=0;i<fNmodules;i++){
1136 g = this->GetGeomMatrix(i);
1137 g->GetTranslation(t);
1138 g->GetAngles(ro);
1139 r = r0= TMath::Hypot(t[1],t[0]);
1140 phi = TMath::ATan2(t[1],t[0]);
1141 rphi = r0*phi;
1142 r += ran.Gaus(0.0,stran[0]);
1143 rphi += ran.Gaus(0.0,stran[1]);
1144 phi = rphi/r0;
1145 t[0] = r*TMath::Cos(phi);
1146 t[1] = r*TMath::Sin(phi);
1147 t[2] += ran.Gaus(0.0,stran[2]);
1148 for(j=0;j<3;j++){
1149 ro[j] += ran.Gaus(0.0, srot[j]);
1150 } // end for j
1151 g->SetTranslation(t);
1152 g->SetAngles(ro);
1153 } // end for i
1154 return;
593e9459 1155}
1156//______________________________________________________________________
1157void AliITSgeom::GeantToTracking(AliITSgeom &source){
85f1e34a 1158 // Copy the geometry data but change it to go between the ALICE
1159 // Global coordinate system to that used by the ITS tracking. A slightly
1160 // different coordinate system is used when tracking. This coordinate
1161 // system is only relevant when the geometry represents the cylindrical
1162 // ALICE ITS geometry. For tracking the Z axis is left alone but X-> -Y
1163 // and Y-> X such that X always points out of the ITS cylinder for every
1164 // layer including layer 1 (where the detectors are mounted upside down).
1165 // Inputs are:
1166 // AliITSgeom &source The AliITSgeom class with which to make this
1167 // a copy of.
1168 // Outputs are:
1169 // return *this The a new copy of source.
1170 //Begin_Html
1171 /*
1172 <img src="picts/ITS/AliITSgeomMatrix_T1.gif">
1173 */
1174 //End_Html
1175 Int_t i,j,k,l,id[3];
1176 Double_t r0[3][3],r1[3][3];
1177 Double_t a0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
1178 Double_t a1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
1179
1180 *this = source; // copy everything
1181 for(i=0;i<GetIndexMax();i++){
1182 GetGeomMatrix(i)->GetIndex(id);
1183 GetGeomMatrix(i)->GetMatrix(r0);
1184 if(id[0]==1){ // Layer 1 is treated different from the others.
1185 for(j=0;j<3;j++) for(k=0;k<3;k++){
1186 r1[j][k] = 0.;
1187 for(l=0;l<3;l++) r1[j][k] += a0[j][l]*r0[l][k];
1188 } // end for j,k
1189 }else{
1190 for(j=0;j<3;j++) for(k=0;k<3;k++){
1191 r1[j][k] = 0.;
1192 for(l=0;l<3;l++) r1[j][k] += a1[j][l]*r0[l][k];
1193 } // end for j,k
1194 } // end if
1195 GetGeomMatrix(i)->SetMatrix(r1);
1196 } // end for i
1197 this->fTrans = (this->fTrans && 0xfffe) + 1; // set bit 0 true.
1198 return;
58005f18 1199}
269f57ed 1200//______________________________________________________________________
85f1e34a 1201Int_t AliITSgeom::GetNearest(const Double_t g[3],Int_t lay){
1202 // Finds the Detector (Module) that is nearest the point g [cm] in
1203 // ALICE Global coordinates. If layer !=0 then the search is restricted
1204 // to Detectors (Modules) in that particular layer.
1205 // Inputs are:
1206 // Double_t g[3] The ALICE Cartesean global coordinate from which the
1207 // distance is to be calculated with.
1208 // Int_t lay The layer to restrict the search to. If layer=0 then
1209 // all layers are searched. Default is lay=0.
1210 // Outputs are:
1211 // return The module number representing the nearest module.
1212 Int_t i,l,a,e,in=0;
1213 Double_t d,dn=1.0e10;
1214 Bool_t t=lay!=0; // skip if lay = 0 default value check all layers.
085bb6ed 1215
85f1e34a 1216 for(i=0;i<fNmodules;i++){
1217 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
1218 if((d=GetGeomMatrix(i)->Distance2(g))<dn){
1219 dn = d;
1220 in = i;
1221 } // end if
1222 } // end for i
1223 return in;
085bb6ed 1224}
269f57ed 1225//______________________________________________________________________
85f1e34a 1226void AliITSgeom::GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay){
1227 // Finds 27 Detectors (Modules) that are nearest the point g [cm] in
1228 // ALICE Global coordinates. If layer !=0 then the search is restricted
1229 // to Detectors (Modules) in that particular layer. The number 27 comes
1230 // from including the nearest detector and all those around it (up, down,
1231 // left, right, forwards, backwards, and the corners).
1232 // Inputs are:
1233 // Double_t g[3] The ALICE Cartesean global coordinate from which the
1234 // distance is to be calculated with.
1235 // Int_t lay The layer to restrict the search to. If layer=0 then
1236 // all layers are searched. Default is lay=0.
1237 // Outputs are:
1238 // Int_t n[27] The module number representing the nearest 27 modules
1239 // in order.
1240 Int_t i,l,a,e,in[27]={0,0,0,0,0,0,0,0,0,
1241 0,0,0,0,0,0,0,0,0,
1242 0,0,0,0,0,0,0,0,0,};
1243 Double_t d,dn[27]={1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1244 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1245 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1246 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1247 1.0e10,1.0e10,1.0e10};
1248 Bool_t t=(lay!=0); // skip if lay = 0 default value check all layers.
269f57ed 1249
85f1e34a 1250 for(i=0;i<fNmodules;i++){
1251 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
1252 for(a=0;a<27;a++){
1253 d = GetGeomMatrix(i)->Distance2(g);
1254 if(d<dn[a]){
1255 for(e=26;e>a;e--){dn[e] = dn[e-1];in[e] = in[e-1];}
1256 dn[a] = d; in[a] = i;
1257 } // end if d<dn[i]
1258 } // end for a
1259 } // end for i
1260 for(i=0;i<27;i++) n[i] = in[i];
269f57ed 1261}
1262//----------------------------------------------------------------------