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