]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUSDigit.cxx
Updated hydro macro
[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 this signal is <= smallest then don't add it.
166   if (fNTracks==(kBuffSize-1) && signal <= fSignal[kBuffSize-1]) return;
167   //
168   for (i=fNTracks;i--;) {
169     if (signal > fSignal[i]) {
170       fSignal[i+1] = fSignal[i];
171       fTrack[i+1]  = fTrack[i];
172       fHits[i+1]   = fHits[i];
173     } else {
174       fSignal[i+1] = signal;
175       fTrack[i+1]  = track;
176       fHits[i+1]   = hit;
177       fNTracks++;
178       return; // put it in the right place, now exit.
179     } //  end if
180   } // end if; end for i
181   //
182   // Still haven't found the right place. Must be at top of list.
183   fSignal[0] = signal;
184   fTrack[0]  = track;
185   fHits[0]   = hit;
186   fNTracks++;
187   return;
188 }
189
190 //______________________________________________________________________
191 void AliITSUSDigit::Add(const AliITSUSDigit *pl)
192 {
193   // Adds the contents of pl to this
194   // pl could come from different module and index 
195   Double_t sigT = 0.0;
196   for(int i=pl->GetNTracks();i--;) {
197     double sig = pl->GetSignal(i); 
198     AddSignal(pl->GetTrack(i),pl->GetHit(i),sig);
199     sigT += sig;
200   } // end for i
201   fTsignal += (pl->fTsignal - sigT);
202   fNoise   += pl->fNoise;
203   return;
204   //
205 }
206
207 //______________________________________________________________________
208 void AliITSUSDigit::AddTo(Int_t fileIndex,const AliITSUSDigit *pl) 
209 {
210   // Adds the contents of pl to this with track number off set given by
211   // fileIndex.
212   // Inputs:
213   //    Int_t fileIndex      track number offset value
214   //    AliITSUSDigit *pl  an AliITSUSDigit to be added to this class.
215   //
216   for (int i=pl->GetNTracks();i--;) AddSignal(pl->GetTrack(i)+fileIndex,pl->GetHit(i),pl->GetSignal(i));
217   fSignalAfterElect += (pl->fSignalAfterElect + pl->fNoise - fNoise);
218   fNoise = pl->fNoise;
219 }
220
221 //______________________________________________________________________
222 void AliITSUSDigit::ShiftIndices(Int_t fileIndex)
223 {
224   // Shift track numbers
225   //
226   for (int i=GetNTracks();i--;) fTrack[i] += fileIndex;
227 }
228
229 //______________________________________________________________________
230 Int_t AliITSUSDigit::Compare(const TObject* obj) const
231 {
232   // compare objects
233   if (GetUniqueID()<obj->GetUniqueID()) return -1;
234   if (GetUniqueID()>obj->GetUniqueID()) return  1;
235   return 0;
236 }
237
238 //______________________________________________________________________
239 void AliITSUSDigit::Print(Option_t*) const 
240 {
241   // print itself
242   printf("Mod: %4d Index:%7d Ntr:%2d | TotSignal:%.2e Noise:%.2e ROCycle: %d|",
243          fModule,GetUniqueID(),fNTracks,fTsignal,fNoise,fROCycle);
244   for (int i=0;i<fNTracks;i++) printf("%d(%.2e) |",fTrack[i],fSignal[i]); printf("\n");
245 }