]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSpList.cxx
3059669be3b14005e165f81cd9e1f309e399c45f
[u/mrichter/AliRoot.git] / ITS / AliITSpList.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 /* $Id$ */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <iostream.h>
20 #include <iomanip.h>
21 #include <TObjArray.h>
22 #include <TRandom.h>
23 #include <TMath.h>
24
25 #include "AliITSpList.h"
26
27 //______________________________________________________________________
28
29 ClassImp(AliITSpList);
30 //______________________________________________________________________
31 AliITSpList::AliITSpList(){
32     // Default constructor
33     // Inputs:
34     //    none.
35     // Outputs:
36     //    none.
37     // Return:
38     //    A zeroed/empty AliITSpList class.
39
40     fNi = 0;
41     fNj = 0;
42     fa  = 0;
43 }
44 //______________________________________________________________________
45 AliITSpList::AliITSpList(Int_t imax,Int_t jmax){
46     // Standard constructor
47     // Inputs:
48     //    none.
49     // Outputs:
50     //    none.
51     // Return:
52     //    A setup AliITSpList class.
53
54     fNi = imax;
55     fNj = jmax;
56     fEnteries = 0;
57     fa  = new TObjArray(fNi*fNj); // elements are zeroed by 
58                                   // TObjArray creator
59 }
60 //______________________________________________________________________
61 AliITSpList::~AliITSpList(){
62     // Default destructor
63     // Inputs:
64     //    none.
65     // Outputs:
66     //    none.
67     // Return:
68     //    a properly destroyed class
69
70     for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
71         delete fa->At(i);
72         fa->AddAt(0,i); // zero content
73     } // end for i && if
74     fNi = 0;
75     fNj = 0;
76     delete fa;
77     fa  = 0;
78     fEnteries = 0;
79 }
80 //______________________________________________________________________
81 void AliITSpList::ClearMap(){
82     // Delete all AliITSpListItems and zero TObjArray.
83     // Inputs:
84     //    none.
85     // Outputs:
86     //    none.
87     // Return:
88     //    A zeroed AliITSpList class.
89
90     fa->Delete();
91 //    for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
92 //        delete fa->At(i);
93 //        fa->AddAt(0,i); // zero content
94 //    } // end for i && if
95     fEnteries = 0;
96 }
97 //______________________________________________________________________
98 void AliITSpList::DeleteHit(Int_t i,Int_t j){
99     // Delete a particular AliITSpListItems and zero TObjArray.
100     // Inputs:
101     //    Int_t i   Row number
102     //    Int_t j   Columns number
103     // Outputs:
104     //    none.
105     // Return:
106     //    none.
107     Int_t k = GetIndex(i,j);
108
109     if(fa->At(k)!=0){
110         delete fa->At(k);
111         fa->AddAt(0,k); // zero content
112     } // end for i && if
113     if(k==fEnteries-1) fEnteries--;
114 }
115 //______________________________________________________________________
116 AliITSpList& AliITSpList::operator=(const AliITSpList &source){
117     // = operator
118     // Inputs:
119     //    const AliITSpList &source    A AliITSpList object.
120     // Outputs:
121     //    none.
122     // Return:
123     //    A copied AliITSpList object.
124
125     if(this == &source) return *this;
126
127     if(this->fa!=0){ // if this->fa exists delete it first.
128         for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
129             delete fa->At(i);
130             fa->AddAt(0,i); // zero content
131         } // end for i && if
132         delete this->fa;
133     } // end if this->fa!=0
134     this->fNi = source.fNi;
135     this->fNj = source.fNj;
136     this->fa = new TObjArray(*(source.fa));
137     this->fEnteries = source.fEnteries;
138
139     return *this;
140 }
141 //______________________________________________________________________
142 AliITSpList::AliITSpList(AliITSpList &source){
143     // Copy operator
144     // Inputs:
145     //    AliITSpList &source   A AliITSpList Object
146     // Outputs:
147     //    none.
148     // Return:
149     //    A copied AliITSpList object
150
151     *this = source;
152 }
153 //______________________________________________________________________
154 void AliITSpList::AddItemTo(Int_t fileIndex, AliITSpListItem *pl) {
155     // Adds the contents of pl to the list with track number off set given by
156     // fileIndex.
157     // Creates the AliITSpListItem if needed.
158     // Inputs:
159     //    Int_t fileIndex      track number offset value
160     //    AliITSpListItem *pl  an AliITSpListItem to be added to this class.
161     // Outputs:
162     //    none.
163     // Return:
164     //    none.
165     Int_t index = pl->GetIndex();
166
167     if( fa->At( index ) == 0 ) { // most create AliITSpListItem
168         fa->AddAt(new AliITSpListItem(-2,-1,pl->GetModule(),index,0.0),index);
169     } // end if
170  
171     ((AliITSpListItem*)(fa->At(index)))->AddTo(fileIndex,pl);
172     if(index>=fEnteries) fEnteries = index +1;
173 }
174 //______________________________________________________________________
175 void AliITSpList::AddSignal(Int_t i,Int_t j,Int_t trk,Int_t ht,Int_t mod,
176                        Double_t signal){
177     // Adds a Signal value to the TObjArray at i,j. Creates the AliITSpListItem
178     // if needed.
179     // Inputs:
180     //    Int_t i         Row number for this signal
181     //    Int_t j         Column number for this signal
182     //    Int_t trk       Track number creating this signal
183     //    Int_t ht        Hit number creating this signal
184     //    Int_t mod       The module where this signal is in
185     //    Double_t signal The signal (ionization)
186     // Outputs:
187     //    none.
188     // Return:
189     //    none.
190     Int_t index = GetIndex(i,j);
191
192     if(GetpListItem(index)==0){ // most create AliITSpListItem
193         fa->AddAt(new AliITSpListItem(trk,ht,mod,GetIndex(i,j),signal),index);
194     }else{ // AliITSpListItem exists, just add signal to it.
195         GetpListItem(index)->AddSignal(trk,ht,mod,index,signal);
196     } // end if
197     if(index>=fEnteries) fEnteries = index +1;
198 }
199 //______________________________________________________________________
200 void AliITSpList::AddNoise(Int_t i,Int_t j,Int_t mod,Double_t noise){
201     // Adds a noise value to the TObjArray at i,j. Creates the AliITSpListItem
202     // if needed.
203     // Inputs:
204     //    Int_t i        Row number for this noise
205     //    Int_t j        Column number for this noise
206     //    Double_t noise The noise signal value.
207     // Outputs:
208     //    none.
209     // Return:
210     //    none.
211     Int_t index = GetIndex(i,j);
212
213     if(GetpListItem(index)==0){ // most create AliITSpListItem
214         fa->AddAt(new AliITSpListItem(mod,index,noise),index);
215     }else{ // AliITSpListItem exists, just add signal to it.
216         GetpListItem(index)->AddNoise(mod,index,noise);
217     } // end if
218     if(index>=fEnteries) fEnteries = index +1;
219 }
220 //______________________________________________________________________
221
222 ClassImp(AliITSpListItem)
223 //______________________________________________________________________
224 AliITSpListItem::AliITSpListItem(){
225     // Default constructor
226     // Inputs:
227     //    none.
228     // Outputs:
229     //    none.
230     // Return:
231     //    A zeroed/empty AliITSpListItem class.
232
233     fmodule = -1;
234     findex  = -1;
235     for(Int_t i=0;i<this->fkSize;i++){
236         this->fTrack[i]  = -2;
237         this->fHits[i]   = -1;
238         this->fSignal[i] = 0.0;
239     } // end if i
240     fTsignal = 0.0;
241     fNoise   = 0.0;
242 }
243 //______________________________________________________________________
244 AliITSpListItem::AliITSpListItem(Int_t module,Int_t index,Double_t noise){
245     // Standard noise constructor
246     // Inputs:
247     //    Int_t module   The module where this noise occurred
248     //    Int_t index    The cell index where this noise occurred
249     //    Double_t noise The value of the noise.
250     // Outputs:
251     //    none.
252     // Return:
253     //    A setup and noise filled AliITSpListItem class.
254
255     this->fmodule    = module;
256     this->findex     = index;
257     for(Int_t i=0;i<this->fkSize;i++){
258         this->fTrack[i]  = -2;
259         this->fSignal[i] = 0.0;
260         this->fHits[i]   = -1;
261     } // end if i
262     this->fTsignal = 0.0;
263     this->fNoise   = noise;
264 }
265 //______________________________________________________________________
266 AliITSpListItem::AliITSpListItem(Int_t track,Int_t hit,Int_t module,
267                                Int_t index,Double_t signal){
268     // Standard signal constructor
269     // Inputs:
270     //    Int_t track     The track number which produced this signal
271     //    Int_t hit       The hit number which produced this signal
272     //    Int_t module    The module where this signal occurred
273     //    Int_t index     The cell index where this signal occurred
274     //    Double_t signal The value of the signal (ionization)
275     // Outputs:
276     //    none.
277     // Return:
278     //    A setup and signal filled  AliITSpListItem class.
279
280     this->fmodule    = module;
281     this->findex     = index;
282     this->fTrack[0]  = track;
283     this->fHits[0]   = hit;
284     this->fSignal[0] = signal;
285     for(Int_t i=1;i<this->fkSize;i++){
286         this->fTrack[i]  = -2;
287         this->fSignal[i] = 0.0;
288         this->fHits[i]   = -1;
289     } // end if i
290     this->fTsignal = signal;
291     this->fNoise   = 0.0;
292 }
293 //______________________________________________________________________
294 AliITSpListItem::~AliITSpListItem(){
295     // Destructor
296     // Inputs:
297     //    none.
298     // Outputs:
299     //    none.
300     // Return:
301     //    A properly destroyed AliITSpListItem class.
302 /*
303     this->fmodule = 0;
304     this->findex  = 0;
305     for(Int_t i=0;i<=this->GetNsignals();i++){
306         this->fTrack[i]  = 0;
307         this->fSignal[i] = 0.0;
308         this->fHits[i]   = 0;
309     } // end if i
310     this->fTsignal = 0.0;
311     this->fNoise   = 0.0;
312 */    
313 }
314 //______________________________________________________________________
315 AliITSpListItem& AliITSpListItem::operator=(const AliITSpListItem &source){
316     // = operator
317     // Inputs:
318     //    AliITSpListItem &source   A AliITSpListItem Object
319     // Outputs:
320     //    none.
321     // Return:
322     //    A copied AliITSpListItem object
323
324     if(this == &source) return *this;
325
326     this->fmodule = source.fmodule;
327     this->findex  = source.findex;
328     for(Int_t i=0;i<this->fkSize;i++){
329         this->fTrack[i]  = source.fTrack[i];
330         this->fSignal[i] = source.fSignal[i];
331         this->fHits[i]   = source.fHits[i];
332     } // end if i
333     this->fTsignal = source.fTsignal;
334     this->fNoise   = source.fNoise;
335
336     return *this;
337 }
338 //______________________________________________________________________
339 AliITSpListItem::AliITSpListItem(AliITSpListItem &source){
340     // Copy operator
341     // Inputs:
342     //    AliITSpListItem &source   A AliITSpListItem Object
343     // Outputs:
344     //    none.
345     // Return:
346     //    A copied AliITSpListItem object
347
348     *this = source;
349 }
350 //______________________________________________________________________
351 void AliITSpListItem::AddSignal(Int_t track,Int_t hit,Int_t module,
352                                Int_t index,Double_t signal){
353     // Adds this track number and signal to the pList and orders them
354     // Inputs:
355     //    Int_t track     The track number which produced this signal
356     //    Int_t hit       The hit number which produced this signal
357     //    Int_t module    The module where this signal occurred
358     //    Int_t index     The cell index where this signal occurred
359     //    Double_t signal The value of the signal (ionization)
360     // Outputs:
361     //    none.
362     // Return:
363     //    none.
364     Int_t    i,j,trk,hts;
365     Double_t sig;
366     Bool_t   flg=kFALSE;
367
368     if(findex!=index || fmodule!=module) 
369         Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
370                  index,findex,module,fmodule);
371     fTsignal += signal; // Keep track of sum signal.
372     for(i=0;i<fkSize;i++) if( track==fTrack[i] && hit==fHits[i]){
373         fSignal[i] += signal;
374         flg = kTRUE;
375     } // end for i & if.
376     if(flg){ // resort arrays.  
377         for(i=1;i<fkSize;i++){
378             j = i;
379             while(j>0 && fSignal[j]>fSignal[j-1]){
380                 trk = fTrack[j-1];
381                 hts = fHits[j-1];
382                 sig = fSignal[j-1];
383                 fTrack[j-1]  = fTrack[j];
384                 fHits[j-1]   = fHits[j];
385                 fSignal[j-1] = fSignal[j];                
386                 fTrack[j]  = trk;
387                 fHits[j]   = hts;
388                 fSignal[j] = sig;
389                 j--;
390             } // end while
391         } // end if i
392         return;
393     } // end if added to existing and resorted array
394
395     // new entry add it in order.
396     // if this signal is <= smallest then don't add it.
397     if(signal <= fSignal[fkSize-1]) return;
398     for(i=fkSize-2;i>=0;i--){
399         if(signal > fSignal[i]){
400             fSignal[i+1] = fSignal[i];
401             fTrack[i+1]  = fTrack[i];
402             fHits[i+1]   = fHits[i];
403         }else{
404             fSignal[i+1] = signal;
405             fTrack[i+1]  = track;
406             fHits[i+1]   = hit;
407             return; // put it in the right place, now exit.
408         } //  end if
409     } // end if; end for i
410     // Still haven't found the right place. Must be at top of list.
411     fSignal[0] = signal;
412     fTrack[0]  = track;
413     fHits[0]   = hit;
414     return;
415 }
416 //______________________________________________________________________
417 void AliITSpListItem::AddNoise(Int_t module,Int_t index,Double_t noise){
418     // Adds noise to this existing list.
419     // Inputs:
420     //    Int_t module   The module where this noise occurred
421     //    Int_t index    The cell index where this noise occurred
422     //    Double_t noise The value of the noise.
423     // Outputs:
424     //    none.
425     // Return:
426     //    none.
427
428     if(findex!=index || fmodule!=module) 
429         Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
430             index,findex,module,fmodule);
431     fNoise += noise; // Keep track of sum signal.
432 }
433 //______________________________________________________________________
434 void AliITSpListItem::AddTo(Int_t fileIndex,AliITSpListItem *pl){
435     // Adds the contents of pl to this with track number off set given by
436     // fileIndex.
437     // Inputs:
438     //    Int_t fileIndex      track number offset value
439     //    AliITSpListItem *pl  an AliITSpListItem to be added to this class.
440     // Outputs:
441     //    none.
442     // Return:
443     //    none.
444     Int_t i,trk;
445     Double_t sig=0.0;
446
447     for(i=0;i<pl->GetNsignals();i++){
448         trk = pl->GetTrack(i);
449         trk += fileIndex;
450         this->AddSignal(trk,pl->GetHit(i),pl->GetModule(),
451                             pl->GetIndex(),pl->GetSignal(i));
452         sig += pl->GetSignal(i);
453     } // end for i
454     this->fNoise   += pl->fNoise;
455     return;
456 }
457 //______________________________________________________________________
458 Int_t AliITSpListItem::ShiftIndex(Int_t in,Int_t trk){
459     // Shift an index number to occupy the upper four bits. No longer used.
460     // Inputs:
461     //    Int_t in   The file number
462     //    Int_t trk  The track number
463     // Outputs:
464     //    none.
465     // Return:
466     //    Int_t The track number with the file number in the upper bits.
467     Int_t si = sizeof(Int_t) * 8;
468     UInt_t uin,utrk; // use UInt_t to avoid integer overflow-> goes negative.
469
470     uin = in;
471     utrk = trk;
472     for(Int_t i=0;i<si-4;i++) uin *= 2;
473     uin += utrk;
474     in = uin;
475     return in;
476 }
477 //______________________________________________________________________
478 void AliITSpListItem::Print(ostream *os){
479     //Standard output format for this class
480     // Inputs:
481     //    ostream *os  The output stream
482     // Outputs:
483     //    none.
484     // Return:
485     //    none.
486     Int_t i;
487
488     *os << fmodule <<","<<findex<<",";
489     *os << fkSize <<",";
490     for(i=0;i<fkSize;i++) *os << fTrack[i] <<",";
491     for(i=0;i<fkSize;i++) *os << fHits[i] <<",";
492     for(i=0;i<fkSize;i++) *os << fSignal[i] <<",";
493     *os << fTsignal <<","<< fNoise;
494 }
495 //______________________________________________________________________
496 void AliITSpListItem::Read(istream *is){
497     // Standard output streaming function.
498     // Inputs:
499     //    istream *is The input stream
500     // Outputs:
501     //    none.
502     // Return:
503     //    none.
504     Int_t i,iss;
505
506     *is >> fmodule >> findex;
507     *is >> iss; // read in fkSize
508     for(i=0;i<fkSize&&i<iss;i++) *is >> fTrack[i];
509     for(i=0;i<fkSize&&i<iss;i++) *is >> fHits[i];
510     for(i=0;i<fkSize&&i<iss;i++) *is >> fSignal[i];
511     *is >> fTsignal >> fNoise;
512 }
513 //______________________________________________________________________
514 ostream &operator<<(ostream &os,AliITSpListItem &source){
515     // Standard output streaming function.
516     // Inputs:
517     //    ostream &os             The output stream
518     //    AliITSpListItem &source The AliITSpListItem object to be written out.
519     // Outputs:
520     //    none.
521     // Return:
522     //    ostream  The output stream
523
524     source.Print(&os);
525     return os;
526 }
527 //______________________________________________________________________
528 istream &operator>>(istream &os,AliITSpListItem &source){
529     // Standard output streaming function.
530     // Inputs:
531     //    istream os              The input stream
532     //    AliITSpListItem &source The AliITSpListItem object to be inputted
533     // Outputs:
534     //    none.
535     // Return:
536     //    istream The input stream.
537
538     source.Read(&os);
539     return os;
540 }
541