]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSpListItem.cxx
- Protection added for null or empty input chains
[u/mrichter/AliRoot.git] / ITS / AliITSpListItem.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2004, 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 #include <Riostream.h>
16 #include <TMath.h>
17 #include "AliLog.h"
18 #include "AliITSpListItem.h"
19 // ************************************************************************
20 // the data member "fa" of the AliITSpList class
21 // is a TObjectArray of AliITSpListItem objects
22 // each AliITSpListItem object contains information related to
23 // the digitization such signal, noise, module number,...
24 // plus some info related to the simulation (hits/track)
25 // in order to allow efficiency studies
26 //************************************************************************
27 ClassImp(AliITSpListItem)
28 //______________________________________________________________________
29 AliITSpListItem::AliITSpListItem():
30 fmodule(-1),
31 findex(-1),
32 fTsignal(0.0),
33 fNoise(0.0),
34 fSignalAfterElect(0.0){
35     // Default constructor
36     // Inputs:
37     //    none.
38     // Outputs:
39     //    none.
40     // Return:
41     //    A zeroed/empty AliITSpListItem class.
42
43     for(Int_t i=0;i<this->fgksize;i++){
44         this->fTrack[i]  = -2;
45         this->fHits[i]   = -1;
46         this->fSignal[i] = 0.0;
47     } // end if i
48 }
49 //______________________________________________________________________
50 AliITSpListItem::AliITSpListItem(Int_t module,Int_t index,Double_t noise):
51 fmodule(module),
52 findex(index),
53 fTsignal(0.0),
54 fNoise(noise),
55 fSignalAfterElect(0.0){
56     // Standard noise constructor
57     // Inputs:
58     //    Int_t module   The module where this noise occurred
59     //    Int_t index    The cell index where this noise occurred
60     //    Double_t noise The value of the noise.
61     // Outputs:
62     //    none.
63     // Return:
64     //    A setup and noise filled AliITSpListItem class.
65
66     for(Int_t i=0;i<this->fgksize;i++){
67         this->fTrack[i]  = -2;
68         this->fSignal[i] = 0.0;
69         this->fHits[i]   = -1;
70     } // end if i
71 }
72 //______________________________________________________________________
73 AliITSpListItem::AliITSpListItem(Int_t track,Int_t hit,Int_t module,
74                                Int_t index,Double_t signal):
75 fmodule(module),
76 findex(index),
77 fTsignal(signal),
78 fNoise(0.0),
79 fSignalAfterElect(0.0){
80     // Standard signal constructor
81     // Inputs:
82     //    Int_t track     The track number which produced this signal
83     //    Int_t hit       The hit number which produced this signal
84     //    Int_t module    The module where this signal occurred
85     //    Int_t index     The cell index where this signal occurred
86     //    Double_t signal The value of the signal (ionization)
87     // Outputs:
88     //    none.
89     // Return:
90     //    A setup and signal filled  AliITSpListItem class.
91
92     this->fTrack[0]  = track;
93     this->fHits[0]   = hit;
94     this->fSignal[0] = signal;
95     for(Int_t i=1;i<this->fgksize;i++){
96         this->fTrack[i]  = -2;
97         this->fSignal[i] = 0.0;
98         this->fHits[i]   = -1;
99     } // end if i
100 }
101 //______________________________________________________________________
102 AliITSpListItem::~AliITSpListItem(){
103     // Destructor
104     // Inputs:
105     //    none.
106     // Outputs:
107     //    none.
108     // Return:
109     //    A properly destroyed AliITSpListItem class.
110
111 }
112 //______________________________________________________________________
113 AliITSpListItem& AliITSpListItem::operator=(const AliITSpListItem &source){
114     // = operator
115     // Inputs:
116     //    AliITSpListItem &source   A AliITSpListItem Object
117     // Outputs:
118     //    none.
119     // Return:
120     //    A copied AliITSpListItem object
121   this->~AliITSpListItem();
122   new(this) AliITSpListItem(source);
123   return *this;
124
125 }
126 //______________________________________________________________________
127 AliITSpListItem::AliITSpListItem(const AliITSpListItem &source) : 
128 TObject(source),
129 fmodule(source.fmodule),
130 findex(source.findex),
131 fTsignal(source.fTsignal),
132 fNoise(source.fNoise),
133 fSignalAfterElect(source.fSignalAfterElect){
134     // Copy operator
135     // Inputs:
136     //    AliITSpListItem &source   A AliITSpListItem Object
137     // Outputs:
138     //    none.
139     // Return:
140     //    A copied AliITSpListItem object
141   
142     for(Int_t i=0;i<this->fgksize;i++){
143       this->fTrack[i]  = source.fTrack[i];
144       this->fSignal[i] = source.fSignal[i];
145       this->fHits[i]   = source.fHits[i];
146     } // end if i
147
148 }
149 //______________________________________________________________________
150 void AliITSpListItem::AddSignal(Int_t track,Int_t hit,Int_t module,
151                                Int_t index,Double_t signal){
152     // Adds this track number and signal to the pList and orders them
153     // Inputs:
154     //    Int_t track     The track number which produced this signal
155     //    Int_t hit       The hit number which produced this signal
156     //    Int_t module    The module where this signal occurred
157     //    Int_t index     The cell index where this signal occurred
158     //    Double_t signal The value of the signal (ionization)
159     // Outputs:
160     //    none.
161     // Return:
162     //    none.
163     Int_t    i,j,trk,hts;
164     Double_t sig;
165     Bool_t   flg=kFALSE;
166
167     if (TMath::Abs(signal)>2147483647.0) {
168       //PH 2147483647 is the max. integer
169       //PH This apparently is a problem which needs investigation
170       AliWarning(Form("Too big or too small signal value %f",signal));
171       signal = TMath::Sign((Double_t)2147483647,signal);
172     }
173     if(findex!=index || fmodule!=module) 
174         Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
175                  index,findex,module,fmodule);
176     fTsignal += signal; // Keep track of sum signal.
177
178     //    for(i=0;i<fgksize;i++) if( track==fTrack[i] && hit==fHits[i] ){
179     for(i=0;i<fgksize;i++) if( track==fTrack[i]  ){
180         fSignal[i] += signal;
181         flg = kTRUE;
182     } // end for i & if.
183     //cout << "track="<<track<<endl;
184     if(flg){ // resort arrays.  
185         for(i=1;i<fgksize;i++){
186             j = i;
187             while(j>0 && fSignal[j]>fSignal[j-1]){
188                 trk = fTrack[j-1];
189                 hts = fHits[j-1];
190                 sig = fSignal[j-1];
191                 fTrack[j-1]  = fTrack[j];
192                 fHits[j-1]   = fHits[j];
193                 fSignal[j-1] = fSignal[j];                
194                 fTrack[j]  = trk;
195                 fHits[j]   = hts;
196                 fSignal[j] = sig;
197                 //cout << "#fTrack["<<j-1<<"]="<<fTrack[j-1]<< " fTrack["<<
198                 // j<<"]="<<fTrack[j]<<endl;
199                 j--;
200             } // end while
201         } // end if i
202         return;
203     } // end if added to existing and resorted array
204
205     // new entry add it in order.
206     // if this signal is <= smallest then don't add it.
207     if(signal <= fSignal[fgksize-1]) return;
208     for(i=fgksize-2;i>=0;i--){
209         if(signal > fSignal[i]){
210             fSignal[i+1] = fSignal[i];
211             fTrack[i+1]  = fTrack[i];
212             fHits[i+1]   = fHits[i];
213         }else{
214             fSignal[i+1] = signal;
215             fTrack[i+1]  = track;
216             fHits[i+1]   = hit;
217             return; // put it in the right place, now exit.
218         } //  end if
219         //cout << "$fTrack["<<i+1<<"]="<<fTrack[i+1]<< " fTrack["<<i<<"]="
220         //<<fTrack[i]<< " fHits["<<i+1<<"]="<<fHits[i+1]<< " fHits["<<i<<"]="
221         //<<fHits[i]<< " fSignal["<<i+1<<"]="<<fSignal[i+1]<< " fSignal["<<i
222         //<<"]="<<fSignal[i]<<endl;
223     } // end if; end for i
224     // Still haven't found the right place. Must be at top of list.
225     fSignal[0] = signal;
226     fTrack[0]  = track;
227     fHits[0]   = hit;
228     //cout << "$fTrack["<<0<<"]="<<fTrack[0]<<" fHits["<<0<<"]="<<fHits[0]
229     //<<" fSignal["<<0<<"]="<<fSignal[0]<<endl;
230     return;
231 }
232 //______________________________________________________________________
233 void AliITSpListItem::AddNoise(Int_t module,Int_t index,Double_t noise){
234     // Adds noise to this existing list.
235     // Inputs:
236     //    Int_t module   The module where this noise occurred
237     //    Int_t index    The cell index where this noise occurred
238     //    Double_t noise The value of the noise.
239     // Outputs:
240     //    none.
241     // Return:
242     //    none.
243
244     if(findex!=index || fmodule!=module) 
245         Warning("AddNoise","index=%d != findex=%d or module=%d != fmodule=%d",
246             index,findex,module,fmodule);
247     fNoise += noise; // Keep track of sum signal.
248 }
249 //______________________________________________________________________
250 void AliITSpListItem::AddSignalAfterElect(Int_t module,Int_t index,Double_t signal){
251     // Adds signal after electronics to this existing list.
252     // Inputs:
253     //    Int_t module   The module where this noise occurred
254     //    Int_t index    The cell index where this noise occurred
255     //    Double_t signal The value of the signal.
256     // Outputs:
257     //    none.
258     // Return:
259     //    none.
260
261     if(findex!=index || fmodule!=module) 
262         Warning("AddSignalAfterElect","index=%d != findex=%d or module=%d "
263                 "!= fmodule=%d",index,findex,module,fmodule);
264     fSignalAfterElect += signal; // Keep track of sum signal.
265 }
266 //______________________________________________________________________
267 void AliITSpListItem::Add(AliITSpListItem *pl){
268     // Adds the contents of pl to this
269     // pl could come from different module and index 
270     // Inputs:
271     //    AliITSpListItem *pl  an AliITSpListItem to be added to this class.
272     // Outputs:
273     //    none.
274     // Return:
275     //    none.
276     Int_t i;
277     Double_t sig  = 0.0;
278     Double_t sigT = 0.0;
279
280     for(i=0;i<pl->GetNsignals();i++){
281         sig = pl->GetSignal(i); 
282         if( sig <= 0.0 ) break; // no more signals
283         AddSignal(pl->GetTrack(i),pl->GetHit(i),fmodule,findex,sig);
284         sigT += sig;
285     } // end for i
286     fTsignal += (pl->fTsignal - sigT);
287     fNoise   += pl->fNoise;
288     return;
289 }
290 //______________________________________________________________________
291 void AliITSpListItem::AddTo(Int_t fileIndex,AliITSpListItem *pl){
292     // Adds the contents of pl to this with track number off set given by
293     // fileIndex.
294     // Inputs:
295     //    Int_t fileIndex      track number offset value
296     //    AliITSpListItem *pl  an AliITSpListItem to be added to this class.
297     // Outputs:
298     //    none.
299     // Return:
300     //    none.
301     Int_t i,trk;
302     Double_t sig  = 0.0;
303
304     Int_t module = pl->GetModule();
305     Int_t index  = pl->GetIndex();
306     for(i=0;i<pl->GetNsignals();i++){
307         sig = pl->GetSignal(i); 
308         if( sig <= 0.0 ) break; // no more signals
309         trk = pl->GetTrack(i);
310         trk += fileIndex; 
311         AddSignal(trk,pl->GetHit(i),module,index,sig);
312     } // end for i
313     fSignalAfterElect += (pl->fSignalAfterElect + pl->fNoise - fNoise);
314     fNoise = pl->fNoise;
315     return;
316 }
317 //______________________________________________________________________
318 Int_t AliITSpListItem::ShiftIndex(Int_t in,Int_t trk) const {
319     // Shift an index number to occupy the upper four bits. No longer used.
320     // Inputs:
321     //    Int_t in   The file number
322     //    Int_t trk  The track number
323     // Outputs:
324     //    none.
325     // Return:
326     //    Int_t The track number with the file number in the upper bits.
327     Int_t si = sizeof(Int_t) * 8;
328     UInt_t uin,utrk; // use UInt_t to avoid interger overflow-> goes negative.
329
330     uin = in;
331     utrk = trk;
332     for(Int_t i=0;i<si-4;i++) uin *= 2;
333     uin += utrk;
334     in = uin;
335     return in;
336 }
337 //______________________________________________________________________
338 void AliITSpListItem::Print(ostream *os) const {
339     //Standard output format for this class
340     // Inputs:
341     //    ostream *os  The output stream
342     // Outputs:
343     //    none.
344     // Return:
345     //    none.
346     Int_t i;
347
348     *os << fmodule <<","<<findex<<",";
349     *os << fgksize <<",";
350     for(i=0;i<fgksize;i++) *os << fTrack[i] <<",";
351     for(i=0;i<fgksize;i++) *os << fHits[i] <<",";
352     for(i=0;i<fgksize;i++) *os << fSignal[i] <<",";
353     *os << fTsignal <<","<< fNoise << "," << fSignalAfterElect;
354 }
355 //______________________________________________________________________
356 void AliITSpListItem::Read(istream *is){
357     // Standard output streaming function.
358     // Inputs:
359     //    istream *is The input stream
360     // Outputs:
361     //    none.
362     // Return:
363     //    none.
364     Int_t i,iss;
365
366     *is >> fmodule >> findex;
367     *is >> iss; // read in fgksize
368     for(i=0;i<fgksize&&i<iss;i++) *is >> fTrack[i];
369     for(i=0;i<fgksize&&i<iss;i++) *is >> fHits[i];
370     for(i=0;i<fgksize&&i<iss;i++) *is >> fSignal[i];
371     *is >> fTsignal >> fNoise >> fSignalAfterElect;
372 }
373 //______________________________________________________________________
374 ostream &operator<<(ostream &os,AliITSpListItem &source){
375     // Standard output streaming function.
376     // Inputs:
377     //    ostream &os             The output stream
378     //    AliITSpListItem &source The AliITSpListItem object to be written out.
379     // Outputs:
380     //    none.
381     // Return:
382     //    ostream  The output stream
383
384     source.Print(&os);
385     return os;
386 }
387 //______________________________________________________________________
388 istream &operator>>(istream &os,AliITSpListItem &source){
389     // Standard output streaming function.
390     // Inputs:
391     //    istream os              The input stream
392     //    AliITSpListItem &source The AliITSpListItem object to be inputted
393     // Outputs:
394     //    none.
395     // Return:
396     //    istream The input stream.
397
398     source.Read(&os);
399     return os;
400 }