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.2.4.3 2000/06/26 07:39:42 kowal2
19 Changes to obey the coding rules
21 Revision 1.2.4.2 2000/06/25 08:38:41 kowal2
22 Splitted from AliTPCtracking
24 Revision 1.2.4.1 2000/06/14 16:45:13 kowal2
25 Improved algorithms. Compiler warnings removed.
27 Revision 1.2 2000/04/17 09:37:33 kowal2
28 removed obsolete AliTPCDigitsDisplay.C
30 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
32 Digits handling in a new data structure
38 ///////////////////////////////////////////////////////////////////////////////
40 // Alice segment manager object //
42 // AliSimDigits object (derived from AliDigits) //
43 // provide additional track information to digit //
45 // Origin: Marian Ivanov GSI Darmstadt //
49 ///////////////////////////////////////////////////////////////////////////////
54 #include "AliSegmentID.h"
56 #include "AliArrayI.h"
57 #include "AliArrayS.h"
58 #include "AliDigits.h"
59 #include "AliSimDigits.h"
64 //_____________________________________________________________________________
65 //_____________________________________________________________________________
66 //_____________________________________________________________________________
67 ClassImp(AliSimDigits)
69 AliSimDigits::AliSimDigits()
71 // AliDigits::Invalite();
76 AliSimDigits::~AliSimDigits()
78 // AliDigits::Invalidate();
79 if (fTracks != 0) fTracks->Delete();
80 if (fTrIndex != 0) fTrIndex->Delete();
84 void AliSimDigits::InvalidateTrack()
87 //set default (invalid parameters)
88 if ( fTracks != 0) delete fTracks;
89 fTracks = new AliArrayI;
90 if ( fTrIndex != 0) delete fTrIndex;
91 fTrIndex = new AliArrayI;
93 for (Int_t i = 0; i<3; i++){
99 void AliSimDigits::AllocateTrack(Int_t length)
102 //construct empty buffer fElements and fTracks with size fNrows x fNcols x
106 fTracks->Set(fNcols*fNrows*fNlevel);
111 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
115 if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
116 if (fTrBufType == 1) return GetTrackID1(row, column,level);
117 if (fTrBufType == 2) return GetTrackID2(row, column,level);
121 void AliSimDigits::ExpandTrackBuffer()
124 //expand buffer to two dimensional array
126 Error("ExpandBuffer", "buffer doesn't exist");
129 if (fTrBufType==0) return; //buffer expanded
130 if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
131 if (fTrBufType==2) ExpandTrackBuffer2();
135 void AliSimDigits::CompresTrackBuffer(Int_t bufType)
138 //compres buffer according buffertype algorithm
141 Error("CompressBuffer", "buffer doesn't exist");
144 if (fTrBufType == bufType) return;
146 if (fTrBufType>0) ExpandTrackBuffer();
147 if (fTrBufType !=0) {
148 Error("CompressBuffer", "buffer doesn't exist");
151 //compress buffer of type 1
153 if (bufType==1) {CompresTrackBuffer1();return;}
154 if (bufType==2) CompresTrackBuffer2();
158 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
160 //return track ID of digits - for buffer compresion 2
162 i = level*fNcols+column;
163 if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
165 n2 = fTrIndex->At(i+1);
166 n1 = fTrIndex->At(i);
170 for (i = n1;(i<n2);i++){
172 Int_t num = fTracks->At(i);
178 num = fTracks->At(i);
191 if ( (row>=rowold) && (row<=rownew) ) return id;
192 if (row < rownew ) return -2; //empty track
197 void AliSimDigits::ExpandTrackBuffer1()
200 //expand track compressed according algorithm 1 (track id comression independent to the digit compression)
201 // !!in expanded tracks we don't use fTrIndex array
205 Int_t all = fNrows*fNcols; //total number of digits
206 Int_t elems = all*fNlevel; //length of the buffer
208 AliArrayI * buf = new AliArrayI;
218 //oposite signa means how many unwrited (under threshold) values
219 Int_t num = fTracks->At(i);
220 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
223 Int_t id = fTracks->At(i);
224 for (j = 0; j<num; j++,row++) (*buf)[level*all+col*fNrows+row]=id;
234 }//end of loop over digits
239 void AliSimDigits::CompresTrackBuffer1()
242 //comress track according algorithm 1 (track id comression independent to the digit compression)
246 AliArrayI * buf = new AliArrayI; //create new buffer
247 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
248 AliArrayI * index = new AliArrayI;
249 index->Set(fNcols*fNlevel);
251 Int_t icurrent=-1; //current index
252 Int_t izero; //number of zero
253 Int_t inum; //number of digits with the same current track id
254 Int_t lastID =0; //last track id
255 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
256 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
260 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
261 Int_t id=0; //current id
262 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
263 id = GetTrackIDFast(row,col,lev);
265 if ( inum> 0 ) { //if we have some tracks in buffer
267 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
268 (*buf)[icurrent] = inum;
270 (*buf)[icurrent] = lastID;
279 //if we have currently izero count of non tracks digits
281 if (icurrent>=buf->fN) buf->Expand(icurrent*2);
282 (*buf)[icurrent]= -izero; //write how many under zero
288 //if we change track id from another track id
290 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
291 (*buf)[icurrent] = inum;
293 (*buf)[icurrent] = lastID;
302 }//end of loop over rows
304 //if we have currently izero count of non tracks digits
306 if (icurrent>=buf->fN) buf->Expand(icurrent*2);
307 (*buf)[icurrent]= -izero; //write how many under zero
309 if ( inum> 0 ) { //if we have some tracks in buffer
311 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
312 (*buf)[icurrent] = inum;
314 (*buf)[icurrent] = id;
316 }//end of loop over columns
317 }//end of loop over differnet track level
318 buf->Expand(icurrent+1);
327 void AliSimDigits::ExpandTrackBuffer2()
330 //comress track according algorithm 2 (track id comression according digit compression)
334 void AliSimDigits::CompresTrackBuffer2()
337 //comress track according algorithm 2 (track id comression according digit compression)
342 Int_t AliSimDigits::GetTrackID2(Int_t row, Int_t column, Int_t level)
344 //returnb track id of digits - for buffer compresion 2
350 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
351 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
354 //draw digits in given array
358 sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
359 if ( (fNrows<1)|| (fNcols<1)) {
362 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
364 //set histogram values
365 for (Int_t i = 0; i<fNrows;i++)
366 for (Int_t j = 0; j<fNcols;j++)
367 his->Fill(i,j,GetTrackIDFast(i,j,level));
369 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
373 if (his==0) return 0;
374 if (option!=0) his->Draw(option);
379 TClonesArray * AliSimDigits::GenerTPCClonesArray(TClonesArray * arr)
382 //generate TClonnesArray of digits
384 TClonesArray * digits;
385 if (arr==0) digits=new TClonesArray("AliTPCdigit",300);
387 Int_t index = digits->GetEntriesFast();
388 for (Int_t row =0; row<fNrows; row++)
389 for (Int_t col =0; col<fNcols; col++){
390 Int_t amp = GetDigit(row,col);
391 if (amp>GetThreshold()){
396 dig.fPadRow =fSegmentID;
397 dig.fSector =fSegmentID;
398 dig.fTracks[0]= GetTrackID(row,col,0);
399 dig.fTracks[1]= GetTrackID(row,col,1);
400 dig.fTracks[2]= GetTrackID(row,col,2);
401 TClonesArray &ldigits = *digits;
402 new(ldigits[index++]) AliTPCdigit(dig);