1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////
19 // ITS geometry manipulation routines. //
20 // Created April 15 1999. //
22 // By: Bjorn S. Nilsen //
24 // Updated May 27 1999. //
25 // Added Cylindrical random and global based changes. //
26 // Added function PrintComparison. //
27 ///////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////////
31 // The local coordinate system by, default, is show in the following
32 // figures. Also shown are the ladder numbering scheme.
35 <img src="picts/ITS/AliITSgeomMatrix_L1.gif">
38 <font size=+2 color=blue>
39 <p>This shows the relative geometry differences between the ALICE Global
40 coordinate system and the local detector coordinate system.
45 <img src="picts/ITS/its1+2_convention_front_5.gif">
48 <font size=+2 color=blue>
49 <p>This shows the front view of the SPDs and the orientation of the local
50 pixel coordinate system. Note that the inner pixel layer has its y coordinate
51 in the opposite direction from all of the other layers.
56 <img src="picts/ITS/its3+4_convention_front_5.gif">
59 <font size=+2 color=blue>
60 <p>This shows the front view of the SDDs and the orientation of the local
61 pixel coordinate system.
66 <img src="picts/ITS/its5+6_convention_front_5.gif">
69 <font size=+2 color=blue>
70 <p>This shows the front view of the SSDs and the orientation of the local
71 pixel coordinate system.
77 ////////////////////////////////////////////////////////////////////////
79 ////////////////////////////////////////////////////////////////////////
82 // Written by Bjorn S. Nilsen
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.
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.
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.
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
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.
118 ////////////////////////////////////////////////////////////////////////
119 #include <Riostream.h>
120 //#include <stdlib.h>
122 //#include <string.h>
128 #include "AliITSgeom.h"
129 #include "AliITSgeomSPD.h"
130 #include "AliITSgeomSDD.h"
131 #include "AliITSgeomSSD.h"
135 //______________________________________________________________________
136 AliITSgeom::AliITSgeom(){
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.
141 fTrans = 0; // standard GEANT global/local coordinate system.
147 strcpy(fVersion,"test");
150 //______________________________________________________________________
151 AliITSgeom::AliITSgeom(Int_t itype,Int_t nlayers,Int_t *nlads,Int_t *ndets,
153 // A simple constructor to set basic geometry class variables
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.
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];}
177 fGm = new TObjArray(mods,0);
178 fShape = new TObjArray(5); // default value
179 for(i=0;i<5;i++) fShape->AddAt(0,i);
180 strcpy(fVersion,"test");
183 //______________________________________________________________________
184 void AliITSgeom::CreatMatrix(Int_t mod,Int_t lay,Int_t lad,Int_t det,
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.
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.
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].
207 Double_t r[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
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];
216 fGm->AddAt(new AliITSgeomMatrix(idet,id,r,tran),mod);
218 //______________________________________________________________________
219 AliITSgeom::~AliITSgeom(){
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.
227 //for(Int_t i=0;i<fNlayers;i++) delete fGm->At(i);
231 if(fNlad!=0) delete[] fNlad;
232 if(fNdet!=0) delete[] fNdet;
239 //______________________________________________________________________
240 void AliITSgeom::ReadNewFile(const char *filename){
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
251 // const char *filename The file name of the file to be read in.
255 const char *cmda[]={"Version" ,"fTrans" ,"fNmodules",
256 "fNlayers" ,"fNladers","fNdetectors",
257 "fNDetectorTypes","fShape" ,"Matrix"};
258 Int_t i,j,lNdetTypes,ldet;
260 AliITSgeomSPD *spd=0;
261 AliITSgeomSDD *sdd=0;
262 AliITSgeomSSD *ssd=0;
263 AliITSgeomMatrix *m=0;
267 filtmp = gSystem->ExpandPathName(filename);
268 cout << "AliITSgeom, Reading New .det file " << filtmp << endl;
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;}
276 if(c=='/'){for(;fp->get(c)!=NULL,c!='\n';);continue;}
279 for(;fp->get(c)!=NULL,c!='*';);
289 for(i=0;i<ncmd;i++) if(strcmp(cmd,cmda[i])==0) break;
300 for(j=0;j<fGm->GetEntriesFast();j++) delete fGm->At(j);
303 fGm = new TObjArray(fNmodules,0);
307 if(fNlad!=0) delete fNlad;
308 if(fNdet!=0) delete fNdet;
309 fNlad = new Int_t[fNlayers];
310 fNdet = new Int_t[fNlayers];
313 for(j=0;j<fNlayers;j++) *fp >> fNlad[j];
315 case 5: // fNdetectors
316 for(j=0;j<fNlayers;j++) *fp >> fNdet[j];
318 case 6: // fNDetectorTypes
321 for(j=0;j<fShape->GetEntriesFast();j++) delete fShape->At(j);
324 fShape = new TObjArray(lNdetTypes,0);
328 if(fShape==0) fShape = new TObjArray(5,0);
331 spd = new AliITSgeomSPD();
333 ReSetShape(ldet,spd);
336 case kSDD : case kSDDp:
337 sdd = new AliITSgeomSDD();
339 ReSetShape(ldet,sdd);
342 case kSSD : case kSSDp :
343 ssd = new AliITSgeomSSD();
345 ReSetShape(ldet,ssd);
349 Error("ReadNewFile","Unknown fShape type number=%d c=%c",ldet,c);
350 for(;fp->get(c)==NULL,c!='\n';); // skip to end of line.
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);
364 Error("ReadNewFile","Data line i=%d c=%c",i,c);
365 for(;fp->get(c)==NULL,c!='\n';); // skip this line
373 //______________________________________________________________________
374 void AliITSgeom::WriteNewFile(const char *filename){
375 // Writes AliITSgeom, AliITSgeomMatrix, and the defined AliITSgeomS*D
376 // classes to a file in a format that is more readable and commendable.
378 // const char *filename The file name of the file to be write to.
385 filtmp = gSystem->ExpandPathName(filename);
386 cout << "AliITSgeom, Writing New .det file " << filtmp << endl;
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;
394 *fp << ", kSSDp=" << (Int_t) kSSDp << ", and kSDDp=" << (Int_t) kSDDp;
396 *fp << "Version " << fVersion << endl;//This should be consistent with the
398 *fp << "fTrans " << fTrans << endl;
399 *fp << "fNmodules " << fNmodules << endl;
400 *fp << "fNlayers " << fNlayers << endl;
402 for(i=0;i<fNlayers;i++) *fp << fNlad[i] << " ";
404 *fp << "fNdetectors ";
405 for(i=0;i<fNlayers;i++) *fp << fNdet[i] << " ";
407 *fp << "fNDetectorTypes " << fShape->GetEntriesFast() << endl;
408 for(i=0;i<fShape->GetEntriesFast();i++){
409 if(!IsShapeDefined(i)) continue; // only print out used shapes.
412 *fp << "fShape " << (Int_t) kSPD << " ";
413 *fp << *((AliITSgeomSPD*)(fShape->At(i)));
416 *fp << "fShape " << (Int_t) kSDD << " ";
417 *fp << *((AliITSgeomSDD*)(fShape->At(i)));
419 case kSSD : case kSSDp :
420 *fp << "fShape " << i << " ";
421 *fp << *((AliITSgeomSSD*)(fShape->At(i)));
424 Error("AliITSgeom::WriteNewFile","Unknown Shape value");
427 for(i=0;i<fNmodules;i++){
428 *fp << "Matrix " << i << " ";
429 *fp << *GetGeomMatrix(i);
431 *fp << "//End of File" << endl;;
436 //______________________________________________________________________
437 AliITSgeom::AliITSgeom(const char *filename){
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.
441 // const char *filename The file name of the file to be read in.
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;
452 filtmp = gSystem->ExpandPathName(filename);
453 cout << "AliITSgeom reading old .det file " << filtmp << endl;
455 strcpy(fVersion,"DefauleV5");
456 pf = fopen(filtmp,"r");
458 fNlayers = 6; // set default number of ladders
460 fNlad = new Int_t[fNlayers];
461 fNdet = new Int_t[fNlayers];
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.
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.
475 delete[] fNlad;delete[] fNdet;
476 ReadNewFile(filename);
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);
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);
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
496 } // end if lm>fNlayers
497 // counted the number of ladders and detectors now allocate space.
498 fGm = new TObjArray(fNmodules,0);
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.
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);
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;
528 case 1: case 2: // layer 1 or2 SPD
529 fGm->AddAt(new AliITSgeomMatrix(rot6,kSPD,id,tran),lm++);
531 case 3: case 4: // layer 3 or 4 SDD
532 fGm->AddAt(new AliITSgeomMatrix(rot6,kSDD,id,tran),lm++);
534 case 5: case 6: // layer 5 or 6 SSD
535 fGm->AddAt(new AliITSgeomMatrix(rot6,kSSD,id,tran),lm++);
538 } // end while ever loop
541 //______________________________________________________________________
542 AliITSgeom::AliITSgeom(const AliITSgeom &source) : TObject(source){
543 // The copy constructor for the AliITSgeom class. It calls the
544 // = operator function. See the = operator function for more details.
546 // AliITSgeom &source The AliITSgeom class with which to make this
551 *this = source; // Just use the = operator for now.
554 //______________________________________________________________________
555 AliITSgeom& AliITSgeom::operator=(const 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.
562 // AliITSgeom &source The AliITSgeom class with which to make this
565 // return *this The a new copy of source.
568 if(this == &source) return *this; // don't assign to ones self.
570 // if there is an old structure allocated delete it first.
572 for(i=0;i<this->fNmodules;i++) delete this->fGm->At(i);
575 if(fNlad != 0) delete[] fNlad;
576 if(fNdet != 0) delete[] fNdet;
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.
586 this->fGm = new TObjArray(this->fNmodules,0);
587 for(i=0;i<this->fNmodules;i++){
588 this->fGm->AddAt(new AliITSgeomMatrix(*(
589 (AliITSgeomMatrix*)(source.fGm->At(i)))),i);
593 //______________________________________________________________________
594 Int_t AliITSgeom::GetModuleIndex(Int_t lay,Int_t lad,Int_t det){
595 // This routine computes the module index number from the layer,
596 // ladder, and detector numbers. The number of ladders and detectors
597 // per layer is determined when this geometry package is constructed,
598 // see AliITSgeom(const char *filename) for specifics.
600 // Int_t lay The layer number. Starting from 1.
601 // Int_t lad The ladder number. Starting from 1.
602 // Int_t det The detector number. Starting from 1.
604 // return the module index number, starting from zero.
607 i = fNdet[lay-1] * (lad-1) + det - 1;
609 for(k=0;k<lay-1;k++) j += fNdet[k]*fNlad[k];
611 if(i>=fNmodules) return -1;
612 GetGeomMatrix(i)->GetIndex(id);
613 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
614 // Array of modules fGm is not in expected order. Search for this index
615 for(i=0;i<fNmodules;i++){
616 GetGeomMatrix(i)->GetIndex(id);
617 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
619 // This layer ladder and detector combination does not exist return -1.
622 //______________________________________________________________________
623 void AliITSgeom::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det){
624 // This routine computes the layer, ladder and detector number
625 // given the module index number. The number of ladders and detectors
626 // per layer is determined when this geometry package is constructed,
627 // see AliITSgeom(const char *filename) for specifics.
629 // Int_t index The module index number, starting from zero.
631 // Int_t lay The layer number. Starting from 1.
632 // Int_t lad The ladder number. Starting from 1.
633 // Int_t det The detector number. Starting from 1.
635 AliITSgeomMatrix *g = GetGeomMatrix(index);
638 Error("GetModuleId","Can not get GeoMatrix for index = %d",index);
639 lay = -1; lad = -1; det = -1;
644 lay = id[0]; lad = id[1]; det = id[2];
648 // The old way kept for posterity.
652 for(k=0;k<fNlayers;k++){
653 j += fNdet[k]*fNlad[k];
657 i = index -j + fNdet[k]*fNlad[k];
659 for(k=0;k<fNlad[lay-1];k++){
664 det = 1+i-fNdet[lay-1]*k;
668 //______________________________________________________________________
669 Int_t AliITSgeom::GetStartDet(Int_t dtype){
670 // returns the starting module index value for a give type of detector id.
671 // This assumes that the detector types are different on different layers
672 // and that they are not mixed up.
674 // Int_t dtype A detector type number. 0 for SPD, 1 for SDD, and 2 for SSD.
676 // return the module index for the first occurance of that detector type.
680 return GetModuleIndex(1,1,1);
683 return GetModuleIndex(3,1,1);
686 return GetModuleIndex(5,1,1);
689 Warning("GetStartDet","undefined detector type %d",dtype);
693 Warning("GetStartDet","undefined detector type %d",dtype);
696 //______________________________________________________________________
697 Int_t AliITSgeom::GetLastDet(Int_t dtype){
698 // returns the last module index value for a give type of detector id.
699 // This assumes that the detector types are different on different layers
700 // and that they are not mixed up.
702 // Int_t dtype A detector type number. 0 for SPD, 1 for SDD, and 2 for SSD.
704 // return the module index for the last occurance of that detector type.
717 Warning("GetLastDet","undefined detector type %d",dtype);
721 Warning("GetLastDet","undefined detector type %d",dtype);
724 //______________________________________________________________________
725 void AliITSgeom::PrintComparison(FILE *fp,AliITSgeom *other){
726 // This function was primarily created for diagnostic reasons. It
727 // print to a file pointed to by the file pointer fp the difference
728 // between two AliITSgeom classes. The format of the file is basicly,
729 // define d? to be the difference between the same element of the two
730 // classes. For example dfrx = this->GetGeomMatrix(i)->frx
731 // - other->GetGeomMatrix(i)->frx.
732 // if(at least one of dfx0, dfy0, dfz0,dfrx,dfry,dfrz are non zero) then
733 // print layer ladder detector dfx0 dfy0 dfz0 dfrx dfry dfrz
734 // if(at least one of the 9 elements of dfr[] are non zero) then print
735 // layer ladder detector dfr[0] dfr[1] dfr[2]
736 // dfr[3] dfr[4] dfr[5]
737 // dfr[6] dfr[7] dfr[8]
738 // Only non zero values are printed to save space. The differences are
739 // typical written to a file because there are usually a lot of numbers
740 // printed out and it is usually easier to read them in some nice editor
741 // rather than zooming quickly past you on a screen. fprintf is used to
742 // do the printing. The fShapeIndex difference is not printed at this time.
744 // FILE *fp A file pointer to an opened file for writing in which
745 // the results of the comparison will be written.
746 // AliITSgeom *other The other AliITSgeom class to which this one is
750 Int_t i,j,idt[3],ido[3];
751 Double_t tt[3],to[3]; // translation
752 Double_t rt[3],ro[3]; // phi in radians
753 Double_t mt[3][3],mo[3][3]; // matrixes
754 AliITSgeomMatrix *gt,*go;
757 for(i=0;i<this->fNmodules;i++){
758 gt = this->GetGeomMatrix(i);
759 go = other->GetGeomMatrix(i);
763 for(i=0;i<3;i++) t = t&&idt[i]!=ido[i];
764 if(t) fprintf(fp,"%4.4d %1.1d %2.2d %2.2d %1.1d %2.2d %2.2d\n",i,
765 idt[0],idt[1],idt[2],ido[0],ido[1],ido[2]);
766 gt->GetTranslation(tt);
767 go->GetTranslation(to);
771 for(i=0;i<3;i++) t = t&&tt[i]!=to[i];
772 if(t) fprintf(fp,"%1.1d %2.2d %2.2d dTrans=%f %f %f drot=%f %f %f\n",
773 idt[0],idt[1],idt[2],
774 tt[0]-to[0],tt[1]-to[1],tt[2]-to[2],
775 rt[0]-ro[0],rt[1]-ro[1],rt[2]-ro[2]);
779 for(i=0;i<3;i++)for(j=0;j<3;j++) t = mt[i][j] != mo[i][j];
781 fprintf(fp,"%1.1d %2.2d %2.2d dfr= %e %e %e\n",
782 idt[0],idt[1],idt[2],
783 mt[0][0]-mo[0][0],mt[0][1]-mo[0][1],mt[0][2]-mo[0][2]);
784 fprintf(fp," dfr= %e %e %e\n",
785 mt[1][0]-mo[1][0],mt[1][1]-mo[1][1],mt[1][2]-mo[1][2]);
786 fprintf(fp," dfr= %e %e %e\n",
787 mt[2][0]-mo[2][0],mt[2][1]-mo[2][1],mt[2][2]-mo[2][2]);
792 //______________________________________________________________________
793 void AliITSgeom::PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det){
794 // This function prints out the coordinate transformations for
795 // the particular detector defined by layer, ladder, and detector
796 // to the file pointed to by the File pointer fp. fprintf statements
797 // are used to print out the numbers. The format is
798 // layer ladder detector Trans= fx0 fy0 fz0 rot= frx fry frz
800 // dfr= fr[0] fr[1] fr[2]
801 // dfr= fr[3] fr[4] fr[5]
802 // dfr= fr[6] fr[7] fr[8]
803 // By indicating which detector, some control over the information
804 // is given to the user. The output it written to the file pointed
805 // to by the file pointer fp. This can be set to stdout if you want.
807 // FILE *fp A file pointer to an opened file for writing in which
808 // the results of the comparison will be written.
809 // Int_t lay The layer number. Starting from 1.
810 // Int_t lad The ladder number. Starting from 1.
811 // Int_t det The detector number. Starting from 1.
814 AliITSgeomMatrix *gt;
815 Double_t t[3],r[3],m[3][3];
817 gt = this->GetGeomMatrix(GetModuleIndex(lay,lad,det));
818 gt->GetTranslation(t);
820 fprintf(fp,"%1.1d %2.2d %2.2d Trans=%f %f %f rot=%f %f %f Shape=%d\n",
821 lay,lad,det,t[0],t[1],t[2],r[0],r[1],r[2],
822 gt->GetDetectorIndex());
824 fprintf(fp," dfr= %e %e %e\n",m[0][0],m[0][1],m[0][2]);
825 fprintf(fp," dfr= %e %e %e\n",m[1][0],m[1][1],m[1][2]);
826 fprintf(fp," dfr= %e %e %e\n",m[2][0],m[2][1],m[2][2]);
829 //______________________________________________________________________
830 ofstream & AliITSgeom::PrintGeom(ofstream &rb){
831 // Stream out an object of class AliITSgeom to standard output.
833 // ofstream &rb The output streaming buffer.
835 // ofstream &rb The output streaming buffer.
838 rb.setf(ios::scientific);
840 rb << fNmodules << " ";
841 rb << fNlayers << " ";
842 for(i=0;i<fNlayers;i++) rb << fNlad[i] << " ";
843 for(i=0;i<fNlayers;i++) rb << fNdet[i] << "\n";
844 for(i=0;i<fNmodules;i++) {
845 rb <<setprecision(16) << *(GetGeomMatrix(i)) << "\n";
847 rb << fShape->GetEntries()<<endl;
848 for(i=0;i<fShape->GetEntries();i++) if(fShape->At(i)!=0) switch (i){
850 rb << kSPD <<","<< (AliITSgeomSPD*)(fShape->At(kSPD));
853 rb << kSDD <<","<< (AliITSgeomSDD*)(fShape->At(kSDD));
856 rb << kSSD <<","<< (AliITSgeomSSD*)(fShape->At(kSSD));
859 rb << kSSDp <<","<< (AliITSgeomSSD*)(fShape->At(kSSDp));
862 rb << kSDDp <<","<< (AliITSgeomSDD*)(fShape->At(kSDDp));
864 } // end for i / switch
867 //______________________________________________________________________
868 ifstream & AliITSgeom::ReadGeom(ifstream &rb){
869 // Stream in an object of class AliITSgeom from standard input.
871 // ifstream &rb The input streaming buffer.
873 // ifstream &rb The input streaming buffer.
876 fNlad = new Int_t[fNlayers];
877 fNdet = new Int_t[fNlayers];
879 for(i=0;i<fNmodules;i++) delete GetGeomMatrix(i);
883 rb >> fTrans >> fNmodules >> fNlayers;
884 fNlad = new Int_t[fNlayers];
885 fNdet = new Int_t[fNlayers];
886 for(i=0;i<fNlayers;i++) rb >> fNlad[i];
887 for(i=0;i<fNlayers;i++) rb >> fNdet[i];
888 fGm = new TObjArray(fNmodules,0);
889 for(i=0;i<fNmodules;i++){
890 fGm->AddAt(new AliITSgeomMatrix,i);
891 rb >> *(GetGeomMatrix(i));
894 fShape = new TObjArray(i);
895 for(i=0;i<fShape->GetEntries();i++) {
899 AliITSgeomSPD *s = new AliITSgeomSPD();
901 fShape->AddAt(s,kSPD);}
904 AliITSgeomSDD *s = new AliITSgeomSDD();
906 fShape->AddAt(s,kSDD);}
909 AliITSgeomSSD *s = new AliITSgeomSSD();
911 fShape->AddAt(s,kSSD);}
914 AliITSgeomSSD *s = new AliITSgeomSSD();
916 fShape->AddAt(s,kSSDp);}
919 AliITSgeomSDD *s = new AliITSgeomSDD();
921 fShape->AddAt(s,kSDDp);}
927 //______________________________________________________________________
928 // The following routines modify the transformation of "this"
929 // geometry transformations in a number of different ways.
930 //______________________________________________________________________
931 void AliITSgeom::GlobalChange(const Float_t *tran,const Float_t *rot){
932 // This function performs a Cartesian translation and rotation of
933 // the full ITS from its default position by an amount determined by
934 // the three element arrays tran and rot. If every element
935 // of tran and rot are zero then there is no change made
936 // the geometry. The change is global in that the exact same translation
937 // and rotation is done to every detector element in the exact same way.
938 // The units of the translation are those of the Monte Carlo, usually cm,
939 // and those of the rotation are in radians. The elements of tran
940 // are tran[0] = x, tran[1] = y, and tran[2] = z.
941 // The elements of rot are rot[0] = rx, rot[1] = ry, and
942 // rot[2] = rz. A change in x will move the hole ITS in the ALICE
943 // global x direction, the same for a change in y. A change in z will
944 // result in a translation of the ITS as a hole up or down the beam line.
945 // A change in the angles will result in the inclination of the ITS with
946 // respect to the beam line, except for an effective rotation about the
947 // beam axis which will just rotate the ITS as a hole about the beam axis.
949 // Float_t *tran A 3 element array representing the global translations.
950 // the elements are x,y,z in cm.
951 // Float_t *rot A 3 element array representing the global rotation
952 // angles about the three axis x,y,z in radians
959 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
960 for(i=0;i<fNmodules;i++){
961 g = this->GetGeomMatrix(i);
962 g->GetTranslation(t);
968 g->SetTranslation(t);
973 //______________________________________________________________________
974 void AliITSgeom::GlobalCylindericalChange(const Float_t *tran,
976 // This function performs a cylindrical translation and rotation of
977 // each ITS element by a fixed about in radius, rphi, and z from its
978 // default position by an amount determined by the three element arrays
979 // tran and rot. If every element of tran and
980 // rot are zero then there is no change made the geometry. The
981 // change is global in that the exact same distance change in translation
982 // and rotation is done to every detector element in the exact same way.
983 // The units of the translation are those of the Monte Carlo, usually cm,
984 // and those of the rotation are in radians. The elements of tran
985 // are tran[0] = r, tran[1] = rphi, and tran[2] = z.
986 // The elements of rot are rot[0] = rx, rot[1] = ry, and
987 // rot[2] = rz. A change in r will results in the increase of the
988 // radius of each layer by the same about. A change in rphi will results in
989 // the rotation of each layer by a different angle but by the same
990 // circumferential distance. A change in z will result in a translation
991 // of the ITS as a hole up or down the beam line. A change in the angles
992 // will result in the inclination of the ITS with respect to the beam
993 // line, except for an effective rotation about the beam axis which will
994 // just rotate the ITS as a hole about the beam axis.
996 // Float_t *tran A 3 element array representing the global translations.
997 // the elements are r,theta,z in cm/radians.
998 // Float_t *rot A 3 element array representing the global rotation
999 // angles about the three axis x,y,z in radians
1003 Double_t t[3],ro[3],r,r0,phi,rphi;
1004 AliITSgeomMatrix *g;
1006 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
1007 for(i=0;i<fNmodules;i++){
1008 g = this->GetGeomMatrix(i);
1009 g->GetTranslation(t);
1011 r = r0= TMath::Hypot(t[1],t[0]);
1012 phi = TMath::ATan2(t[1],t[0]);
1017 t[0] = r*TMath::Cos(phi);
1018 t[1] = r*TMath::Sin(phi);
1023 g->SetTranslation(t);
1028 //______________________________________________________________________
1029 void AliITSgeom::RandomChange(const Float_t *stran,const Float_t *srot){
1030 // This function performs a Gaussian random displacement and/or
1031 // rotation about the present global position of each active
1032 // volume/detector of the ITS. The sigma of the random displacement
1033 // is determined by the three element array stran, for the
1034 // x y and z translations, and the three element array srot,
1035 // for the three rotation about the axis x y and z.
1037 // Float_t *stran A 3 element array representing the global translations
1038 // variances. The elements are x,y,z in cm.
1039 // Float_t *srot A 3 element array representing the global rotation
1040 // angles variances about the three axis x,y,z in radians.
1045 AliITSgeomMatrix *g;
1047 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
1048 for(i=0;i<fNmodules;i++){
1049 g = this->GetGeomMatrix(i);
1050 g->GetTranslation(t);
1053 t[j] += gRandom->Gaus(0.0,stran[j]);
1054 r[j] += gRandom->Gaus(0.0, srot[j]);
1056 g->SetTranslation(t);
1061 //______________________________________________________________________
1062 void AliITSgeom::RandomCylindericalChange(const Float_t *stran,
1063 const Float_t *srot){
1064 // This function performs a Gaussian random displacement and/or
1065 // rotation about the present global position of each active
1066 // volume/detector of the ITS. The sigma of the random displacement
1067 // is determined by the three element array stran, for the
1068 // r rphi and z translations, and the three element array srot,
1069 // for the three rotation about the axis x y and z. This random change
1070 // in detector position allow for the simulation of a random uncertainty
1071 // in the detector positions of the ITS.
1073 // Float_t *stran A 3 element array representing the global translations
1074 // variances. The elements are r,theta,z in cm/readians.
1075 // Float_t *srot A 3 element array representing the global rotation
1076 // angles variances about the three axis x,y,z in radians.
1080 Double_t t[3],ro[3],r,r0,phi,rphi;
1082 AliITSgeomMatrix *g;
1084 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
1085 for(i=0;i<fNmodules;i++){
1086 g = this->GetGeomMatrix(i);
1087 g->GetTranslation(t);
1089 r = r0= TMath::Hypot(t[1],t[0]);
1090 phi = TMath::ATan2(t[1],t[0]);
1092 r += ran.Gaus(0.0,stran[0]);
1093 rphi += ran.Gaus(0.0,stran[1]);
1095 t[0] = r*TMath::Cos(phi);
1096 t[1] = r*TMath::Sin(phi);
1097 t[2] += ran.Gaus(0.0,stran[2]);
1099 ro[j] += ran.Gaus(0.0, srot[j]);
1101 g->SetTranslation(t);
1106 //______________________________________________________________________
1107 void AliITSgeom::GeantToTracking(AliITSgeom &source){
1108 // Copy the geometry data but change it to go between the ALICE
1109 // Global coordinate system to that used by the ITS tracking. A slightly
1110 // different coordinate system is used when tracking. This coordinate
1111 // system is only relevant when the geometry represents the cylindrical
1112 // ALICE ITS geometry. For tracking the Z axis is left alone but X-> -Y
1113 // and Y-> X such that X always points out of the ITS cylinder for every
1114 // layer including layer 1 (where the detectors are mounted upside down).
1116 // AliITSgeom &source The AliITSgeom class with which to make this
1119 // return *this The a new copy of source.
1122 <img src="picts/ITS/AliITSgeomMatrix_T1.gif">
1125 Int_t i,j,k,l,id[3];
1126 Double_t r0[3][3],r1[3][3];
1127 Double_t a0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
1128 Double_t a1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
1130 *this = source; // copy everything
1131 for(i=0;i<GetIndexMax();i++){
1132 GetGeomMatrix(i)->GetIndex(id);
1133 GetGeomMatrix(i)->GetMatrix(r0);
1134 if(id[0]==1){ // Layer 1 is treated different from the others.
1135 for(j=0;j<3;j++) for(k=0;k<3;k++){
1137 for(l=0;l<3;l++) r1[j][k] += a0[j][l]*r0[l][k];
1140 for(j=0;j<3;j++) for(k=0;k<3;k++){
1142 for(l=0;l<3;l++) r1[j][k] += a1[j][l]*r0[l][k];
1145 GetGeomMatrix(i)->SetMatrix(r1);
1147 this->fTrans = (this->fTrans && 0xfffe) + 1; // set bit 0 true.
1150 //______________________________________________________________________
1151 Int_t AliITSgeom::GetNearest(const Double_t g[3],Int_t lay){
1152 // Finds the Detector (Module) that is nearest the point g [cm] in
1153 // ALICE Global coordinates. If layer !=0 then the search is restricted
1154 // to Detectors (Modules) in that particular layer.
1156 // Double_t g[3] The ALICE Cartesean global coordinate from which the
1157 // distance is to be calculated with.
1158 // Int_t lay The layer to restrict the search to. If layer=0 then
1159 // all layers are searched. Default is lay=0.
1161 // return The module number representing the nearest module.
1163 Double_t d,dn=1.0e10;
1164 Bool_t t=lay!=0; // skip if lay = 0 default value check all layers.
1166 for(i=0;i<fNmodules;i++){
1167 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
1168 if((d=GetGeomMatrix(i)->Distance2(g))<dn){
1175 //______________________________________________________________________
1176 void AliITSgeom::GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay){
1177 // Finds 27 Detectors (Modules) that are nearest the point g [cm] in
1178 // ALICE Global coordinates. If layer !=0 then the search is restricted
1179 // to Detectors (Modules) in that particular layer. The number 27 comes
1180 // from including the nearest detector and all those around it (up, down,
1181 // left, right, forwards, backwards, and the corners).
1183 // Double_t g[3] The ALICE Cartesean global coordinate from which the
1184 // distance is to be calculated with.
1185 // Int_t lay The layer to restrict the search to. If layer=0 then
1186 // all layers are searched. Default is lay=0.
1188 // Int_t n[27] The module number representing the nearest 27 modules
1190 Int_t i,l,a,e,in[27]={0,0,0,0,0,0,0,0,0,
1192 0,0,0,0,0,0,0,0,0,};
1193 Double_t d,dn[27]={1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1194 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1195 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1196 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1197 1.0e10,1.0e10,1.0e10};
1198 Bool_t t=(lay!=0); // skip if lay = 0 default value check all layers.
1200 for(i=0;i<fNmodules;i++){
1201 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
1203 d = GetGeomMatrix(i)->Distance2(g);
1205 for(e=26;e>a;e--){dn[e] = dn[e-1];in[e] = in[e-1];}
1206 dn[a] = d; in[a] = i;
1210 for(i=0;i<27;i++) n[i] = in[i];
1212 //----------------------------------------------------------------------