]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSmodule.cxx
Log replaced by Id
[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 /* $Id$ */
17
18 #include <TArrayI.h>
19
20 #include <stdlib.h>
21
22 #include "AliRun.h"
23 #include "AliITS.h"
24 #include "AliITShit.h"
25 #include "AliITSmodule.h"
26 #include "AliITSgeom.h"
27
28 ClassImp(AliITSmodule)
29
30 //_______________________________________________________________________
31 //
32 // Impementation of class AliITSmodule
33 //
34 // created by: A. Bouchm, W. Peryt, S. Radomski, P. Skowronski 
35 //             R. Barbers, B. Batyunia, B. S. Nilsen
36 // ver 1.0     CERN 16.09.1999
37 //_______________________________________________________________________
38 //________________________________________________________________________
39 // 
40 // Constructors and deconstructor
41 //________________________________________________________________________
42 //
43 AliITSmodule::AliITSmodule() {
44     // constructor
45
46     fHitsM       = 0;
47     fTrackIndex  = 0;
48     fHitIndex    = 0;
49     fITS         = 0;
50
51 }
52 //_________________________________________________________________________
53 AliITSmodule::AliITSmodule(Int_t index) {
54   // constructor
55
56     fIndex      = index;
57     fHitsM      = new TObjArray();
58     fTrackIndex = new TArrayI(16);
59     fHitIndex   = new TArrayI(16);
60     fITS        = (AliITS*)(gAlice->GetDetector("ITS"));
61 }
62 //__________________________________________________________________________
63 AliITSmodule::~AliITSmodule() {
64     // The destructor for AliITSmodule. Before destoring AliITSmodule
65     // we must first destroy all of it's members.
66
67     if(fHitsM){
68       fHitsM->Delete();
69       delete fHitsM;
70       fHitsM = 0;
71     } // end if
72     delete fTrackIndex;
73     delete fHitIndex;
74     fITS = 0; // We don't delete this pointer since it is just a copy.
75 }
76 //____________________________________________________________________________
77 AliITSmodule::AliITSmodule(const AliITSmodule &source){
78 ////////////////////////////////////////////////////////////////////////
79 //     Copy Constructor 
80 ////////////////////////////////////////////////////////////////////////
81   Error("AliITSmodule","AliITSmodule class has not to be copied! Exit.");
82   exit(1);
83 }
84 //_____________________________________________________________________________
85 AliITSmodule& AliITSmodule::operator=(const AliITSmodule &source){
86 ////////////////////////////////////////////////////////////////////////
87 //    Assignment operator 
88 ////////////////////////////////////////////////////////////////////////
89   Error("AliITSmodule","AliITSmodule class has not to be copied! Exit.");
90   exit(1);
91   return *this; // fake return neded on Sun
92 }
93 //_________________________________________________________________________
94 // 
95 // Hits management
96 //__________________________________________________________________________
97 Int_t AliITSmodule::AddHit(AliITShit* hit,Int_t t,Int_t h) {
98 // Hits management
99
100   //printf("AddHit: beginning hit %p t h %d %d\n",hit,t,h);
101     fHitsM->AddLast(new AliITShit(*hit));
102     Int_t fNhitsM = fHitsM->GetEntriesFast();
103     if(fNhitsM-1>=fTrackIndex->GetSize()){ // need to expand the TArrayI
104       fTrackIndex->Set(fNhitsM+64);
105     } // end if
106     if(fNhitsM-1>=fHitIndex->GetSize()){ // need to expand the TArrayI
107       fHitIndex->Set(fNhitsM+64);
108     } // end if
109     (*fTrackIndex)[fNhitsM-1] = t;
110     (*fHitIndex)[fNhitsM-1]   = h;
111     return fNhitsM;
112 }
113 //___________________________________________________________________________
114 Double_t AliITSmodule::PathLength(Int_t index,AliITShit *itsHit1,
115                                   AliITShit *itsHit2){
116   // path lenght
117    Float_t  x1g,y1g,z1g;   
118    Float_t  x2g,y2g,z2g;
119    Double_t s;
120
121    itsHit1->GetPositionG(x1g,y1g,z1g);
122    itsHit2->GetPositionG(x2g,y2g,z2g);
123
124    s = TMath::Sqrt( ((Double_t)(x2g-x1g)*(Double_t)(x2g-x1g)) +
125                     ((Double_t)(y2g-y1g)*(Double_t)(y2g-y1g)) +
126                     ((Double_t)(z2g-z1g)*(Double_t)(z2g-z1g))  );
127    return s;
128 }
129 //___________________________________________________________________________
130 void AliITSmodule::PathLength(Int_t index,
131                               Float_t x,Float_t y,Float_t z,
132                               Int_t status,Int_t &nseg,
133                               Float_t &x1,Float_t &y1,Float_t &z1,
134                               Float_t &dx1,Float_t &dy1,Float_t &dz1,
135                               Int_t &flag){
136   // path length
137     static Float_t x0,y0,z0;
138
139     if ((status&0x0002)!=0){ // entering
140         x0 = x;
141         y0 = y;
142         z0 = z;
143         nseg = 0;
144         flag = 1;
145     }else{
146         x1 = x0;
147         y1 = y0;
148         z1 = z0;
149         dx1 = x-x1;
150         dy1 = y-y1;
151         dz1 = z-z1;
152         nseg++;
153         if ((status&0x0004)!=0) flag = 0; //exiting
154         if ((status&0x0001)!=0) flag = 2; // inside
155         else flag = 2; //inside ?
156         x0 = x;
157         y0 = y;
158         z0 = z;
159     } // end if
160 }
161 //___________________________________________________________________________
162 Bool_t AliITSmodule::LineSegmentL(Int_t hitindex,Double_t &a,Double_t &b,
163                                   Double_t &c,Double_t &d,
164                                   Double_t &e,Double_t &f,Double_t &de){
165   // line segment
166     AliITShit *h1;
167     Double_t t;
168
169     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
170
171     h1 = (AliITShit *) (fHitsM->At(hitindex));
172     if(h1->StatusEntering()){ // if track entering volume, get index for next
173                               // step
174         return kFALSE;
175     } // end if StatusEntering()
176     // else stepping
177     de = h1->GetIonization();
178     h1->GetPositionL0(a,c,e,t);
179     h1->GetPositionL(b,d,f);
180     b = b - a;
181     d = d - c;
182     f = f - e;
183     return kTRUE;
184 }
185 //___________________________________________________________________________
186 Bool_t AliITSmodule::LineSegmentG(Int_t hitindex,Double_t &a,Double_t &b,
187                                   Double_t &c,Double_t &d,
188                                   Double_t &e,Double_t &f,Double_t &de){
189   // line segment
190     AliITShit *h1;
191     Double_t t;
192
193     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
194
195     h1 = (AliITShit *) (fHitsM->At(hitindex));
196     if(h1->StatusEntering()){ // if track entering volume, get index for next
197                               // step
198         return kFALSE;
199     } // end if StatusEntering()
200     // else stepping
201     de = h1->GetIonization();
202     h1->GetPositionG0(a,c,e,t);
203     h1->GetPositionG(b,d,f);
204     b = b - a;
205     d = d - c;
206     f = f - e;
207     return kTRUE;
208 }
209 //___________________________________________________________________________
210 Bool_t AliITSmodule::LineSegmentL(Int_t hitindex,Double_t &a,Double_t &b,
211                                   Double_t &c,Double_t &d,
212                                   Double_t &e,Double_t &f,
213                                   Double_t &de,Int_t &track){
214   // line segmente
215     AliITShit *h1;
216     Double_t t;
217
218     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
219
220     h1 = (AliITShit *) (fHitsM->At(hitindex));
221     if(h1->StatusEntering()){ // if track entering volume, get index for next
222                               // step
223         track = h1->GetTrack();
224         return kFALSE;
225     } // end if StatusEntering()
226     // else stepping
227     de = h1->GetIonization();
228     h1->GetPositionL0(a,c,e,t);
229     h1->GetPositionL(b,d,f);
230     b = b - a;
231     d = d - c;
232     f = f - e;
233     track = h1->GetTrack();
234     return kTRUE;
235 }
236 //___________________________________________________________________________
237 Bool_t AliITSmodule::LineSegmentG(Int_t hitindex,Double_t &a,Double_t &b,
238                                   Double_t &c,Double_t &d,
239                                   Double_t &e,Double_t &f,
240                                   Double_t &de,Int_t &track){
241   // line segment
242     AliITShit *h1;
243     Double_t t;
244
245     if(hitindex>= fHitsM->GetEntriesFast()) return kFALSE;
246
247     h1 = (AliITShit *) (fHitsM->At(hitindex));
248     if(h1->StatusEntering()){ // if track entering volume, get index for next
249                               // step
250         track = h1->GetTrack();
251         return kFALSE;
252     } // end if StatusEntering()
253     // else stepping
254     de = h1->GetIonization();
255     h1->GetPositionG0(a,c,e,t);
256     h1->GetPositionG(b,d,f);
257     b = b - a;
258     d = d - c;
259     f = f - e;
260     track = h1->GetTrack();
261     return kTRUE;
262 }
263 //______________________________________________________________________
264 Bool_t AliITSmodule::MedianHitG(AliITShit *h1,AliITShit *h2,
265                                 Float_t &x,Float_t &y,Float_t &z){
266     // Computes the mean hit location for a set of hits that make up a track
267     // passing through a volume. Returns kFALSE untill the the track leaves
268     // the volume.
269     // median hit
270    AliITSgeom *gm = fITS->GetITSgeom();
271    Float_t x1l=0.,y1l=0.,z1l=0.;
272    Float_t x2l=0.,y2l=0.,z2l=0.;
273    Float_t xMl,yMl=0,zMl;
274    Float_t l[3], g[3];
275
276    h1->GetPositionG(x1l,y1l,z1l);
277    h2->GetPositionG(x2l,y2l,z2l);
278
279    if((y2l*y1l)<0.) {
280      xMl = (-y1l / (y2l-y1l))*(x2l-x1l) + x1l;
281      zMl = (-y1l / (y2l-y1l))*(z2l-z1l) + z1l;
282    } else {
283      xMl = 0.5*(x1l+x2l);
284      zMl = 0.5*(z1l+z2l);
285    }
286
287    l[0] = xMl;
288    l[1] = yMl;
289    l[2] = zMl;
290    gm->LtoG(h1->GetModule(),l,g);
291    x = g[0];
292    y = g[1];
293    z = g[2];
294    return kTRUE;
295 }
296 //___________________________________________________________________________
297 void AliITSmodule::MedianHitG(Int_t index,
298                               Float_t hitx1,Float_t hity1,Float_t hitz1,
299                               Float_t hitx2,Float_t hity2,Float_t hitz2,
300                               Float_t &xMg, Float_t &yMg, Float_t &zMg){
301   // median hit
302    AliITSgeom *gm = fITS->GetITSgeom();
303    Float_t x1l,y1l,z1l;
304    Float_t x2l,y2l,z2l;
305    Float_t xMl,yMl=0,zMl;
306    Float_t l[3], g[3];
307
308    g[0] = hitx1;
309    g[1] = hity1;
310    g[2] = hitz1;
311    gm->GtoL(index,g,l);
312    x1l = l[0];
313    y1l = l[1];
314    z1l = l[2];
315
316    g[0] = hitx2;
317    g[1] = hity2;
318    g[2] = hitz2;
319    gm->GtoL(index,g,l);
320    x2l = l[0];
321    y2l = l[1];
322    z2l = l[2];
323
324    if((y2l*y1l)<0.) {
325      xMl = (-y1l / (y2l-y1l))*(x2l-x1l) + x1l;
326      zMl = (-y1l / (y2l-y1l))*(z2l-z1l) + z1l;
327    } else {
328      xMl = 0.5*(x1l+x2l);
329      zMl = 0.5*(z1l+z2l);
330    }
331
332    l[0] = xMl;
333    l[1] = yMl;
334    l[2] = zMl;
335    gm->LtoG(index,l,g);
336    xMg = g[0];
337    yMg = g[1];
338    zMg = g[2];
339 }
340 //___________________________________________________________________________
341 Bool_t AliITSmodule::MedianHitL( AliITShit *itsHit1, 
342                              AliITShit *itsHit2, 
343                              Float_t &xMl, Float_t &yMl, Float_t &zMl){
344   // median hit
345    Float_t x1l,y1l,z1l;
346    Float_t x2l,y2l,z2l;
347
348    itsHit1->GetPositionL(x1l,y1l,z1l);
349    itsHit2->GetPositionL(x2l,y2l,z2l);
350
351    yMl = 0.0;
352    if((y2l*y1l)<0.) {
353      xMl = (-y1l / (y2l-y1l))*(x2l-x1l) + x1l;
354      zMl = (-y1l / (y2l-y1l))*(z2l-z1l) + z1l;       
355    } else {
356      xMl = 0.5*(x1l+x2l);
357      zMl = 0.5*(z1l+z2l);
358    }
359    return kTRUE;
360 }
361 //___________________________________________________________________________
362 void AliITSmodule::MedianHit(Int_t index,
363                              Float_t xg,Float_t yg,Float_t zg,
364                              Int_t status,
365                              Float_t &xMg,Float_t &yMg,Float_t &zMg,
366                              Int_t &flag){
367   // median hit
368    static Float_t x1,y1,z1;
369
370    if ((status&0x0002)!=0){ // entering
371        x1 = xg;
372        y1 = yg;
373        z1 = zg;
374        flag = 1;
375    } else if ((status&0x0004)!=0){ // exiting
376        MedianHitG(index,x1,y1,z1,xg,yg,zg,xMg,yMg,zMg);
377        flag = 0;
378    } // end if
379    else  flag = 1;
380 }
381 //___________________________________________________________________________
382 void AliITSmodule::GetID(Int_t &lay,Int_t &lad,Int_t &det){
383   // get ID
384         fITS->GetITSgeom()->GetModuleId(fIndex,lay,lad,det);
385         return ;
386 }
387