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.7 2002/10/23 07:17:33 alibrary
19 Introducing Riostream.h
21 Revision 1.6 2002/01/21 17:15:23 kowal2
24 Revision 1.5 2001/11/24 16:10:22 kowal2
27 Revision 1.4 2000/10/05 16:01:49 kowal2
28 Corrected for memory leaks.
30 Revision 1.3 2000/06/30 12:07:49 kowal2
31 Updated from the TPC-PreRelease branch
33 Revision 1.2.4.3 2000/06/26 07:39:42 kowal2
34 Changes to obey the coding rules
36 Revision 1.2.4.2 2000/06/25 08:38:41 kowal2
37 Splitted from AliTPCtracking
39 Revision 1.2.4.1 2000/06/14 16:45:13 kowal2
40 Improved algorithms. Compiler warnings removed.
42 Revision 1.2 2000/04/17 09:37:33 kowal2
43 removed obsolete AliTPCDigitsDisplay.C
45 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
47 Digits handling in a new data structure
53 ///////////////////////////////////////////////////////////////////////////////
55 // Alice segment manager object //
57 // AliSimDigits object (derived from AliDigits) //
58 // provide additional track information to digit //
60 // Origin: Marian Ivanov GSI Darmstadt //
64 ///////////////////////////////////////////////////////////////////////////////
67 #include <Riostream.h>
69 #include "AliSegmentID.h"
71 #include "AliArrayI.h"
72 #include "AliArrayS.h"
73 #include "AliDigits.h"
74 #include "AliSimDigits.h"
76 #include <TClonesArray.h>
80 //_____________________________________________________________________________
81 //_____________________________________________________________________________
82 //_____________________________________________________________________________
83 ClassImp(AliSimDigits)
85 AliSimDigits::AliSimDigits()
87 // AliDigits::Invalite();
92 AliSimDigits::~AliSimDigits()
104 void AliSimDigits::InvalidateTrack()
107 //set default (invalid parameters)
108 if ( fTracks != 0) delete fTracks;
109 fTracks = new AliArrayI;
110 if ( fTrIndex != 0) delete fTrIndex;
111 fTrIndex = new AliArrayI;
113 for (Int_t i = 0; i<3; i++){
119 void AliSimDigits::AllocateTrack(Int_t length)
122 //construct empty buffer fElements and fTracks with size fNrows x fNcols x
126 fTracks->Set(fNcols*fNrows*fNlevel);
131 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
135 if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
136 if (fTrBufType == 1) return GetTrackID1(row, column,level);
137 if (fTrBufType == 2) return GetTrackID2(row, column,level);
141 void AliSimDigits::ExpandTrackBuffer()
144 //expand buffer to two dimensional array
146 Error("ExpandBuffer", "buffer doesn't exist");
149 if (fTrBufType==0) return; //buffer expanded
150 if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
151 if (fTrBufType==2) ExpandTrackBuffer2();
155 void AliSimDigits::CompresTrackBuffer(Int_t bufType)
158 //compres buffer according buffertype algorithm
161 Error("CompressBuffer", "buffer doesn't exist");
164 if (fTrBufType == bufType) return;
166 if (fTrBufType>0) ExpandTrackBuffer();
167 if (fTrBufType !=0) {
168 Error("CompressBuffer", "buffer doesn't exist");
171 //compress buffer of type 1
173 if (bufType==1) {CompresTrackBuffer1();return;}
174 if (bufType==2) CompresTrackBuffer2();
178 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
180 //return track ID of digits - for buffer compresion 2
182 i = level*fNcols+column;
183 if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
185 n2 = fTrIndex->At(i+1);
186 n1 = fTrIndex->At(i);
190 for (i = n1;(i<n2);i++){
192 Int_t num = fTracks->At(i);
198 num = fTracks->At(i);
211 if ( (row>=rowold) && (row<=rownew) ) return id;
212 if (row < rownew ) return -2; //empty track
217 void AliSimDigits::ExpandTrackBuffer1()
220 //expand track compressed according algorithm 1 (track id comression independent to the digit compression)
221 // !!in expanded tracks we don't use fTrIndex array
225 Int_t all = fNrows*fNcols; //total number of digits
226 Int_t elems = all*fNlevel; //length of the buffer
228 AliArrayI * buf = new AliArrayI;
238 //oposite signa means how many unwrited (under threshold) values
239 Int_t num = fTracks->At(i);
240 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
243 Int_t id = fTracks->At(i);
244 for (j = 0; j<num; j++,row++) (*buf)[level*all+col*fNrows+row]=id;
254 }//end of loop over digits
259 void AliSimDigits::CompresTrackBuffer1()
262 //comress track according algorithm 1 (track id comression independent to the digit compression)
266 AliArrayI * buf = new AliArrayI; //create new buffer
267 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
268 AliArrayI * index = new AliArrayI;
269 index->Set(fNcols*fNlevel);
273 Int_t icurrent=-1; //current index
274 Int_t izero; //number of zero
275 Int_t inum; //number of digits with the same current track id
276 Int_t lastID =0; //last track id
278 Int_t *cbuff=fTracks->GetArray(); //MI change
280 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
281 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
285 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
286 Int_t id=0; //current id
287 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
288 id = *cbuff; //MI change
289 // id = GetTrackIDFast(row,col,lev);
291 if ( inum> 0 ) { //if we have some tracks in buffer
293 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2+1); //MI change - allocate +1
294 (*buf)[icurrent] = inum;
296 (*buf)[icurrent] = lastID;
305 //if we have currently izero count of non tracks digits
307 if (icurrent>=buf->fN) buf->Expand(icurrent*2+1);
308 (*buf)[icurrent]= -izero; //write how many under zero
314 //if we change track id from another track id
316 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2+1);
317 (*buf)[icurrent] = inum;
319 (*buf)[icurrent] = lastID;
328 }//end of loop over row
330 //if we have currently izero count of non tracks digits
332 if (icurrent>=buf->fN) buf->Expand(icurrent*2);
333 (*buf)[icurrent]= -izero; //write how many under zero
335 if ( inum> 0 ) { //if we have some tracks in buffer
337 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
338 (*buf)[icurrent] = inum;
340 (*buf)[icurrent] = id;
342 }//end of loop over columns
343 }//end of loop over differnet track level
344 buf->Expand(icurrent+1);
353 void AliSimDigits::ExpandTrackBuffer2()
356 //comress track according algorithm 2 (track id comression according digit compression)
360 void AliSimDigits::CompresTrackBuffer2()
363 //comress track according algorithm 2 (track id comression according digit compression)
368 Int_t AliSimDigits::GetTrackID2(Int_t row, Int_t column, Int_t level)
370 //returnb track id of digits - for buffer compresion 2
376 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
377 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
380 //draw digits in given array
384 sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
385 if ( (fNrows<1)|| (fNcols<1)) {
388 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
390 //set histogram values
391 for (Int_t i = 0; i<fNrows;i++)
392 for (Int_t j = 0; j<fNcols;j++)
393 his->Fill(i,j,GetTrackIDFast(i,j,level));
395 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
399 if (his==0) return 0;
400 if (option!=0) his->Draw(option);
405 TClonesArray * AliSimDigits::GenerTPCClonesArray(TClonesArray * arr)
408 //generate TClonnesArray of digits
410 TClonesArray * digits;
411 if (arr==0) digits=new TClonesArray("AliTPCdigit",300);
413 Int_t index = digits->GetEntriesFast();
414 for (Int_t row =0; row<fNrows; row++)
415 for (Int_t col =0; col<fNcols; col++){
416 Int_t amp = GetDigit(row,col);
417 if (amp>GetThreshold()){
422 dig.fPadRow =fSegmentID;
423 dig.fSector =fSegmentID;
424 dig.GetTracks()[0]= GetTrackID(row,col,0);
425 dig.GetTracks()[1]= GetTrackID(row,col,1);
426 dig.GetTracks()[2]= GetTrackID(row,col,2);
427 TClonesArray &ldigits = *digits;
428 new(ldigits[index++]) AliTPCdigit(dig);