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