AliRoot Core  edcc906 (edcc906)
AliSimDigits.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
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  **************************************************************************/
15 
16 
23 
24 #include "TClass.h"
25 #include <Riostream.h>
26 #include "TError.h"
27 #include "AliSegmentID.h"
28 #include "AliH2F.h"
29 #include "TArrayI.h"
30 #include "AliDigits.h"
31 #include "AliSimDigits.h"
32 #include <TClonesArray.h>
33 #include <stdlib.h>
34 
35 
36 //_____________________________________________________________________________
37 //_____________________________________________________________________________
38 //_____________________________________________________________________________
40 ClassImp(AliSimDigits)
42 
44  :AliDigits(),
45  fTracks(0),
46  fTrIndex(0),
47  fNlevel(0),
48  fTrBufType(0)
49 {
50  // AliDigits::Invalite();
51 
52  InvalidateTrack();
53 }
54 //
56  :AliDigits(),
57  fTracks(0),
58  fTrIndex(0),
59  fNlevel(0),
60  fTrBufType(0)
61 {
63 
64  fTrIndex = param.fTrIndex;
65 }
66 //
68 {
69 
70  if (fTracks != 0) {
71  delete fTracks;
72  }
73  if (fTrIndex != 0) {
74  delete fTrIndex;
75  }
76 
77 }
79 {
81 
82  if(this!=&param){
83  fTrIndex=param.fTrIndex;
84  }
85  return (*this);
86 }
87 
88 //__________________________________________________________________
90 {
92 
93  if ( fTracks != 0) delete fTracks;
94  fTracks = new TArrayI;
95  if ( fTrIndex != 0) delete fTrIndex;
96  fTrIndex = new TArrayI;
97 
98  for (Int_t i = 0; i<3; i++){
99  fTracks->Set(0);
100  fTrIndex->Set(0);
101  }
102 }
103 
104 void AliSimDigits::AllocateTrack(Int_t length)
105 {
108 
109  InvalidateTrack();
110  fNlevel = length;
112  fTrIndex->Set(0);
113  fTrBufType =0;
114 }
115 
116 Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
117 {
119 
120  if (fTrBufType == 0) return GetTrackIDFast(row, column,level);
121  if (fTrBufType == 1) return GetTrackID1(row, column,level);
122  if (fTrBufType == 2) return GetTrackID2(row, column,level);
123  return 0;
124 }
125 
127 {
129 
130  if (fTrBufType<0) {
131  Error("ExpandBuffer", "buffer doesn't exist");
132  return;
133  }
134  if (fTrBufType==0) return; //buffer expanded
135  if (fTrBufType==1) {ExpandTrackBuffer1(); return;}
136  if (fTrBufType==2) ExpandTrackBuffer2();
137 
138 }
139 
141 {
143 
144  if (fTrBufType<0) {
145  Error("CompressBuffer", "buffer doesn't exist");
146  return;
147  }
148  if (fTrBufType == bufType) return;
149  //
150  if (fTrBufType>0) ExpandTrackBuffer();
151  if (fTrBufType !=0) {
152  Error("CompressBuffer", "buffer doesn't exist");
153  return;
154  }
155  //compress buffer of type 1
156 
157  if (bufType==1) {CompresTrackBuffer1();return;}
158  if (bufType==2) CompresTrackBuffer2();
159 
160 }
161 
162 Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
163 {
165 
166  Int_t i,n1,n2;
167  i = level*fNcols+column;
168  if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
169  else
170  n2 = fTrIndex->At(i+1);
171  n1 = fTrIndex->At(i);
172  Int_t rownew = 0;
173  Int_t rowold=0;
174  Int_t id;
175  for (i = n1;(i<n2);i++){
176  id = 0;
177  Int_t num = fTracks->At(i);
178  if (num<0) {
179  rownew-=num;
180  rowold = rownew;
181  i++;
182  if (i<n2){
183  num = fTracks->At(i);
184  rownew+=num;
185  i++;
186  id = fTracks->At(i);
187  }
188  }
189  else {
190  rowold = rownew;
191  rownew+=num;
192  i++;
193  id = fTracks->At(i);
194  }
195  id-=2;
196  if ( (row>=rowold) && (row<rownew) ) return id;
197  if (row < rownew ) return -2; //empty track
198  }
199  return -2;
200 }
201 
203 {
206 
207  fTrBufType = 0;
208  Int_t i,j;
209  Int_t all = fNrows*fNcols; //total number of digits
210  Int_t elems = all*fNlevel; //length of the buffer
211 
212  TArrayI * buf = new TArrayI;
213  Int_t *bufData = (Int_t *) calloc(elems, sizeof(Int_t));
214  buf->Adopt(elems, bufData);
215  fTrIndex->Set(0);
216  //
217  Int_t level = 0;
218  Int_t col=0;
219  Int_t row = 0;
220  Int_t n=fTracks->fN;
221  //
222  for (i=0;i<n;i++){
223  //oposite signa means how many unwrited (under threshold) values
224  Int_t num = fTracks->At(i);
225  if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
226  else {
227  num %= 10000000; //PH: take into account the case of underlying events
228  i++;
229  Int_t id = fTracks->At(i);
230  for (j = 0; j<num; j++,row++) {
231  if (level*all+col*fNrows+row<elems) (*buf)[level*all+col*fNrows+row]=id;
232  }
233  }
234  if (row>=fNrows) {
235  row=0;
236  col++;
237  }
238  if (col>=fNcols) {
239  col=0;
240  level++;
241  }
242  }//end of loop over digits
243  delete fTracks;
244  fTracks = buf;
245 }
246 
248 {
250 
251  fTrBufType = 1;
252 
253  TArrayI * buf = new TArrayI; //create new buffer
254  buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
255  TArrayI * index = new TArrayI;
256  index->Set(fNcols*fNlevel);
257  // Int_t * pindex =
258 
259 
260  Int_t icurrent=-1; //current index
261  Int_t izero; //number of zero
262  Int_t inum; //number of digits with the same current track id
263  Int_t lastID =0; //last track id
264 
265  Int_t *cbuff=fTracks->GetArray(); //MI change
266 
267  for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
268  for (Int_t col = 0; col<fNcols; col++){ //loop over columns
269  izero = 0;
270  inum = 0;
271  lastID = 0;
272  (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
273  Int_t id=0; //current id
274  for (Int_t row = 0; row< fNrows;row++){ //loop over rows
275  id = *cbuff; //MI change
276  // id = GetTrackIDFast(row,col,lev);
277  if (id <= 0) {
278  if ( inum> 0 ) { //if we have some tracks in buffer
279  icurrent++;
280  if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1); //MI change - allocate +1
281  (*buf)[icurrent] = inum;
282  icurrent++;
283  (*buf)[icurrent] = lastID;
284  inum = 0;
285  lastID = 0;
286  }
287  izero++;
288  }
289  else
290  if (id != lastID)
291  if ( izero > 0 ) {
292  //if we have currently izero count of non tracks digits
293  icurrent++;
294  if (icurrent>=buf->fN) buf->Set(icurrent*2+1);
295  (*buf)[icurrent]= -izero; //write how many under zero
296  inum++;
297  izero = 0;
298  lastID = id;
299  }
300  else{
301  //if we change track id from another track id
302  icurrent++;
303  if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1);
304  (*buf)[icurrent] = inum;
305  icurrent++;
306  (*buf)[icurrent] = lastID;
307  lastID = id;
308  inum = 1;
309  izero = 0;
310  }
311  else {
312  inum++;
313  }
314  cbuff++; //MI change
315  }//end of loop over row
316  if ( izero > 0 ) {
317  //if we have currently izero count of non tracks digits
318  icurrent++;
319  if (icurrent>=buf->fN) buf->Set(icurrent*2);
320  (*buf)[icurrent]= -izero; //write how many under zero
321  }
322  if ( inum> 0 ) { //if we have some tracks in buffer
323  icurrent++;
324  if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2);
325  (*buf)[icurrent] = inum;
326  icurrent++;
327  (*buf)[icurrent] = id;
328  }
329  }//end of loop over columns
330  }//end of loop over differnet track level
331  buf->Set(icurrent+1);
332  delete fTracks;
333  fTracks = buf;
334  delete fTrIndex;
335  fTrIndex = index;
336 }
337 
338 
339 
341 {
343 
344  fTrBufType = 0;
345 }
346 
348 {
350 
351  fTrBufType = 2;
352 }
353 
354 
355 Int_t AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
356 {
358 
359  return -2;
360 }
361 
362 
363 
364 AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
365  Float_t x1, Float_t x2, Float_t y1, Float_t y2)
366 {
370 
371  char ch[30];
372  //sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
373  snprintf(ch,30,"Track Segment_%d level %d ",GetID(),level );
374  if ( (fNrows<1)|| (fNcols<1)) {
375  return 0;
376  }
377  AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
379  //set histogram values
380  for (Int_t i = 0; i<fNrows;i++)
381  for (Int_t j = 0; j<fNcols;j++)
382  his->Fill(i,j,GetTrackIDFast(i,j,level));
383  if (x1>=0) {
384  AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
385  delete his;
386  his=h2fsub;
387  }
388  if (his==0) return 0;
389  if (option!=0) his->Draw(option);
390  else his->Draw();
391  return his;
392 }
393 
396 
397  for (Int_t i=0;i<fNcols;i++){ //pads
398  for(Int_t j=1;j<fNrows-1;j++){ //time bins
399  // first and last time bins are checked separately
400  if(GetDigitFast(j,i)){// nonzero digit
401  if (!GetDigitFast(j-1,i) && !GetDigitFast(j+1,i)) {
402  SetDigitFast(0,j,i);
403  SetTrackIDFast(-2,j,i,0);
404  SetTrackIDFast(-2,j,i,1);
405  SetTrackIDFast(-2,j,i,2);
406  }
407  }
408  }//time
409 
410  if(GetDigitFast(0,i) && !GetDigitFast(1,i)) {
411  SetDigitFast(0,0,i);
412  SetTrackIDFast(-2,0,i,0);
413  SetTrackIDFast(-2,0,i,1);
414  SetTrackIDFast(-2,0,i,2);
415  }
416  if(GetDigitFast(fNrows-1,i) && !GetDigitFast(fNrows-2,i)){
417  SetDigitFast(0,fNrows-1,i);
418  SetTrackIDFast(-2,fNrows-1,i,0);
419  SetTrackIDFast(-2,fNrows-1,i,1);
420  SetTrackIDFast(-2,fNrows-1,i,2);
421  }
422  }//pads
423 
424 }
425 
virtual ~AliSimDigits()
void SetTrackIDFast(Int_t value, Int_t row, Int_t column, Int_t level)
Definition: AliSimDigits.h:69
void ExpandTrackBuffer2()
TArrayI * fTrIndex
index position of column
Definition: AliSimDigits.h:50
void GlitchFilter()
Int_t fNlevel
number of tracks etries for one digit
Definition: AliSimDigits.h:51
void AllocateTrack(Int_t length)
virtual Int_t GetTrackID(Int_t row, Int_t column, Int_t level)
void CompresTrackBuffer2()
void ExpandTrackBuffer1()
Short_t GetDigitFast(Int_t row, Int_t column)
Definition: AliDigits.h:92
AliH2F * DrawTracks(const char *option=0, Int_t level=0, Float_t x1=-1, Float_t x2=-1, Float_t y1=-1, Float_t y2=-1)
TArrayI * fTracks
buffer of track index
Definition: AliSimDigits.h:49
virtual void CompresTrackBuffer(Int_t bufType)
Int_t GetTrackID2(Int_t row, Int_t column, Int_t level)
virtual void ExpandTrackBuffer()
Int_t GetID()
Definition: AliSegmentID.h:19
Int_t GetTrackIDFast(Int_t row, Int_t column, Int_t level)
Definition: AliSimDigits.h:61
void SetDigitFast(Short_t value, Int_t row, Int_t column)
Definition: AliDigits.h:115
Definition: AliH2F.h:16
AliH2F * GetSubrange2d(Float_t xmin, Float_t xmax, Float_t ymin, Float_t ymax)
Definition: AliH2F.cxx:183
Int_t fNrows
number of rows in Segment
Definition: AliDigits.h:63
AliSimDigits & operator=(const AliSimDigits &digits)
Int_t fTrBufType
buffer type of the tracks
Definition: AliSimDigits.h:52
Int_t fNcols
number of collumns in Segment
Definition: AliDigits.h:64
void InvalidateTrack()
void CompresTrackBuffer1()
Int_t GetTrackID1(Int_t row, Int_t column, Int_t level)