3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
8 /////////////////////////////////////////////////////////////////////////
9 // ITS geometry manipulation routines.
10 // Created April 15 1999.
12 // By: Bjorn S. Nilsen
14 // A package of geometry routines to do transformations between
15 // local, detector active area, and ALICE global coordinate system in such
16 // a way as to allow for detector alignment studies and the like. All of
17 // the information needed to do the coordinate transformation are kept in
18 // a specialized structure for ease of implementation.
19 /////////////////////////////////////////////////////////////////////////
21 #include "TObjArray.h"
22 #include "AliITSgeomSPD.h"
23 #include "AliITSgeomSDD.h"
24 #include "AliITSgeomSSD.h"
26 ////////////////////////////////////////////////////////////////////////
27 // The structure ITS_geom:
28 // The structure ITS_geom has been defined to hold all of the
29 // information necessary to do the coordinate transformations for one
30 // detector between the ALICE Cartesian global and the detector local
31 // coordinate systems. The rotations are implemented in the following
32 // order, Rz*Ry*Rx*(Vglobal-Vtrans)=Vlocal (in matrix notation).
33 // In addition it contains an index to the TObjArray containing all of
34 // the information about the shape of the active detector volume, and
35 // any other useful detector parameters. See the definition of *fShape
36 // below and the classes AliITSgeomSPD, AliITSgeomSDD, and AliITSgeomSSD
37 // for a full description. This structure is not available outside of
41 // The index to the array of detector shape information. In this way
42 // only an index is needed to be stored and not all of the shape
43 // information. This saves much space since most, if not all, of the
44 // detectors of a give type have the same shape information and are only
45 // placed in a different spot in the ALICE/ITS detector.
47 // Float_t fx0,fy0,fz0
48 // The Cartesian translation vector used to define part of the
49 // coordinate transformation. The units of the translation are kept
50 // in the Monte Carlo distance units, usually cm.
52 // Float_t frx,fry,frz
53 // The three rotation angles that define the rotation matrix. The
54 // angles are, frx the rotation about the x axis. fry the rotation about
55 // the "new" or "rotated" y axis. frz the rotation about the "new" or
56 // "rotated" z axis. These angles, although redundant with the rotation
57 // matrix fr, are kept for speed. This allows for their retrieval without
58 // having to compute them each and every time. The angles are kept in
62 // The 3x3 rotation matrix defined by the angles frx, fry, and frz,
63 // for the Global to Local transformation is
64 // |fr[0] fr[1] fr[2]| | cos(frz) sin(frz) 0| | cos(fry) 0 sin(fry)|
65 // fr=|fr[3] fr[4] fr[4]|=|-sin(frz) cos(frz) 0|*| 0 1 0 |
66 // |fr[6] fr[7] fr[8]| | 0 0 1| |-sin(fry) 0 cos(fry)|
69 // *|0 cos(frx) sin(frx)|
70 // |0 -sin(frx) cos(frx)|
72 // Even though this information is redundant with the three rotation
73 // angles, because this transformation matrix can be used so much it is
74 // kept to speed things up a lot. The coordinate system used is Cartesian.
75 ////////////////////////////////////////////////////////////////////////
78 Int_t fShapeIndex; // Shape index for this volume
79 Float_t fx0,fy0,fz0; // Translation vector
80 Float_t frx,fry,frz; // Rotation about axis, angle radians
81 Float_t fr[9]; // the rotation matrix
84 //_______________________________________________________________________
86 class AliITSgeom : public TObject {
87 ////////////////////////////////////////////////////////////////////////
90 // Written by Bjorn S. Nilsen
95 // The number of ITS layers for this geometry. By default this
96 // is 6, but can be modified by the creator function if there are
97 // more layers defined.
100 // A pointer to an array fNlayers long containing the number of
101 // ladders for each layer. This array is typically created and filled
102 // by the AliITSgeom creator function.
105 // A pointer to an array fNlayers long containing the number of
106 // active detector volumes for each ladder. This array is typically
107 // created and filled by the AliITSgeom creator function.
110 // A pointer to an array of pointers pointing to the ITS_geom
111 // structure containing the coordinate transformation information.
112 // The ITS_geom structure corresponding to layer=lay, ladder=lad,
113 // and detector=det is gotten by fg[lay-1][(fNlad[lay-1]*(lad-1)+det-1)].
114 // In this way a lot of space is saved over trying to keep a three
115 // dimensional array fNlayersXmax(fNlad)Xmax(fNdet), since the number
116 // of detectors typically increases with layer number.
119 // A pointer to an array of TObjects containing the detailed shape
120 // information for each type of detector used in the ITS. For example
121 // I have created AliITSgeomSPD, AliITSgeomSDD, and AliITSgeomSSD as
122 // example structures, derived from TObjects, to hold the detector
123 // information. I would recommend that one element in each of these
124 // structures, that which describes the shape of the active volume,
125 // be one of the ROOT classes derived from TShape. In this way it would
126 // be easy to have the display program display the correct active
127 // ITS volumes. See the example classes AliITSgeomSPD, AliITSgeomSDD,
128 // and AliITSgeomSSD for a more detailed example.
133 // The default constructor for the AliITSgeom class. It, by default,
134 // sets fNlayers to zero and zeros all pointers.
136 // AliITSgeom(const char *filename)
137 // The constructor for the AliITSgeom class. All of the data to fill
138 // this structure is read in from the file given my the input filename.
140 // AliITSgeom(AliITSgeom &source)
141 // The copy constructor for the AliITSgeom class. It calls the
142 // = operator function. See the = operator function for more details.
144 // void operator=(AliITSgeom &source)
145 // The = operator function for the AliITSgeom class. It makes an
146 // independent copy of the class in such a way that any changes made
147 // to the copied class will not affect the source class in any way.
148 // This is required for many ITS alignment studies where the copied
149 // class is then modified by introducing some misalignment.
152 // The destructor for the AliITSgeom class. If the arrays fNlad,
153 // fNdet, or fg have had memory allocated to them, there pointer values
154 // are non zero, then this memory space is freed and they are set
155 // to zero. In addition, fNlayers is set to zero. The destruction of
156 // TObjArray fShape is, by default, handled by the TObjArray destructor.
158 // Int_t GetNdetectors(Int_t layer)
159 // This function returns the number of detectors/ladder for a give
160 // layer. In particular it returns fNdet[layer-1].
162 // Int_t GetNladders(Int_t layer)
163 // This function returns the number of ladders for a give layer. In
164 // particular it returns fNlad[layer-1].
166 // Int_t GetNlayers()
167 // This function returns the number of layers defined in the ITS
168 // geometry. In particular it returns fNlayers.
170 // GetAngles(Int_t layer,Int_t ladder,Int_t detector,
171 // Float_t &rx, Float_t &ry, Float_t &rz)
172 // This function returns the rotation angles for a give detector on
173 // a give ladder in a give layer in the three floating point variables
174 // provided. rx = frx, fy = fry, rz = frz. The angles are in radians
176 // GetTrans(Int_t layer,Int_t ladder,Int_t detector,
177 // Float_t &x, Float_t &y, Float_t &z)
178 // This function returns the Cartesian translation for a give
179 // detector on a give ladder in a give layer in the three floating
180 // point variables provided. x = fx0, y = fy0, z = fz0. The units are
181 // those of the Monte Carlo, generally cm.
183 // SetByAngles(Int_t layer,Int_t ladder,Int_t detector,
184 // Float_t &rx, Float_t &ry, Float_t &rz)
185 // This function computes a new rotation matrix based on the angles
186 // rx, ry, and rz (in radians) for a give detector on the give ladder
187 // in the give layer. A new
188 // fg[layer-1][(fNlad[layer-1]*(ladder-1)+detector-1)].fr[] array is
191 // SetTrans(Int_t layer,Int_t ladder,Int_t detector,
192 // Float_t x, Float_t y, Float_t z)
193 // This function sets a new translation vector, given by the three
194 // variables x, y, and z, for the Cartesian coordinate transformation
195 // for the detector defined by layer, ladder and detector.
197 // GetRotMatrix(Int_t layer, Int_t ladder, Int_t detector, Float_t *mat)
198 // Returns, in the Float_t array pointed to by mat, the full rotation
199 // matrix for the give detector defined by layer, ladder, and detector.
200 // It returns all nine elements of fr in the ITS_geom structure. See the
201 // description of the ITS_geom structure for further details of this
204 // GtoL(Int_t layer, Int_t ladder, Int_t detector,
205 // const Float_t *g, Float_t *l)
206 // The function that does the global ALICE Cartesian coordinate
207 // to local active volume detector Cartesian coordinate transformation.
208 // The local detector coordinate system is determined by the layer,
209 // ladder, and detector numbers. The global coordinates are entered by
210 // the three element Float_t array g and the local coordinate values
211 // are returned by the three element Float_t array l. The order of the
212 // three elements are g[0]=x, g[1]=y, and g[2]=z, similarly for l.
214 // GtoL(const Int_t *Id, const Float_t *g, Float_t *l)
215 // The function that does the global ALICE Cartesian coordinate
216 // to local active volume detector Cartesian coordinate transformation.
217 // The local detector coordinate system is determined by the three
218 // element array Id containing as it's three elements Id[0]=layer,
219 // Id[1]=ladder, and Id[2]=detector numbers. The global coordinates
220 // are entered by the three element Float_t array g and the local
221 // coordinate values are returned by the three element Float_t array l.
222 // The order of the three elements are g[0]=x, g[1]=y, and g[2]=z,
225 // LtoG(Int_t layer, Int_t ladder, Int_t detector,
226 // const Float_t *l, Float_t *g)
227 // The function that does the local active volume detector Cartesian
228 // coordinate to global ALICE Cartesian coordinate transformation.
229 // The local detector coordinate system is determined by the layer,
230 // ladder, and detector numbers. The local coordinates are entered by
231 // the three element Float_t array l and the global coordinate values
232 // are returned by the three element Float_t array g. The order of the
233 // three elements are l[0]=x, l[1]=y, and l[2]=z, similarly for g.
235 // LtoG(const Int_t *Id, const Float_t *l, Float_t *g)
236 // The function that does the local active volume detector Cartesian
237 // coordinate to global ALICE Cartesian coordinate transformation.
238 // The local detector coordinate system is determined by the three
239 // element array Id containing as it's three elements Id[0]=layer,
240 // Id[1]=ladder, and Id[2]=detector numbers. The local coordinates
241 // are entered by the three element Float_t array l and the global
242 // coordinate values are returned by the three element Float_t array g.
243 // The order of the three elements are l[0]=x, l[1]=y, and l[2]=z,
247 // This function returns the version number of this AliITSgeom
250 // AddShape(TObject *shape)
251 // This function adds one more shape element to the TObjArray
252 // fShape. It is primarily used in the constructor functions of the
253 // AliITSgeom class. The pointer *shape can be the pointer to any
254 // class that is derived from TObject (this is true for nearly every
255 // ROOT class). This does not appear to be working properly at this time.
257 // PrintComparison(FILE *fp, AliITSgeom *other)
258 // This function was primarily created for diagnostic reasons. It
259 // print to a file pointed to by the file pointer fp the difference
260 // between two AliITSgeom classes. The format of the file is basicly,
261 // define d? to be the difference between the same element of the two
262 // classes. For example dfrx = this->fg[i][j].frx - other->fg[i][j].frx.
263 // if(at least one of dfx0, dfy0, dfz0,dfrx,dfry,dfrz are non zero) then print
264 // layer ladder detector dfx0 dfy0 dfz0 dfrx dfry dfrz
265 // if(at least one of the 9 elements of dfr[] are non zero) then print
266 // layer ladder detector dfr[0] dfr[1] dfr[2]
267 // dfr[3] dfr[4] dfr[5]
268 // dfr[6] dfr[7] dfr[8]
269 // Only non zero values are printed to save space. The differences are
270 // typical written to a file because there are usually a lot of numbers
271 // printed out and it is usually easier to read them in some nice editor
272 // rather than zooming quickly past you on a screen. fprintf is used to
273 // do the printing. The fShapeIndex difference is not printed at this time.
275 // PrintData(FILE *fp, Int_t layer, Int_t ladder, Int_t detector)
276 // This function prints out the coordinate transformations for
277 // the particular detector defined by layer, ladder, and detector
278 // to the file pointed to by the File pointer fp. fprinf statements
279 // are used to print out the numbers. The format is
280 // layer ladder detector Trans= fx0 fy0 fz0 rot= frx fry frz Shape=fShapeIndex
281 // dfr= fr[0] fr[1] fr[2]
282 // dfr= fr[3] fr[4] fr[5]
283 // dfr= fr[6] fr[7] fr[8]
284 // By indicating which detector, some control over the information
285 // is given to the user. The output it written to the file pointed
286 // to by the file pointer fp. This can be set to stdout if you want.
288 // Streamer(TBuffer &R__b)
289 // The default Streamer function "written by ROOT" doesn't write out
290 // the arrays referenced by pointers. Therefore, a specific Streamer function
291 // has to be written. This function should not be modified but instead added
292 // on to so that older versions can still be read. The proper handling of
293 // the version dependent streamer function hasn't been written do to the lack
294 // of finding an example at the time of writting.
296 //----------------------------------------------------------------------
298 // The following member functions are defined to modify an existing
299 // AliITSgeom data structure. They were developed for the use in doing
300 // alignment studies of the ITS.
302 // GlobalChange(Float_t *dtranslation, Float_t *drotation)
303 // This function performs a Cartesian translation and rotation of
304 // the full ITS from its default position by an amount determined by
305 // the three element arrays dtranslation and drotation. If every element
306 // of dtranslation and drotation are zero then there is no change made
307 // the geometry. The change is global in that the exact same translation
308 // and rotation is done to every detector element in the exact same way.
309 // The units of the translation are those of the Monte Carlo, usually cm,
310 // and those of the rotation are in radians. The elements of dtranslation
311 // are dtranslation[0] = x, dtranslation[1] = y, and dtranslation[2] = z.
312 // The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
313 // drotation[2] = rz. A change in x will move the hole ITS in the ALICE
314 // global x direction, the same for a change in y. A change in z will
315 // result in a translation of the ITS as a hole up or down the beam line.
316 // A change in the angles will result in the inclination of the ITS with
317 // respect to the beam line, except for an effective rotation about the
318 // beam axis which will just rotate the ITS as a hole about the beam axis.
320 // GlobalCylindericalChange(Float_t *dtranslation, Float_t *drotation)
321 // This function performs a cylindrical translation and rotation of
322 // each ITS element by a fixed about in radius, rphi, and z from its
323 // default position by an amount determined by the three element arrays
324 // dtranslation and drotation. If every element of dtranslation and
325 // drotation are zero then there is no change made the geometry. The
326 // change is global in that the exact same distance change in translation
327 // and rotation is done to every detector element in the exact same way.
328 // The units of the translation are those of the Monte Carlo, usually cm,
329 // and those of the rotation are in radians. The elements of dtranslation
330 // are dtranslation[0] = r, dtranslation[1] = rphi, and dtranslation[2] = z.
331 // The elements of drotation are drotation[0] = rx, drotation[1] = ry, and
332 // drotation[2] = rz. A change in r will results in the increase of the
333 // radius of each layer by the same about. A change in rphi will results in
334 // the rotation of each layer by a different angle but by the same
335 // circumferential distance. A change in z will result in a translation
336 // of the ITS as a hole up or down the beam line. A change in the angles
337 // will result in the inclination of the ITS with respect to the beam
338 // line, except for an effective rotation about the beam axis which will
339 // just rotate the ITS as a hole about the beam axis.
341 // RandomChange(Float_t *stranslation, Float_t *srotation)
342 // This function performs a Gaussian random displacement and/or
343 // rotation about the present global position of each active
344 // volume/detector of the ITS. The sigma of the random displacement
345 // is determined by the three element array stranslation, for the
346 // x y and z translations, and the three element array srotation,
347 // for the three rotation about the axis x y and z.
349 // RandomCylindericalChange(Float_t *stranslation, Float_t *srotation)
350 // This function performs a Gaussian random displacement and/or
351 // rotation about the present global position of each active
352 // volume/detector of the ITS. The sigma of the random displacement
353 // is determined by the three element array stranslation, for the
354 // r rphi and z translations, and the three element array srotation,
355 // for the three rotation about the axis x y and z. This random change
356 // in detector position allow for the simulation of a random uncertainty
357 // in the detector positions of the ITS.
358 ////////////////////////////////////////////////////////////////////////
360 Int_t fNlayers; // The number of layers.
361 Int_t *fNlad; // Array of the number of ladders/layer(layer)
362 Int_t *fNdet; // Array of the number of detectors/ladder(layer)
363 ITS_geom **fg; // Structure of translation and rotation.
364 TObjArray *fShape; // Array of shapes and detector information.
367 AliITSgeom(); // Default constructor
368 AliITSgeom(const char *filename); // Constructor
369 AliITSgeom(AliITSgeom &source); // Copy constructor
370 void operator=(AliITSgeom &source);// = operator
371 virtual ~AliITSgeom(); // Default destructor
372 // this is a dummy routine for now.
373 Int_t GetNdetectors(Int_t layer) const {return fNdet[layer-1];}
374 Int_t GetNladders(Int_t layer) const {return fNlad[layer-1];}
375 Int_t GetNlayers() const {return fNlayers;}
376 void GetAngles(Int_t lay,Int_t lad,Int_t det,
377 Float_t &rx,Float_t &ry,Float_t &rz)const {
378 rx = fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].frx;
379 ry = fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fry;
380 rz = fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].frz;}
381 void GetTrans(Int_t lay,Int_t lad,Int_t det,
382 Float_t &x,Float_t &y,Float_t &z)const {
383 x = fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fx0;
384 y = fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fy0;
385 z = fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fz0;}
386 void SetByAngles(Int_t lay,Int_t lad,Int_t det,
387 Float_t rx,Float_t ry,Float_t rz);
388 void SetTrans(Int_t lay,Int_t lad,Int_t det,
389 Float_t x,Float_t y,Float_t z){
390 fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fx0 = x;
391 fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fy0 = y;
392 fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fz0 = z;}
393 void GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Float_t *mat);
394 void GtoL(Int_t lay,Int_t lad,Int_t det,const Float_t *g,Float_t *l);
395 void GtoL(const Int_t *id,const Float_t *g,Float_t *l);
396 void GtoL(const Int_t index,const Float_t *g,Float_t *l);
397 void GtoLMomentum(Int_t lay,Int_t lad,Int_t det,const Float_t *g,Float_t *l);
398 void LtoG(Int_t lay,Int_t lad,Int_t det,const Float_t *l,Float_t *g);
399 void LtoG(const Int_t *id,const Float_t *l,Float_t *g);
400 void LtoG(const Int_t index,const Float_t *l,Float_t *g);
401 void LtoGMomentum(Int_t lay,Int_t lad,Int_t det,const Float_t *l,Float_t *g);
402 Int_t GetModuleIndex(Int_t lay,Int_t lad,Int_t det);
403 void GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det);
404 void GlobalChange(Float_t *tran,Float_t *rot);
405 void GlobalCylindericalChange(Float_t *tran,Float_t *rot);
406 void RandomChange(Float_t *stran,Float_t *srot);
407 void RandomCylindericalChange(Float_t *stran,Float_t *srot);
408 void PrintComparison(FILE *fp,AliITSgeom *other);
409 void PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det);
410 ofstream &PrintGeom(ofstream &out);
411 ifstream &ReadGeom(ifstream &in);
412 virtual Int_t IsVersion() const {return 0;}
413 void AddShape(TObject *shp){fShape->AddLast(shp);}
414 virtual TObject *GetShape(Int_t lay,Int_t lad,Int_t det)
415 const {return fShape->At(fg[lay-1][fNdet[lay-1]*(lad-1)+det-1].fShapeIndex);}
417 ClassDef(AliITSgeom,1)