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