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