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
87 fTrIndex=param.fTrIndex;
91 //__________________________________________________________________
92 void AliSimDigits::InvalidateTrack()
95 //set default (invalid parameters)
96 if ( fTracks != 0) delete fTracks;
97 fTracks = new TArrayI;
98 if ( fTrIndex != 0) delete fTrIndex;
99 fTrIndex = new TArrayI;
101 for (Int_t i = 0; i<3; i++){
107 void AliSimDigits::AllocateTrack(Int_t length)
110 //construct empty buffer fElements and fTracks with size fNrows x fNcols x
114 fTracks->Set(fNcols*fNrows*fNlevel);
119 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
123 if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
124 if (fTrBufType == 1) return GetTrackID1(row, column,level);
125 if (fTrBufType == 2) return GetTrackID2(row, column,level);
129 void AliSimDigits::ExpandTrackBuffer()
132 //expand buffer to two dimensional array
134 Error("ExpandBuffer", "buffer doesn't exist");
137 if (fTrBufType==0) return; //buffer expanded
138 if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
139 if (fTrBufType==2) ExpandTrackBuffer2();
143 void AliSimDigits::CompresTrackBuffer(Int_t bufType)
146 //compres buffer according buffertype algorithm
149 Error("CompressBuffer", "buffer doesn't exist");
152 if (fTrBufType == bufType) return;
154 if (fTrBufType>0) ExpandTrackBuffer();
155 if (fTrBufType !=0) {
156 Error("CompressBuffer", "buffer doesn't exist");
159 //compress buffer of type 1
161 if (bufType==1) {CompresTrackBuffer1();return;}
162 if (bufType==2) CompresTrackBuffer2();
166 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
168 //return track ID of digits - for buffer compresion 2
170 i = level*fNcols+column;
171 if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
173 n2 = fTrIndex->At(i+1);
174 n1 = fTrIndex->At(i);
178 for (i = n1;(i<n2);i++){
180 Int_t num = fTracks->At(i);
186 num = fTracks->At(i);
199 if ( (row>=rowold) && (row<rownew) ) return id;
200 if (row < rownew ) return -2; //empty track
205 void AliSimDigits::ExpandTrackBuffer1()
208 //expand track compressed according algorithm 1 (track id comression independent to the digit compression)
209 // !!in expanded tracks we don't use fTrIndex array
213 Int_t all = fNrows*fNcols; //total number of digits
214 Int_t elems = all*fNlevel; //length of the buffer
216 TArrayI * buf = new TArrayI;
226 //oposite signa means how many unwrited (under threshold) values
227 Int_t num = fTracks->At(i);
228 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
230 num %= 10000000; //PH: take into account the case of underlying events
232 Int_t id = fTracks->At(i);
233 for (j = 0; j<num; j++,row++) {
234 if (level*all+col*fNrows+row<elems) (*buf)[level*all+col*fNrows+row]=id;
245 }//end of loop over digits
250 void AliSimDigits::CompresTrackBuffer1()
253 //comress track according algorithm 1 (track id comression independent to the digit compression)
257 TArrayI * buf = new TArrayI; //create new buffer
258 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
259 TArrayI * index = new TArrayI;
260 index->Set(fNcols*fNlevel);
264 Int_t icurrent=-1; //current index
265 Int_t izero; //number of zero
266 Int_t inum; //number of digits with the same current track id
267 Int_t lastID =0; //last track id
269 Int_t *cbuff=fTracks->GetArray(); //MI change
271 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
272 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
276 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
277 Int_t id=0; //current id
278 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
279 id = *cbuff; //MI change
280 // id = GetTrackIDFast(row,col,lev);
282 if ( inum> 0 ) { //if we have some tracks in buffer
284 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1); //MI change - allocate +1
285 (*buf)[icurrent] = inum;
287 (*buf)[icurrent] = lastID;
296 //if we have currently izero count of non tracks digits
298 if (icurrent>=buf->fN) buf->Set(icurrent*2+1);
299 (*buf)[icurrent]= -izero; //write how many under zero
305 //if we change track id from another track id
307 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1);
308 (*buf)[icurrent] = inum;
310 (*buf)[icurrent] = lastID;
319 }//end of loop over row
321 //if we have currently izero count of non tracks digits
323 if (icurrent>=buf->fN) buf->Set(icurrent*2);
324 (*buf)[icurrent]= -izero; //write how many under zero
326 if ( inum> 0 ) { //if we have some tracks in buffer
328 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2);
329 (*buf)[icurrent] = inum;
331 (*buf)[icurrent] = id;
333 }//end of loop over columns
334 }//end of loop over differnet track level
335 buf->Set(icurrent+1);
344 void AliSimDigits::ExpandTrackBuffer2()
347 //comress track according algorithm 2 (track id comression according digit compression)
351 void AliSimDigits::CompresTrackBuffer2()
354 //comress track according algorithm 2 (track id comression according digit compression)
359 Int_t AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
361 //returnb track id of digits - for buffer compresion 2
367 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
368 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
371 //draw digits in given array
375 sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
376 if ( (fNrows<1)|| (fNcols<1)) {
379 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
381 //set histogram values
382 for (Int_t i = 0; i<fNrows;i++)
383 for (Int_t j = 0; j<fNcols;j++)
384 his->Fill(i,j,GetTrackIDFast(i,j,level));
386 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
390 if (his==0) return 0;
391 if (option!=0) his->Draw(option);
396 TClonesArray * AliSimDigits::GenerTPCClonesArray(TClonesArray * arr)
399 //generate TClonnesArray of digits
401 TClonesArray * digits;
402 if (arr==0) digits=new TClonesArray("AliTPCdigit",300);
404 Int_t index = digits->GetEntriesFast();
405 for (Int_t row =0; row<fNrows; row++)
406 for (Int_t col =0; col<fNcols; col++){
407 Int_t amp = GetDigit(row,col);
408 if (amp>GetThreshold()){
413 dig.fPadRow =fSegmentID;
414 dig.fSector =fSegmentID;
415 dig.GetTracks()[0]= GetTrackID(row,col,0);
416 dig.GetTracks()[1]= GetTrackID(row,col,1);
417 dig.GetTracks()[2]= GetTrackID(row,col,2);
418 TClonesArray &ldigits = *digits;
419 new(ldigits[index++]) AliTPCdigit(dig);
424 void AliSimDigits::GlitchFilter(){
426 // glitch filter, optionally
429 for (Int_t i=0;i<fNcols;i++){ //pads
430 for(Int_t j=1;j<fNrows-1;j++){ //time bins
431 // first and last time bins are checked separately
432 if(GetDigitFast(j,i)){// nonzero digit
433 if (!GetDigitFast(j-1,i) && !GetDigitFast(j+1,i)) {
435 SetTrackIDFast(-2,j,i,0);
436 SetTrackIDFast(-2,j,i,1);
437 SetTrackIDFast(-2,j,i,2);
442 if(GetDigitFast(0,i) && !GetDigitFast(1,i)) {
444 SetTrackIDFast(-2,0,i,0);
445 SetTrackIDFast(-2,0,i,1);
446 SetTrackIDFast(-2,0,i,2);
448 if(GetDigitFast(fNrows-1,i) && !GetDigitFast(fNrows-2,i)){
449 SetDigitFast(0,fNrows-1,i);
450 SetTrackIDFast(-2,fNrows-1,i,0);
451 SetTrackIDFast(-2,fNrows-1,i,1);
452 SetTrackIDFast(-2,fNrows-1,i,2);