]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUSDigit.cxx
added new data member for max clusters/track
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUSDigit.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 <TMath.h>
16 #include "AliLog.h"
17 #include "AliITSUSDigit.h"
18 ClassImp(AliITSUSDigit)
19
20 using std::istream;
21 using std::swap;
22 using namespace TMath;
23
24 // Addapted from ITS/AliITSpListItem, ruben.shahoyan@cern.ch
25
26 //______________________________________________________________________
27 AliITSUSDigit::AliITSUSDigit() 
28 : fModule(0)
29   ,fNTracks(0)
30   ,fROCycle(0)
31   ,fTsignal(0.0)
32   ,fNoise(0.0)
33   ,fSignalAfterElect(0.0)
34 {
35   // Default constructor
36   for (int i=kBuffSize;i--;) {
37     fTrack[i] = -2;
38     fHits[i] = -1;
39     fSignal[i] = 0;
40   }
41 }
42
43 //______________________________________________________________________
44 AliITSUSDigit::AliITSUSDigit(UInt_t module,UInt_t index,Double_t noise,Int_t roCycle) 
45   :fModule(module)
46   ,fNTracks(0)
47   ,fROCycle(roCycle)
48   ,fTsignal(0.0)
49   ,fNoise(noise)
50   ,fSignalAfterElect(0.0)
51 {
52   // Standard noise constructor
53   SetUniqueID(index);
54   for (int i=kBuffSize;i--;) {
55     fTrack[i] = -2;
56     fHits[i] = -1;
57     fSignal[i] = 0;
58   }
59 }
60
61 //______________________________________________________________________
62 AliITSUSDigit::AliITSUSDigit(Int_t track,Int_t hit,UInt_t module,UInt_t index,Double_t signal,Int_t roCycle)
63   :fModule(module)
64   ,fNTracks(1)
65   ,fROCycle(roCycle)
66   ,fTsignal(signal)
67   ,fNoise(0.0)
68   ,fSignalAfterElect(0.0)
69 {
70   // Standard signal constructor
71   // Inputs:
72   //    Int_t track     The track number which produced this signal
73   //    Int_t hit       The hit number which produced this signal
74   //    Int_t module    The module where this signal occurred
75   //    Int_t index     The cell index where this signal occurred
76   //    Double_t signal The value of the signal (ionization)
77   //    Int_t roCycle   Read-Out cycle
78   SetUniqueID(index);
79   fTrack[0]  = track;
80   fHits[0]   = hit;
81   fSignal[0] = signal;
82   for (int i=1;i<kBuffSize;i++) {
83     fTrack[i] = -2;
84     fHits[i] = -1;
85     fSignal[i] = 0;
86   }
87 }
88
89 //______________________________________________________________________
90 AliITSUSDigit& AliITSUSDigit::operator=(const AliITSUSDigit &source)
91 {
92   // = operator
93   if (&source!=this) {
94     this->~AliITSUSDigit();
95     new(this) AliITSUSDigit(source);
96   }
97   return *this;
98   //
99 }
100
101 //______________________________________________________________________
102 AliITSUSDigit::AliITSUSDigit(const AliITSUSDigit &source) 
103   :TObject(source)
104   ,fModule(source.fModule)
105   ,fNTracks(source.fNTracks)
106   ,fROCycle(source.fROCycle)
107   ,fTsignal(source.fTsignal)
108   ,fNoise(source.fNoise)
109   ,fSignalAfterElect(source.fSignalAfterElect)
110 {
111   // Copy operator
112   for(Int_t i=kBuffSize;i--;) {
113     fTrack[i]  = source.fTrack[i];
114     fSignal[i] = source.fSignal[i];
115     fHits[i]   = source.fHits[i];
116   } // end if i
117   //
118 }
119
120 //______________________________________________________________________
121 void AliITSUSDigit::AddSignal(Int_t track,Int_t hit,Double_t signal)
122 {
123   // Adds this track number and signal to the pList and orders them
124   // Inputs:
125   //    Int_t track     The track number which produced this signal
126   //    Int_t hit       The hit number which produced this signal
127   //    Int_t module    The module where this signal occurred
128   //    Int_t index     The cell index where this signal occurred
129   //    Double_t signal The value of the signal (ionization)
130   Int_t    i,j;
131   Bool_t   flg=kFALSE;
132   //
133   if (Abs(signal)>2147483647.0) {
134     //PH 2147483647 is the max. integer
135     //PH This apparently is a problem which needs investigation
136     AliWarning(Form("Too big or too small signal value %f",signal));
137     signal = Sign((Double_t)2147483647,signal);
138   }
139   //
140   fTsignal += signal; // Keep track of sum signal.
141   for (i=fNTracks;i--;) {
142     if ( track==fTrack[i]  ) {
143       fSignal[i] += signal;
144       flg = kTRUE;
145       break;
146     } // end for i & if.
147   }
148   //
149   if (flg) {
150     if (fNTracks>1) { // resort arrays.  
151       for (i=1;i<fNTracks;i++) {
152         j = i;
153         while(j>0 && fSignal[j]>fSignal[j-1]) {
154           std::swap(fTrack[j-1],fTrack[j]);
155           std::swap(fHits[j-1] ,fHits[j]);
156           std::swap(fSignal[j-1],fSignal[j]);
157           j--;
158         } // end while
159       } // end if i
160     } // end if added to existing and resorted array
161     return;
162   }
163   //
164   // new entry add it in order.
165   if (fNTracks==(kBuffSize-1) && signal<=fSignal[kBuffSize-1]) return;   // if this signal is <= smallest then don't add it.
166   //
167   for (i=fNTracks;i--;) {
168     if (signal > fSignal[i]) { // shift smaller signals to the end of the list
169       if (i<kBuffSize-2) {     // (if there is a space...)
170         fSignal[i+1] = fSignal[i];
171         fTrack[i+1]  = fTrack[i];
172         fHits[i+1]   = fHits[i];
173       }
174     } else {
175       fSignal[i+1] = signal;
176       fTrack[i+1]  = track;
177       fHits[i+1]   = hit;
178       if (fNTracks<kBuffSize-1) fNTracks++;
179       return; // put it in the right place, now exit.
180     } //  end if
181   } // end if; end for i
182   //
183   // Still haven't found the right place. Must be at top of list.
184   fSignal[0] = signal;
185   fTrack[0]  = track;
186   fHits[0]   = hit;
187   fNTracks++;
188   return;
189 }
190
191 //______________________________________________________________________
192 void AliITSUSDigit::Add(const AliITSUSDigit *pl)
193 {
194   // Adds the contents of pl to this
195   // pl could come from different module and index 
196   Double_t sigT = 0.0;
197   for(int i=pl->GetNTracks();i--;) {
198     double sig = pl->GetSignal(i); 
199     AddSignal(pl->GetTrack(i),pl->GetHit(i),sig);
200     sigT += sig;
201   } // end for i
202   fTsignal += (pl->fTsignal - sigT);
203   fNoise   += pl->fNoise;
204   return;
205   //
206 }
207
208 //______________________________________________________________________
209 void AliITSUSDigit::AddTo(Int_t fileIndex,const AliITSUSDigit *pl) 
210 {
211   // Adds the contents of pl to this with track number off set given by
212   // fileIndex.
213   // Inputs:
214   //    Int_t fileIndex      track number offset value
215   //    AliITSUSDigit *pl  an AliITSUSDigit to be added to this class.
216   //
217   for (int i=pl->GetNTracks();i--;) AddSignal(pl->GetTrack(i)+fileIndex,pl->GetHit(i),pl->GetSignal(i));
218   fSignalAfterElect += (pl->fSignalAfterElect + pl->fNoise - fNoise);
219   fNoise = pl->fNoise;
220 }
221
222 //______________________________________________________________________
223 void AliITSUSDigit::ShiftIndices(Int_t fileIndex)
224 {
225   // Shift track numbers
226   //
227   for (int i=GetNTracks();i--;) fTrack[i] += fileIndex;
228 }
229
230 //______________________________________________________________________
231 Int_t AliITSUSDigit::Compare(const TObject* obj) const
232 {
233   // compare objects
234   if (GetUniqueID()<obj->GetUniqueID()) return -1;
235   if (GetUniqueID()>obj->GetUniqueID()) return  1;
236   return 0;
237 }
238
239 //______________________________________________________________________
240 void AliITSUSDigit::Print(Option_t*) const 
241 {
242   // print itself
243   printf("Mod: %4d Index:%7d Ntr:%2d | TotSignal:%.2e Noise:%.2e ROCycle: %d|",
244          fModule,GetUniqueID(),fNTracks,fTsignal,fNoise,fROCycle);
245   for (int i=0;i<fNTracks;i++) printf("%d(%.2e) |",fTrack[i],fSignal[i]); printf("\n");
246 }