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