1 /**************************************************************************
2 * Copyright(c) 1998-2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 #include "AliITSUSDigit.h"
18 ClassImp(AliITSUSDigit)
22 using namespace TMath;
24 // Addapted from ITS/AliITSpListItem, ruben.shahoyan@cern.ch
26 //______________________________________________________________________
27 AliITSUSDigit::AliITSUSDigit()
33 ,fSignalAfterElect(0.0)
35 // Default constructor
36 for (int i=kBuffSize;i--;) {
43 //______________________________________________________________________
44 AliITSUSDigit::AliITSUSDigit(UInt_t chip,UInt_t index,Double_t noise,Int_t roCycle)
50 ,fSignalAfterElect(0.0)
52 // Standard noise constructor
54 for (int i=kBuffSize;i--;) {
61 //______________________________________________________________________
62 AliITSUSDigit::AliITSUSDigit(Int_t track,Int_t hit,UInt_t chip,UInt_t index,Double_t signal,Int_t roCycle)
68 ,fSignalAfterElect(0.0)
70 // Standard signal constructor
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 chip The chip 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
82 for (int i=1;i<kBuffSize;i++) {
89 //______________________________________________________________________
90 AliITSUSDigit& AliITSUSDigit::operator=(const AliITSUSDigit &source)
94 this->~AliITSUSDigit();
95 new(this) AliITSUSDigit(source);
101 //______________________________________________________________________
102 AliITSUSDigit::AliITSUSDigit(const AliITSUSDigit &source)
105 ,fNTracks(source.fNTracks)
106 ,fROCycle(source.fROCycle)
107 ,fTsignal(source.fTsignal)
108 ,fNoise(source.fNoise)
109 ,fSignalAfterElect(source.fSignalAfterElect)
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];
120 //______________________________________________________________________
121 void AliITSUSDigit::AddSignal(Int_t track,Int_t hit,Double_t signal)
123 // Adds this track number and signal to the pList and orders them
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 chip The chip 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)
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);
140 fTsignal += signal; // Keep track of sum signal.
141 for (i=fNTracks;i--;) {
142 if ( track==fTrack[i] ) {
143 fSignal[i] += signal;
150 if (fNTracks>1) { // resort arrays.
151 for (i=1;i<fNTracks;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]);
160 } // end if added to existing and resorted array
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.
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];
175 fSignal[i+1] = signal;
178 if (fNTracks<kBuffSize-1) fNTracks++;
179 return; // put it in the right place, now exit.
181 } // end if; end for i
183 // Still haven't found the right place. Must be at top of list.
191 //______________________________________________________________________
192 void AliITSUSDigit::Add(const AliITSUSDigit *pl)
194 // Adds the contents of pl to this
195 // pl could come from different chip and index
197 for(int i=pl->GetNTracks();i--;) {
198 double sig = pl->GetSignal(i);
199 AddSignal(pl->GetTrack(i),pl->GetHit(i),sig);
202 fTsignal += (pl->fTsignal - sigT);
203 fNoise += pl->fNoise;
208 //______________________________________________________________________
209 void AliITSUSDigit::AddTo(Int_t fileIndex,const AliITSUSDigit *pl)
211 // Adds the contents of pl to this with track number off set given by
214 // Int_t fileIndex track number offset value
215 // AliITSUSDigit *pl an AliITSUSDigit to be added to this class.
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);
222 //______________________________________________________________________
223 void AliITSUSDigit::ShiftIndices(Int_t fileIndex)
225 // Shift track numbers
227 for (int i=GetNTracks();i--;) fTrack[i] += fileIndex;
230 //______________________________________________________________________
231 Int_t AliITSUSDigit::Compare(const TObject* obj) const
234 if (GetUniqueID()<obj->GetUniqueID()) return -1;
235 if (GetUniqueID()>obj->GetUniqueID()) return 1;
239 //______________________________________________________________________
240 void AliITSUSDigit::Print(Option_t*) const
243 printf("Mod: %4d Index:%7d Ntr:%2d | TotSignal:%.2e Noise:%.2e ROCycle: %d|",
244 fChip,GetUniqueID(),fNTracks,fTsignal,fNoise,fROCycle);
245 for (int i=0;i<fNTracks;i++) printf("%d(%.2e) |",fTrack[i],fSignal[i]); printf("\n");