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 Revision 1.15 2001/02/07 20:23:21 nilsen
19 Fixed bug with HP and no unget in iostream.h. Now using putback instead.
20 Other changes and fixes also included.
22 Revision 1.14 2001/02/03 00:00:29 nilsen
23 New version of AliITSgeom and related files. Now uses automatic streamers,
24 set up for new formatted .det file which includes detector information.
25 Additional smaller modifications are still to come.
27 Revision 1.11 2000/10/02 16:32:35 barbera
28 Forward declaration added
30 Revision 1.4.4.15 2000/10/02 15:52:05 barbera
31 Forward declaration added
33 Revision 1.10 2000/09/05 14:25:50 nilsen
34 Made fixes for HP compiler. All function parameter default values placed
35 in .h file. Fixed the usual problem with HP comilers and the "for(Int_t i..."
36 business. Replaced casting (Double_t [3][3]) to (Double_t (*)[3]) for HP.
37 Lastly removed all "const" before function parameters which were 2 dim. arrays,
38 because on HP root generates some strange code (?). Thanks Peter for the
41 Revision 1.9 2000/08/29 20:19:03 nilsen
42 Removed dependancy on structure AliITSeomS and replaced it with class
43 AliITSgeomMatrix. Added many new functions with many new arguments. Most
44 in the form of in line functions for speed.
46 Revision 1.4.4.6 2000/06/04 16:33:32 Nilsen
47 A restructured AliITSgeom class. Now used AliITSgeomMatrix.
49 Revision 1.4.4.5 2000/03/04 23:42:39 Nilsen
50 Updated the comments/documentations and improved the maintainability of the
53 Revision 1.4.4.4 2000/03/02 21:27:07 Nilsen
54 Added two functions, SetByAngles and SetTrans.
56 Revision 1.4.4.3 2000/01/23 03:09:10 Nilsen
57 // fixed compiler warnings for new function LtLErrorMatrix(...)
59 Revision 1.4.4.2 2000/01/19 23:18:20 Nilsen
60 Added transformations of Error matrix to AliITSgeom and fixed some typos
61 in AliITS.h and AliITShitIndex.h
63 Revision 1.4.4.1 2000/01/12 19:03:32 Nilsen
64 This is the version of the files after the merging done in December 1999.
65 See the ReadMe110100.txt file for details
67 Revision 1.4 1999/10/15 07:03:20 fca
68 Fixed bug in GetModuleId(Int_t index,Int_t &lay,Int_t &lad, Int_t &det) and
69 a typo in the creator. aliroot need to be rerun to get a fixed geometry.
71 Revision 1.3 1999/10/04 15:20:12 fca
72 Correct syntax accepted by g++ but not standard for static members, remove minor warnings
74 Revision 1.2 1999/09/29 09:24:20 fca
75 Introduction of the Copyright and cvs Log
79 ///////////////////////////////////////////////////////////////////////
80 // ITS geometry manipulation routines. //
81 // Created April 15 1999. //
83 // By: Bjorn S. Nilsen //
85 // Updated May 27 1999. //
86 // Added Cylindrical random and global based changes. //
87 // Added function PrintComparison. //
88 ///////////////////////////////////////////////////////////////////////
91 ////////////////////////////////////////////////////////////////////////
92 // The local coordinate system by, default, is show in the following
93 // figures. Also shown are the ladder numbering scheme.
96 <img src="picts/ITS/AliITSgeomMatrix_L1.gif">
99 <font size=+2 color=blue>
100 <p>This shows the relative geometry differences between the ALICE Global
101 coordinate system and the local detector coordinate system.
106 <img src="picts/ITS/its1+2_convention_front_5.gif">
109 <font size=+2 color=blue>
110 <p>This shows the front view of the SPDs and the orientation of the local
111 pixel coordinate system. Note that the inner pixel layer has its y coordinate
112 in the opposite direction from all of the other layers.
117 <img src="picts/ITS/its3+4_convention_front_5.gif">
120 <font size=+2 color=blue>
121 <p>This shows the front view of the SDDs and the orientation of the local
122 pixel coordinate system.
127 <img src="picts/ITS/its5+6_convention_front_5.gif">
130 <font size=+2 color=blue>
131 <p>This shows the front view of the SSDs and the orientation of the local
132 pixel coordinate system.
138 ////////////////////////////////////////////////////////////////////////
140 ////////////////////////////////////////////////////////////////////////
143 // Written by Bjorn S. Nilsen
148 // The number of ITS layers for this geometry. By default this
149 // is 6, but can be modified by the creator function if there are
150 // more layers defined.
153 // A pointer to an array fNlayers long containing the number of
154 // ladders for each layer. This array is typically created and filled
155 // by the AliITSgeom creator function.
158 // A pointer to an array fNlayers long containing the number of
159 // active detector volumes for each ladder. This array is typically
160 // created and filled by the AliITSgeom creator function.
162 // AliITSgeomMatrix *fGm
163 // A pointer to an array of AliITSgeomMatrix classes. One element
164 // per module (detector) in the ITS. AliITSgeomMatrix basicly contains
165 // all of the necessary information about the detector and it's coordinate
169 // A pointer to an array of TObjects containing the detailed shape
170 // information for each type of detector used in the ITS. For example
171 // I have created AliITSgeomSPD, AliITSgeomSDD, and AliITSgeomSSD as
172 // example structures, derived from TObjects, to hold the detector
173 // information. I would recommend that one element in each of these
174 // structures, that which describes the shape of the active volume,
175 // be one of the ROOT classes derived from TShape. In this way it would
176 // be easy to have the display program display the correct active
177 // ITS volumes. See the example classes AliITSgeomSPD, AliITSgeomSDD,
178 // and AliITSgeomSSD for a more detailed example.
179 ////////////////////////////////////////////////////////////////////////
180 #include <iostream.h>
193 #include "AliITSgeom.h"
194 //#include "AliITSgeomMatrix.h" // include in AliITSgeom.h
195 #include "AliITSgeomSPD.h"
196 #include "AliITSgeomSDD.h"
197 #include "AliITSgeomSSD.h"
201 //_____________________________________________________________________
202 AliITSgeom::AliITSgeom(){
203 ////////////////////////////////////////////////////////////////////////
204 // The default constructor for the AliITSgeom class. It, by default,
205 // sets fNlayers to zero and zeros all pointers.
206 ////////////////////////////////////////////////////////////////////////
207 // Default constructor.
208 // Do not allocate anything zero everything
209 fTrans = 0; // standard GEANT global/local coordinate system.
215 strcpy(fVersion,"test");
218 //_____________________________________________________________________
219 AliITSgeom::AliITSgeom(Int_t itype,Int_t nlayers,Int_t *nlads,Int_t *ndets,
221 ////////////////////////////////////////////////////////////////////////
222 // A simple constructor to set basic geometry class variables
224 // itype the type of transofmation kept.
225 // 0 => Standard Geant
226 // bit 1 => ITS tracking
227 // bit 2 => A change in the coordiante system has been made.
228 // others are still to be defined as needed.
229 // nlayers The number of ITS layers also set the size of the arrays
230 // *nlads an array of the number of ladders for each layer
231 // *ndets an array of the number of detectors per ladder for each layer.
232 ////////////////////////////////////////////////////////////////////////
237 fNlad = new Int_t[nlayers];
238 fNdet = new Int_t[nlayers];
239 for(i=0;i<nlayers;i++){fNlad[i] = nlads[i];fNdet[i] = ndets[i];}
241 fGm = new TObjArray(mods,0);
242 fShape = new TObjArray(5); // default value
243 for(i=0;i<5;i++) fShape->AddAt(0,i);
244 strcpy(fVersion,"test");
247 //______________________________________________________________________
248 void AliITSgeom::CreatMatrix(Int_t mod,Int_t lay,Int_t lad,Int_t det,
249 AliITSDetector idet,Double_t tran[3],
252 Double_t r[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
254 if(fGm->At(mod)!=0) delete fGm->At(mod);
255 id[0] = lay; id[1] = lad; id[2] = det;
256 if(rot[9]!=0.0) { // null rotation
257 r[0][0] = rot[0]; r[0][1] = rot[1]; r[0][2] = rot[2];
258 r[1][0] = rot[3]; r[1][1] = rot[4]; r[1][2] = rot[5];
259 r[2][0] = rot[6]; r[2][1] = rot[7]; r[2][2] = rot[8];
261 fGm->AddAt(new AliITSgeomMatrix(idet,id,r,tran),mod);
263 //_____________________________________________________________________
264 AliITSgeom::~AliITSgeom(){
265 ////////////////////////////////////////////////////////////////////////
266 // The destructor for the AliITSgeom class. If the arrays fNlad,
267 // fNdet, or fGm have had memory allocated to them, there pointer values
268 // are non zero, then this memory space is freed and they are set
269 // to zero. In addition, fNlayers is set to zero. The destruction of
270 // TObjArray fShape is, by default, handled by the TObjArray destructor.
271 ////////////////////////////////////////////////////////////////////////
272 // Default destructor.
273 // if arrays exist delete them. Then set everything to zero.
275 for(Int_t i=0;i<fNlayers;i++) delete fGm->At(i);
278 if(fNlad!=0) delete[] fNlad;
279 if(fNdet!=0) delete[] fNdet;
286 //______________________________________________________________________
287 void AliITSgeom::ReadNewFile(const char *filename){
289 const char *cmda[]={"Version" ,"fTrans" ,"fNmodules",
290 "fNlayers" ,"fNladers","fNdetectors",
291 "fNDetectorTypes","fShape" ,"Matrix"};
292 Int_t i,j,lNdetTypes,ldet;
301 filtmp = gSystem->ExpandPathName(filename);
302 cout << "AliITSgeom, Reading New .det file " << filtmp << endl;
303 fp = new ifstream(filtmp,ios::in); // open file to write
304 while(fp->get(c)!=NULL){ // for ever loop
305 if(c==' ') continue; // remove blanks
306 if(c=='\n') continue;
307 if(c=='#' || c=='!'){for(;fp->get(c)!=NULL,c!='\n';); continue;}
310 if(c=='/'){for(;fp->get(c)!=NULL,c!='\n';);continue;}
313 for(;fp->get(c)!=NULL,c!='*';);
324 for(i=0;i<ncmd;i++) if(strcmp(cmd,cmda[i])==0) break;
335 for(j=0;j<fGm->GetEntriesFast();j++) delete fGm->At(j);
338 fGm = new TObjArray(fNmodules,0);
342 if(fNlad!=0) delete fNlad;
343 if(fNdet!=0) delete fNdet;
344 fNlad = new Int_t[fNlayers];
345 fNdet = new Int_t[fNlayers];
348 for(j=0;j<fNlayers;j++) *fp >> fNlad[j];
350 case 5: // fNdetectors
351 for(j=0;j<fNlayers;j++) *fp >> fNdet[j];
353 case 6: // fNDetectorTypes
356 for(j=0;j<fShape->GetEntriesFast();j++) delete fShape->At(j);
359 fShape = new TObjArray(lNdetTypes,0);
363 if(fShape==0) fShape = new TObjArray(5,0);
366 ReSetShape(ldet,(TObject*) new AliITSgeomSPD());
367 spd = (AliITSgeomSPD*) (fShape->At(ldet));
372 ReSetShape(ldet,(TObject*) new AliITSgeomSDD());
373 sdd = (AliITSgeomSDD*) (fShape->At(ldet));
377 case kSSD : case kSSDp :
378 ReSetShape(ldet,(TObject*) new AliITSgeomSSD());
379 ssd = (AliITSgeomSSD*) (fShape->At(ldet));
384 Error("ReadNewFile","Unknown fShape type number=%d c=%c",ldet,c);
385 for(;fp->get(c)==NULL,c!='\n';); // skip to end of line.
391 if(fGm==0) fGm = new TObjArray(2270,0);
392 if(fGm->At(ldet)!=0) delete (fGm->At(ldet));
393 fGm->AddAt((TObject*)new AliITSgeomMatrix(),ldet);
394 m = (AliITSgeomMatrix*) fGm->At(ldet);
399 Error("ReadNewFile","Data line i=%d c=%c",i,c);
400 for(;fp->get(c)==NULL,c!='\n';); // skip this line
408 //______________________________________________________________________
409 void AliITSgeom::WriteNewFile(const char *filename){
410 // Writes AliITSgeom, AliITSgeomMatrix, and the defined AliITSgeomS*D classes
411 // to a file in a format that is more readable and commentable.
416 filtmp = gSystem->ExpandPathName(filename);
417 cout << "AliITSgeom, Writing New .det file " << filtmp << endl;
418 fp = new ofstream(filtmp,ios::out); // open file to write
419 *fp << "//Comment lines begin with two //, one #, or one !" << endl;
420 *fp << "#Blank lines are skipped including /* and */ sections." << endl;
421 *fp << "!and, in principle the order of the lines is not important" <<endl;
422 *fp << "/* In AliITSgeom.h are defined an enumerated type called" << endl;
423 *fp << " AliITSDetectors These are kSPD=" << (Int_t) kSPD ;
424 *fp << ", kSDD=" << (Int_t) kSDD << ", kSSD=" << (Int_t) kSSD;
425 *fp << ", kSSDp=" << (Int_t) kSSDp << ", and kSDDp=" << (Int_t) kSDDp;
427 *fp << "Version " << fVersion << endl;//This should be consistant with the
429 *fp << "fTrans " << fTrans << endl;
430 *fp << "fNmodules " << fNmodules << endl;
431 *fp << "fNlayers " << fNlayers << endl;
433 for(i=0;i<fNlayers;i++) *fp << fNlad[i] << " ";
435 *fp << "fNdetectors ";
436 for(i=0;i<fNlayers;i++) *fp << fNdet[i] << " ";
438 *fp << "fNDetectorTypes " << fShape->GetEntriesFast() << endl;
439 for(i=0;i<fShape->GetEntriesFast();i++){
440 if(!IsShapeDefined(i)) continue; // only print out used shapes.
443 *fp << "fShape " << (Int_t) kSPD << " ";
444 *fp << *((AliITSgeomSPD*)(fShape->At(i)));
447 *fp << "fShape " << (Int_t) kSDD << " ";
448 *fp << *((AliITSgeomSDD*)(fShape->At(i)));
450 case kSSD : case kSSDp :
451 *fp << "fShape " << i << " ";
452 *fp << *((AliITSgeomSSD*)(fShape->At(i)));
455 Error("AliITSgeom::WriteNewFile","Unknown Shape value");
458 for(i=0;i<fNmodules;i++){
459 *fp << "Matrix " << i << " ";
460 *fp << *GetGeomMatrix(i);
462 *fp << "//End of File" << endl;;
467 //_____________________________________________________________________
468 AliITSgeom::AliITSgeom(const char *filename){
469 ////////////////////////////////////////////////////////////////////////
470 // The constructor for the AliITSgeom class. All of the data to fill
471 // this structure is read in from the file given my the input filename.
472 ////////////////////////////////////////////////////////////////////////
476 Float_t x,y,z,o,p,q,r,s,t;
477 Double_t rot6[6],tran[3];
478 char buf[200],*buff=0; // input character buffer;
481 filtmp = gSystem->ExpandPathName(filename);
482 cout << "AliITSgeom reading old .det file " << filtmp << endl;
484 strcpy(fVersion,"DefauleV5");
485 pf = fopen(filtmp,"r");
487 fNlayers = 6; // set default number of ladders
489 fNlad = new Int_t[fNlayers];
490 fNdet = new Int_t[fNlayers];
492 // find the number of ladders and detectors in this geometry.
493 for(i=0;i<fNlayers;i++){fNlad[i]=fNdet[i]=0;} // zero out arrays
494 while(fgets(buf,200,pf)!=NULL){ // for ever loop
495 for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces.
499 // remove blank lines and comments.
500 if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'||
501 (buff[0]=='/'&&buff[1]=='/')) continue;
502 if(isalpha(buff[0])) { // must be the new file formated file.
504 delete[] fNlad;delete[] fNdet;
505 ReadNewFile(filename);
507 } // end if isalpha(buff[0])
508 sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f",
509 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
511 if(l<1 || l>fNlayers) {
512 printf("error in file %s layer=%d min. is 1 max is %d\n",
513 filename,l,fNlayers);
517 if(l<=fNlayers&&fNlad[l-1]<a) fNlad[l-1] = a;
518 if(l<=fNlayers&&fNdet[l-1]<d) fNdet[l-1] = d;
519 } // end while ever loop
525 } // end if lm>fNlayers
526 // counted the number of ladders and detectors now allocate space.
527 fGm = new TObjArray(fNmodules,0);
529 // Set up Shapes for a default configuration of 6 layers.
530 fTrans = 0; // standard GEANT global/local coordinate system.
531 // prepare to read in transforms
532 lm = 0; // reuse lm as counter of modules.
533 rewind(pf); // start over reading file
534 while(fgets(buf,200,pf)!=NULL){ // for ever loop
535 for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces.
539 // remove blank lines and comments.
540 if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'||
541 (buff[0]=='/'&&buff[1]=='/')) continue;
542 x = y = z = o = p = q = r = s = t = 0.0;
543 sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f",
544 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
545 if(l<1 || l>fNlayers) {
546 printf("error in file %s layer=%d min. is 1 max is %d/n",
547 filename,l,fNlayers);
550 id[0] = l;id[1] = a;id[2] = d;
551 tran[0] = tran[1] = tran[2] = 0.0;
552 tran[0] = (Double_t)x;tran[1] = (Double_t)y;tran[2] = (Double_t)z;
553 rot6[0] = rot6[1] = rot6[2] = rot6[3] = rot6[4] = rot6[5] =0.0;
554 rot6[0] = (Double_t)o;rot6[1] = (Double_t)p;rot6[2] = (Double_t)q;
555 rot6[3] = (Double_t)r;rot6[4] = (Double_t)s;rot6[5] = (Double_t)t;
557 case 1: case 2: // layer 1 or2 SPD
558 fGm->AddAt(new AliITSgeomMatrix(rot6,kSPD,id,tran),lm++);
560 case 3: case 4: // layer 3 or 4 SDD
561 fGm->AddAt(new AliITSgeomMatrix(rot6,kSDD,id,tran),lm++);
563 case 5: case 6: // layer 5 or 6 SSD
564 fGm->AddAt(new AliITSgeomMatrix(rot6,kSSD,id,tran),lm++);
567 } // end while ever loop
571 //________________________________________________________________________
572 AliITSgeom::AliITSgeom(AliITSgeom &source){
573 ////////////////////////////////////////////////////////////////////////
574 // The copy constructor for the AliITSgeom class. It calls the
575 // = operator function. See the = operator function for more details.
576 ////////////////////////////////////////////////////////////////////////
578 *this = source; // Just use the = operator for now.
583 //________________________________________________________________________
584 void AliITSgeom::operator=(AliITSgeom &source){
585 ////////////////////////////////////////////////////////////////////////
586 // The = operator function for the AliITSgeom class. It makes an
587 // independent copy of the class in such a way that any changes made
588 // to the copied class will not affect the source class in any way.
589 // This is required for many ITS alignment studies where the copied
590 // class is then modified by introducing some misalignment.
591 ////////////////////////////////////////////////////////////////////////
594 if(this == &source) return; // don't assign to ones self.
596 // if there is an old structure allocated delete it first.
598 for(i=0;i<this->fNmodules;i++) delete this->fGm->At(i);
601 if(fNlad != 0) delete[] fNlad;
602 if(fNdet != 0) delete[] fNdet;
604 this->fTrans = source.fTrans;
605 this->fNmodules = source.fNmodules;
606 this->fNlayers = source.fNlayers;
607 this->fNlad = new Int_t[fNlayers];
608 for(i=0;i<this->fNlayers;i++) this->fNlad[i] = source.fNlad[i];
609 this->fNdet = new Int_t[fNlayers];
610 for(i=0;i<this->fNlayers;i++) this->fNdet[i] = source.fNdet[i];
611 this->fShape = new TObjArray(*(source.fShape));//This does not make a proper copy.
612 this->fGm = new TObjArray(this->fNmodules,0);
613 for(i=0;i<this->fNmodules;i++){
614 this->fGm->AddAt(new AliITSgeomMatrix(*(
615 (AliITSgeomMatrix*)(source.fGm->At(i)))),i);
618 }//_____________________________________________________________________
619 Int_t AliITSgeom::GetModuleIndex(const Int_t lay,const Int_t lad,
621 ////////////////////////////////////////////////////////////////////////
622 // This routine computes the module index number from the layer,
623 // ladder, and detector numbers. The number of ladders and detectors
624 // per layer is determined when this geometry package is constructed,
625 // see AliITSgeom(const char *filename) for specifics.
626 ////////////////////////////////////////////////////////////////////////
629 i = fNdet[lay-1] * (lad-1) + det - 1;
631 for(k=0;k<lay-1;k++) j += fNdet[k]*fNlad[k];
633 GetGeomMatrix(i)->GetIndex(id);
634 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
635 // Array of modules fGm is not in expected order. Search for this index
636 for(i=0;i<fNmodules;i++){
637 GetGeomMatrix(i)->GetIndex(id);
638 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
640 // This layer ladder and detector combination does not exist return -1.
643 //______________________________________________________________________
644 void AliITSgeom::GetModuleId(const Int_t index,
645 Int_t &lay,Int_t &lad,Int_t &det){
646 ////////////////////////////////////////////////////////////////////////
647 // This routine computes the layer, ladder and detector number
648 // given the module index number. The number of ladders and detectors
649 // per layer is determined when this geometry package is constructed,
650 // see AliITSgeom(const char *filename) for specifics.
651 ////////////////////////////////////////////////////////////////////////
654 GetGeomMatrix(index)->GetIndex(id);
655 lay = id[0]; lad = id[1]; det = id[2];
658 // The old way kept for posterity.
662 for(k=0;k<fNlayers;k++){
663 j += fNdet[k]*fNlad[k];
667 i = index -j + fNdet[k]*fNlad[k];
669 for(k=0;k<fNlad[lay-1];k++){
674 det = 1+i-fNdet[lay-1]*k;
678 //___________________________________________________________________________
679 Int_t AliITSgeom::GetStartDet(const Int_t dtype){
680 /////////////////////////////////////////////////////////////////////////
681 // returns the starting module index value for a give type of detector id
682 /////////////////////////////////////////////////////////////////////////
686 return GetModuleIndex(1,1,1);
689 return GetModuleIndex(3,1,1);
692 return GetModuleIndex(5,1,1);
695 printf("<AliITSgeom::GetFirstDet> undefined detector type\n");
699 printf("<AliITSgeom::GetFirstDet> undefined detector type\n");
703 //___________________________________________________________________________
704 Int_t AliITSgeom::GetLastDet(const Int_t dtype){
705 /////////////////////////////////////////////////////////////////////////
706 // returns the last module index value for a give type of detector id
707 /////////////////////////////////////////////////////////////////////////
720 printf("<AliITSgeom::GetLastDet> undefined detector type\n");
724 printf("<AliITSgeom::GetLastDet> undefined detector type\n");
728 //___________________________________________________________________________
729 void AliITSgeom::PrintComparison(FILE *fp,AliITSgeom *other){
730 ////////////////////////////////////////////////////////////////////////
731 // This function was primarily created for diagnostic reasons. It
732 // print to a file pointed to by the file pointer fp the difference
733 // between two AliITSgeom classes. The format of the file is basicly,
734 // define d? to be the difference between the same element of the two
735 // classes. For example dfrx = this->GetGeomMatrix(i)->frx
736 // - other->GetGeomMatrix(i)->frx.
737 // if(at least one of dfx0, dfy0, dfz0,dfrx,dfry,dfrz are non zero) then print
738 // layer ladder detector dfx0 dfy0 dfz0 dfrx dfry dfrz
739 // if(at least one of the 9 elements of dfr[] are non zero) then print
740 // layer ladder detector dfr[0] dfr[1] dfr[2]
741 // dfr[3] dfr[4] dfr[5]
742 // dfr[6] dfr[7] dfr[8]
743 // Only non zero values are printed to save space. The differences are
744 // typical written to a file because there are usually a lot of numbers
745 // printed out and it is usually easier to read them in some nice editor
746 // rather than zooming quickly past you on a screen. fprintf is used to
747 // do the printing. The fShapeIndex difference is not printed at this time.
748 ////////////////////////////////////////////////////////////////////////
749 Int_t i,j,idt[3],ido[3];
750 Double_t tt[3],to[3]; // translation
751 Double_t rt[3],ro[3]; // phi in radians
752 Double_t mt[3][3],mo[3][3]; // matrixes
753 AliITSgeomMatrix *gt,*go;
756 for(i=0;i<this->fNmodules;i++){
757 gt = this->GetGeomMatrix(i);
758 go = other->GetGeomMatrix(i);
762 for(i=0;i<3;i++) t = t&&idt[i]!=ido[i];
763 if(t) fprintf(fp,"%4.4d %1.1d %2.2d %2.2d %1.1d %2.2d %2.2d\n",i,
764 idt[0],idt[1],idt[2],ido[0],ido[1],ido[2]);
765 gt->GetTranslation(tt);
766 go->GetTranslation(to);
770 for(i=0;i<3;i++) t = t&&tt[i]!=to[i];
771 if(t) fprintf(fp,"%1.1d %2.2d %2.2d dTrans=%f %f %f drot=%f %f %f\n",
772 idt[0],idt[1],idt[2],
773 tt[0]-to[0],tt[1]-to[1],tt[2]-to[2],
774 rt[0]-ro[0],rt[1]-ro[1],rt[2]-ro[2]);
778 for(i=0;i<3;i++)for(j=0;j<3;j++) t = mt[i][j] != mo[i][j];
780 fprintf(fp,"%1.1d %2.2d %2.2d dfr= %e %e %e\n",
781 idt[0],idt[1],idt[2],
782 mt[0][0]-mo[0][0],mt[0][1]-mo[0][1],mt[0][2]-mo[0][2]);
783 fprintf(fp," dfr= %e %e %e\n",
784 mt[1][0]-mo[1][0],mt[1][1]-mo[1][1],mt[1][2]-mo[1][2]);
785 fprintf(fp," dfr= %e %e %e\n",
786 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,
794 const Int_t lay,const Int_t lad,const Int_t det){
795 ////////////////////////////////////////////////////////////////////////
796 // This function prints out the coordinate transformations for
797 // the particular detector defined by layer, ladder, and detector
798 // to the file pointed to by the File pointer fp. fprintf statements
799 // are used to print out the numbers. The format is
800 // layer ladder detector Trans= fx0 fy0 fz0 rot= frx fry frz Shape=fShapeIndex
801 // dfr= fr[0] fr[1] fr[2]
802 // dfr= fr[3] fr[4] fr[5]
803 // dfr= fr[6] fr[7] fr[8]
804 // By indicating which detector, some control over the information
805 // is given to the user. The output it written to the file pointed
806 // to by the file pointer fp. This can be set to stdout if you want.
807 ////////////////////////////////////////////////////////////////////////
808 AliITSgeomMatrix *gt;
809 Double_t t[3],r[3],m[3][3];
811 gt = this->GetGeomMatrix(GetModuleIndex(lay,lad,det));
812 gt->GetTranslation(t);
814 fprintf(fp,"%1.1d %2.2d %2.2d Trans=%f %f %f rot=%f %f %f Shape=%d\n",
815 lay,lad,det,t[0],t[1],t[2],r[0],r[1],r[2],
816 gt->GetDetectorIndex());
818 fprintf(fp," dfr= %e %e %e\n",m[0][0],m[0][1],m[0][2]);
819 fprintf(fp," dfr= %e %e %e\n",m[1][0],m[1][1],m[1][2]);
820 fprintf(fp," dfr= %e %e %e\n",m[2][0],m[2][1],m[2][2]);
823 //___________________________________________________________________________
824 ofstream & AliITSgeom::PrintGeom(ofstream &R__b){
825 ////////////////////////////////////////////////////////////////////////
826 // Stream out an object of class AliITSgeom to standard output.
827 ////////////////////////////////////////////////////////////////////////
830 R__b.setf(ios::scientific);
831 R__b << fTrans << " ";
832 R__b << fNmodules << " ";
833 R__b << fNlayers << " ";
834 for(i=0;i<fNlayers;i++) R__b << fNlad[i] << " ";
835 for(i=0;i<fNlayers;i++) R__b << fNdet[i] << "\n";
836 for(i=0;i<fNmodules;i++) {
837 R__b <<setprecision(16) << *(GetGeomMatrix(i)) << "\n";
841 //___________________________________________________________________________
842 ifstream & AliITSgeom::ReadGeom(ifstream &R__b){
843 ////////////////////////////////////////////////////////////////////////
844 // Stream in an object of class AliITSgeom from standard input.
845 ////////////////////////////////////////////////////////////////////////
848 fNlad = new Int_t[fNlayers];
849 fNdet = new Int_t[fNlayers];
851 for(i=0;i<fNmodules;i++) delete GetGeomMatrix(i);
855 R__b >> fTrans >> fNmodules >> fNlayers;
856 fNlad = new Int_t[fNlayers];
857 fNdet = new Int_t[fNlayers];
858 for(i=0;i<fNlayers;i++) R__b >> fNlad[i];
859 for(i=0;i<fNlayers;i++) R__b >> fNdet[i];
860 fGm = new TObjArray(fNmodules,0);
861 for(i=0;i<fNmodules;i++){
862 fGm->AddAt(new AliITSgeomMatrix,i);
863 R__b >> *(GetGeomMatrix(i));
867 //___________________________________________________________________________
869 //______________________________________________________________________
870 // The following routines modify the transformation of "this"
871 // geometry transformations in a number of different ways.
872 //______________________________________________________________________
873 void AliITSgeom::GlobalChange(const Float_t *tran,const Float_t *rot){
874 ////////////////////////////////////////////////////////////////////////
875 // This function performs a Cartesian translation and rotation of
876 // the full ITS from its default position by an amount determined by
877 // the three element arrays dtranslation and drotation. If every element
878 // of dtranslation and drotation are zero then there is no change made
879 // the geometry. The change is global in that the exact same translation
880 // and rotation is done to every detector element in the exact same way.
881 // The units of the translation are those of the Monte Carlo, usually cm,
882 // and those of the rotation are in radians. The elements of dtranslation
883 // are dtranslation[0] = x, dtranslation[1] = y, and dtranslation[2] = z.
884 // The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
885 // drotation[2] = rz. A change in x will move the hole ITS in the ALICE
886 // global x direction, the same for a change in y. A change in z will
887 // result in a translation of the ITS as a hole up or down the beam line.
888 // A change in the angles will result in the inclination of the ITS with
889 // respect to the beam line, except for an effective rotation about the
890 // beam axis which will just rotate the ITS as a hole about the beam axis.
891 ////////////////////////////////////////////////////////////////////////
896 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
897 for(i=0;i<fNmodules;i++){
898 g = this->GetGeomMatrix(i);
899 g->GetTranslation(t);
905 g->SetTranslation(t);
910 //___________________________________________________________________________
911 void AliITSgeom::GlobalCylindericalChange(const Float_t *tran,const Float_t *rot){
912 ////////////////////////////////////////////////////////////////////////
913 // This function performs a cylindrical translation and rotation of
914 // each ITS element by a fixed about in radius, rphi, and z from its
915 // default position by an amount determined by the three element arrays
916 // dtranslation and drotation. If every element of dtranslation and
917 // drotation are zero then there is no change made the geometry. The
918 // change is global in that the exact same distance change in translation
919 // and rotation is done to every detector element in the exact same way.
920 // The units of the translation are those of the Monte Carlo, usually cm,
921 // and those of the rotation are in radians. The elements of dtranslation
922 // are dtranslation[0] = r, dtranslation[1] = rphi, and dtranslation[2] = z.
923 // The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
924 // drotation[2] = rz. A change in r will results in the increase of the
925 // radius of each layer by the same about. A change in rphi will results in
926 // the rotation of each layer by a different angle but by the same
927 // circumferential distance. A change in z will result in a translation
928 // of the ITS as a hole up or down the beam line. A change in the angles
929 // will result in the inclination of the ITS with respect to the beam
930 // line, except for an effective rotation about the beam axis which will
931 // just rotate the ITS as a hole about the beam axis.
932 ////////////////////////////////////////////////////////////////////////
934 Double_t t[3],ro[3],r,r0,phi,rphi;
937 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
938 for(i=0;i<fNmodules;i++){
939 g = this->GetGeomMatrix(i);
940 g->GetTranslation(t);
942 r = r0= TMath::Hypot(t[1],t[0]);
943 phi = TMath::ATan2(t[1],t[0]);
948 t[0] = r*TMath::Cos(phi);
949 t[1] = r*TMath::Sin(phi);
954 g->SetTranslation(t);
959 //___________________________________________________________________________
960 void AliITSgeom::RandomChange(const Float_t *stran,const Float_t *srot){
961 ////////////////////////////////////////////////////////////////////////
962 // This function performs a Gaussian random displacement and/or
963 // rotation about the present global position of each active
964 // volume/detector of the ITS. The sigma of the random displacement
965 // is determined by the three element array stran, for the
966 // x y and z translations, and the three element array srot,
967 // for the three rotation about the axis x y and z.
968 ////////////////////////////////////////////////////////////////////////
974 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
975 for(i=0;i<fNmodules;i++){
976 g = this->GetGeomMatrix(i);
977 g->GetTranslation(t);
980 t[j] += ran.Gaus(0.0,stran[j]);
981 r[j] += ran.Gaus(0.0, srot[j]);
983 g->SetTranslation(t);
988 //___________________________________________________________________________
989 void AliITSgeom::RandomCylindericalChange(const Float_t *stran,
990 const Float_t *srot){
991 ////////////////////////////////////////////////////////////////////////
992 // This function performs a Gaussian random displacement and/or
993 // rotation about the present global position of each active
994 // volume/detector of the ITS. The sigma of the random displacement
995 // is determined by the three element array stran, for the
996 // r rphi and z translations, and the three element array srot,
997 // for the three rotation about the axis x y and z. This random change
998 // in detector position allow for the simulation of a random uncertainty
999 // in the detector positions of the ITS.
1000 ////////////////////////////////////////////////////////////////////////
1002 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]);
1014 r += ran.Gaus(0.0,stran[0]);
1015 rphi += ran.Gaus(0.0,stran[1]);
1017 t[0] = r*TMath::Cos(phi);
1018 t[1] = r*TMath::Sin(phi);
1019 t[2] += ran.Gaus(0.0,stran[2]);
1021 ro[j] += ran.Gaus(0.0, srot[j]);
1023 g->SetTranslation(t);
1028 //______________________________________________________________________
1029 void AliITSgeom::GeantToTracking(AliITSgeom &source){
1030 /////////////////////////////////////////////////////////////////////////
1031 // Copy the geometry data but change it to go between the ALICE
1032 // Global coordinate system to that used by the ITS tracking. A slightly
1033 // different coordinate system is used when tracking. This coordinate
1034 // system is only relevant when the geometry represents the cylindrical
1035 // ALICE ITS geometry. For tracking the Z axis is left alone but X-> -Y
1036 // and Y-> X such that X always points out of the ITS cylinder for every
1037 // layer including layer 1 (where the detectors are mounted upside down).
1040 <img src="picts/ITS/AliITSgeomMatrix_T1.gif">
1043 ////////////////////////////////////////////////////////////////////////
1044 Int_t i,j,k,l,id[3];
1045 Double_t R0[3][3],R1[3][3];
1046 Double_t A0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
1047 Double_t A1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
1049 *this = source; // copy everything
1050 for(i=0;i<GetIndexMax();i++){
1051 GetGeomMatrix(i)->GetIndex(id);
1052 GetGeomMatrix(i)->GetMatrix(R0);
1053 if(id[0]==1){ // Layer 1 is treated different from the others.
1054 for(j=0;j<3;j++) for(k=0;k<3;k++){
1056 for(l=0;l<3;l++) R1[j][k] += A0[j][l]*R0[l][k];
1059 for(j=0;j<3;j++) for(k=0;k<3;k++){
1061 for(l=0;l<3;l++) R1[j][k] += A1[j][l]*R0[l][k];
1064 GetGeomMatrix(i)->SetMatrix(R1);
1066 this->fTrans = (this->fTrans && 0xfffe) + 1; // set bit 0 true.
1069 //______________________________________________________________________
1070 Int_t AliITSgeom::GetNearest(const Double_t g[3],const Int_t lay){
1071 ////////////////////////////////////////////////////////////////////////
1072 // Finds the Detector (Module) that is nearest the point g [cm] in
1073 // ALICE Global coordinates. If layer !=0 then the search is restricted
1074 // to Detectors (Modules) in that particular layer.
1075 ////////////////////////////////////////////////////////////////////////
1077 Double_t d,dn=1.0e10;
1078 Bool_t t=lay!=0; // skip if lay = 0 default value check all layers.
1080 for(i=0;i<fNmodules;i++){
1081 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
1082 if((d=GetGeomMatrix(i)->Distance2(g))<dn){
1089 //______________________________________________________________________
1090 void AliITSgeom::GetNearest27(const Double_t g[3],Int_t n[27],const Int_t lay){
1091 ////////////////////////////////////////////////////////////////////////
1092 // Finds 27 Detectors (Modules) that are nearest the point g [cm] in
1093 // ALICE Global coordinates. If layer !=0 then the search is restricted
1094 // to Detectors (Modules) in that particular layer. The number 27 comes
1095 // from including the nearest detector and all those around it (up, down,
1096 // left, right, forwards, backwards, and the corners).
1097 ////////////////////////////////////////////////////////////////////////
1098 Int_t i,l,a,e,in[27]={0,0,0,0,0,0,0,0,0,
1100 0,0,0,0,0,0,0,0,0,};
1101 Double_t d,dn[27]={1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1102 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1103 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1104 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
1105 1.0e10,1.0e10,1.0e10};
1106 Bool_t t=(lay!=0); // skip if lay = 0 default value check all layers.
1108 for(i=0;i<fNmodules;i++){
1109 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
1111 d = GetGeomMatrix(i)->Distance2(g);
1113 for(e=26;e>a;e--){dn[e] = dn[e-1];in[e] = in[e-1];}
1114 dn[a] = d; in[a] = i;
1118 for(i=0;i<27;i++) n[i] = in[i];
1120 //----------------------------------------------------------------------