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()
48 // AliDigits::Invalite();
53 AliSimDigits::~AliSimDigits()
65 void AliSimDigits::InvalidateTrack()
68 //set default (invalid parameters)
69 if ( fTracks != 0) delete fTracks;
70 fTracks = new TArrayI;
71 if ( fTrIndex != 0) delete fTrIndex;
72 fTrIndex = new TArrayI;
74 for (Int_t i = 0; i<3; i++){
80 void AliSimDigits::AllocateTrack(Int_t length)
83 //construct empty buffer fElements and fTracks with size fNrows x fNcols x
87 fTracks->Set(fNcols*fNrows*fNlevel);
92 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
96 if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
97 if (fTrBufType == 1) return GetTrackID1(row, column,level);
98 if (fTrBufType == 2) return GetTrackID2(row, column,level);
102 void AliSimDigits::ExpandTrackBuffer()
105 //expand buffer to two dimensional array
107 Error("ExpandBuffer", "buffer doesn't exist");
110 if (fTrBufType==0) return; //buffer expanded
111 if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
112 if (fTrBufType==2) ExpandTrackBuffer2();
116 void AliSimDigits::CompresTrackBuffer(Int_t bufType)
119 //compres buffer according buffertype algorithm
122 Error("CompressBuffer", "buffer doesn't exist");
125 if (fTrBufType == bufType) return;
127 if (fTrBufType>0) ExpandTrackBuffer();
128 if (fTrBufType !=0) {
129 Error("CompressBuffer", "buffer doesn't exist");
132 //compress buffer of type 1
134 if (bufType==1) {CompresTrackBuffer1();return;}
135 if (bufType==2) CompresTrackBuffer2();
139 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
141 //return track ID of digits - for buffer compresion 2
143 i = level*fNcols+column;
144 if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
146 n2 = fTrIndex->At(i+1);
147 n1 = fTrIndex->At(i);
151 for (i = n1;(i<n2);i++){
153 Int_t num = fTracks->At(i);
159 num = fTracks->At(i);
172 if ( (row>=rowold) && (row<rownew) ) return id;
173 if (row < rownew ) return -2; //empty track
178 void AliSimDigits::ExpandTrackBuffer1()
181 //expand track compressed according algorithm 1 (track id comression independent to the digit compression)
182 // !!in expanded tracks we don't use fTrIndex array
186 Int_t all = fNrows*fNcols; //total number of digits
187 Int_t elems = all*fNlevel; //length of the buffer
189 TArrayI * buf = new TArrayI;
199 //oposite signa means how many unwrited (under threshold) values
200 Int_t num = fTracks->At(i);
201 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
203 num %= 10000000; //PH: take into account the case of underlying events
205 Int_t id = fTracks->At(i);
206 for (j = 0; j<num; j++,row++) {
207 if (level*all+col*fNrows+row<elems) (*buf)[level*all+col*fNrows+row]=id;
218 }//end of loop over digits
223 void AliSimDigits::CompresTrackBuffer1()
226 //comress track according algorithm 1 (track id comression independent to the digit compression)
230 TArrayI * buf = new TArrayI; //create new buffer
231 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
232 TArrayI * index = new TArrayI;
233 index->Set(fNcols*fNlevel);
237 Int_t icurrent=-1; //current index
238 Int_t izero; //number of zero
239 Int_t inum; //number of digits with the same current track id
240 Int_t lastID =0; //last track id
242 Int_t *cbuff=fTracks->GetArray(); //MI change
244 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
245 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
249 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
250 Int_t id=0; //current id
251 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
252 id = *cbuff; //MI change
253 // id = GetTrackIDFast(row,col,lev);
255 if ( inum> 0 ) { //if we have some tracks in buffer
257 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1); //MI change - allocate +1
258 (*buf)[icurrent] = inum;
260 (*buf)[icurrent] = lastID;
269 //if we have currently izero count of non tracks digits
271 if (icurrent>=buf->fN) buf->Set(icurrent*2+1);
272 (*buf)[icurrent]= -izero; //write how many under zero
278 //if we change track id from another track id
280 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1);
281 (*buf)[icurrent] = inum;
283 (*buf)[icurrent] = lastID;
292 }//end of loop over row
294 //if we have currently izero count of non tracks digits
296 if (icurrent>=buf->fN) buf->Set(icurrent*2);
297 (*buf)[icurrent]= -izero; //write how many under zero
299 if ( inum> 0 ) { //if we have some tracks in buffer
301 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2);
302 (*buf)[icurrent] = inum;
304 (*buf)[icurrent] = id;
306 }//end of loop over columns
307 }//end of loop over differnet track level
308 buf->Set(icurrent+1);
317 void AliSimDigits::ExpandTrackBuffer2()
320 //comress track according algorithm 2 (track id comression according digit compression)
324 void AliSimDigits::CompresTrackBuffer2()
327 //comress track according algorithm 2 (track id comression according digit compression)
332 Int_t AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
334 //returnb track id of digits - for buffer compresion 2
340 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
341 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
344 //draw digits in given array
348 sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
349 if ( (fNrows<1)|| (fNcols<1)) {
352 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
354 //set histogram values
355 for (Int_t i = 0; i<fNrows;i++)
356 for (Int_t j = 0; j<fNcols;j++)
357 his->Fill(i,j,GetTrackIDFast(i,j,level));
359 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
363 if (his==0) return 0;
364 if (option!=0) his->Draw(option);
369 TClonesArray * AliSimDigits::GenerTPCClonesArray(TClonesArray * arr)
372 //generate TClonnesArray of digits
374 TClonesArray * digits;
375 if (arr==0) digits=new TClonesArray("AliTPCdigit",300);
377 Int_t index = digits->GetEntriesFast();
378 for (Int_t row =0; row<fNrows; row++)
379 for (Int_t col =0; col<fNcols; col++){
380 Int_t amp = GetDigit(row,col);
381 if (amp>GetThreshold()){
386 dig.fPadRow =fSegmentID;
387 dig.fSector =fSegmentID;
388 dig.GetTracks()[0]= GetTrackID(row,col,0);
389 dig.GetTracks()[1]= GetTrackID(row,col,1);
390 dig.GetTracks()[2]= GetTrackID(row,col,2);
391 TClonesArray &ldigits = *digits;
392 new(ldigits[index++]) AliTPCdigit(dig);