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