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