AliITSpList.h Increased array size from 5 to 10. Set new version number from
[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
c7d528c6 33 // Inputs:
34 // none.
35 // Outputs:
36 // none.
37 // Return:
38 // A zeroed/empty AliITSpList class.
2134176d 39
40 fNi = 0;
41 fNj = 0;
42 fa = 0;
43}
44//______________________________________________________________________
45AliITSpList::AliITSpList(Int_t imax,Int_t jmax){
46 // Standard constructor
c7d528c6 47 // Inputs:
48 // none.
49 // Outputs:
50 // none.
51 // Return:
52 // A setup AliITSpList class.
2134176d 53
54 fNi = imax;
55 fNj = jmax;
56 fa = new TObjArray(fNi*fNj); // elements are zeroed by
57 // TObjArray creator
58}
59//______________________________________________________________________
60AliITSpList::~AliITSpList(){
61 // Default destructor
c7d528c6 62 // Inputs:
63 // none.
64 // Outputs:
65 // none.
66 // Return:
67 // a properly destroyed class
2134176d 68
69 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
c7d528c6 70 delete fa->At(i);
71 fa->AddAt(0,i); // zero content
2134176d 72 } // end for i && if
73 fNi = 0;
74 fNj = 0;
75 delete fa;
76 fa = 0;
77}
78//______________________________________________________________________
79void AliITSpList::ClearMap(){
80 // Delete all AliITSpListItems and zero TObjArray.
c7d528c6 81 // Inputs:
82 // none.
83 // Outputs:
84 // none.
85 // Return:
86 // A zeroed AliITSpList class.
2134176d 87
88 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
c7d528c6 89 delete fa->At(i);
90 fa->AddAt(0,i); // zero content
2134176d 91 } // end for i && if
92}
93//______________________________________________________________________
94void AliITSpList::DeleteHit(Int_t i,Int_t j){
95 // Delete a particular AliITSpListItems and zero TObjArray.
c7d528c6 96 // Inputs:
97 // Int_t i Row number
98 // Int_t j Columns number
99 // Outputs:
100 // none.
101 // Return:
102 // none.
2134176d 103 Int_t k = GetIndex(i,j);
104
105 if(fa->At(k)!=0){
c7d528c6 106 delete fa->At(k);
107 fa->AddAt(0,k); // zero content
2134176d 108 } // end for i && if
109}
110//______________________________________________________________________
111AliITSpList& AliITSpList::operator=(const AliITSpList &source){
112 // = operator
c7d528c6 113 // Inputs:
114 // const AliITSpList &source A AliITSpList object.
115 // Outputs:
116 // none.
117 // Return:
118 // A copied AliITSpList object.
2134176d 119
120 if(this == &source) return *this;
121
122 if(this->fa!=0){ // if this->fa exists delete it first.
c7d528c6 123 for(Int_t i=0;i<GetMaxIndex();i++) if(fa->At(i)!=0){
124 delete fa->At(i);
125 fa->AddAt(0,i); // zero content
126 } // end for i && if
127 delete this->fa;
2134176d 128 } // end if this->fa!=0
129 this->fNi = source.fNi;
130 this->fNj = source.fNj;
131 this->fa = new TObjArray(*(source.fa));
132
133 return *this;
134}
135//______________________________________________________________________
136AliITSpList::AliITSpList(AliITSpList &source){
137 // Copy operator
c7d528c6 138 // Inputs:
139 // AliITSpList &source A AliITSpList Object
140 // Outputs:
141 // none.
142 // Return:
143 // A copied AliITSpList object
2134176d 144
145 *this = source;
146}
147//______________________________________________________________________
c7d528c6 148void AliITSpList::AddItemTo(Int_t fileIndex, AliITSpListItem *pl) {
149 // Adds the contents of pl to the list with track number off set given by
150 // fileIndex.
151 // Creates the AliITSpListItem if needed.
152 // Inputs:
153 // Int_t fileIndex track number offset value
154 // AliITSpListItem *pl an AliITSpListItem to be added to this class.
155 // Outputs:
156 // none.
157 // Return:
158 // none.
159 Int_t index = pl->GetIndex();
160
161 if( fa->At( index ) == 0 ) { // most create AliITSpListItem
162 fa->AddAt(new AliITSpListItem(-2,-1,pl->GetModule(),index,0.0),index);
163 } // end if
164
165 ((AliITSpListItem*)(fa->At( index )))->AddTo( fileIndex, pl );
166}
167//______________________________________________________________________
2134176d 168void AliITSpList::AddSignal(Int_t i,Int_t j,Int_t trk,Int_t ht,Int_t mod,
c7d528c6 169 Double_t signal){
2134176d 170 // Adds a Signal value to the TObjArray at i,j. Creates the AliITSpListItem
171 // if needed.
c7d528c6 172 // Inputs:
173 // Int_t i Row number for this signal
174 // Int_t j Column number for this signal
175 // Int_t trk Track number creating this signal
176 // Int_t ht Hit number creating this signal
177 // Int_t mod The module where this signal is in
178 // Double_t signal The signal (ionization)
179 // Outputs:
180 // none.
181 // Return:
182 // none.
2134176d 183
184 if(GetpListItem(i,j)==0){ // most create AliITSpListItem
c7d528c6 185 fa->AddAt(new AliITSpListItem(trk,ht,mod,GetIndex(i,j),signal),
186 GetIndex(i,j));
2134176d 187 }else{ // AliITSpListItem exists, just add signal to it.
c7d528c6 188 GetpListItem(i,j)->AddSignal(trk,ht,mod,GetIndex(i,j),signal);
2134176d 189 } // end if
190}
191//______________________________________________________________________
192void AliITSpList::AddNoise(Int_t i,Int_t j,Int_t mod,Double_t noise){
193 // Adds a noise value to the TObjArray at i,j. Creates the AliITSpListItem
194 // if needed.
c7d528c6 195 // Inputs:
196 // Int_t i Row number for this noise
197 // Int_t j Column number for this noise
198 // Double_t noise The noise signal value.
199 // Outputs:
200 // none.
201 // Return:
202 // none.
2134176d 203
204 if(GetpListItem(i,j)==0){ // most create AliITSpListItem
c7d528c6 205 fa->AddAt(new AliITSpListItem(mod,GetIndex(i,j),noise),
206 GetIndex(i,j));
2134176d 207 }else{ // AliITSpListItem exists, just add signal to it.
c7d528c6 208 GetpListItem(i,j)->AddNoise(mod,GetIndex(i,j),noise);
2134176d 209 } // end if
210}
211//______________________________________________________________________
212
213ClassImp(AliITSpListItem)
214//______________________________________________________________________
215AliITSpListItem::AliITSpListItem(){
216 // Default constructor
c7d528c6 217 // Inputs:
218 // none.
219 // Outputs:
220 // none.
221 // Return:
222 // A zeroed/empty AliITSpListItem class.
2134176d 223
224 fmodule = -1;
225 findex = -1;
226 for(Int_t i=0;i<this->fkSize;i++){
c7d528c6 227 this->fTrack[i] = -2;
228 this->fHits[i] = -1;
229 this->fSignal[i] = 0.0;
2134176d 230 } // end if i
231 fTsignal = 0.0;
232 fNoise = 0.0;
233}
234//______________________________________________________________________
235AliITSpListItem::AliITSpListItem(Int_t module,Int_t index,Double_t noise){
236 // Standard noise constructor
c7d528c6 237 // Inputs:
238 // Int_t module The module where this noise occurred
239 // Int_t index The cell index where this noise occurred
240 // Double_t noise The value of the noise.
241 // Outputs:
242 // none.
243 // Return:
244 // A setup and noise filled AliITSpListItem class.
2134176d 245
246 this->fmodule = module;
247 this->findex = index;
248 for(Int_t i=0;i<this->fkSize;i++){
c7d528c6 249 this->fTrack[i] = -2;
250 this->fSignal[i] = 0.0;
251 this->fHits[i] = -1;
2134176d 252 } // end if i
253 this->fTsignal = 0.0;
254 this->fNoise = noise;
255}
256//______________________________________________________________________
257AliITSpListItem::AliITSpListItem(Int_t track,Int_t hit,Int_t module,
c7d528c6 258 Int_t index,Double_t signal){
2134176d 259 // Standard signal constructor
c7d528c6 260 // Inputs:
261 // Int_t track The track number which produced this signal
262 // Int_t hit The hit number which produced this signal
263 // Int_t module The module where this signal occurred
264 // Int_t index The cell index where this signal occurred
265 // Double_t signal The value of the signal (ionization)
266 // Outputs:
267 // none.
268 // Return:
269 // A setup and signal filled AliITSpListItem class.
2134176d 270
271 this->fmodule = module;
272 this->findex = index;
273 this->fTrack[0] = track;
274 this->fHits[0] = hit;
275 this->fSignal[0] = signal;
276 for(Int_t i=1;i<this->fkSize;i++){
c7d528c6 277 this->fTrack[i] = -2;
278 this->fSignal[i] = 0.0;
279 this->fHits[i] = -1;
2134176d 280 } // end if i
281 this->fTsignal = signal;
282 this->fNoise = 0.0;
283}
284//______________________________________________________________________
285AliITSpListItem::~AliITSpListItem(){
c7d528c6 286 // Destructor
287 // Inputs:
288 // none.
289 // Outputs:
290 // none.
291 // Return:
292 // A properly destroyed AliITSpListItem class.
293/*
2134176d 294 this->fmodule = 0;
c7d528c6 295 this->findex = 0;
2134176d 296 for(Int_t i=0;i<=this->GetNsignals();i++){
c7d528c6 297 this->fTrack[i] = 0;
298 this->fSignal[i] = 0.0;
299 this->fHits[i] = 0;
2134176d 300 } // end if i
301 this->fTsignal = 0.0;
c7d528c6 302 this->fNoise = 0.0;
303*/
2134176d 304}
305//______________________________________________________________________
306AliITSpListItem& AliITSpListItem::operator=(const AliITSpListItem &source){
307 // = operator
c7d528c6 308 // Inputs:
309 // AliITSpListItem &source A AliITSpListItem Object
310 // Outputs:
311 // none.
312 // Return:
313 // A copied AliITSpListItem object
2134176d 314
315 if(this == &source) return *this;
316
317 this->fmodule = source.fmodule;
318 this->findex = source.findex;
319 for(Int_t i=0;i<this->fkSize;i++){
c7d528c6 320 this->fTrack[i] = source.fTrack[i];
321 this->fSignal[i] = source.fSignal[i];
322 this->fHits[i] = source.fHits[i];
2134176d 323 } // end if i
324 this->fTsignal = source.fTsignal;
325 this->fNoise = source.fNoise;
326
327 return *this;
328}
329//______________________________________________________________________
330AliITSpListItem::AliITSpListItem(AliITSpListItem &source){
331 // Copy operator
c7d528c6 332 // Inputs:
333 // AliITSpListItem &source A AliITSpListItem Object
334 // Outputs:
335 // none.
336 // Return:
337 // A copied AliITSpListItem object
2134176d 338
339 *this = source;
340}
341//______________________________________________________________________
342void AliITSpListItem::AddSignal(Int_t track,Int_t hit,Int_t module,
c7d528c6 343 Int_t index,Double_t signal){
344 // Adds this track number and signal to the pList and orders them
345 // Inputs:
346 // Int_t track The track number which produced this signal
347 // Int_t hit The hit number which produced this signal
348 // Int_t module The module where this signal occurred
349 // Int_t index The cell index where this signal occurred
350 // Double_t signal The value of the signal (ionization)
351 // Outputs:
352 // none.
353 // Return:
354 // none.
2134176d 355 Int_t i,j,trk,hts;
356 Double_t sig;
357 Bool_t flg=kFALSE;
358
359 if(findex!=index || fmodule!=module)
c7d528c6 360 Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
361 index,findex,module,fmodule);
2134176d 362 fTsignal += signal; // Keep track of sum signal.
c7d528c6 363 for(i=0;i<fkSize;i++) if( track==fTrack[i] && hit==fHits[i]){
364 fSignal[i] += signal;
365 flg = kTRUE;
2134176d 366 } // end for i & if.
c7d528c6 367 if(flg){ // resort arrays.
368 for(i=1;i<fkSize;i++){
369 j = i;
370 while(j>0 && fSignal[j]>fSignal[j-1]){
371 trk = fTrack[j-1];
372 hts = fHits[j-1];
373 sig = fSignal[j-1];
374 fTrack[j-1] = fTrack[j];
375 fHits[j-1] = fHits[j];
376 fSignal[j-1] = fSignal[j];
377 fTrack[j] = trk;
378 fHits[j] = hts;
379 fSignal[j] = sig;
380 j--;
381 } // end while
382 } // end if i
383 return;
384 } // end if added to existing and resorted array
9176630b 385
ab5aed76 386 // new entry add it in order.
387 // if this signal is <= smallest then don't add it.
388 if(signal <= fSignal[fkSize-1]) return;
389 for(i=fkSize-2;i>=0;i--){
c7d528c6 390 if(signal > fSignal[i]){
391 fSignal[i+1] = fSignal[i];
392 fTrack[i+1] = fTrack[i];
393 fHits[i+1] = fHits[i];
394 }else{
395 fSignal[i+1] = signal;
396 fTrack[i+1] = track;
397 fHits[i+1] = hit;
398 return; // put it in the right place, now exit.
399 } // end if
ab5aed76 400 } // end if; end for i
401 // Still haven't found the right place. Must be at top of list.
402 fSignal[0] = signal;
403 fTrack[0] = track;
404 fHits[0] = hit;
405 return;
2134176d 406}
407//______________________________________________________________________
408void AliITSpListItem::AddNoise(Int_t module,Int_t index,Double_t noise){
c7d528c6 409 // Adds noise to this existing list.
410 // Inputs:
411 // Int_t module The module where this noise occurred
412 // Int_t index The cell index where this noise occurred
413 // Double_t noise The value of the noise.
414 // Outputs:
415 // none.
416 // Return:
417 // none.
2134176d 418
419 if(findex!=index || fmodule!=module)
c7d528c6 420 Warning("AddSignal","index=%d != findex=%d or module=%d != fmodule=%d",
421 index,findex,module,fmodule);
2134176d 422 fNoise += noise; // Keep track of sum signal.
423}
424//______________________________________________________________________
425void AliITSpListItem::AddTo(Int_t fileIndex,AliITSpListItem *pl){
426 // Adds the contents of pl to this with track number off set given by
427 // fileIndex.
c7d528c6 428 // Inputs:
429 // Int_t fileIndex track number offset value
430 // AliITSpListItem *pl an AliITSpListItem to be added to this class.
431 // Outputs:
432 // none.
433 // Return:
434 // none.
2134176d 435 Int_t i,trk;
436 Double_t sig=0.0;
437
c7d528c6 438 for(i=0;i<pl->GetNsignals();i++){
439 trk = pl->GetTrack(i);
440 trk += fileIndex;
441 this->AddSignal(trk,pl->GetHit(i),pl->GetModule(),
442 pl->GetIndex(),pl->GetSignal(i));
443 sig += pl->GetSignal(i);
2134176d 444 } // end for i
445 this->fNoise += pl->fNoise;
446 return;
447}
448//______________________________________________________________________
449Int_t AliITSpListItem::ShiftIndex(Int_t in,Int_t trk){
c7d528c6 450 // Shift an index number to occupy the upper four bits. No longer used.
451 // Inputs:
452 // Int_t in The file number
453 // Int_t trk The track number
454 // Outputs:
455 // none.
456 // Return:
457 // Int_t The track number with the file number in the upper bits.
2134176d 458 Int_t si = sizeof(Int_t) * 8;
c7d528c6 459 UInt_t uin,utrk; // use UInt_t to avoid integer overflow-> goes negative.
2134176d 460
461 uin = in;
462 utrk = trk;
463 for(Int_t i=0;i<si-4;i++) uin *= 2;
464 uin += utrk;
465 in = uin;
466 return in;
467}
468//______________________________________________________________________
469void AliITSpListItem::Print(ostream *os){
470 //Standard output format for this class
c7d528c6 471 // Inputs:
472 // ostream *os The output stream
473 // Outputs:
474 // none.
475 // Return:
476 // none.
2134176d 477 Int_t i;
478
479 *os << fmodule <<","<<findex<<",";
480 *os << fkSize <<",";
481 for(i=0;i<fkSize;i++) *os << fTrack[i] <<",";
482 for(i=0;i<fkSize;i++) *os << fHits[i] <<",";
483 for(i=0;i<fkSize;i++) *os << fSignal[i] <<",";
484 *os << fTsignal <<","<< fNoise;
485}
486//______________________________________________________________________
487void AliITSpListItem::Read(istream *is){
488 // Standard output streaming function.
c7d528c6 489 // Inputs:
490 // istream *is The input stream
491 // Outputs:
492 // none.
493 // Return:
494 // none.
2134176d 495 Int_t i,iss;
496
497 *is >> fmodule >> findex;
498 *is >> iss; // read in fkSize
499 for(i=0;i<fkSize&&i<iss;i++) *is >> fTrack[i];
500 for(i=0;i<fkSize&&i<iss;i++) *is >> fHits[i];
501 for(i=0;i<fkSize&&i<iss;i++) *is >> fSignal[i];
502 *is >> fTsignal >> fNoise;
503}
504//______________________________________________________________________
505ostream &operator<<(ostream &os,AliITSpListItem &source){
506 // Standard output streaming function.
c7d528c6 507 // Inputs:
508 // ostream &os The output stream
509 // AliITSpListItem &source The AliITSpListItem object to be written out.
510 // Outputs:
511 // none.
512 // Return:
513 // ostream The output stream
2134176d 514
515 source.Print(&os);
516 return os;
517}
518//______________________________________________________________________
519istream &operator>>(istream &os,AliITSpListItem &source){
520 // Standard output streaming function.
c7d528c6 521 // Inputs:
522 // istream os The input stream
523 // AliITSpListItem &source The AliITSpListItem object to be inputted
524 // Outputs:
525 // none.
526 // Return:
527 // istream The input stream.
2134176d 528
529 source.Read(&os);
530 return os;
531}
c7d528c6 532