]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSmodule.cxx
Added macro for visualization of the TOF ROOT geometry
[u/mrichter/AliRoot.git] / ITS / AliITSmodule.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                          *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.12  2002/06/10 17:31:03  nilsen
19 Replaced TArrayI expansion with Root version.
20
21 Revision 1.11  2002/06/04 18:43:15  nilsen
22 Fix to avoid divide by zero problem in MedianHitG and MedianHitL for track
23 that enter and exit the same side of a detector sensitive volume. Needed
24 for Fast simulation. Thanks to Nicola Carrer.
25
26 Revision 1.10  2002/03/15 17:21:54  nilsen
27 Removed zero-ing of fModules variable in constructors.
28
29 Revision 1.9  2000/10/04 19:46:39  barbera
30 Corrected by F. Carminati for v3.04
31
32 Revision 1.8  2000/10/02 16:32:57  barbera
33 Forward declarations added and formatting
34
35 Revision 1.3.4.8  2000/10/02 15:55:26  barbera
36 Forward declarations added and formatting
37
38 Revision 1.7  2000/09/22 12:36:38  nilsen
39 Minor changes to improve compilation and create less NOISE.
40
41 Revision 1.6  2000/07/10 16:07:18  fca
42 Release version of ITS code
43
44 Revision 1.3.4.2  2000/03/02 21:42:29  nilsen 
45 Linked AliDetector::fDigit to AliITSmodule::fDigitsM and AliITS::fITSRecPoints
46 to AliITSmodule::fRecPointsM. Renamed AliITSmodule::fPointsM to fRecPointsM.
47 Removed the deletion of fDigitsM from the distructor since it is only a copy
48 of what is in AliDetector. Fixed a bug in the functions LineSegmentL and
49 LineSegmentG. Added two new versions of LineSegmentL and LineSegmentG to
50 additionaly return track number from the hit. Removed FastPoint function,
51 haven't found anywere it was used, also it had very many problems, should
52 just call FastPointSPD... .
53
54 Revision 1.3.4.1  2000/01/12 19:03:32  nilsen
55 This is the version of the files after the merging done in December 1999.
56 See the ReadMe110100.txt file for details
57
58 Revision 1.3  1999/10/04 15:20:12  fca
59 Correct syntax accepted by g++ but not standard for static members, remove minor warnings
60
61 Revision 1.2  1999/09/29 09:24:20  fca
62 Introduction of the Copyright and cvs Log
63
64 */
65
66 #include <TArrayI.h>
67
68 #include <stdlib.h>
69
70 #include "AliRun.h"
71 #include "AliITS.h"
72 #include "AliITShit.h"
73 #include "AliITSmodule.h"
74 #include "AliITSgeom.h"
75
76 ClassImp(AliITSmodule)
77
78 //_______________________________________________________________________
79 //
80 // Impementation of class AliITSmodule
81 //
82 // created by: A. Bouchm, W. Peryt, S. Radomski, P. Skowronski 
83 //             R. Barbers, B. Batyunia, B. S. Nilsen
84 // ver 1.0     CERN 16.09.1999
85 //_______________________________________________________________________
86 //________________________________________________________________________
87 // 
88 // Constructors and deconstructor
89 //________________________________________________________________________
90 //
91 AliITSmodule::AliITSmodule() {
92     // constructor
93
94     fHitsM       = 0;
95     fTrackIndex  = 0;
96     fHitIndex    = 0;
97     fITS         = 0;
98
99 }
100 //_________________________________________________________________________
101 AliITSmodule::AliITSmodule(Int_t index) {
102   // constructor
103
104     fIndex      = index;
105     fHitsM      = new TObjArray();
106     fTrackIndex = new TArrayI(16);
107     fHitIndex   = new TArrayI(16);
108     fITS        = (AliITS*)(gAlice->GetDetector("ITS"));
109 }
110 //__________________________________________________________________________
111 AliITSmodule::~AliITSmodule() {
112     // The destructor for AliITSmodule. Before destoring AliITSmodule
113     // we must first destroy all of it's members.
114
115     if(fHitsM){
116         for(Int_t i=0;i<fHitsM->GetEntriesFast();i++) 
117             delete ((AliITShit *)(fHitsM->At(i)));
118         // must delete each object in the TObjArray.
119         delete fHitsM;
120     } // end if
121     delete fTrackIndex;
122     delete fHitIndex;
123     fITS = 0; // We don't delete this pointer since it is just a copy.
124 }
125 //____________________________________________________________________________
126 AliITSmodule::AliITSmodule(const AliITSmodule &source){
127 ////////////////////////////////////////////////////////////////////////
128 //     Copy Constructor 
129 ////////////////////////////////////////////////////////////////////////
130   printf("AliITSmodule error: AliITSmodule class has not to be copied! Exit.\n");
131   exit(1);
132 }
133
134 //_____________________________________________________________________________
135 AliITSmodule& AliITSmodule::operator=(const AliITSmodule &source){
136 ////////////////////////////////////////////////////////////////////////
137 //    Assignment operator 
138 ////////////////////////////////////////////////////////////////////////
139   printf("AliITSmodule error: AliITSmodule class has not to be copied! Exit.\n");
140   exit(1);
141   return *this; // fake return neded on Sun
142
143
144 //_________________________________________________________________________
145 // 
146 // Hits management
147 //__________________________________________________________________________
148 Int_t AliITSmodule::AddHit(AliITShit* hit,Int_t t,Int_t h) {
149 // Hits management
150
151   //printf("AddHit: beginning hit %p t h %d %d\n",hit,t,h);
152     fHitsM->AddLast(new AliITShit(*hit));
153     Int_t fNhitsM = fHitsM->GetEntriesFast();
154     if(fNhitsM-1>=fTrackIndex->GetSize()){ // need to expand the TArrayI
155       fTrackIndex->Set(fNhitsM+64);
156     } // end if
157     if(fNhitsM-1>=fHitIndex->GetSize()){ // need to expand the TArrayI
158       fHitIndex->Set(fNhitsM+64);
159     } // end if
160     (*fTrackIndex)[fNhitsM-1] = t;
161     (*fHitIndex)[fNhitsM-1]   = h;
162     return fNhitsM;
163 }
164 //___________________________________________________________________________
165 Double_t AliITSmodule::PathLength(Int_t index,AliITShit *itsHit1,
166                                   AliITShit *itsHit2){
167   // path lenght
168    Float_t  x1g,y1g,z1g;   
169    Float_t  x2g,y2g,z2g;
170    Double_t s;
171
172    itsHit1->GetPositionG(x1g,y1g,z1g);
173    itsHit2->GetPositionG(x2g,y2g,z2g);
174
175    s = TMath::Sqrt( ((Double_t)(x2g-x1g)*(Double_t)(x2g-x1g)) +
176                     ((Double_t)(y2g-y1g)*(Double_t)(y2g-y1g)) +
177                     ((Double_t)(z2g-z1g)*(Double_t)(z2g-z1g))  );
178    return s;
179 }
180 //___________________________________________________________________________
181 void AliITSmodule::PathLength(Int_t index,
182                               Float_t x,Float_t y,Float_t z,
183                               Int_t status,Int_t &nseg,
184                               Float_t &x1,Float_t &y1,Float_t &z1,
185                               Float_t &dx1,Float_t &dy1,Float_t &dz1,
186                               Int_t &flag){
187   // path length
188     static Float_t x0,y0,z0;
189
190     if ((status&0x0002)!=0){ // entering
191         x0 = x;
192         y0 = y;
193         z0 = z;
194         nseg = 0;
195         flag = 1;
196     }else{
197         x1 = x0;
198         y1 = y0;
199         z1 = z0;
200         dx1 = x-x1;
201         dy1 = y-y1;
202         dz1 = z-z1;
203         nseg++;
204         if ((status&0x0004)!=0) flag = 0; //exiting
205         if ((status&0x0001)!=0) flag = 2; // inside
206         else flag = 2; //inside ?
207         x0 = x;
208         y0 = y;
209         z0 = z;
210     } // end if
211 }
212 //___________________________________________________________________________
213 Bool_t AliITSmodule::LineSegmentL(Int_t hitindex,Double_t &a,Double_t &b,
214                                   Double_t &c,Double_t &d,
215                                   Double_t &e,Double_t &f,Double_t &de){
216   // line segment
217     static Int_t hitindex0;
218     AliITShit *h0,*h1;
219
220     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
221
222     h1 = (AliITShit *) (fHitsM->At(hitindex));
223     if(h1->StatusEntering()){ // if track entering volume, get index for next
224                               // step
225         hitindex0 = hitindex;
226         return kFALSE;
227     } // end if StatusEntering()
228     // else stepping
229     h0 = (AliITShit *) (fHitsM->At(hitindex0));
230     de = h1->GetIonization();
231     h0->GetPositionL(a,c,e);
232     h1->GetPositionL(b,d,f);
233     b = b - a;
234     d = d - c;
235     f = f - e;
236     hitindex0 = hitindex;
237     return kTRUE;
238 }
239 //___________________________________________________________________________
240 Bool_t AliITSmodule::LineSegmentG(Int_t hitindex,Double_t &a,Double_t &b,
241                                   Double_t &c,Double_t &d,
242                                   Double_t &e,Double_t &f,Double_t &de){
243   // line segment
244     static Int_t hitindex0;
245     AliITShit *h0,*h1;
246
247     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
248
249     h1 = (AliITShit *) (fHitsM->At(hitindex));
250     if(h1->StatusEntering()){ // if track entering volume, get index for next
251                               // step
252         hitindex0 = hitindex;
253         return kFALSE;
254     } // end if StatusEntering()
255     // else stepping
256     h0 = (AliITShit *) (fHitsM->At(hitindex0));
257     de = h1->GetIonization();
258     h0->GetPositionG(a,c,e);
259     h1->GetPositionG(b,d,f);
260     b = b - a;
261     d = d - c;
262     f = f - e;
263     hitindex0 = hitindex;
264     return kTRUE;
265 }
266 //___________________________________________________________________________
267 Bool_t AliITSmodule::LineSegmentL(Int_t hitindex,Double_t &a,Double_t &b,
268                                   Double_t &c,Double_t &d,
269                                   Double_t &e,Double_t &f,
270                                   Double_t &de,Int_t &track){
271   // line segmente
272     static Int_t hitindex0;
273     AliITShit *h0,*h1;
274
275     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
276
277     h1 = (AliITShit *) (fHitsM->At(hitindex));
278     if(h1->StatusEntering()){ // if track entering volume, get index for next
279                               // step
280         hitindex0 = hitindex;
281         track = h1->GetTrack();
282         return kFALSE;
283     } // end if StatusEntering()
284     // else stepping
285     h0 = (AliITShit *) (fHitsM->At(hitindex0));
286     de = h1->GetIonization();
287     h0->GetPositionL(a,c,e);
288     h1->GetPositionL(b,d,f);
289     b = b - a;
290     d = d - c;
291     f = f - e;
292     hitindex0 = hitindex;
293     track = h1->GetTrack();
294     return kTRUE;
295 }
296 //___________________________________________________________________________
297 Bool_t AliITSmodule::LineSegmentG(Int_t hitindex,Double_t &a,Double_t &b,
298                                   Double_t &c,Double_t &d,
299                                   Double_t &e,Double_t &f,
300                                   Double_t &de,Int_t &track){
301   // line segment
302     static Int_t hitindex0;
303     AliITShit *h0,*h1;
304
305     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
306
307     h1 = (AliITShit *) (fHitsM->At(hitindex));
308     if(h1->StatusEntering()){ // if track entering volume, get index for next
309                               // step
310         hitindex0 = hitindex;
311         track = h1->GetTrack();
312         return kFALSE;
313     } // end if StatusEntering()
314     // else stepping
315     h0 = (AliITShit *) (fHitsM->At(hitindex0));
316     de = h1->GetIonization();
317     h0->GetPositionG(a,c,e);
318     h1->GetPositionG(b,d,f);
319     b = b - a;
320     d = d - c;
321     f = f - e;
322     hitindex0 = hitindex;
323     track = h1->GetTrack();
324     return kTRUE;
325 }
326 //______________________________________________________________________
327 Bool_t AliITSmodule::MedianHitG(AliITShit *h1,AliITShit *h2,
328                                 Float_t &x,Float_t &y,Float_t &z){
329     // Computes the mean hit location for a set of hits that make up a track
330     // passing through a volume. Returns kFALSE untill the the track leaves
331     // the volume.
332     // median hit
333    AliITSgeom *gm = fITS->GetITSgeom();
334    Float_t x1l=0.,y1l=0.,z1l=0.;
335    Float_t x2l=0.,y2l=0.,z2l=0.;
336    Float_t xMl,yMl=0,zMl;
337    Float_t l[3], g[3];
338
339    h1->GetPositionG(x1l,y1l,z1l);
340    h2->GetPositionG(x2l,y2l,z2l);
341
342    // Modified by N.Carrer. In very rare occasions the track may be just
343    // tangent to the module. Therefore the entrance and exit points have the
344    // same y.
345    if( (y2l-y1l) != 0.0 ) {
346      xMl = (-y1l / (y2l-y1l))*(x2l-x1l) + x1l;
347      zMl = (-y1l / (y2l-y1l))*(z2l-z1l) + z1l;
348    } else {
349      xMl = 0.5*(x1l+x2l);
350      zMl = 0.5*(z1l+z2l);
351    }
352
353    l[0] = xMl;
354    l[1] = yMl;
355    l[2] = zMl;
356    gm->LtoG(h1->GetModule(),l,g);
357    x = g[0];
358    y = g[1];
359    z = g[2];
360    return kTRUE;
361 }
362 //___________________________________________________________________________
363 void AliITSmodule::MedianHitG(Int_t index,
364                               Float_t hitx1,Float_t hity1,Float_t hitz1,
365                               Float_t hitx2,Float_t hity2,Float_t hitz2,
366                               Float_t &xMg, Float_t &yMg, Float_t &zMg){
367   // median hit
368    AliITSgeom *gm = fITS->GetITSgeom();
369    Float_t x1l,y1l,z1l;
370    Float_t x2l,y2l,z2l;
371    Float_t xMl,yMl=0,zMl;
372    Float_t l[3], g[3];
373
374    g[0] = hitx1;
375    g[1] = hity1;
376    g[2] = hitz1;
377    gm->GtoL(index,g,l);
378    x1l = l[0];
379    y1l = l[1];
380    z1l = l[2];
381
382    g[0] = hitx2;
383    g[1] = hity2;
384    g[2] = hitz2;
385    gm->GtoL(index,g,l);
386    x2l = l[0];
387    y2l = l[1];
388    z2l = l[2];
389
390    // Modified by N.Carrer. In very rare occasions the track may be just
391    // tangent to the module. Therefore the entrance and exit points have the
392    // same y.
393    if( (y2l-y1l) != 0.0 ) {
394      xMl = (-y1l / (y2l-y1l))*(x2l-x1l) + x1l;
395      zMl = (-y1l / (y2l-y1l))*(z2l-z1l) + z1l;
396    } else {
397      xMl = 0.5*(x1l+x2l);
398      zMl = 0.5*(z1l+z2l);
399    }
400
401    l[0] = xMl;
402    l[1] = yMl;
403    l[2] = zMl;
404    gm->LtoG(index,l,g);
405    xMg = g[0];
406    yMg = g[1];
407    zMg = g[2];
408 }
409 //___________________________________________________________________________
410 Bool_t AliITSmodule::MedianHitL( AliITShit *itsHit1, 
411                              AliITShit *itsHit2, 
412                              Float_t &xMl, Float_t &yMl, Float_t &zMl){
413   // median hit
414    Float_t x1l,y1l,z1l;
415    Float_t x2l,y2l,z2l;
416
417    itsHit1->GetPositionL(x1l,y1l,z1l);
418    itsHit2->GetPositionL(x2l,y2l,z2l);
419
420    yMl = 0.0;
421    // Modified by N.Carrer. In very rare occasions the track may be just
422    // tangent to the module. Therefore the entrance and exit points have the
423    // same y.
424    if( (y2l-y1l) != 0.0 ) {
425      xMl = (-y1l / (y2l-y1l))*(x2l-x1l) + x1l;
426      zMl = (-y1l / (y2l-y1l))*(z2l-z1l) + z1l;       
427    } else {
428      xMl = 0.5*(x1l+x2l);
429      zMl = 0.5*(z1l+z2l);
430    }
431    return kTRUE;
432 }
433 //___________________________________________________________________________
434 void AliITSmodule::MedianHit(Int_t index,
435                              Float_t xg,Float_t yg,Float_t zg,
436                              Int_t status,
437                              Float_t &xMg,Float_t &yMg,Float_t &zMg,
438                              Int_t &flag){
439   // median hit
440    static Float_t x1,y1,z1;
441
442    if ((status&0x0002)!=0){ // entering
443        x1 = xg;
444        y1 = yg;
445        z1 = zg;
446        flag = 1;
447    } else if ((status&0x0004)!=0){ // exiting
448        MedianHitG(index,x1,y1,z1,xg,yg,zg,xMg,yMg,zMg);
449        flag = 0;
450    } // end if
451    else  flag = 1;
452 }
453 //___________________________________________________________________________
454 void AliITSmodule::GetID(Int_t &lay,Int_t &lad,Int_t &det){
455   // get ID
456         fITS->GetITSgeom()->GetModuleId(fIndex,lay,lad,det);
457         return ;
458 }
459