1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 Revision 1.2 1999/09/29 09:24:20 fca
19 Introduction of the Copyright and cvs Log
23 ///////////////////////////////////////////////////////////////////////
24 // ITS geometry manimulaiton routines. //
25 // Created April 15 1999. //
27 // By: Bjorn S. Nilsen //
29 // Updated May 27 1999. //
30 // Added Cylinderical random and global based changes. //
31 // Added function PrintComparison. //
32 ///////////////////////////////////////////////////////////////////////
37 #include "AliITSgeom.h"
42 //_____________________________________________________________________
43 AliITSgeom::AliITSgeom(){
44 ////////////////////////////////////////////////////////////////////////
45 // The default constructor for the AliITSgeom class. It, by default,
46 // sets fNlayers to zero and zeros all pointers.
47 ////////////////////////////////////////////////////////////////////////
48 // Default constructor.
49 // Do not allocate anything zero everything
58 //_____________________________________________________________________
59 AliITSgeom::~AliITSgeom(){
60 ////////////////////////////////////////////////////////////////////////
61 // The destructor for the AliITSgeom class. If the arrays fNlad,
62 // fNdet, or fg have had memory allocated to them, there pointer values
63 // are non zero, then this memory space is freed and they are set
64 // to zero. In addition, fNlayers is set to zero. The destruction of
65 // TObjArray fShape is, by default, handled by the TObjArray destructor.
66 ////////////////////////////////////////////////////////////////////////
67 // Default destructor.
68 // if arrays exist delet them. Then set everything to zero.
70 for(Int_t i=0;i<fNlayers;i++) delete[] fg[i];
73 if(fNlad!=0) delete[] fNlad;
74 if(fNdet!=0) delete[] fNdet;
82 //_____________________________________________________________________
83 AliITSgeom::AliITSgeom(const char *filename){
84 ////////////////////////////////////////////////////////////////////////
85 // The constructor for the AliITSgeom class. All of the data to fill
86 // this structure is read in from the file given my the input filename.
87 ////////////////////////////////////////////////////////////////////////
92 Float_t x,y,z,o,p,q,r,s,t;
93 Double_t oor,pr,qr,rr,sr,tr; // Radians
95 Double_t si; // sin(angle)
96 Double_t PI = TMath::Pi(), byPI = PI/180.;
98 pf = fopen(filename,"r");
100 fNlayers = 6; // set default number of ladders
101 fNlad = new Int_t[fNlayers];
102 fNdet = new Int_t[fNlayers];
103 // find the number of laders and detectors in this geometry.
104 for(i=0;i<fNlayers;i++){fNlad[i]=fNdet[i]=0;} // zero out arrays
105 for(;;){ // for ever loop
106 i = fscanf(pf,"%d %d %d %f %f %f %f %f %f %f %f %f",
107 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
109 if(l<1 || l>fNlayers) {
110 printf("error in file %s layer=%d min is 1 max is %d/n",
111 filename,l,fNlayers);
114 if(fNlad[l-1]<a) fNlad[l-1] = a;
115 if(fNdet[l-1]<d) fNdet[l-1] = d;
116 } // end for ever loop
117 // counted the number of laders and detectors now allocate space.
118 fg = new ITS_geom* [fNlayers];
119 for(i=0;i<fNlayers;i++){
121 l = fNlad[i]*fNdet[i];
122 fg[i] = new ITS_geom[l]; // allocate space for transforms
125 // Set up Shapes for a default configuration of 6 layers.
126 fShape = new TObjArray;
127 AddShape((TObject *) new AliITSgeomSPD()); // shape 0
128 AddShape((TObject *) new AliITSgeomSDD()); // shape 1
129 AddShape((TObject *) new AliITSgeomSPD()); // shape 2
131 // prepair to read in transforms
132 rewind(pf); // start over reading file
133 for(;;){ // for ever loop
134 i = fscanf(pf,"%d %d %d %f %f %f %f %f %f %f %f %f",
135 &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t);
137 if(l<1 || l>fNlayers) {
138 printf("error in file %s layer=%d min is 1 max is %d/n",
139 filename,l,fNlayers);
142 l--; a--; d--; // shift layer, lader, and detector counters to zero base
143 i = d + a*fNdet[l]; // position of this detector
156 si = sin(oor);if(o== 90.0) si = +1.0;
157 if(o==270.0) si = -1.0;
158 if(o== 0.0||o==180.) si = 0.0;
159 lr[0] = si * cos(pr);
160 lr[1] = si * sin(pr);
161 lr[2] = cos(oor);if(o== 90.0||o==270.) lr[2] = 0.0;
162 if(o== 0.0) lr[2] = +1.0;
163 if(o==180.0) lr[2] = -1.0;
164 si = sin(qr);if(q== 90.0) si = +1.0;
165 if(q==270.0) si = -1.0;
166 if(q== 0.0||q==180.) si = 0.0;
167 lr[3] = si * cos(rr);
168 lr[4] = si * sin(rr);
169 lr[5] = cos(qr);if(q== 90.0||q==270.) lr[5] = 0.0;
170 if(q== 0.0) lr[5] = +1.0;
171 if(q==180.0) lr[5] = -1.0;
172 si = sin(sr);if(r== 90.0) si = +1.0;
173 if(r==270.0) si = -1.0;
174 if(r== 0.0||r==180.) si = 0.0;
175 lr[6] = si * cos(tr);
176 lr[7] = si * sin(tr);
177 lr[8] = cos(sr);if(r== 90.0||r==270.0) lr[8] = 0.0;
178 if(r== 0.0) lr[8] = +1.0;
179 if(r==180.0) lr[8] = -1.0;
180 // Normalize these elements
181 for(a=0;a<3;a++){// reuse float si and integers a and d.
183 for(d=0;d<3;d++) si += lr[3*a+d]*lr[3*a+d];
184 si = TMath::Sqrt(1./si);
185 for(d=0;d<3;d++) g->fr[3*a+d] = lr[3*a+d] = si*lr[3*a+d];
187 // get angles from matrix up to a phase of 180 degrees.
188 oor = atan2(lr[7],lr[8]);if(oor<0.0) oor += 2.0*PI;
189 pr = asin(lr[2]); if(pr<0.0) pr += 2.0*PI;
190 qr = atan2(lr[3],lr[0]);if(qr<0.0) qr += 2.0*PI;
194 // l = layer-1 at this point.
195 if(l==0||l==1) g->fShapeIndex = 0; // SPD's
196 else if(l==2||l==3) g->fShapeIndex = 1; // SDD's
197 else if(l==4||l==5) g->fShapeIndex = 2; // SSD's
198 } // end for ever loop
202 //________________________________________________________________________
203 AliITSgeom::AliITSgeom(AliITSgeom &source){
204 ////////////////////////////////////////////////////////////////////////
205 // The copy constructor for the AliITSgeom class. It calls the
206 // = operator function. See the = operator function for more details.
207 ////////////////////////////////////////////////////////////////////////
208 source = *this; // Just use the = operator for now.
212 //________________________________________________________________________
213 void AliITSgeom::operator=(AliITSgeom &source){
214 ////////////////////////////////////////////////////////////////////////
215 // The = operator function for the AliITSgeom class. It makes an
216 // independent copy of the class in such a way that any changes made
217 // to the copied class will not affect the source class in any way.
218 // This is required for many ITS alignment studies where the copied
219 // class is then modified by introducing some misalignment.
220 ////////////////////////////////////////////////////////////////////////
223 if(this == &source) return; // don't assign to ones self.
225 // if there is an old structure allocated delete it first.
227 for(i=0;i<fNlayers;i++) delete[] fg[i];
230 if(fNlad != 0) delete[] fNlad;
231 if(fNdet != 0) delete[] fNdet;
233 fNlayers = source.fNlayers;
234 fNlad = new Int_t[fNlayers];
235 for(i=0;i<fNlayers;i++) fNlad[i] = source.fNlad[i];
236 fNdet = new Int_t[fNlayers];
237 for(i=0;i<fNlayers;i++) fNdet[i] = source.fNdet[i];
238 fShape = new TObjArray(*(source.fShape));//This does not make a proper copy.
239 fg = new ITS_geom* [fNlayers];
240 for(i=0;i<fNlayers;i++){
241 fg[i] = new ITS_geom[fNlad[i]*fNdet[i]];
242 for(j=0;j<(fNlad[i]*fNdet[i]);j++){
243 fg[i][j].fShapeIndex = source.fg[i][j].fShapeIndex;
244 fg[i][j].fx0 = source.fg[i][j].fx0;
245 fg[i][j].fy0 = source.fg[i][j].fy0;
246 fg[i][j].fz0 = source.fg[i][j].fz0;
247 fg[i][j].frx = source.fg[i][j].frx;
248 fg[i][j].fry = source.fg[i][j].fry;
249 fg[i][j].frz = source.fg[i][j].frz;
250 for(k=0;k<9;k++) fg[i][j].fr[k] = source.fg[i][j].fr[k];
257 //________________________________________________________________________
258 void AliITSgeom::GtoL(Int_t lay,Int_t lad,Int_t det,
259 const Float_t *g,Float_t *l){
260 ////////////////////////////////////////////////////////////////////////
261 // The function that does the global ALICE Cartesian coordinate
262 // to local active volume detector Cartesian coordinate transformation.
263 // The local detector coordinate system is determined by the layer,
264 // ladder, and detector numbers. The global coordinates are entered by
265 // the three element Float_t array g and the local coordinate values
266 // are returned by the three element Float_t array l. The order of the
267 // three elements are g[0]=x, g[1]=y, and g[2]=z, similarly for l.
268 ////////////////////////////////////////////////////////////////////////
273 gl = &(fg[lay][fNdet[lay]*lad+det]);
278 l[0] = gl->fr[0]*x + gl->fr[1]*y + gl->fr[2]*z;
279 l[1] = gl->fr[3]*x + gl->fr[4]*y + gl->fr[5]*z;
280 l[2] = gl->fr[6]*x + gl->fr[7]*y + gl->fr[8]*z;
284 //________________________________________________________________________
285 void AliITSgeom::GtoL(const Int_t *id,const Float_t *g,Float_t *l){
286 ////////////////////////////////////////////////////////////////////////
287 // The function that does the local active volume detector Cartesian
288 // coordinate to global ALICE Cartesian coordinate transformation.
289 // The local detector coordinate system is determined by the layer,
290 // ladder, and detector numbers. The local coordinates are entered by
291 // the three element Float_t array l and the global coordinate values
292 // are returned by the three element Float_t array g. The order of the
293 // three elements are l[0]=x, l[1]=y, and l[2]=z, similarly for g.
294 ////////////////////////////////////////////////////////////////////////
299 lay = id[0]; lad = id[1]; det = id[2];
301 gl = &(fg[lay][fNdet[lay]*lad+det]);
306 l[0] = gl->fr[0]*x + gl->fr[1]*y + gl->fr[2]*z;
307 l[1] = gl->fr[3]*x + gl->fr[4]*y + gl->fr[5]*z;
308 l[2] = gl->fr[6]*x + gl->fr[7]*y + gl->fr[8]*z;
311 //________________________________________________________________________
312 void AliITSgeom::GtoL(const Int_t index,const Float_t *g,Float_t *l){
313 ////////////////////////////////////////////////////////////////////////
314 // The function that does the local active volume detector Cartesian
315 // coordinate to global ALICE Cartesian coordinate transformation.
316 // The local detector coordinate system is determined by the detector
317 // index numbers (see GetModuleIndex and GetModuleID). The local
318 // coordinates are entered by the three element Float_t array l and the
319 // global coordinate values are returned by the three element Float_t array g.
320 // The order of the three elements are l[0]=x, l[1]=y, and l[2]=z, similarly
322 ////////////////////////////////////////////////////////////////////////
327 this->GetModuleId(index,lay,lad,det);
329 gl = &(fg[lay][fNdet[lay]*lad+det]);
334 l[0] = gl->fr[0]*x + gl->fr[1]*y + gl->fr[2]*z;
335 l[1] = gl->fr[3]*x + gl->fr[4]*y + gl->fr[5]*z;
336 l[2] = gl->fr[6]*x + gl->fr[7]*y + gl->fr[8]*z;
340 //________________________________________________________________________
341 void AliITSgeom::LtoG(Int_t lay,Int_t lad,Int_t det,
342 const Float_t *l,Float_t *g){
343 ////////////////////////////////////////////////////////////////////////
344 // The function that does the local active volume detector Cartesian
345 // coordinate to global ALICE Cartesian coordinate transformation.
346 // The local detector coordinate system is determined by the layer,
347 // ladder, and detector numbers. The local coordinates are entered by
348 // the three element Float_t array l and the global coordinate values
349 // are returned by the three element Float_t array g. The order of the
350 // three elements are l[0]=x, l[1]=y, and l[2]=z, similarly for g.
351 ////////////////////////////////////////////////////////////////////////
356 gl = &(fg[lay][fNdet[lay]*lad+det]);
358 x = gl->fr[0]*l[0] + gl->fr[3]*l[1] + gl->fr[6]*l[2];
359 y = gl->fr[1]*l[0] + gl->fr[4]*l[1] + gl->fr[7]*l[2];
360 z = gl->fr[2]*l[0] + gl->fr[5]*l[1] + gl->fr[8]*l[2];
367 //________________________________________________________________________
368 void AliITSgeom::LtoG(const Int_t *id,const Float_t *l,Float_t *g){
369 ////////////////////////////////////////////////////////////////////////
370 // The function that does the local active volume detector Cartesian
371 // coordinate to global ALICE Cartesian coordinate transformation.
372 // The local detector coordinate system is determined by the three
373 // element array Id containing as it's three elements Id[0]=layer,
374 // Id[1]=ladder, and Id[2]=detector numbers. The local coordinates
375 // are entered by the three element Float_t array l and the global
376 // coordinate values are returned by the three element Float_t array g.
377 // The order of the three elements are l[0]=x, l[1]=y, and l[2]=z,
379 ////////////////////////////////////////////////////////////////////////
384 lay = id[0]; lad = id[1]; det = id[2];
386 gl = &(fg[lay][fNdet[lay]*lad+det]);
388 x = gl->fr[0]*l[0] + gl->fr[3]*l[1] + gl->fr[6]*l[2];
389 y = gl->fr[1]*l[0] + gl->fr[4]*l[1] + gl->fr[7]*l[2];
390 z = gl->fr[2]*l[0] + gl->fr[5]*l[1] + gl->fr[8]*l[2];
396 //________________________________________________________________________
397 void AliITSgeom::LtoG(const Int_t index,const Float_t *l,Float_t *g){
398 ////////////////////////////////////////////////////////////////////////
399 // The function that does the local active volume detector Cartesian
400 // coordinate to global ALICE Cartesian coordinate transformation.
401 // The local detector coordinate system is determined by the detector
402 // index number (see GetModuleIndex and GetModuleId). The local coordinates
403 // are entered by the three element Float_t array l and the global
404 // coordinate values are returned by the three element Float_t array g.
405 // The order of the three elements are l[0]=x, l[1]=y, and l[2]=z,
407 ////////////////////////////////////////////////////////////////////////
412 this->GetModuleId(index,lay,lad,det);
414 gl = &(fg[lay][fNdet[lay]*lad+det]);
416 x = gl->fr[0]*l[0] + gl->fr[3]*l[1] + gl->fr[6]*l[2];
417 y = gl->fr[1]*l[0] + gl->fr[4]*l[1] + gl->fr[7]*l[2];
418 z = gl->fr[2]*l[0] + gl->fr[5]*l[1] + gl->fr[8]*l[2];
424 //________________________________________________________________________
425 void AliITSgeom::GtoLMomentum(Int_t lay,Int_t lad,Int_t det,
426 const Float_t *g,Float_t *l){
427 ////////////////////////////////////////////////////////////////////////
428 // The function that does the global ALICE Cartesian momentum
429 // to local active volume detector Cartesian momentum transformation.
430 // The local detector coordinate system is determined by the layer,
431 // ladder, and detector numbers. The global momentums are entered by
432 // the three element Float_t array g and the local momentums values
433 // are returned by the three element Float_t array l. The order of the
434 // three elements are g[0]=x, g[1]=y, and g[2]=z, similarly for l.
435 ////////////////////////////////////////////////////////////////////////
440 gl = &(fg[lay][fNdet[lay]*lad+det]);
445 l[0] = gl->fr[0]*px + gl->fr[1]*py + gl->fr[2]*pz;
446 l[1] = gl->fr[3]*px + gl->fr[4]*py + gl->fr[5]*pz;
447 l[2] = gl->fr[6]*px + gl->fr[7]*py + gl->fr[8]*pz;
450 //________________________________________________________________________
451 void AliITSgeom::LtoGMomentum(Int_t lay,Int_t lad,Int_t det,
452 const Float_t *l,Float_t *g){
453 ////////////////////////////////////////////////////////////////////////
454 // The function that does the local active volume detector Cartesian
455 // momentum to global ALICE Cartesian momentum transformation.
456 // The local detector momentum system is determined by the layer,
457 // ladder, and detector numbers. The locall momentums are entered by
458 // the three element Float_t array l and the global momentum values
459 // are returned by the three element Float_t array g. The order of the
460 // three elements are l[0]=x, l[1]=y, and l[2]=z, similarly for g.
461 ////////////////////////////////////////////////////////////////////////
466 gl = &(fg[lay][fNdet[lay]*lad+det]);
468 px = gl->fr[0]*l[0] + gl->fr[3]*l[1] + gl->fr[6]*l[2];
469 py = gl->fr[1]*l[0] + gl->fr[4]*l[1] + gl->fr[7]*l[2];
470 pz = gl->fr[2]*l[0] + gl->fr[5]*l[1] + gl->fr[8]*l[2];
476 //___________________________________________________________________________
477 Int_t AliITSgeom::GetModuleIndex(Int_t lay,Int_t lad,Int_t det){
480 i = fNdet[lay-1] * (lad-1) + det - 1;
482 for(k=0;k<lay-1;k++) j += fNdet[k]*fNlad[k];
485 //___________________________________________________________________________
486 void AliITSgeom::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det){
490 for(k=0;k<fNlayers;k++){
491 j += fNdet[k]*fNlad[k];
495 i = index -j + fNdet[k]*fNlad[k];
497 for(k=0;k<fNlad[lay-1];k++){
502 det = 1+i-fNdet[lay-1]*k;
505 //___________________________________________________________________________
506 void AliITSgeom::GlobalChange(Float_t *tran,Float_t *rot){
507 ////////////////////////////////////////////////////////////////////////
508 // This function performs a Cartesian translation and rotation of
509 // the full ITS from its default position by an amount determined by
510 // the three element arrays dtranslation and drotation. If every element
511 // of dtranslation and drotation are zero then there is no change made
512 // the geometry. The change is global in that the exact same translation
513 // and rotation is done to every detector element in the exact same way.
514 // The units of the translation are those of the Monte Carlo, usually cm,
515 // and those of the rotation are in radians. The elements of dtranslation
516 // are dtranslation[0] = x, dtranslation[1] = y, and dtranslation[2] = z.
517 // The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
518 // drotation[2] = rz. A change in x will move the hole ITS in the ALICE
519 // global x direction, the same for a change in y. A change in z will
520 // result in a translation of the ITS as a hole up or down the beam line.
521 // A change in the angles will result in the inclination of the ITS with
522 // respect to the beam line, except for an effective rotation about the
523 // beam axis which will just rotate the ITS as a hole about the beam axis.
524 ////////////////////////////////////////////////////////////////////////
527 Double_t sx,cx,sy,cy,sz,cz;
530 for(i=0;i<fNlayers;i++){
531 for(j=0;j<fNlad[i];j++) for(k=0;k<fNdet[i];k++){
532 l = fNdet[i]*j+k; // resolved index
540 rx = gl->frx; ry = gl->fry; rz = gl->frz;
541 sx = sin(rx); cx = cos(rx);
542 sy = sin(ry); cy = cos(ry);
543 sz = sin(rz); cz = cos(rz);
545 gl->fr[1] = -cz*sy*sx - sz*cx;
546 gl->fr[2] = -cz*sy*cx + sz*sx;
548 gl->fr[4] = -sz*sy*sx + cz*cx;
549 gl->fr[5] = -sz*sy*cx - cz*sx;
558 //___________________________________________________________________________
559 void AliITSgeom::GlobalCylindericalChange(Float_t *tran,Float_t *rot){
560 ////////////////////////////////////////////////////////////////////////
561 // This function performs a cylindrical translation and rotation of
562 // each ITS element by a fixed about in radius, rphi, and z from its
563 // default position by an amount determined by the three element arrays
564 // dtranslation and drotation. If every element of dtranslation and
565 // drotation are zero then there is no change made the geometry. The
566 // change is global in that the exact same distance change in translation
567 // and rotation is done to every detector element in the exact same way.
568 // The units of the translation are those of the Monte Carlo, usually cm,
569 // and those of the rotation are in radians. The elements of dtranslation
570 // are dtranslation[0] = r, dtranslation[1] = rphi, and dtranslation[2] = z.
571 // The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
572 // drotation[2] = rz. A change in r will results in the increase of the
573 // radius of each layer by the same about. A change in rphi will results in
574 // the rotation of each layer by a different angle but by the same
575 // circumferential distance. A change in z will result in a translation
576 // of the ITS as a hole up or down the beam line. A change in the angles
577 // will result in the inclination of the ITS with respect to the beam
578 // line, except for an effective rotation about the beam axis which will
579 // just rotate the ITS as a hole about the beam axis.
580 ////////////////////////////////////////////////////////////////////////
582 Double_t rx,ry,rz,r,phi,rphi; // phi in radians
583 Double_t sx,cx,sy,cy,sz,cz,r0;
586 // printf("trans=%f %f %f rot=%f %f %f\n",tran[0],tran[1],tran[2],
587 // rot[0],rot[1],rot[2]);
588 for(i=0;i<fNlayers;i++){
589 for(j=0;j<fNlad[i];j++) for(k=0;k<fNdet[i];k++){
590 l = fNdet[i]*j+k; // resolved index
592 r = r0= TMath::Hypot(gl->fy0,gl->fx0);
593 phi = atan2(gl->fy0,gl->fx0);
598 gl->fx0 = r*TMath::Cos(phi);
599 gl->fy0 = r*TMath::Sin(phi);
604 rx = gl->frx; ry = gl->fry; rz = gl->frz;
605 sx = sin(rx); cx = cos(rx);
606 sy = sin(ry); cy = cos(ry);
607 sz = sin(rz); cz = cos(rz);
609 gl->fr[1] = -cz*sy*sx - sz*cx;
610 gl->fr[2] = -cz*sy*cx + sz*sx;
612 gl->fr[4] = -sz*sy*sx + cz*cx;
613 gl->fr[5] = -sz*sy*cx - cz*sx;
622 //___________________________________________________________________________
623 void AliITSgeom::RandomChange(Float_t *stran,Float_t *srot){
624 ////////////////////////////////////////////////////////////////////////
625 // This function performs a Gaussian random displacement and/or
626 // rotation about the present global position of each active
627 // volume/detector of the ITS. The sigma of the random displacement
628 // is determined by the three element array stranslation, for the
629 // x y and z translations, and the three element array srotation,
630 // for the three rotation about the axis x y and z.
631 ////////////////////////////////////////////////////////////////////////
634 Double_t sx,cx,sy,cy,sz,cz;
638 for(i=0;i<fNlayers;i++){
639 for(j=0;j<fNlad[i];j++) for(k=0;k<fNdet[i];k++){
640 l = fNdet[i]*j+k; // resolved index
642 gl->fx0 += ran.Gaus(0.0,stran[0]);
643 gl->fy0 += ran.Gaus(0.0,stran[1]);
644 gl->fz0 += ran.Gaus(0.0,stran[2]);
645 gl->frx += ran.Gaus(0.0, srot[0]);
646 gl->fry += ran.Gaus(0.0, srot[1]);
647 gl->frz += ran.Gaus(0.0, srot[2]);
648 rx = gl->frx; ry = gl->fry; rz = gl->frz;
649 sx = sin(rx); cx = cos(rx);
650 sy = sin(ry); cy = cos(ry);
651 sz = sin(rz); cz = cos(rz);
653 gl->fr[1] = -cz*sy*sx - sz*cx;
654 gl->fr[2] = -cz*sy*cx + sz*sx;
656 gl->fr[4] = -sz*sy*sx + cz*cx;
657 gl->fr[5] = -sz*sy*cx - cz*sx;
666 //___________________________________________________________________________
667 void AliITSgeom::RandomCylindericalChange(Float_t *stran,Float_t *srot){
668 ////////////////////////////////////////////////////////////////////////
669 // This function performs a Gaussian random displacement and/or
670 // rotation about the present global position of each active
671 // volume/detector of the ITS. The sigma of the random displacement
672 // is determined by the three element array stranslation, for the
673 // r rphi and z translations, and the three element array srotation,
674 // for the three rotation about the axis x y and z. This random change
675 // in detector position allow for the simulation of a random uncertainty
676 // in the detector positions of the ITS.
677 ////////////////////////////////////////////////////////////////////////
679 Double_t rx,ry,rz,r,phi,x,y; // phi in radians
680 Double_t sx,cx,sy,cy,sz,cz,r0;
684 // printf("trans=%f %f %f rot=%f %f %f\n",stran[0],stran[1],stran[2],
685 // srot[0],srot[1],srot[2]);
686 for(i=0;i<fNlayers;i++){
687 for(j=0;j<fNlad[i];j++) for(k=0;k<fNdet[i];k++){
688 l = fNdet[i]*j+k; // resolved index
692 r = r0= TMath::Hypot(y,x);
693 phi = TMath::ATan2(y,x);
694 // if(phi<0.0) phi += 2.0*TMath::Pi();
695 r += ran.Gaus(0.0,stran[0]);
696 phi += ran.Gaus(0.0,stran[1])/r0;
697 // printf("fx0=%f fy0=%f rcos(phi)=%f rsin(phi)=%f\n",gl->fx0,gl->fy0,
698 // r*TMath::Cos(phi),r*TMath::Sin(phi));
699 gl->fx0 = r*TMath::Cos(phi);
700 gl->fy0 = r*TMath::Sin(phi);
701 // printf("r0=%f r=%f hypot=%f phi0=%f phi=%f ATan2=%f\n",
702 // r0,r,TMath::Hypot(gl->fy0,gl->fx0),
703 // phi0,phi,TMath::ATan2(gl->fy0,gl->fx0));
704 gl->fz0 += ran.Gaus(0.0,stran[2]);
705 gl->frx += ran.Gaus(0.0, srot[0]);
706 gl->fry += ran.Gaus(0.0, srot[1]);
707 gl->frz += ran.Gaus(0.0, srot[2]);
708 rx = gl->frx; ry = gl->fry; rz = gl->frz;
709 sx = sin(rx); cx = cos(rx);
710 sy = sin(ry); cy = cos(ry);
711 sz = sin(rz); cz = cos(rz);
713 gl->fr[1] = -cz*sy*sx - sz*cx;
714 gl->fr[2] = -cz*sy*cx + sz*sx;
716 gl->fr[4] = -sz*sy*sx + cz*cx;
717 gl->fr[5] = -sz*sy*cx - cz*sx;
726 //___________________________________________________________________________
727 void AliITSgeom::SetByAngles(Int_t lay,Int_t lad,Int_t det,
728 Float_t rx,Float_t ry,Float_t rz){
729 ////////////////////////////////////////////////////////////////////////
730 // This function computes a new rotation matrix based on the angles
731 // rx, ry, and rz (in radians) for a give detector on the give ladder
732 // in the give layer. A new
733 // fg[layer-1][(fNlad[layer-1]*(ladder-1)+detector-1)].fr[] array is
735 ////////////////////////////////////////////////////////////////////////
737 Double_t sx,cx,sy,cy,sz,cz;
739 lay--; lad--; det--; // set to zero base now.
740 g = &(fg[lay][fNdet[lay]*lad+det]);
742 sx = sin(rx); cx = cos(rx);
743 sy = sin(ry); cy = cos(ry);
744 sz = sin(rz); cz = cos(rz);
749 g->fr[1] = -cz*sy*sx - sz*cx;
750 g->fr[2] = -cz*sy*cx + sz*sx;
752 g->fr[4] = -sz*sy*sx + cz*cx;
753 g->fr[5] = -sz*sy*cx - cz*sx;
760 //___________________________________________________________________________
761 void AliITSgeom::GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Float_t *mat){
762 ////////////////////////////////////////////////////////////////////////
763 // Returns, in the Float_t array pointed to by mat, the full rotation
764 // matrix for the give detector defined by layer, ladder, and detector.
765 // It returns all nine elements of fr in the ITS_geom structure. See the
766 // description of the ITS_geom structure for further details of this
768 ////////////////////////////////////////////////////////////////////////
772 lay--; lad--; det--; // shift to base 0
773 g = &(fg[lay][fNdet[lay]*lad+det]);
774 for(i=0;i<9;i++) mat[i] = g->fr[i];
778 //___________________________________________________________________________
779 void AliITSgeom::PrintComparison(FILE *fp,AliITSgeom *other){
780 ////////////////////////////////////////////////////////////////////////
781 // This function was primarily created for diagnostic reasons. It
782 // print to a file pointed to by the file pointer fp the difference
783 // between two AliITSgeom classes. The format of the file is basicly,
784 // define d? to be the difference between the same element of the two
785 // classes. For example dfrx = this->fg[i][j].frx - other->fg[i][j].frx.
786 // if(at least one of dfx0, dfy0, dfz0,dfrx,dfry,dfrz are non zero) then print
787 // layer ladder detector dfx0 dfy0 dfz0 dfrx dfry dfrz
788 // if(at least one of the 9 elements of dfr[] are non zero) then print
789 // layer ladder detector dfr[0] dfr[1] dfr[2]
790 // dfr[3] dfr[4] dfr[5]
791 // dfr[6] dfr[7] dfr[8]
792 // Only non zero values are printed to save space. The differences are
793 // typical written to a file because there are usually a lot of numbers
794 // printed out and it is usually easier to read them in some nice editor
795 // rather than zooming quickly past you on a screen. fprintf is used to
796 // do the printing. The fShapeIndex difference is not printed at this time.
797 ////////////////////////////////////////////////////////////////////////
799 Double_t xt,yt,zt,xo,yo,zo;
800 Double_t rxt,ryt,rzt,rxo,ryo,rzo; // phi in radians
804 for(i=0;i<this->fNlayers;i++){
805 for(j=0;j<this->fNlad[i];j++) for(k=0;k<this->fNdet[i];k++){
806 l = this->fNdet[i]*j+k; // resolved index
807 gt = &(this->fg[i][l]);
808 go = &(other->fg[i][l]);
809 xt = gt->fx0; yt = gt->fy0; zt = gt->fz0;
810 xo = go->fx0; yo = go->fy0; zo = go->fz0;
811 rxt = gt->frx; ryt = gt->fry; rzt = gt->frz;
812 rxo = go->frx; ryo = go->fry; rzo = go->frz;
813 if(!(xt==xo&&yt==yo&&zt==zo&&rxt==rxo&&ryt==ryo&&rzt==rzo))
814 fprintf(fp,"%1.1d %2.2d %2.2d dTrans=%f %f %f drot=%f %f %f\n",
815 i+1,j+1,k+1,xt-xo,yt-yo,zt-zo,rxt-rxo,ryt-ryo,rzt-rzo);
817 for(i=0;i<9;i++) t = gt->fr[i] != go->fr[i];
819 fprintf(fp,"%1.1d %2.2d %2.2d dfr= %e %e %e\n",i+1,j+1,k+1,
820 gt->fr[0]-go->fr[0],gt->fr[1]-go->fr[1],gt->fr[2]-go->fr[2]);
821 fprintf(fp," dfr= %e %e %e\n",
822 gt->fr[3]-go->fr[3],gt->fr[4]-go->fr[4],gt->fr[5]-go->fr[5]);
823 fprintf(fp," dfr= %e %e %e\n",
824 gt->fr[6]-go->fr[6],gt->fr[7]-go->fr[7],gt->fr[8]-go->fr[8]);
831 //___________________________________________________________________________
832 void AliITSgeom::PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det){
833 ////////////////////////////////////////////////////////////////////////
834 // This function prints out the coordinate transformations for
835 // the particular detector defined by layer, ladder, and detector
836 // to the file pointed to by the File pointer fp. fprinf statements
837 // are used to print out the numbers. The format is
838 // layer ladder detector Trans= fx0 fy0 fz0 rot= frx fry frz Shape=fShapeIndex
839 // dfr= fr[0] fr[1] fr[2]
840 // dfr= fr[3] fr[4] fr[5]
841 // dfr= fr[6] fr[7] fr[8]
842 // By indicating which detector, some control over the information
843 // is given to the user. The output it written to the file pointed
844 // to by the file pointer fp. This can be set to stdout if you want.
845 ////////////////////////////////////////////////////////////////////////
852 l = this->fNdet[i]*j+k; // resolved index
853 gt = &(this->fg[i][l]);
854 fprintf(fp,"%1.1d %2.2d %2.2d Trans=%f %f %f rot=%f %f %f Shape=%d\n",
855 i+1,j+1,k+1,gt->fx0,gt->fy0,gt->fz0,gt->frx,gt->fry,gt->frz,
857 fprintf(fp," dfr= %e %e %e\n",gt->fr[0],gt->fr[1],gt->fr[2]);
858 fprintf(fp," dfr= %e %e %e\n",gt->fr[3],gt->fr[4],gt->fr[5]);
859 fprintf(fp," dfr= %e %e %e\n",gt->fr[6],gt->fr[7],gt->fr[8]);
862 //___________________________________________________________________________
863 void AliITSgeom::Streamer(TBuffer &R__b){
864 ////////////////////////////////////////////////////////////////////////
865 // The default Streamer function "written by ROOT" doesn't write out
866 // the arrays referenced by pointers. Therefore, a specific Streamer function
867 // has to be written. This function should not be modified but instead added
868 // on to so that older versions can still be read. The proper handling of
869 // the version dependent streamer function hasn't been written do to the lack
870 // of finding an example at the time of writting.
871 ////////////////////////////////////////////////////////////////////////
872 // Stream an object of class AliITSgeom.
875 if (R__b.IsReading()) {
876 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
877 TObject::Streamer(R__b);
879 if(fNlad!=0) delete[] fNlad;
880 if(fNdet!=0) delete[] fNdet;
881 fNlad = new Int_t[fNlayers];
882 fNdet = new Int_t[fNlayers];
883 for(i=0;i<fNlayers;i++) R__b >> fNlad[i];
884 for(i=0;i<fNlayers;i++) R__b >> fNdet[i];
886 for(i=0;i<fNlayers;i++) delete[] fg[i];
889 fg = new ITS_geom*[fNlayers];
890 for(i=0;i<fNlayers;i++){
891 fg[i] = new ITS_geom[fNlad[i]*fNdet[i]];
892 for(j=0;j<fNlad[i]*fNdet[i];j++){
893 R__b >> fg[i][j].fShapeIndex;
894 R__b >> fg[i][j].fx0;
895 R__b >> fg[i][j].fy0;
896 R__b >> fg[i][j].fz0;
897 R__b >> fg[i][j].frx;
898 R__b >> fg[i][j].fry;
899 R__b >> fg[i][j].frz;
900 for(k=0;k<9;k++) R__b >> fg[i][j].fr[k];
905 R__b.WriteVersion(AliITSgeom::IsA());
906 TObject::Streamer(R__b);
908 for(i=0;i<fNlayers;i++) R__b << fNlad[i];
909 for(i=0;i<fNlayers;i++) R__b << fNdet[i];
910 for(i=0;i<fNlayers;i++) for(j=0;j<fNlad[i]*fNdet[i];j++){
911 R__b << fg[i][j].fShapeIndex;
912 R__b << fg[i][j].fx0;
913 R__b << fg[i][j].fy0;
914 R__b << fg[i][j].fz0;
915 R__b << fg[i][j].frx;
916 R__b << fg[i][j].fry;
917 R__b << fg[i][j].frz;
918 for(k=0;k<9;k++) R__b << fg[i][j].fr[k];
924 //___________________________________________________________________________
925 ofstream & AliITSgeom::PrintGeom(ofstream &R__b){
926 ////////////////////////////////////////////////////////////////////////
927 // The default Streamer function "written by ROOT" doesn't write out
928 // the arrays referenced by pointers. Therefore, a specific Streamer function
929 // has to be written. This function should not be modified but instead added
930 // on to so that older versions can still be read. The proper handling of
931 // the version dependent streamer function hasn't been written do to the lack
932 // of finding an example at the time of writting.
933 ////////////////////////////////////////////////////////////////////////
934 // Stream an object of class AliITSgeom.
937 R__b.setf(ios::scientific);
938 R__b << fNlayers << " ";
939 for(i=0;i<fNlayers;i++) R__b << fNlad[i] << " ";
940 for(i=0;i<fNlayers;i++) R__b << fNdet[i] << "\n";
941 for(i=0;i<fNlayers;i++) for(j=0;j<fNlad[i]*fNdet[i];j++){
942 R__b <<setprecision(16) << fg[i][j].fShapeIndex << " ";
943 R__b <<setprecision(16) << fg[i][j].fx0 << " ";
944 R__b <<setprecision(16) << fg[i][j].fy0 << " ";
945 R__b <<setprecision(16) << fg[i][j].fz0 << " ";
946 R__b <<setprecision(16) << fg[i][j].frx << " ";
947 R__b <<setprecision(16) << fg[i][j].fry << " ";
948 R__b <<setprecision(16) << fg[i][j].frz << "\n";
949 for(k=0;k<9;k++) R__b <<setprecision(16) << fg[i][j].fr[k] << " ";
956 //___________________________________________________________________________
957 ifstream & AliITSgeom::ReadGeom(ifstream &R__b){
958 ////////////////////////////////////////////////////////////////////////
959 // The default Streamer function "written by ROOT" doesn't write out
960 // the arrays referenced by pointers. Therefore, a specific Streamer function
961 // has to be written. This function should not be modified but instead added
962 // on to so that older versions can still be read. The proper handling of
963 // the version dependent streamer function hasn't been written do to the lack
964 // of finding an example at the time of writting.
965 ////////////////////////////////////////////////////////////////////////
966 // Stream an object of class AliITSgeom.
970 if(fNlad!=0) delete[] fNlad;
971 if(fNdet!=0) delete[] fNdet;
972 fNlad = new Int_t[fNlayers];
973 fNdet = new Int_t[fNlayers];
974 for(i=0;i<fNlayers;i++) R__b >> fNlad[i];
975 for(i=0;i<fNlayers;i++) R__b >> fNdet[i];
977 for(i=0;i<fNlayers;i++) delete[] fg[i];
980 fg = new ITS_geom*[fNlayers];
981 for(i=0;i<fNlayers;i++){
982 fg[i] = new ITS_geom[fNlad[i]*fNdet[i]];
983 for(j=0;j<fNlad[i]*fNdet[i];j++){
984 R__b >> fg[i][j].fShapeIndex;
985 R__b >> fg[i][j].fx0;
986 R__b >> fg[i][j].fy0;
987 R__b >> fg[i][j].fz0;
988 R__b >> fg[i][j].frx;
989 R__b >> fg[i][j].fry;
990 R__b >> fg[i][j].frz;
991 for(k=0;k<9;k++) R__b >> fg[i][j].fr[k];