]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSdigit.cxx
Corrections needed on HP
[u/mrichter/AliRoot.git] / ITS / AliITSdigit.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 ////////////////////////////////////////////////
19 //  Digits classes for all ITS detectors      //
20 ////////////////////////////////////////////////
21 #include <TObjArray.h>
22 #include <TArrayI.h>
23 #include <TArrayF.h>
24 #include <TMath.h>
25 #include "AliITSdigit.h"
26
27 //______________________________________________________________________
28 ClassImp(AliITSdigit)
29 AliITSdigit::AliITSdigit(const Int_t *digits) {
30   // Creates a real data digit object
31
32   fCoord1       = digits[0];
33   fCoord2       = digits[1];
34   fSignal       = digits[2];
35 }
36 //______________________________________________________________________
37 void AliITSdigit::Print(ostream *os){
38     //Standard output format for this class
39
40     *os << fCoord1 <<","<< fCoord2 <<","<< fSignal;
41 }
42 //______________________________________________________________________
43 void AliITSdigit::Read(istream *os){
44     //Standard input for this class
45
46     *os >> fCoord1 >> fCoord2 >> fSignal;
47 }
48 //______________________________________________________________________
49 ostream &operator<<(ostream &os,AliITSdigit &source){
50     // Standard output streaming function.
51
52     source.Print(&os);
53     return os;
54 }
55 //______________________________________________________________________
56 istream &operator>>(istream &os,AliITSdigit &source){
57     // Standard output streaming function.
58
59     source.Read(&os);
60     return os;
61 }
62 //______________________________________________________________________
63 ClassImp(AliITSdigitSPD)
64 AliITSdigitSPD::AliITSdigitSPD():AliITSdigit(){
65     // default constructor, zero coordinates and set array
66     // elements to clearly unphysical values. A value of 0 may
67     // be a valide track of hit number.
68     Int_t i;
69
70     for(i=0;i<fkSspd;i++) fTracks[i]  = -3;
71     for(i=0;i<fkSspd;i++) fHits[i]    = -1;
72 }
73 //______________________________________________________________________
74 AliITSdigitSPD::AliITSdigitSPD(const Int_t *digits){
75     // Creates a SPD digit object
76     Int_t i;
77
78     for(i=0;i<fkSspd;i++) fTracks[i]  = -3;
79     for(i=0;i<fkSspd;i++) fHits[i]    = -1;
80     fCoord1       = digits[0];
81     fCoord2       = digits[1];
82     fSignal       = 1;
83     fSignalSPD    = digits[2];
84 }
85 //______________________________________________________________________
86 AliITSdigitSPD::AliITSdigitSPD(const Int_t *digits,const Int_t *tracks,
87                                const Int_t *hits){
88     // Creates a simulated SPD digit object
89
90     for(Int_t i=0; i<fkSspd; i++) {
91         fTracks[i] = tracks[i];
92         fHits[i]   = hits[i];
93     } // end for i
94     fCoord1       = digits[0];
95     fCoord2       = digits[1];
96     fSignal       = 1;
97     fSignalSPD    = digits[2];
98 }
99 //______________________________________________________________________
100 Int_t AliITSdigitSPD::GetListOfTracks(TArrayI &t){
101     // Fills the TArrayI t with the tracks found in fTracks removing
102     // duplicated tracks, but otherwise in the same order. It will return
103     // the number of tracks and fill the remaining elements to the array
104     // t with -1.
105     // Inputs:
106     //   TArrayI  &t Reference to a TArrayI to contain the list of
107     //               nonduplicated track numbers.
108     // Output:
109     //   TArrayI  &t The input array filled with the nonduplicated track
110     //               numbers.
111     // Return:
112     //   Int_t The number of none -1 entries in the TArrayI t.
113     Int_t nt = t.GetSize();
114     Int_t nth = this->GetNTracks();
115     Int_t n = 0,i,j;
116     Bool_t inlist = kFALSE;
117
118     t.Reset(-1); // -1 array.
119     for(i=0;i<nth;i++) {
120         if(this->GetTrack(i) == -1) continue;
121         inlist = kFALSE;
122         for(j=0;j<n;j++)if(this->GetTrack(i) == t.At(j)) inlist = kTRUE;
123         if(!inlist){ // add to end of list
124             t.AddAt(this->GetTrack(i),n);
125             if(n<nt) n++;
126         } // end if
127     } // end for i
128     return n;
129 }
130 //______________________________________________________________________
131 void AliITSdigitSPD::Print(ostream *os){
132     //Standard output format for this class
133     Int_t i;
134
135     AliITSdigit::Print(os);
136     for(i=0;i<fkSspd;i++) *os <<","<< fTracks[i];
137     for(i=0;i<fkSspd;i++) *os <<","<< fHits[i];
138     *os << "," << fSignalSPD;
139 }
140 //______________________________________________________________________
141 void AliITSdigitSPD::Read(istream *os){
142     //Standard input for this class
143     Int_t i;
144
145     AliITSdigit::Read(os);
146     for(i=0;i<fkSspd;i++) *os >> fTracks[i];
147     for(i=0;i<fkSspd;i++) *os >> fHits[i];
148     *os >> fSignalSPD;
149 }
150 //______________________________________________________________________
151 ostream &operator<<(ostream &os,AliITSdigitSPD &source){
152     // Standard output streaming function.
153
154     source.Print(&os);
155     return os;
156 }
157 //______________________________________________________________________
158 istream &operator>>(istream &os,AliITSdigitSPD &source){
159     // Standard output streaming function.
160
161     source.Read(&os);
162     return os;
163 }
164 //______________________________________________________________________
165 ClassImp(AliITSdigitSDD)
166 AliITSdigitSDD::AliITSdigitSDD():AliITSdigit(){
167     // default constructor, zero coordinates and set array
168     // elements to clearly unphysical values. A value of 0 may
169     // be a valide track of hit number.
170     Int_t i;
171
172     for(i=0;i<fkSsdd;i++) fTracks[i] = -3;
173     for(i=0;i<fkSsdd;i++) fHits[i]   = -1;
174     fPhysics = 0;
175     for(i=0;i<fkSsdd;i++) fTcharges[i] = 0;
176 }
177 //________________________________________________________________________
178 AliITSdigitSDD::AliITSdigitSDD(Float_t phys,const Int_t *digits):
179     AliITSdigit(digits){
180     // Creates a simulated SDD digit object to be updated
181
182     fPhysics = phys;
183 }
184 //_____________________________________________________________________________
185 AliITSdigitSDD::AliITSdigitSDD(Float_t phys,const Int_t *digits,
186                                const Int_t *tracks,const Int_t *hits,
187                                const Float_t *charges):
188     AliITSdigit(digits){
189     // Creates a simulated SDD digit object
190
191     fPhysics = phys;
192     for(Int_t i=0; i<fkSsdd; i++) {
193         fTcharges[i] = charges[i];
194         fTracks[i]   = tracks[i];
195         fHits[i]     = hits[i];
196     } // end for i
197 }
198 //______________________________________________________________________
199 Int_t AliITSdigitSDD::GetListOfTracks(TArrayI &t,TArrayF &c){
200     // Fills the TArrayI t with the tracks found in fTracks removing
201     // duplicated tracks, summing up their charge, and ordering the tracks
202     // by the charge contributed to this digit. It will return
203     // the number of tracks and fill the remaining elements to the array
204     // t with -1.
205     // Inputs:
206     //   TArrayI  &t Reference to a TArrayI to contain the list of
207     //               nonduplicated track numbers.
208     //   TArrayF  &c Reference to a TArrayF to contain the summed charge
209     //               contributed by each track.
210     // Output:
211     //   TArrayI  &t The input array filled with the nonduplicated track
212     //               numbers.
213     //   TArrayF  &c The input array filled with the summed charge 
214     //               contributed by the corresponding track in the array t.
215     // Return:
216     //   Int_t The number of none -1 entries in the TArrayI t.
217     Int_t nt = t.GetSize();
218     nt = TMath::Min(nt,c.GetSize());
219     Int_t nth = this->GetNTracks();
220     Int_t n = 0,i,j;
221     Bool_t inlist = kFALSE;
222
223     t.Reset(-1); // -1 array.
224     c.Reset(0.0); // zero array.
225     for(i=0;i<nth;i++) {
226         if(this->GetTrack(i) == -1) continue;
227         inlist = kFALSE;
228         for(j=0;j<n;j++)if(this->GetTrack(i) == t.At(j)){
229             inlist = kTRUE;
230             c.AddAt(this->GetCharge(i)+c.At(j),j);
231         } // end for j/end if
232         if(!inlist){ // add to end of list
233             t.AddAt(this->GetTrack(i),n);
234             c.AddAt(this->GetCharge(i),n);
235             if(n<nt) n++;
236         } // end if
237     } // end for i
238
239     // Now lets sort the TArrays according to the charge. This algorithm
240     // is based on the method from Chapter 8 section 1 Straight Insertion
241     // sort. Wiliam H. Press, Saul A. Teukolsky, William T. Vetterling
242     // and Brian P. Flannery, "Numerical Recipeis in C, The Art of Scientific
243     // Computing", second Edition page 330 (1997).
244     Int_t   tr;
245     Float_t ch;
246     for(i=0;i<n;i++){
247         tr = t.At(i);
248         ch = c.At(i);
249         j = i-1;
250         while(j>-1 && c.At(j)>ch){
251             t.AddAt(t.At(j+1),j);
252             c.AddAt(c.At(j+1),j);
253             j--;
254         } // end while
255         t.AddAt(tr,j+1);
256         c.AddAt(ch,j+1);
257     } // end for i
258     //
259     return n;
260 }
261 //______________________________________________________________________
262 void AliITSdigitSDD::Print(ostream *os){
263     //Standard output format for this class
264     Int_t i;
265
266     AliITSdigit::Print(os);
267     *os <<","<< fPhysics;
268     for(i=0; i<fkSsdd; i++) *os <<","<< fTcharges[i];
269     for(i=0; i<fkSsdd; i++) *os <<","<< fTracks[i];
270     for(i=0; i<fkSsdd; i++) *os <<","<< fHits[i];
271 }
272 //______________________________________________________________________
273 void AliITSdigitSDD::Read(istream *os){
274     //Standard input for this class
275     Int_t i;
276
277     AliITSdigit::Read(os);
278     *os >>fPhysics;
279     for(i=0; i<fkSsdd; i++) *os >> fTcharges[i];
280     for(i=0; i<fkSsdd; i++) *os >> fTracks[i];
281     for(i=0; i<fkSsdd; i++) *os >> fHits[i];
282 }
283 //______________________________________________________________________
284 ostream &operator<<(ostream &os,AliITSdigitSDD &source){
285     // Standard output streaming function.
286
287     source.Print(&os);
288     return os;
289 }
290 //______________________________________________________________________
291 istream &operator>>(istream &os,AliITSdigitSDD &source){
292     // Standard output streaming function.
293
294     source.Read(&os);
295     return os;
296 }
297 //______________________________________________________________________
298 ClassImp(AliITSTransientDigit)
299 AliITSTransientDigit::AliITSTransientDigit(Float_t phys,const Int_t *digits): 
300     AliITSdigitSDD(phys,digits) {
301     // Creates a digit object in a list of digits to be updated
302
303     fTrackList   = new TObjArray;  
304 }
305 //__________________________________________________________________________
306 AliITSTransientDigit::AliITSTransientDigit(const AliITSTransientDigit &source):
307  AliITSdigitSDD(source){
308     // Copy Constructor 
309     if(&source == this) return;
310     this->fTrackList = source.fTrackList;
311     return;
312 }
313 //_________________________________________________________________________
314 AliITSTransientDigit& AliITSTransientDigit::operator=(
315     const AliITSTransientDigit &source) {
316     // Assignment operator
317     if(&source == this) return *this;
318     this->fTrackList = source.fTrackList;
319     return *this;
320 }
321 //______________________________________________________________________
322 void AliITSTransientDigit::Print(ostream *os){
323     //Standard output format for this class
324
325     AliITSdigitSDD::Print(os);
326 }
327 //______________________________________________________________________
328 void AliITSTransientDigit::Read(istream *os){
329     //Standard input for this class
330
331     AliITSdigitSDD::Read(os);
332 }
333 //______________________________________________________________________
334 ostream &operator<<(ostream &os,AliITSTransientDigit &source){
335     // Standard output streaming function.
336
337     source.Print(&os);
338     return os;
339 }
340 //______________________________________________________________________
341 istream &operator>>(istream &os,AliITSTransientDigit &source){
342     // Standard output streaming function.
343
344     source.Read(&os);
345     return os;
346 }
347 //______________________________________________________________________
348 ClassImp(AliITSdigitSSD)
349 AliITSdigitSSD::AliITSdigitSSD():AliITSdigit(){
350     // default constructor
351     Int_t i;
352
353     for(i=0; i<fkSssd; i++) fTracks[i] = -3;
354     for(i=0; i<fkSssd; i++) fHits[i] = -1;
355 }
356 //__________________________________________________________________________
357 AliITSdigitSSD::AliITSdigitSSD(const Int_t *digits):AliITSdigit(digits){
358     // Creates a real SSD digit object
359 }
360 //_____________________________________________________________________________
361 AliITSdigitSSD::AliITSdigitSSD(const Int_t *digits,const Int_t *tracks,
362                                const Int_t *hits):AliITSdigit(digits){
363     // Creates a simulated SSD digit object
364
365     for(Int_t i=0; i<fkSssd; i++) {
366         fTracks[i] = tracks[i];
367         fHits[i]   = hits[i];
368     } // end for i
369 }
370 //______________________________________________________________________
371 Int_t AliITSdigitSSD::GetListOfTracks(TArrayI &t){
372     // Fills the TArrayI t with the tracks found in fTracks removing
373     // duplicated tracks, but otherwise in the same order. It will return
374     // the number of tracks and fill the remaining elements to the array
375     // t with -1.
376     // Inputs:
377     //   TArrayI  &t Reference to a TArrayI to contain the list of
378     //               nonduplicated track numbers.
379     // Output:
380     //   TArrayI  &t The input array filled with the nonduplicated track
381     //               numbers.
382     // Return:
383     //   Int_t The number of none -1 entries in the TArrayI t.
384     Int_t nt = t.GetSize();
385     Int_t nth = this->GetNTracks();
386     Int_t n = 0,i,j;
387     Bool_t inlist = kFALSE;
388
389     t.Reset(-1); // -1 array.
390     for(i=0;i<nth;i++) {
391         if(this->GetTrack(i) == -1) continue;
392         inlist = kFALSE;
393         for(j=0;j<n;j++)if(this->GetTrack(i) == t.At(j)) inlist = kTRUE;
394         if(!inlist){ // add to end of list
395             t.AddAt(this->GetTrack(i),n);
396             if(n<nt) n++;
397         } // end if
398     } // end for i
399     return n;
400 }
401 //______________________________________________________________________
402 void AliITSdigitSSD::Print(ostream *os){
403     //Standard output format for this class
404     Int_t i;
405
406     AliITSdigit::Print(os);
407     for(i=0; i<fkSssd; i++) *os <<","<< fTracks[i];
408     for(i=0; i<fkSssd; i++) *os <<","<< fHits[i];
409 }
410 //______________________________________________________________________
411 void AliITSdigitSSD::Read(istream *os){
412     //Standard input for this class
413     Int_t i;
414
415     AliITSdigit::Read(os);
416     for(i=0; i<fkSssd; i++) *os >> fTracks[i];
417     for(i=0; i<fkSssd; i++) *os >> fHits[i];
418 }
419 //______________________________________________________________________
420 ostream &operator<<(ostream &os,AliITSdigitSSD &source){
421     // Standard output streaming function.
422
423     source.Print(&os);
424     return os;
425 }
426 //______________________________________________________________________
427 istream &operator>>(istream &os,AliITSdigitSSD &source){
428     // Standard output streaming function.
429
430     source.Read(&os);
431     return os;
432 }