Added include file that are no londer included in AliITSgeom.h
[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
16/*
17$Log$
a8a6107b 18Revision 1.12 2001/01/17 15:41:27 barbera
19Some corrections suggested by Peter Hristov added
20
89855786 21Revision 1.11 2000/10/02 16:32:35 barbera
22Forward declaration added
23
92c19c36 24Revision 1.4.4.15 2000/10/02 15:52:05 barbera
25Forward declaration added
26
27Revision 1.10 2000/09/05 14:25:50 nilsen
28Made fixes for HP compiler. All function parameter default values placed
29in .h file. Fixed the usual problem with HP comilers and the "for(Int_t i..."
30business. Replaced casting (Double_t [3][3]) to (Double_t (*)[3]) for HP.
31Lastly removed all "const" before function parameters which were 2 dim. arrays,
32because on HP root generates some strange code (?). Thanks Peter for the
33changes.
34
d962cab4 35Revision 1.9 2000/08/29 20:19:03 nilsen
36Removed dependancy on structure AliITSeomS and replaced it with class
37AliITSgeomMatrix. Added many new functions with many new arguments. Most
38in the form of in line functions for speed.
39
269f57ed 40Revision 1.4.4.6 2000/06/04 16:33:32 Nilsen
41A restructured AliITSgeom class. Now used AliITSgeomMatrix.
42
43Revision 1.4.4.5 2000/03/04 23:42:39 Nilsen
593e9459 44Updated the comments/documentations and improved the maintainability of the
45code.
46
269f57ed 47Revision 1.4.4.4 2000/03/02 21:27:07 Nilsen
593e9459 48Added two functions, SetByAngles and SetTrans.
49
269f57ed 50Revision 1.4.4.3 2000/01/23 03:09:10 Nilsen
593e9459 51// fixed compiler warnings for new function LtLErrorMatrix(...)
52
269f57ed 53Revision 1.4.4.2 2000/01/19 23:18:20 Nilsen
593e9459 54Added transformations of Error matrix to AliITSgeom and fixed some typos
55in AliITS.h and AliITShitIndex.h
56
269f57ed 57Revision 1.4.4.1 2000/01/12 19:03:32 Nilsen
593e9459 58This is the version of the files after the merging done in December 1999.
59See the ReadMe110100.txt file for details
60
61Revision 1.4 1999/10/15 07:03:20 fca
62Fixed bug in GetModuleId(Int_t index,Int_t &lay,Int_t &lad, Int_t &det) and
63a typo in the creator. aliroot need to be rerun to get a fixed geometry.
64
aa6248e2 65Revision 1.3 1999/10/04 15:20:12 fca
66Correct syntax accepted by g++ but not standard for static members, remove minor warnings
67
ad0e60d9 68Revision 1.2 1999/09/29 09:24:20 fca
69Introduction of the Copyright and cvs Log
70
4c039060 71*/
72
58005f18 73///////////////////////////////////////////////////////////////////////
593e9459 74// ITS geometry manipulation routines. //
58005f18 75// Created April 15 1999. //
76// version: 0.0.0 //
77// By: Bjorn S. Nilsen //
78// version: 0.0.1 //
79// Updated May 27 1999. //
593e9459 80// Added Cylindrical random and global based changes. //
58005f18 81// Added function PrintComparison. //
82///////////////////////////////////////////////////////////////////////
593e9459 83
84
85////////////////////////////////////////////////////////////////////////
593e9459 86// The local coordinate system by, default, is show in the following
87// figures. Also shown are the ladder numbering scheme.
88//Begin_Html
89/*
269f57ed 90<img src="picts/ITS/AliITSgeomMatrix_L1.gif">
91</pre>
92<br clear=left>
93<font size=+2 color=blue>
94<p>This shows the relative geometry differences between the ALICE Global
95coordinate system and the local detector coordinate system.
96</font>
97<pre>
98
99<pre>
593e9459 100<img src="picts/ITS/its1+2_convention_front_5.gif">
101</pre>
102<br clear=left>
103<font size=+2 color=blue>
104<p>This shows the front view of the SPDs and the orientation of the local
105pixel coordinate system. Note that the inner pixel layer has its y coordinate
106in the opposite direction from all of the other layers.
107</font>
108<pre>
109
110<pre>
111<img src="picts/ITS/its3+4_convention_front_5.gif">
112</pre>
113<br clear=left>
114<font size=+2 color=blue>
115<p>This shows the front view of the SDDs and the orientation of the local
116pixel coordinate system.
117</font>
118<pre>
119
120<pre>
121<img src="picts/ITS/its5+6_convention_front_5.gif">
122</pre>
123<br clear=left>
124<font size=+2 color=blue>
125<p>This shows the front view of the SSDs and the orientation of the local
126pixel coordinate system.
127</font>
128<pre>
129*/
130//End_Html
269f57ed 131//
593e9459 132////////////////////////////////////////////////////////////////////////
133
134////////////////////////////////////////////////////////////////////////
135//
136// version: 0
137// Written by Bjorn S. Nilsen
138//
139// Data Members:
140//
141// Int_t fNlayers
142// The number of ITS layers for this geometry. By default this
143// is 6, but can be modified by the creator function if there are
144// more layers defined.
145//
146// Int_t *fNlad
147// A pointer to an array fNlayers long containing the number of
148// ladders for each layer. This array is typically created and filled
149// by the AliITSgeom creator function.
150//
151// Int_t *fNdet
152// A pointer to an array fNlayers long containing the number of
153// active detector volumes for each ladder. This array is typically
154// created and filled by the AliITSgeom creator function.
155//
269f57ed 156// AliITSgeomMatrix *fGm
157// A pointer to an array of AliITSgeomMatrix classes. One element
158// per module (detector) in the ITS. AliITSgeomMatrix basicly contains
159// all of the necessary information about the detector and it's coordinate
160// transformations.
593e9459 161//
162// TObjArray *fShape
163// A pointer to an array of TObjects containing the detailed shape
164// information for each type of detector used in the ITS. For example
165// I have created AliITSgeomSPD, AliITSgeomSDD, and AliITSgeomSSD as
166// example structures, derived from TObjects, to hold the detector
167// information. I would recommend that one element in each of these
168// structures, that which describes the shape of the active volume,
169// be one of the ROOT classes derived from TShape. In this way it would
170// be easy to have the display program display the correct active
171// ITS volumes. See the example classes AliITSgeomSPD, AliITSgeomSDD,
172// and AliITSgeomSSD for a more detailed example.
593e9459 173////////////////////////////////////////////////////////////////////////
58005f18 174#include <iostream.h>
269f57ed 175#include <fstream.h>
58005f18 176#include <iomanip.h>
177#include <stdio.h>
269f57ed 178#include <string.h>
179#include <ctype.h>
180#include <TObject.h>
181#include <TRandom.h>
e8189707 182
58005f18 183#include "AliITSgeom.h"
269f57ed 184#include "AliITSgeomMatrix.h"
185#include "AliITSgeomSPD.h"
186#include "AliITSgeomSDD.h"
187#include "AliITSgeomSSD.h"
58005f18 188
189ClassImp(AliITSgeom)
190
191//_____________________________________________________________________
192AliITSgeom::AliITSgeom(){
193////////////////////////////////////////////////////////////////////////
194// The default constructor for the AliITSgeom class. It, by default,
195// sets fNlayers to zero and zeros all pointers.
196////////////////////////////////////////////////////////////////////////
197 // Default constructor.
198 // Do not allocate anything zero everything
269f57ed 199 fTrans = 0; // standard GEANT global/local coordinate system.
58005f18 200 fNlayers = 0;
201 fNlad = 0;
202 fNdet = 0;
269f57ed 203 fGm = 0;
58005f18 204 fShape = 0;
205 return;
206}
207
208//_____________________________________________________________________
209AliITSgeom::~AliITSgeom(){
210////////////////////////////////////////////////////////////////////////
211// The destructor for the AliITSgeom class. If the arrays fNlad,
085bb6ed 212// fNdet, or fGm have had memory allocated to them, there pointer values
58005f18 213// are non zero, then this memory space is freed and they are set
214// to zero. In addition, fNlayers is set to zero. The destruction of
215// TObjArray fShape is, by default, handled by the TObjArray destructor.
216////////////////////////////////////////////////////////////////////////
217 // Default destructor.
593e9459 218 // if arrays exist delete them. Then set everything to zero.
085bb6ed 219 if(fGm!=0){
89855786 220 for(Int_t i=0;i<fNmodules;i++) delete fGm[i];
221 delete [] fGm;
085bb6ed 222 } // end if fGm!=0
58005f18 223 if(fNlad!=0) delete[] fNlad;
224 if(fNdet!=0) delete[] fNdet;
225 fNlayers = 0;
226 fNlad = 0;
227 fNdet = 0;
269f57ed 228 fGm = 0;
58005f18 229 return;
230}
269f57ed 231//______________________________________________________________________
232void AliITSgeom::ReadNewFile(const char *filename){
233 printf("New file format not defined yet\n");
234 return;
235}
58005f18 236//_____________________________________________________________________
237AliITSgeom::AliITSgeom(const char *filename){
238////////////////////////////////////////////////////////////////////////
239// The constructor for the AliITSgeom class. All of the data to fill
240// this structure is read in from the file given my the input filename.
241////////////////////////////////////////////////////////////////////////
242 FILE *pf;
269f57ed 243 Int_t i,lm=0,id[3];
58005f18 244 Int_t l,a,d;
245 Float_t x,y,z,o,p,q,r,s,t;
269f57ed 246 Double_t rot6[6],tran[3];
247 char buf[200],*buff=0; // input character buffer;
58005f18 248
249 pf = fopen(filename,"r");
250
251 fNlayers = 6; // set default number of ladders
269f57ed 252TryAgain:
58005f18 253 fNlad = new Int_t[fNlayers];
254 fNdet = new Int_t[fNlayers];
269f57ed 255 fNmodules = 0;
593e9459 256 // find the number of ladders and detectors in this geometry.
58005f18 257 for(i=0;i<fNlayers;i++){fNlad[i]=fNdet[i]=0;} // zero out arrays
269f57ed 258 while(fgets(buf,200,pf)!=NULL){ // for ever loop
259 for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces.
260 buff = &(buf[i]);
261 break;
262 } // end for i
263 // remove blank lines and comments.
264 if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'||
265 (buff[0]=='/'&&buff[1]=='/')) continue;
266 if(isalpha(buff[0])) { // must be the new file formated file.
267 fclose(pf);
268 delete[] fNlad;delete[] fNdet;
269 ReadNewFile(filename);
270 return;
271 } // end if isalpha(buff[0])
272 sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f",
273 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
274 if(l>lm) lm = l;
58005f18 275 if(l<1 || l>fNlayers) {
269f57ed 276 printf("error in file %s layer=%d min. is 1 max is %d/n",
58005f18 277 filename,l,fNlayers);
278 continue;
279 }// end if l
269f57ed 280 fNmodules++;
281 if(l<=fNlayers&&fNlad[l-1]<a) fNlad[l-1] = a;
282 if(l<=fNlayers&&fNdet[l-1]<d) fNdet[l-1] = d;
283 } // end while ever loop
284 if(lm>fNlayers){
285 delete[] fNlad;
286 delete[] fNdet;
287 fNlayers = lm;
288 goto TryAgain;
289 } // end if lm>fNlayers
593e9459 290 // counted the number of ladders and detectors now allocate space.
269f57ed 291 fGm = new AliITSgeomMatrix*[fNmodules];
58005f18 292
293 // Set up Shapes for a default configuration of 6 layers.
269f57ed 294 fTrans = 0; // standard GEANT global/local coordinate system.
085bb6ed 295 fShape = new TObjArray(3);
269f57ed 296 AddShape((TObject *) new AliITSgeomSPD()); // shape 0
58005f18 297 AddShape((TObject *) new AliITSgeomSDD()); // shape 1
269f57ed 298 AddShape((TObject *) new AliITSgeomSPD()); // shape 2
58005f18 299
593e9459 300 // prepare to read in transforms
269f57ed 301 lm = 0; // reuse lm as counter of modules.
58005f18 302 rewind(pf); // start over reading file
269f57ed 303 while(fgets(buf,200,pf)!=NULL){ // for ever loop
304 for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces.
305 buff = &(buf[i]);
306 break;
307 } // end for i
308 // remove blank lines and comments.
309 if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'||
310 (buff[0]=='/'&&buff[1]=='/')) continue;
311 x = y = z = o = p = q = r = s = t = 0.0;
312 sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f",
313 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
58005f18 314 if(l<1 || l>fNlayers) {
269f57ed 315 printf("error in file %s layer=%d min. is 1 max is %d/n",
58005f18 316 filename,l,fNlayers);
317 continue;
318 }// end if l
269f57ed 319 id[0] = l;id[1] = a;id[2] = d;
320 tran[0] = tran[1] = tran[2] = 0.0;
321 tran[0] = (Double_t)x;tran[1] = (Double_t)y;tran[2] = (Double_t)z;
322 rot6[0] = rot6[1] = rot6[2] = rot6[3] = rot6[4] = rot6[5] =0.0;
323 rot6[0] = (Double_t)o;rot6[1] = (Double_t)p;rot6[2] = (Double_t)q;
324 rot6[3] = (Double_t)r;rot6[4] = (Double_t)s;rot6[5] = (Double_t)t;
325 switch (l){
326 case 1: case 2: // layer 1 or2 SPD
327 fGm[lm++] = new AliITSgeomMatrix(rot6,0,id,tran);
328 break;
329 case 3: case 4: // layer 3 or 4 SDD
330 fGm[lm++] = new AliITSgeomMatrix(rot6,1,id,tran);
331 break;
332 case 5: case 6: // layer 5 or 6 SSD
333 fGm[lm++] = new AliITSgeomMatrix(rot6,2,id,tran);
334 break;
335 } // end switch
336 } // end while ever loop
58005f18 337 fclose(pf);
338}
339
340//________________________________________________________________________
269f57ed 341AliITSgeom::AliITSgeom(AliITSgeom &source){
58005f18 342////////////////////////////////////////////////////////////////////////
343// The copy constructor for the AliITSgeom class. It calls the
344// = operator function. See the = operator function for more details.
345////////////////////////////////////////////////////////////////////////
593e9459 346
347 *this = source; // Just use the = operator for now.
348
349 return;
58005f18 350}
351
352//________________________________________________________________________
269f57ed 353void AliITSgeom::operator=(AliITSgeom &source){
58005f18 354////////////////////////////////////////////////////////////////////////
355// The = operator function for the AliITSgeom class. It makes an
356// independent copy of the class in such a way that any changes made
357// to the copied class will not affect the source class in any way.
358// This is required for many ITS alignment studies where the copied
359// class is then modified by introducing some misalignment.
360////////////////////////////////////////////////////////////////////////
269f57ed 361 Int_t i;
58005f18 362
363 if(this == &source) return; // don't assign to ones self.
364
365 // if there is an old structure allocated delete it first.
269f57ed 366 if(this->fGm != 0){
367 for(i=0;i<this->fNmodules;i++) delete this->fGm[i];
368 delete this->fGm;
085bb6ed 369 } // end if fGm != 0
370 if(fNlad != 0) delete[] fNlad;
371 if(fNdet != 0) delete[] fNdet;
372
269f57ed 373 this->fTrans = source.fTrans;
374 this->fNmodules = source.fNmodules;
375 this->fNlayers = source.fNlayers;
376 this->fNlad = new Int_t[fNlayers];
377 for(i=0;i<this->fNlayers;i++) this->fNlad[i] = source.fNlad[i];
378 this->fNdet = new Int_t[fNlayers];
379 for(i=0;i<this->fNlayers;i++) this->fNdet[i] = source.fNdet[i];
380 this->fShape = new TObjArray(*(source.fShape));//This does not make a proper copy.
381 this->fGm = new AliITSgeomMatrix*[this->fNmodules];
382 for(i=0;i<this->fNmodules;i++){
383 this->fGm[i] = new AliITSgeomMatrix(*(source.fGm[i]));
085bb6ed 384 } // end for i
58005f18 385 return;
269f57ed 386}//_____________________________________________________________________
387Int_t AliITSgeom::GetModuleIndex(const Int_t lay,const Int_t lad,
388 const Int_t det){
593e9459 389////////////////////////////////////////////////////////////////////////
390// This routine computes the module index number from the layer,
391// ladder, and detector numbers. The number of ladders and detectors
392// per layer is determined when this geometry package is constructed,
393// see AliITSgeom(const char *filename) for specifics.
394////////////////////////////////////////////////////////////////////////
269f57ed 395 Int_t i,j,k,id[3];
58005f18 396
397 i = fNdet[lay-1] * (lad-1) + det - 1;
398 j = 0;
399 for(k=0;k<lay-1;k++) j += fNdet[k]*fNlad[k];
269f57ed 400 i = i+j;
401 fGm[i]->GetIndex(id);
402 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
403 // Array of modules fGm is not in expected order. Search for this index
404 for(i=0;i<fNmodules;i++){
405 fGm[i]->GetIndex(id);
406 if(id[0]==lay&&id[1]==lad&&id[2]==det) return i;
407 } // end for i
408 // This layer ladder and detector combination does not exist return -1.
409 return -1;
58005f18 410}
269f57ed 411//______________________________________________________________________
412void AliITSgeom::GetModuleId(const Int_t index,
413 Int_t &lay,Int_t &lad,Int_t &det){
593e9459 414////////////////////////////////////////////////////////////////////////
415// This routine computes the layer, ladder and detector number
416// given the module index number. The number of ladders and detectors
417// per layer is determined when this geometry package is constructed,
418// see AliITSgeom(const char *filename) for specifics.
419////////////////////////////////////////////////////////////////////////
269f57ed 420 Int_t id[3];
58005f18 421
269f57ed 422 fGm[index]->GetIndex(id);
423 lay = id[0]; lad = id[1]; det = id[2];
424 return;
425
426 // The old way kept for posterity.
427/*
428 Int_t i,j,k;
58005f18 429 j = 0;
430 for(k=0;k<fNlayers;k++){
431 j += fNdet[k]*fNlad[k];
aa6248e2 432 if(j>index)break;
58005f18 433 } // end for k
434 lay = k+1;
435 i = index -j + fNdet[k]*fNlad[k];
436 j = 0;
437 for(k=0;k<fNlad[lay-1];k++){
aa6248e2 438 j += fNdet[lay-1];
439 if(j>i)break;
58005f18 440 } // end for k
441 lad = k+1;
442 det = 1+i-fNdet[lay-1]*k;
443 return;
269f57ed 444*/
58005f18 445}
446//___________________________________________________________________________
269f57ed 447Int_t AliITSgeom::GetStartDet(const Int_t dtype){
085bb6ed 448 /////////////////////////////////////////////////////////////////////////
449 // returns the starting module index value for a give type of detector id
450 /////////////////////////////////////////////////////////////////////////
269f57ed 451
452 switch(dtype){
085bb6ed 453 case 0:
269f57ed 454 return GetModuleIndex(1,1,1);
085bb6ed 455 break;
456 case 1:
269f57ed 457 return GetModuleIndex(3,1,1);
085bb6ed 458 break;
459 case 2:
269f57ed 460 return GetModuleIndex(5,1,1);
085bb6ed 461 break;
462 default:
463 printf("<AliITSgeom::GetFirstDet> undefined detector type\n");
269f57ed 464 return 0;
465 } // end switch
085bb6ed 466
269f57ed 467 printf("<AliITSgeom::GetFirstDet> undefined detector type\n");
468 return 0;
085bb6ed 469}
470
471//___________________________________________________________________________
269f57ed 472Int_t AliITSgeom::GetLastDet(const Int_t dtype){
085bb6ed 473 /////////////////////////////////////////////////////////////////////////
474 // returns the last module index value for a give type of detector id
475 /////////////////////////////////////////////////////////////////////////
269f57ed 476
477 switch(dtype){
085bb6ed 478 case 0:
269f57ed 479 return GetLastSPD();
085bb6ed 480 break;
481 case 1:
269f57ed 482 return GetLastSDD();
085bb6ed 483 break;
484 case 2:
269f57ed 485 return GetLastSSD();
085bb6ed 486 break;
487 default:
488 printf("<AliITSgeom::GetLastDet> undefined detector type\n");
269f57ed 489 return 0;
490 } // end switch
491
492 printf("<AliITSgeom::GetLastDet> undefined detector type\n");
493 return 0;
085bb6ed 494}
495
593e9459 496//___________________________________________________________________________
497void AliITSgeom::PrintComparison(FILE *fp,AliITSgeom *other){
498////////////////////////////////////////////////////////////////////////
499// This function was primarily created for diagnostic reasons. It
500// print to a file pointed to by the file pointer fp the difference
501// between two AliITSgeom classes. The format of the file is basicly,
502// define d? to be the difference between the same element of the two
085bb6ed 503// classes. For example dfrx = this->fGm[i][j].frx - other->fGm[i][j].frx.
593e9459 504// if(at least one of dfx0, dfy0, dfz0,dfrx,dfry,dfrz are non zero) then print
505// layer ladder detector dfx0 dfy0 dfz0 dfrx dfry dfrz
506// if(at least one of the 9 elements of dfr[] are non zero) then print
507// layer ladder detector dfr[0] dfr[1] dfr[2]
508// dfr[3] dfr[4] dfr[5]
509// dfr[6] dfr[7] dfr[8]
510// Only non zero values are printed to save space. The differences are
511// typical written to a file because there are usually a lot of numbers
512// printed out and it is usually easier to read them in some nice editor
513// rather than zooming quickly past you on a screen. fprintf is used to
514// do the printing. The fShapeIndex difference is not printed at this time.
515////////////////////////////////////////////////////////////////////////
269f57ed 516 Int_t i,j,idt[3],ido[3];
517 Double_t tt[3],to[3]; // translation
518 Double_t rt[3],ro[3]; // phi in radians
519 Double_t mt[3][3],mo[3][3]; // matrixes
520 AliITSgeomMatrix *gt,*go;
593e9459 521 Bool_t t;
522
269f57ed 523 for(i=0;i<this->fNmodules;i++){
524 gt = this->GetGeomMatrix(i);
525 go = other->GetGeomMatrix(i);
526 gt->GetIndex(idt);
527 go->GetIndex(ido);
528 t = kFALSE;
529 for(i=0;i<3;i++) t = t&&idt[i]!=ido[i];
530 if(t) fprintf(fp,"%4.4d %1.1d %2.2d %2.2d %1.1d %2.2d %2.2d\n",i,
531 idt[0],idt[1],idt[2],ido[0],ido[1],ido[2]);
532 gt->GetTranslation(tt);
533 go->GetTranslation(to);
534 gt->GetAngles(rt);
535 go->GetAngles(ro);
536 t = kFALSE;
537 for(i=0;i<3;i++) t = t&&tt[i]!=to[i];
538 if(t) fprintf(fp,"%1.1d %2.2d %2.2d dTrans=%f %f %f drot=%f %f %f\n",
539 idt[0],idt[1],idt[2],
540 tt[0]-to[0],tt[1]-to[1],tt[2]-to[2],
541 rt[0]-ro[0],rt[1]-ro[1],rt[2]-ro[2]);
593e9459 542 t = kFALSE;
269f57ed 543 gt->GetMatrix(mt);
544 go->GetMatrix(mo);
545 for(i=0;i<3;i++)for(j=0;j<3;j++) t = mt[i][j] != mo[i][j];
593e9459 546 if(t){
269f57ed 547 fprintf(fp,"%1.1d %2.2d %2.2d dfr= %e %e %e\n",
548 idt[0],idt[1],idt[2],
549 mt[0][0]-mo[0][0],mt[0][1]-mo[0][1],mt[0][2]-mo[0][2]);
593e9459 550 fprintf(fp," dfr= %e %e %e\n",
269f57ed 551 mt[1][0]-mo[1][0],mt[1][1]-mo[1][1],mt[1][2]-mo[1][2]);
593e9459 552 fprintf(fp," dfr= %e %e %e\n",
269f57ed 553 mt[2][0]-mo[2][0],mt[2][1]-mo[2][1],mt[2][2]-mo[2][2]);
554 } // end if t
593e9459 555 } // end for i
556 return;
557}
558
559//___________________________________________________________________________
269f57ed 560void AliITSgeom::PrintData(FILE *fp,
561 const Int_t lay,const Int_t lad,const Int_t det){
593e9459 562////////////////////////////////////////////////////////////////////////
563// This function prints out the coordinate transformations for
564// the particular detector defined by layer, ladder, and detector
565// to the file pointed to by the File pointer fp. fprintf statements
566// are used to print out the numbers. The format is
567// layer ladder detector Trans= fx0 fy0 fz0 rot= frx fry frz Shape=fShapeIndex
568// dfr= fr[0] fr[1] fr[2]
569// dfr= fr[3] fr[4] fr[5]
570// dfr= fr[6] fr[7] fr[8]
571// By indicating which detector, some control over the information
572// is given to the user. The output it written to the file pointed
573// to by the file pointer fp. This can be set to stdout if you want.
574////////////////////////////////////////////////////////////////////////
269f57ed 575 AliITSgeomMatrix *gt;
576 Double_t t[3],r[3],m[3][3];
593e9459 577
269f57ed 578 gt = this->GetGeomMatrix(GetModuleIndex(lay,lad,det));
579 gt->GetTranslation(t);
580 gt->GetAngles(r);
593e9459 581 fprintf(fp,"%1.1d %2.2d %2.2d Trans=%f %f %f rot=%f %f %f Shape=%d\n",
269f57ed 582 lay,lad,det,t[0],t[1],t[2],r[0],r[1],r[2],
583 gt->GetDetectorIndex());
584 gt->GetMatrix(m);
585 fprintf(fp," dfr= %e %e %e\n",m[0][0],m[0][1],m[0][2]);
586 fprintf(fp," dfr= %e %e %e\n",m[1][0],m[1][1],m[1][2]);
587 fprintf(fp," dfr= %e %e %e\n",m[2][0],m[2][1],m[2][2]);
593e9459 588 return;
589}
590//___________________________________________________________________________
269f57ed 591ofstream & AliITSgeom::PrintGeom(ofstream &R__b){
593e9459 592////////////////////////////////////////////////////////////////////////
593// The default Streamer function "written by ROOT" doesn't write out
594// the arrays referenced by pointers. Therefore, a specific Streamer function
595// has to be written. This function should not be modified but instead added
596// on to so that older versions can still be read. The proper handling of
597// the version dependent streamer function hasn't been written do to the lack
598// of finding an example at the time of writing.
599////////////////////////////////////////////////////////////////////////
600 // Stream an object of class AliITSgeom.
269f57ed 601 Int_t i;
593e9459 602
269f57ed 603 R__b.setf(ios::scientific);
604 R__b << fTrans << " ";
605 R__b << fNmodules << " ";
606 R__b << fNlayers << " ";
607 for(i=0;i<fNlayers;i++) R__b << fNlad[i] << " ";
608 for(i=0;i<fNlayers;i++) R__b << fNdet[i] << "\n";
609 for(i=0;i<fNmodules;i++) {
610 R__b <<setprecision(16) << *(fGm[i]) << "\n";
611 } // end for i
612 return R__b;
593e9459 613}
614//___________________________________________________________________________
269f57ed 615ifstream & AliITSgeom::ReadGeom(ifstream &R__b){
593e9459 616////////////////////////////////////////////////////////////////////////
617// The default Streamer function "written by ROOT" doesn't write out
618// the arrays referenced by pointers. Therefore, a specific Streamer function
619// has to be written. This function should not be modified but instead added
620// on to so that older versions can still be read. The proper handling of
621// the version dependent streamer function hasn't been written do to the lack
622// of finding an example at the time of writing.
623////////////////////////////////////////////////////////////////////////
624 // Stream an object of class AliITSgeom.
269f57ed 625 Int_t i;
593e9459 626
593e9459 627 fNlad = new Int_t[fNlayers];
628 fNdet = new Int_t[fNlayers];
085bb6ed 629 if(fGm!=0){
269f57ed 630 for(i=0;i<fNmodules;i++) delete fGm[i];
631 delete fGm;
085bb6ed 632 } // end if fGm!=0
269f57ed 633
634 R__b >> fTrans >> fNmodules >> fNlayers;
635 fNlad = new Int_t[fNlayers];
636 fNdet = new Int_t[fNlayers];
637 for(i=0;i<fNlayers;i++) R__b >> fNlad[i];
638 for(i=0;i<fNlayers;i++) R__b >> fNdet[i];
639 fGm = new AliITSgeomMatrix*[fNmodules];
640 for(i=0;i<fNmodules;i++){
641 fGm[i] = new AliITSgeomMatrix;
642 R__b >> *(fGm[i]);
593e9459 643 } // end for i
269f57ed 644 return R__b;
593e9459 645}
a8a6107b 646
593e9459 647//______________________________________________________________________
269f57ed 648// The following routines modify the transformation of "this"
649// geometry transformations in a number of different ways.
593e9459 650//______________________________________________________________________
269f57ed 651void AliITSgeom::GlobalChange(const Float_t *tran,const Float_t *rot){
58005f18 652////////////////////////////////////////////////////////////////////////
653// This function performs a Cartesian translation and rotation of
654// the full ITS from its default position by an amount determined by
655// the three element arrays dtranslation and drotation. If every element
656// of dtranslation and drotation are zero then there is no change made
657// the geometry. The change is global in that the exact same translation
658// and rotation is done to every detector element in the exact same way.
659// The units of the translation are those of the Monte Carlo, usually cm,
660// and those of the rotation are in radians. The elements of dtranslation
661// are dtranslation[0] = x, dtranslation[1] = y, and dtranslation[2] = z.
662// The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
663// drotation[2] = rz. A change in x will move the hole ITS in the ALICE
664// global x direction, the same for a change in y. A change in z will
665// result in a translation of the ITS as a hole up or down the beam line.
666// A change in the angles will result in the inclination of the ITS with
667// respect to the beam line, except for an effective rotation about the
668// beam axis which will just rotate the ITS as a hole about the beam axis.
669////////////////////////////////////////////////////////////////////////
269f57ed 670 Int_t i,j;
671 Double_t t[3],r[3];
672 AliITSgeomMatrix *g;
673
674 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
675 for(i=0;i<fNmodules;i++){
676 g = this->GetGeomMatrix(i);
677 g->GetTranslation(t);
678 g->GetAngles(r);
679 for(j=0;j<3;j++){
680 t[j] += tran[j];
681 r[j] += rot[j];
682 } // end for j
683 g->SetTranslation(t);
684 g->SetAngles(r);
58005f18 685 } // end for i
686 return;
687}
58005f18 688//___________________________________________________________________________
269f57ed 689void AliITSgeom::GlobalCylindericalChange(const Float_t *tran,const Float_t *rot){
58005f18 690////////////////////////////////////////////////////////////////////////
691// This function performs a cylindrical translation and rotation of
692// each ITS element by a fixed about in radius, rphi, and z from its
693// default position by an amount determined by the three element arrays
694// dtranslation and drotation. If every element of dtranslation and
695// drotation are zero then there is no change made the geometry. The
696// change is global in that the exact same distance change in translation
697// and rotation is done to every detector element in the exact same way.
698// The units of the translation are those of the Monte Carlo, usually cm,
699// and those of the rotation are in radians. The elements of dtranslation
700// are dtranslation[0] = r, dtranslation[1] = rphi, and dtranslation[2] = z.
701// The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
702// drotation[2] = rz. A change in r will results in the increase of the
703// radius of each layer by the same about. A change in rphi will results in
704// the rotation of each layer by a different angle but by the same
705// circumferential distance. A change in z will result in a translation
706// of the ITS as a hole up or down the beam line. A change in the angles
707// will result in the inclination of the ITS with respect to the beam
708// line, except for an effective rotation about the beam axis which will
709// just rotate the ITS as a hole about the beam axis.
710////////////////////////////////////////////////////////////////////////
269f57ed 711 Int_t i,j;
712 Double_t t[3],ro[3],r,r0,phi,rphi;
713 AliITSgeomMatrix *g;
714
715 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
716 for(i=0;i<fNmodules;i++){
717 g = this->GetGeomMatrix(i);
718 g->GetTranslation(t);
719 g->GetAngles(ro);
720 r = r0= TMath::Hypot(t[1],t[0]);
721 phi = TMath::ATan2(t[1],t[0]);
58005f18 722 rphi = r0*phi;
723 r += tran[0];
724 rphi += tran[1];
725 phi = rphi/r0;
269f57ed 726 t[0] = r*TMath::Cos(phi);
727 t[1] = r*TMath::Sin(phi);
728 t[2] += tran[2];
729 for(j=0;j<3;j++){
730 ro[j] += rot[j];
731 } // end for j
732 g->SetTranslation(t);
733 g->SetAngles(ro);
58005f18 734 } // end for i
735 return;
736}
58005f18 737//___________________________________________________________________________
269f57ed 738void AliITSgeom::RandomChange(const Float_t *stran,const Float_t *srot){
58005f18 739////////////////////////////////////////////////////////////////////////
740// This function performs a Gaussian random displacement and/or
741// rotation about the present global position of each active
742// volume/detector of the ITS. The sigma of the random displacement
593e9459 743// is determined by the three element array stran, for the
744// x y and z translations, and the three element array srot,
58005f18 745// for the three rotation about the axis x y and z.
746////////////////////////////////////////////////////////////////////////
269f57ed 747 Int_t i,j;
748 Double_t t[3],r[3];
749 TRandom ran;
750 AliITSgeomMatrix *g;
751
752 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
753 for(i=0;i<fNmodules;i++){
754 g = this->GetGeomMatrix(i);
755 g->GetTranslation(t);
756 g->GetAngles(r);
757 for(j=0;j<3;j++){
758 t[j] += ran.Gaus(0.0,stran[j]);
759 r[j] += ran.Gaus(0.0, srot[j]);
760 } // end for j
761 g->SetTranslation(t);
762 g->SetAngles(r);
58005f18 763 } // end for i
764 return;
765}
58005f18 766//___________________________________________________________________________
269f57ed 767void AliITSgeom::RandomCylindericalChange(const Float_t *stran,
768 const Float_t *srot){
58005f18 769////////////////////////////////////////////////////////////////////////
770// This function performs a Gaussian random displacement and/or
771// rotation about the present global position of each active
772// volume/detector of the ITS. The sigma of the random displacement
593e9459 773// is determined by the three element array stran, for the
774// r rphi and z translations, and the three element array srot,
58005f18 775// for the three rotation about the axis x y and z. This random change
776// in detector position allow for the simulation of a random uncertainty
777// in the detector positions of the ITS.
778////////////////////////////////////////////////////////////////////////
269f57ed 779 Int_t i,j;
780 Double_t t[3],ro[3],r,r0,phi,rphi;
781 TRandom ran;
782 AliITSgeomMatrix *g;
783
784 fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true.
785 for(i=0;i<fNmodules;i++){
786 g = this->GetGeomMatrix(i);
787 g->GetTranslation(t);
788 g->GetAngles(ro);
789 r = r0= TMath::Hypot(t[1],t[0]);
790 phi = TMath::ATan2(t[1],t[0]);
791 rphi = r0*phi;
58005f18 792 r += ran.Gaus(0.0,stran[0]);
269f57ed 793 rphi += ran.Gaus(0.0,stran[1]);
794 phi = rphi/r0;
795 t[0] = r*TMath::Cos(phi);
796 t[1] = r*TMath::Sin(phi);
797 t[2] += ran.Gaus(0.0,stran[2]);
798 for(j=0;j<3;j++){
799 ro[j] += ran.Gaus(0.0, srot[j]);
800 } // end for j
801 g->SetTranslation(t);
802 g->SetAngles(ro);
58005f18 803 } // end for i
804 return;
805}
593e9459 806//______________________________________________________________________
807void AliITSgeom::GeantToTracking(AliITSgeom &source){
808/////////////////////////////////////////////////////////////////////////
269f57ed 809// Copy the geometry data but change it to go between the ALICE
810// Global coordinate system to that used by the ITS tracking. A slightly
811// different coordinate system is used when tracking. This coordinate
812// system is only relevant when the geometry represents the cylindrical
813// ALICE ITS geometry. For tracking the Z axis is left alone but X-> -Y
814// and Y-> X such that X always points out of the ITS cylinder for every
815// layer including layer 1 (where the detectors are mounted upside down).
816//Begin_Html
817/*
818<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
819*/
820//End_Html
821////////////////////////////////////////////////////////////////////////
822 Int_t i,j,k,l,id[3];
823 Double_t R0[3][3],R1[3][3];
824 Double_t A0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
825 Double_t A1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
826
827 *this = source; // copy everything
828 for(i=0;i<GetIndexMax();i++){
829 fGm[i]->GetIndex(id);
830 fGm[i]->GetMatrix(R0);
831 if(id[0]==1){ // Layer 1 is treated different from the others.
832 for(j=0;j<3;j++) for(k=0;k<3;k++){
833 R1[j][k] = 0.;
834 for(l=0;l<3;l++) R1[j][k] += A0[j][l]*R0[l][k];
835 } // end for j,k
836 }else{
837 for(j=0;j<3;j++) for(k=0;k<3;k++){
838 R1[j][k] = 0.;
839 for(l=0;l<3;l++) R1[j][k] += A1[j][l]*R0[l][k];
840 } // end for j,k
841 } // end if
842 fGm[i]->SetMatrix(R1);
58005f18 843 } // end for i
269f57ed 844 this->fTrans = (this->fTrans && 0xfffe) + 1; // set bit 0 true.
58005f18 845 return;
846}
269f57ed 847//______________________________________________________________________
d962cab4 848Int_t AliITSgeom::GetNearest(const Double_t g[3],const Int_t lay){
085bb6ed 849////////////////////////////////////////////////////////////////////////
269f57ed 850// Finds the Detector (Module) that is nearest the point g [cm] in
851// ALICE Global coordinates. If layer !=0 then the search is restricted
852// to Detectors (Modules) in that particular layer.
085bb6ed 853////////////////////////////////////////////////////////////////////////
269f57ed 854 Int_t i,l,a,e,in=0;
855 Double_t d,dn=1.0e10;
856 Bool_t t=lay!=0; // skip if lay = 0 default value check all layers.
085bb6ed 857
269f57ed 858 for(i=0;i<fNmodules;i++){
859 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
860 if((d=fGm[i]->Distance2(g))<dn){
861 dn = d;
862 in = i;
863 } // end if
864 } // end for i
865 return in;
085bb6ed 866}
269f57ed 867//______________________________________________________________________
d962cab4 868void AliITSgeom::GetNearest27(const Double_t g[3],Int_t n[27],const Int_t lay){
269f57ed 869////////////////////////////////////////////////////////////////////////
870// Finds 27 Detectors (Modules) that are nearest the point g [cm] in
871// ALICE Global coordinates. If layer !=0 then the search is restricted
872// to Detectors (Modules) in that particular layer. The number 27 comes
873// from including the nearest detector and all those around it (up, down,
874// left, right, forwards, backwards, and the corners).
875////////////////////////////////////////////////////////////////////////
876 Int_t i,l,a,e,in[27]={0,0,0,0,0,0,0,0,0,
877 0,0,0,0,0,0,0,0,0,
878 0,0,0,0,0,0,0,0,0,};
879 Double_t d,dn[27]={1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
880 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
881 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
882 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
883 1.0e10,1.0e10,1.0e10};
884 Bool_t t=(lay!=0); // skip if lay = 0 default value check all layers.
885
886 for(i=0;i<fNmodules;i++){
887 if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
888 for(a=0;a<27;a++){
889 d = fGm[i]->Distance2(g);
890 if(d<dn[a]){
891 for(e=26;e>a;e--){dn[e] = dn[e-1];in[e] = in[e-1];}
892 dn[a] = d; in[a] = i;
893 } // end if d<dn[i]
894 } // end for a
895 } // end for i
896 for(i=0;i<27;i++) n[i] = in[i];
897}
898//----------------------------------------------------------------------