1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Alice segment manager object //
21 // AliSimDigits object (derived from AliDigits) //
22 // provide additional track information to digit //
23 // Origin: Marian Ivanov GSI Darmstadt //
26 ///////////////////////////////////////////////////////////////////////////////
29 #include <Riostream.h>
31 #include "AliSegmentID.h"
34 #include "AliDigits.h"
35 #include "AliSimDigits.h"
36 #include "AliTPCdigit.h"
37 #include <TClonesArray.h>
41 //_____________________________________________________________________________
42 //_____________________________________________________________________________
43 //_____________________________________________________________________________
44 ClassImp(AliSimDigits)
46 AliSimDigits::AliSimDigits()
53 // AliDigits::Invalite();
58 AliSimDigits::AliSimDigits(const AliSimDigits ¶m)
68 fTrIndex = param.fTrIndex;
71 AliSimDigits::~AliSimDigits()
82 AliSimDigits & AliSimDigits::operator =(const AliSimDigits & param)
85 // assignment operator - dummy
88 fTrIndex=param.fTrIndex;
93 //__________________________________________________________________
94 void AliSimDigits::InvalidateTrack()
97 //set default (invalid parameters)
98 if ( fTracks != 0) delete fTracks;
99 fTracks = new TArrayI;
100 if ( fTrIndex != 0) delete fTrIndex;
101 fTrIndex = new TArrayI;
103 for (Int_t i = 0; i<3; i++){
109 void AliSimDigits::AllocateTrack(Int_t length)
112 //construct empty buffer fElements and fTracks with size fNrows x fNcols x
116 fTracks->Set(fNcols*fNrows*fNlevel);
121 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
125 if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
126 if (fTrBufType == 1) return GetTrackID1(row, column,level);
127 if (fTrBufType == 2) return GetTrackID2(row, column,level);
131 void AliSimDigits::ExpandTrackBuffer()
134 //expand buffer to two dimensional array
136 Error("ExpandBuffer", "buffer doesn't exist");
139 if (fTrBufType==0) return; //buffer expanded
140 if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
141 if (fTrBufType==2) ExpandTrackBuffer2();
145 void AliSimDigits::CompresTrackBuffer(Int_t bufType)
148 //compres buffer according buffertype algorithm
151 Error("CompressBuffer", "buffer doesn't exist");
154 if (fTrBufType == bufType) return;
156 if (fTrBufType>0) ExpandTrackBuffer();
157 if (fTrBufType !=0) {
158 Error("CompressBuffer", "buffer doesn't exist");
161 //compress buffer of type 1
163 if (bufType==1) {CompresTrackBuffer1();return;}
164 if (bufType==2) CompresTrackBuffer2();
168 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
170 //return track ID of digits - for buffer compresion 2
172 i = level*fNcols+column;
173 if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
175 n2 = fTrIndex->At(i+1);
176 n1 = fTrIndex->At(i);
180 for (i = n1;(i<n2);i++){
182 Int_t num = fTracks->At(i);
188 num = fTracks->At(i);
201 if ( (row>=rowold) && (row<rownew) ) return id;
202 if (row < rownew ) return -2; //empty track
207 void AliSimDigits::ExpandTrackBuffer1()
210 //expand track compressed according algorithm 1 (track id comression independent to the digit compression)
211 // !!in expanded tracks we don't use fTrIndex array
215 Int_t all = fNrows*fNcols; //total number of digits
216 Int_t elems = all*fNlevel; //length of the buffer
218 TArrayI * buf = new TArrayI;
228 //oposite signa means how many unwrited (under threshold) values
229 Int_t num = fTracks->At(i);
230 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
232 num %= 10000000; //PH: take into account the case of underlying events
234 Int_t id = fTracks->At(i);
235 for (j = 0; j<num; j++,row++) {
236 if (level*all+col*fNrows+row<elems) (*buf)[level*all+col*fNrows+row]=id;
247 }//end of loop over digits
252 void AliSimDigits::CompresTrackBuffer1()
255 //comress track according algorithm 1 (track id comression independent to the digit compression)
259 TArrayI * buf = new TArrayI; //create new buffer
260 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
261 TArrayI * index = new TArrayI;
262 index->Set(fNcols*fNlevel);
266 Int_t icurrent=-1; //current index
267 Int_t izero; //number of zero
268 Int_t inum; //number of digits with the same current track id
269 Int_t lastID =0; //last track id
271 Int_t *cbuff=fTracks->GetArray(); //MI change
273 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
274 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
278 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
279 Int_t id=0; //current id
280 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
281 id = *cbuff; //MI change
282 // id = GetTrackIDFast(row,col,lev);
284 if ( inum> 0 ) { //if we have some tracks in buffer
286 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1); //MI change - allocate +1
287 (*buf)[icurrent] = inum;
289 (*buf)[icurrent] = lastID;
298 //if we have currently izero count of non tracks digits
300 if (icurrent>=buf->fN) buf->Set(icurrent*2+1);
301 (*buf)[icurrent]= -izero; //write how many under zero
307 //if we change track id from another track id
309 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1);
310 (*buf)[icurrent] = inum;
312 (*buf)[icurrent] = lastID;
321 }//end of loop over row
323 //if we have currently izero count of non tracks digits
325 if (icurrent>=buf->fN) buf->Set(icurrent*2);
326 (*buf)[icurrent]= -izero; //write how many under zero
328 if ( inum> 0 ) { //if we have some tracks in buffer
330 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2);
331 (*buf)[icurrent] = inum;
333 (*buf)[icurrent] = id;
335 }//end of loop over columns
336 }//end of loop over differnet track level
337 buf->Set(icurrent+1);
346 void AliSimDigits::ExpandTrackBuffer2()
349 //comress track according algorithm 2 (track id comression according digit compression)
353 void AliSimDigits::CompresTrackBuffer2()
356 //comress track according algorithm 2 (track id comression according digit compression)
361 Int_t AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
363 //returnb track id of digits - for buffer compresion 2
369 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
370 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
373 //draw digits in given array
377 //sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
378 snprintf(ch,30,"Track Segment_%d level %d ",GetID(),level );
379 if ( (fNrows<1)|| (fNcols<1)) {
382 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
384 //set histogram values
385 for (Int_t i = 0; i<fNrows;i++)
386 for (Int_t j = 0; j<fNcols;j++)
387 his->Fill(i,j,GetTrackIDFast(i,j,level));
389 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
393 if (his==0) return 0;
394 if (option!=0) his->Draw(option);
399 TClonesArray * AliSimDigits::GenerTPCClonesArray(TClonesArray * arr)
402 //generate TClonnesArray of digits
404 TClonesArray * digits;
405 if (arr==0) digits=new TClonesArray("AliTPCdigit",300);
407 Int_t index = digits->GetEntriesFast();
408 for (Int_t row =0; row<fNrows; row++)
409 for (Int_t col =0; col<fNcols; col++){
410 Int_t amp = GetDigit(row,col);
411 if (amp>GetThreshold()){
416 dig.fPadRow =fSegmentID;
417 dig.fSector =fSegmentID;
418 dig.GetTracks()[0]= GetTrackID(row,col,0);
419 dig.GetTracks()[1]= GetTrackID(row,col,1);
420 dig.GetTracks()[2]= GetTrackID(row,col,2);
421 TClonesArray &ldigits = *digits;
422 new(ldigits[index++]) AliTPCdigit(dig);
427 void AliSimDigits::GlitchFilter(){
429 // glitch filter, optionally
432 for (Int_t i=0;i<fNcols;i++){ //pads
433 for(Int_t j=1;j<fNrows-1;j++){ //time bins
434 // first and last time bins are checked separately
435 if(GetDigitFast(j,i)){// nonzero digit
436 if (!GetDigitFast(j-1,i) && !GetDigitFast(j+1,i)) {
438 SetTrackIDFast(-2,j,i,0);
439 SetTrackIDFast(-2,j,i,1);
440 SetTrackIDFast(-2,j,i,2);
445 if(GetDigitFast(0,i) && !GetDigitFast(1,i)) {
447 SetTrackIDFast(-2,0,i,0);
448 SetTrackIDFast(-2,0,i,1);
449 SetTrackIDFast(-2,0,i,2);
451 if(GetDigitFast(fNrows-1,i) && !GetDigitFast(fNrows-2,i)){
452 SetDigitFast(0,fNrows-1,i);
453 SetTrackIDFast(-2,fNrows-1,i,0);
454 SetTrackIDFast(-2,fNrows-1,i,1);
455 SetTrackIDFast(-2,fNrows-1,i,2);