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 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
20 Digits handling in a new data structure
25 ///////////////////////////////////////////////////////////////////////////////
27 // Alice segment manager object //
29 // AliSimDigits object (derived from AliDigits) //
30 // provide additional track information to digit //
32 // Origin: Marian Ivanov GSI Darmstadt //
36 ///////////////////////////////////////////////////////////////////////////////
41 #include "AliSegmentID.h"
43 #include "AliArrayI.h"
44 #include "AliArrayS.h"
45 #include "AliDigits.h"
46 #include "AliSimDigits.h"
51 //_____________________________________________________________________________
52 //_____________________________________________________________________________
53 //_____________________________________________________________________________
54 ClassImp(AliSimDigits)
56 AliSimDigits::AliSimDigits()
58 // AliDigits::Invalite();
63 AliSimDigits::~AliSimDigits()
65 // AliDigits::Invalidate();
66 if (fTracks != 0) fTracks->Delete();
67 if (fTrIndex != 0) fTrIndex->Delete();
71 void AliSimDigits::InvalidateTrack()
74 //set default (invalid parameters)
75 if ( fTracks != 0) delete fTracks;
76 fTracks = new AliArrayI;
77 if ( fTrIndex != 0) delete fTrIndex;
78 fTrIndex = new AliArrayI;
80 for (Int_t i = 0; i<3; i++){
86 void AliSimDigits::AllocateTrack(Int_t length)
89 //construct empty buffer fElements and fTracks with size fNrows x fNcols x
93 fTracks->Set(fNcols*fNrows*fNlevel);
98 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
102 if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
103 if (fTrBufType == 1) return GetTrackID1(row, column,level);
104 if (fTrBufType == 2) return GetTrackID2(row, column,level);
108 void AliSimDigits::ExpandTrackBuffer()
111 //expand buffer to two dimensional array
113 Error("ExpandBuffer", "buffer doesn't exist");
116 if (fTrBufType==0) return; //buffer expanded
117 if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
118 if (fTrBufType==2) ExpandTrackBuffer2();
122 void AliSimDigits::CompresTrackBuffer(Int_t bufType)
125 //compres buffer according buffertype algorithm
128 Error("CompressBuffer", "buffer doesn't exist");
131 if (fTrBufType == bufType) return;
133 if (fTrBufType>0) ExpandTrackBuffer();
134 if (fTrBufType !=0) {
135 Error("CompressBuffer", "buffer doesn't exist");
138 //compress buffer of type 1
140 if (bufType==1) {CompresTrackBuffer1();return;}
141 if (bufType==2) CompresTrackBuffer2();
145 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
147 //return track ID of digits - for buffer compresion 2
149 i = level*fNcols+column;
150 if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
152 n2 = fTrIndex->At(i+1);
153 n1 = fTrIndex->At(i);
157 for (i = n1;(i<n2);i++){
159 Int_t num = fTracks->At(i);
165 num = fTracks->At(i);
178 if ( (row>=rowold) && (row<=rownew) ) return ID;
179 if (row < rownew ) return -2; //empty track
184 void AliSimDigits::ExpandTrackBuffer1()
187 //expand track compressed according algorithm 1 (track ID comression independent to the digit compression)
188 // !!in expanded tracks we don't use fTrIndex array
192 Int_t all = fNrows*fNcols; //total number of digits
193 Int_t elems = all*fNlevel; //length of the buffer
195 AliArrayI * buf = new AliArrayI;
205 //oposite signa means how many unwrited (under threshold) values
206 Int_t num = fTracks->At(i);
207 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
210 Int_t ID = fTracks->At(i);
211 for (j = 0; j<num; j++,row++) (*buf)[level*all+col*fNrows+row]=ID;
221 }//end of loop over digits
226 void AliSimDigits::CompresTrackBuffer1()
229 //comress track according algorithm 1 (track ID comression independent to the digit compression)
233 AliArrayI * buf = new AliArrayI; //create new buffer
234 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
235 AliArrayI * index = new AliArrayI;
236 index->Set(fNcols*fNlevel);
238 Int_t icurrent=-1; //current index
239 Int_t izero; //number of zero
240 Int_t inum; //number of digits with the same current track ID
241 Int_t lastID =0; //last track ID
242 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
243 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
247 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
248 Int_t ID; //current ID
249 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
250 ID = GetTrackIDFast(row,col,lev);
252 if ( inum> 0 ) { //if we have some tracks in buffer
254 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
255 (*buf)[icurrent] = inum;
257 (*buf)[icurrent] = lastID;
266 //if we have currently izero count of non tracks digits
268 if (icurrent>=buf->fN) buf->Expand(icurrent*2);
269 (*buf)[icurrent]= -izero; //write how many under zero
275 //if we change track ID from another track ID
277 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
278 (*buf)[icurrent] = inum;
280 (*buf)[icurrent] = lastID;
289 }//end of loop over rows
291 //if we have currently izero count of non tracks digits
293 if (icurrent>=buf->fN) buf->Expand(icurrent*2);
294 (*buf)[icurrent]= -izero; //write how many under zero
296 if ( inum> 0 ) { //if we have some tracks in buffer
298 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
299 (*buf)[icurrent] = inum;
301 (*buf)[icurrent] = ID;
303 }//end of loop over columns
304 }//end of loop over differnet track level
305 buf->Expand(icurrent+1);
314 void AliSimDigits::ExpandTrackBuffer2()
317 //comress track according algorithm 2 (track ID comression according digit compression)
321 void AliSimDigits::CompresTrackBuffer2()
324 //comress track according algorithm 2 (track ID comression according digit compression)
329 Int_t AliSimDigits::GetTrackID2(Int_t row, Int_t column, Int_t level)
331 //returnb track ID of digits - for buffer compresion 2
337 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
338 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
341 //draw digits in given array
345 sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
346 if ( (fNrows<1)|| (fNcols<1)) {
349 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
351 //set histogram values
352 for (Int_t i = 0; i<fNrows;i++)
353 for (Int_t j = 0; j<fNcols;j++)
354 his->Fill(i,j,GetTrackIDFast(i,j,level));
356 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
360 if (his==0) return 0;
361 if (option!=0) his->Draw(option);
366 TClonesArray * AliSimDigits::GenerTPCClonesArray(TClonesArray * arr)
369 //generate TClonnesArray of digits
371 TClonesArray * digits;
372 if (arr==0) digits=new TClonesArray("AliTPCdigit",300);
374 Int_t index = digits->GetEntriesFast();
375 for (Int_t row =0; row<fNrows; row++)
376 for (Int_t col =0; col<fNcols; col++){
377 Int_t amp = GetDigit(row,col);
378 if (amp>GetThreshold()){
383 dig.fPadRow =fSegmentID;
384 dig.fSector =fSegmentID;
385 dig.fTracks[0]= GetTrackID(row,col,0);
386 dig.fTracks[1]= GetTrackID(row,col,1);
387 dig.fTracks[2]= GetTrackID(row,col,2);
388 TClonesArray &ldigits = *digits;
389 new(ldigits[index++]) AliTPCdigit(dig);