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"
33 #include "AliArrayI.h"
34 #include "AliArrayS.h"
35 #include "AliDigits.h"
36 #include "AliSimDigits.h"
37 #include "AliTPCdigit.h"
38 #include <TClonesArray.h>
42 //_____________________________________________________________________________
43 //_____________________________________________________________________________
44 //_____________________________________________________________________________
45 ClassImp(AliSimDigits)
47 AliSimDigits::AliSimDigits()
49 // AliDigits::Invalite();
54 AliSimDigits::~AliSimDigits()
66 void AliSimDigits::InvalidateTrack()
69 //set default (invalid parameters)
70 if ( fTracks != 0) delete fTracks;
71 fTracks = new AliArrayI;
72 if ( fTrIndex != 0) delete fTrIndex;
73 fTrIndex = new AliArrayI;
75 for (Int_t i = 0; i<3; i++){
81 void AliSimDigits::AllocateTrack(Int_t length)
84 //construct empty buffer fElements and fTracks with size fNrows x fNcols x
88 fTracks->Set(fNcols*fNrows*fNlevel);
93 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
97 if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
98 if (fTrBufType == 1) return GetTrackID1(row, column,level);
99 if (fTrBufType == 2) return GetTrackID2(row, column,level);
103 void AliSimDigits::ExpandTrackBuffer()
106 //expand buffer to two dimensional array
108 Error("ExpandBuffer", "buffer doesn't exist");
111 if (fTrBufType==0) return; //buffer expanded
112 if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
113 if (fTrBufType==2) ExpandTrackBuffer2();
117 void AliSimDigits::CompresTrackBuffer(Int_t bufType)
120 //compres buffer according buffertype algorithm
123 Error("CompressBuffer", "buffer doesn't exist");
126 if (fTrBufType == bufType) return;
128 if (fTrBufType>0) ExpandTrackBuffer();
129 if (fTrBufType !=0) {
130 Error("CompressBuffer", "buffer doesn't exist");
133 //compress buffer of type 1
135 if (bufType==1) {CompresTrackBuffer1();return;}
136 if (bufType==2) CompresTrackBuffer2();
140 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
142 //return track ID of digits - for buffer compresion 2
144 i = level*fNcols+column;
145 if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
147 n2 = fTrIndex->At(i+1);
148 n1 = fTrIndex->At(i);
152 for (i = n1;(i<n2);i++){
154 Int_t num = fTracks->At(i);
160 num = fTracks->At(i);
173 if ( (row>=rowold) && (row<rownew) ) return id;
174 if (row < rownew ) return -2; //empty track
179 void AliSimDigits::ExpandTrackBuffer1()
182 //expand track compressed according algorithm 1 (track id comression independent to the digit compression)
183 // !!in expanded tracks we don't use fTrIndex array
187 Int_t all = fNrows*fNcols; //total number of digits
188 Int_t elems = all*fNlevel; //length of the buffer
190 AliArrayI * buf = new AliArrayI;
200 //oposite signa means how many unwrited (under threshold) values
201 Int_t num = fTracks->At(i);
202 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
204 num %= 10000000; //PH: take into account the case of underlying events
206 Int_t id = fTracks->At(i);
207 for (j = 0; j<num; j++,row++) (*buf)[level*all+col*fNrows+row]=id;
217 }//end of loop over digits
222 void AliSimDigits::CompresTrackBuffer1()
225 //comress track according algorithm 1 (track id comression independent to the digit compression)
229 AliArrayI * buf = new AliArrayI; //create new buffer
230 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
231 AliArrayI * index = new AliArrayI;
232 index->Set(fNcols*fNlevel);
236 Int_t icurrent=-1; //current index
237 Int_t izero; //number of zero
238 Int_t inum; //number of digits with the same current track id
239 Int_t lastID =0; //last track id
241 Int_t *cbuff=fTracks->GetArray(); //MI change
243 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
244 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
248 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
249 Int_t id=0; //current id
250 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
251 id = *cbuff; //MI change
252 // id = GetTrackIDFast(row,col,lev);
254 if ( inum> 0 ) { //if we have some tracks in buffer
256 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2+1); //MI change - allocate +1
257 (*buf)[icurrent] = inum;
259 (*buf)[icurrent] = lastID;
268 //if we have currently izero count of non tracks digits
270 if (icurrent>=buf->fN) buf->Expand(icurrent*2+1);
271 (*buf)[icurrent]= -izero; //write how many under zero
277 //if we change track id from another track id
279 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2+1);
280 (*buf)[icurrent] = inum;
282 (*buf)[icurrent] = lastID;
291 }//end of loop over row
293 //if we have currently izero count of non tracks digits
295 if (icurrent>=buf->fN) buf->Expand(icurrent*2);
296 (*buf)[icurrent]= -izero; //write how many under zero
298 if ( inum> 0 ) { //if we have some tracks in buffer
300 if ((icurrent+1)>=buf->fN) buf->Expand(icurrent*2);
301 (*buf)[icurrent] = inum;
303 (*buf)[icurrent] = id;
305 }//end of loop over columns
306 }//end of loop over differnet track level
307 buf->Expand(icurrent+1);
316 void AliSimDigits::ExpandTrackBuffer2()
319 //comress track according algorithm 2 (track id comression according digit compression)
323 void AliSimDigits::CompresTrackBuffer2()
326 //comress track according algorithm 2 (track id comression according digit compression)
331 Int_t AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
333 //returnb track id of digits - for buffer compresion 2
339 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
340 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
343 //draw digits in given array
347 sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
348 if ( (fNrows<1)|| (fNcols<1)) {
351 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
353 //set histogram values
354 for (Int_t i = 0; i<fNrows;i++)
355 for (Int_t j = 0; j<fNcols;j++)
356 his->Fill(i,j,GetTrackIDFast(i,j,level));
358 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
362 if (his==0) return 0;
363 if (option!=0) his->Draw(option);
368 TClonesArray * AliSimDigits::GenerTPCClonesArray(TClonesArray * arr)
371 //generate TClonnesArray of digits
373 TClonesArray * digits;
374 if (arr==0) digits=new TClonesArray("AliTPCdigit",300);
376 Int_t index = digits->GetEntriesFast();
377 for (Int_t row =0; row<fNrows; row++)
378 for (Int_t col =0; col<fNcols; col++){
379 Int_t amp = GetDigit(row,col);
380 if (amp>GetThreshold()){
385 dig.fPadRow =fSegmentID;
386 dig.fSector =fSegmentID;
387 dig.GetTracks()[0]= GetTrackID(row,col,0);
388 dig.GetTracks()[1]= GetTrackID(row,col,1);
389 dig.GetTracks()[2]= GetTrackID(row,col,2);
390 TClonesArray &ldigits = *digits;
391 new(ldigits[index++]) AliTPCdigit(dig);