Last minute big fix (B.Nilsen)
[u/mrichter/AliRoot.git] / ITS / AliITSpList.cxx
CommitLineData
2134176d 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id$ */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <iostream.h>
20#include <iomanip.h>
21#include <TObjArray.h>
22#include <TRandom.h>
23#include <TMath.h>
24
25#include "AliITSpList.h"
26
27//______________________________________________________________________
28
29ClassImp(AliITSpList);
30//______________________________________________________________________
31AliITSpList::AliITSpList(){
32 // Default constructor
33
34 fNi = 0;
35 fNj = 0;
36 fa = 0;
37}
38//______________________________________________________________________
39AliITSpList::AliITSpList(Int_t imax,Int_t jmax){
40 // Standard constructor
41
42 fNi = imax;
43 fNj = jmax;
44 fa = new TObjArray(fNi*fNj); // elements are zeroed by
45 // TObjArray creator
46}
47//______________________________________________________________________
48AliITSpList::~AliITSpList(){
49 // Default destructor
50
51 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
52 delete fa->At(i);
53 fa->AddAt(0,i); // zero content
54 } // end for i && if
55 fNi = 0;
56 fNj = 0;
57 delete fa;
58 fa = 0;
59}
60//______________________________________________________________________
61void AliITSpList::ClearMap(){
62 // Delete all AliITSpListItems and zero TObjArray.
63
64 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
65 delete fa->At(i);
66 fa->AddAt(0,i); // zero content
67 } // end for i && if
68}
69//______________________________________________________________________
70void AliITSpList::DeleteHit(Int_t i,Int_t j){
71 // Delete a particular AliITSpListItems and zero TObjArray.
72 Int_t k = GetIndex(i,j);
73
74 if(fa->At(k)!=0){
75 delete fa->At(k);
76 fa->AddAt(0,k); // zero content
77 } // end for i && if
78}
79//______________________________________________________________________
80AliITSpList& AliITSpList::operator=(const AliITSpList &source){
81 // = operator
82
83 if(this == &source) return *this;
84
85 if(this->fa!=0){ // if this->fa exists delete it first.
86 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
87 delete fa->At(i);
88 fa->AddAt(0,i); // zero content
89 } // end for i && if
90 delete this->fa;
91 } // end if this->fa!=0
92 this->fNi = source.fNi;
93 this->fNj = source.fNj;
94 this->fa = new TObjArray(*(source.fa));
95
96 return *this;
97}
98//______________________________________________________________________
99AliITSpList::AliITSpList(AliITSpList &source){
100 // Copy operator
101
102 *this = source;
103}
104//______________________________________________________________________
105void AliITSpList::AddSignal(Int_t i,Int_t j,Int_t trk,Int_t ht,Int_t mod,
106 Double_t signal){
107 // Adds a Signal value to the TObjArray at i,j. Creates the AliITSpListItem
108 // if needed.
109
110 if(GetpListItem(i,j)==0){ // most create AliITSpListItem
111 fa->AddAt(new AliITSpListItem(trk,ht,mod,GetIndex(i,j),signal),
112 GetIndex(i,j));
113 }else{ // AliITSpListItem exists, just add signal to it.
114 GetpListItem(i,j)->AddSignal(trk,ht,mod,GetIndex(i,j),signal);
115 } // end if
116}
117//______________________________________________________________________
118void AliITSpList::AddNoise(Int_t i,Int_t j,Int_t mod,Double_t noise){
119 // Adds a noise value to the TObjArray at i,j. Creates the AliITSpListItem
120 // if needed.
121
122 if(GetpListItem(i,j)==0){ // most create AliITSpListItem
123 fa->AddAt(new AliITSpListItem(mod,GetIndex(i,j),noise),
124 GetIndex(i,j));
125 }else{ // AliITSpListItem exists, just add signal to it.
126 GetpListItem(i,j)->AddNoise(mod,GetIndex(i,j),noise);
127 } // end if
128}
129//______________________________________________________________________
130
131ClassImp(AliITSpListItem)
132//______________________________________________________________________
133AliITSpListItem::AliITSpListItem(){
134 // Default constructor
135
136 fmodule = -1;
137 findex = -1;
138 for(Int_t i=0;i<this->fkSize;i++){
139 this->fTrack[i] = -2;
140 this->fHits[i] = -2;
141 this->fSignal[i] = 0.0;
142 } // end if i
143 fTsignal = 0.0;
144 fNoise = 0.0;
145}
146//______________________________________________________________________
147AliITSpListItem::AliITSpListItem(Int_t module,Int_t index,Double_t noise){
148 // Standard noise constructor
149
150 this->fmodule = module;
151 this->findex = index;
152 for(Int_t i=0;i<this->fkSize;i++){
153 this->fTrack[i] = -2;
154 this->fSignal[i] = 0.0;
155 this->fHits[i] = 0;
156 } // end if i
157 this->fTsignal = 0.0;
158 this->fNoise = noise;
159}
160//______________________________________________________________________
161AliITSpListItem::AliITSpListItem(Int_t track,Int_t hit,Int_t module,
162 Int_t index,Double_t signal){
163 // Standard signal constructor
164
165 this->fmodule = module;
166 this->findex = index;
167 this->fTrack[0] = track;
168 this->fHits[0] = hit;
169 this->fSignal[0] = signal;
170 for(Int_t i=1;i<this->fkSize;i++){
171 this->fTrack[i] = -2;
172 this->fSignal[i] = 0.0;
173 this->fHits[i] = 0;
174 } // end if i
175 this->fTsignal = signal;
176 this->fNoise = 0.0;
177}
178//______________________________________________________________________
179AliITSpListItem::~AliITSpListItem(){
180 // Denstructor
181
182 this->fmodule = 0;
183 this->findex =0;
184 for(Int_t i=0;i<=this->GetNsignals();i++){
185 this->fTrack[i] = 0;
186 this->fSignal[i] = 0.0;
187 this->fHits[i] = 0;
188 } // end if i
189 this->fTsignal = 0.0;
190 this->fNoise =0.0;
191}
192//______________________________________________________________________
193AliITSpListItem& AliITSpListItem::operator=(const AliITSpListItem &source){
194 // = operator
195
196 if(this == &source) return *this;
197
198 this->fmodule = source.fmodule;
199 this->findex = source.findex;
200 for(Int_t i=0;i<this->fkSize;i++){
201 this->fTrack[i] = source.fTrack[i];
202 this->fSignal[i] = source.fSignal[i];
203 this->fHits[i] = source.fHits[i];
204 } // end if i
205 this->fTsignal = source.fTsignal;
206 this->fNoise = source.fNoise;
207
208 return *this;
209}
210//______________________________________________________________________
211AliITSpListItem::AliITSpListItem(AliITSpListItem &source){
212 // Copy operator
213
214 *this = source;
215}
216//______________________________________________________________________
217void AliITSpListItem::AddSignal(Int_t track,Int_t hit,Int_t module,
218 Int_t index,Double_t signal){
219 // Adds this track number and sinal to the pList and orders them
220 Int_t i,j,trk,hts;
221 Double_t sig;
222 Bool_t flg=kFALSE;
223
224 if(findex!=index || fmodule!=module)
225 Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
226 index,findex,module,fmodule);
227 fTsignal += signal; // Keep track of sum signal.
228 if(signal<=fSignal[fkSize-1]) return; // smaller than smallest
229 for(i=0;i<fkSize;i++)if(track==fTrack[i] && hit ==fHits[i]){
230 fSignal[i] += signal;
231 flg = kTRUE;
232 } // end for i & if.
233 if(flg){ // resort arrays. fkSize is small use Insertin sort.
234 for(i=1;i<fkSize;i++){
235 trk = fTrack[i];
236 hts = fHits[i];
237 sig = fSignal[i];
238 j = i-1;
239 while(j>=0 && fSignal[i]>signal){
240 fTrack[j+1] = fTrack[j];
241 fHits[j+1] = fHits[j];
242 fSignal[j+1] = fSignal[j];
243 j--;
244 } // end while
245 fTrack[j+1] = trk;
246 fHits[j+1] = hts;
247 fSignal[j+1] = sig;
248 } // end if i
ab5aed76 249 return;
250 } // end if added to existing and resorted array
251 // new entry add it in order.
252 // if this signal is <= smallest then don't add it.
253 if(signal <= fSignal[fkSize-1]) return;
254 for(i=fkSize-2;i>=0;i--){
255 if(signal > fSignal[i]){
256 fSignal[i+1] = fSignal[i];
257 fTrack[i+1] = fTrack[i];
258 fHits[i+1] = fHits[i];
259 }else{;
260 fSignal[i] = signal;
261 fTrack[i] = track;
262 fHits[i] = hit;
263 return; // put it in the right place, now exit.
264 } // end if
265 } // end if; end for i
266 // Still haven't found the right place. Must be at top of list.
267 fSignal[0] = signal;
268 fTrack[0] = track;
269 fHits[0] = hit;
270 return;
2134176d 271}
272//______________________________________________________________________
273void AliITSpListItem::AddNoise(Int_t module,Int_t index,Double_t noise){
274 // Addes noise to this existing list.
275
276 if(findex!=index || fmodule!=module)
277 Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
278 index,findex,module,fmodule);
279 fNoise += noise; // Keep track of sum signal.
280}
281//______________________________________________________________________
282void AliITSpListItem::AddTo(Int_t fileIndex,AliITSpListItem *pl){
283 // Adds the contents of pl to this with track number off set given by
284 // fileIndex.
285 Int_t i,trk;
286 Double_t sig=0.0;
287
288 for(i=0;i<pl->GetNsignals()&&i<this->GetNsignals();i++){
289 trk = pl->GetTrack(i);
290 trk = pl->ShiftIndex(fileIndex,trk);
291 this->AddSignal(trk,pl->GetHit(i),pl->GetModule(),pl->GetIndex(),pl->GetSignal(i));
292 sig += pl->GetSignal(i);
293 } // end for i
294 this->fNoise += pl->fNoise;
295 return;
296}
297//______________________________________________________________________
298Int_t AliITSpListItem::ShiftIndex(Int_t in,Int_t trk){
299 // Shift an index number to occupy the upper four bits.
300 Int_t si = sizeof(Int_t) * 8;
301 UInt_t uin,utrk; // use UInt_t to avoid interger overflow-> goes negitive.
302
303 uin = in;
304 utrk = trk;
305 for(Int_t i=0;i<si-4;i++) uin *= 2;
306 uin += utrk;
307 in = uin;
308 return in;
309}
310//______________________________________________________________________
311void AliITSpListItem::Print(ostream *os){
312 //Standard output format for this class
313 Int_t i;
314
315 *os << fmodule <<","<<findex<<",";
316 *os << fkSize <<",";
317 for(i=0;i<fkSize;i++) *os << fTrack[i] <<",";
318 for(i=0;i<fkSize;i++) *os << fHits[i] <<",";
319 for(i=0;i<fkSize;i++) *os << fSignal[i] <<",";
320 *os << fTsignal <<","<< fNoise;
321}
322//______________________________________________________________________
323void AliITSpListItem::Read(istream *is){
324 // Standard output streaming function.
325 Int_t i,iss;
326
327 *is >> fmodule >> findex;
328 *is >> iss; // read in fkSize
329 for(i=0;i<fkSize&&i<iss;i++) *is >> fTrack[i];
330 for(i=0;i<fkSize&&i<iss;i++) *is >> fHits[i];
331 for(i=0;i<fkSize&&i<iss;i++) *is >> fSignal[i];
332 *is >> fTsignal >> fNoise;
333}
334//______________________________________________________________________
335ostream &operator<<(ostream &os,AliITSpListItem &source){
336 // Standard output streaming function.
337
338 source.Print(&os);
339 return os;
340}
341//______________________________________________________________________
342istream &operator>>(istream &os,AliITSpListItem &source){
343 // Standard output streaming function.
344
345 source.Read(&os);
346 return os;
347}