]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCbase/AliSimDigits.cxx
doxy: TPC/TPCbase converted
[u/mrichter/AliRoot.git] / TPC / TPCbase / AliSimDigits.cxx
CommitLineData
cc80f89e 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
7d855b04 16
17/// \class AliSimDigits
18///
19/// Alice segment manager object
20/// AliSimDigits object (derived from AliDigits)
21/// provide additional track information to digit
22/// \author Marian Ivanov GSI Darmstadt
cc80f89e 23
24#include "TClass.h"
19364939 25#include <Riostream.h>
cc80f89e 26#include "TError.h"
27#include "AliSegmentID.h"
28#include "AliH2F.h"
e756ece8 29#include "TArrayI.h"
cc80f89e 30#include "AliDigits.h"
31#include "AliSimDigits.h"
c4aa8648 32#include <TClonesArray.h>
cc80f89e 33
34
35
36//_____________________________________________________________________________
37//_____________________________________________________________________________
38//_____________________________________________________________________________
7d855b04 39/// \cond CLASSIMP
cc80f89e 40ClassImp(AliSimDigits)
7d855b04 41/// \endcond
cc80f89e 42
43AliSimDigits::AliSimDigits()
179c6296 44 :AliDigits(),
45 fTracks(0),
46 fTrIndex(0),
47 fNlevel(0),
48 fTrBufType(0)
cc80f89e 49{
50 // AliDigits::Invalite();
179c6296 51
cc80f89e 52 InvalidateTrack();
53}
179c6296 54//
55AliSimDigits::AliSimDigits(const AliSimDigits &param)
56 :AliDigits(),
57 fTracks(0),
58 fTrIndex(0),
59 fNlevel(0),
60 fTrBufType(0)
61{
7d855b04 62 /// dummy
63
179c6296 64 fTrIndex = param.fTrIndex;
65}
66//
cc80f89e 67AliSimDigits::~AliSimDigits()
68{
c4aa8648 69
70 if (fTracks != 0) {
71 delete fTracks;
72 }
73 if (fTrIndex != 0) {
74 delete fTrIndex;
75 }
cc80f89e 76
77}
179c6296 78AliSimDigits & AliSimDigits::operator =(const AliSimDigits & param)
79{
7d855b04 80 /// assignment operator - dummy
81
63a14ef0 82 if(this!=&param){
83 fTrIndex=param.fTrIndex;
84 }
179c6296 85 return (*this);
86}
cc80f89e 87
179c6296 88//__________________________________________________________________
cc80f89e 89void AliSimDigits::InvalidateTrack()
90{
7d855b04 91 /// set default (invalid parameters)
92
cc80f89e 93 if ( fTracks != 0) delete fTracks;
e756ece8 94 fTracks = new TArrayI;
cc80f89e 95 if ( fTrIndex != 0) delete fTrIndex;
e756ece8 96 fTrIndex = new TArrayI;
cc80f89e 97
98 for (Int_t i = 0; i<3; i++){
99 fTracks->Set(0);
100 fTrIndex->Set(0);
101 }
102}
103
104void AliSimDigits::AllocateTrack(Int_t length)
105{
7d855b04 106 /// construct empty buffer fElements and fTracks with size fNrows x fNcols x
107 /// length
108
cc80f89e 109 InvalidateTrack();
110 fNlevel = length;
111 fTracks->Set(fNcols*fNrows*fNlevel);
112 fTrIndex->Set(0);
113 fTrBufType =0;
114}
115
116Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level)
117{
7d855b04 118 /// Get track ID
119
cc80f89e 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
126void AliSimDigits::ExpandTrackBuffer()
127{
7d855b04 128 /// expand buffer to two dimensional array
129
cc80f89e 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
140void AliSimDigits::CompresTrackBuffer(Int_t bufType)
141{
7d855b04 142 /// compres buffer according buffertype algorithm
143
cc80f89e 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
162Int_t AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
163{
7d855b04 164 /// return track ID of digits - for buffer compresion 2
165
cc80f89e 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;
73042f01 174 Int_t id;
cc80f89e 175 for (i = n1;(i<n2);i++){
73042f01 176 id = 0;
cc80f89e 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++;
73042f01 186 id = fTracks->At(i);
cc80f89e 187 }
188 }
189 else {
190 rowold = rownew;
191 rownew+=num;
192 i++;
73042f01 193 id = fTracks->At(i);
cc80f89e 194 }
73042f01 195 id-=2;
babd135a 196 if ( (row>=rowold) && (row<rownew) ) return id;
cc80f89e 197 if (row < rownew ) return -2; //empty track
198 }
199 return -2;
200}
201
202void AliSimDigits::ExpandTrackBuffer1()
203{
7d855b04 204 /// expand track compressed according algorithm 1 (track id comression independent to the digit compression)
205 /// !!in expanded tracks we don't use fTrIndex array
206
cc80f89e 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
e756ece8 212 TArrayI * buf = new TArrayI;
cc80f89e 213 buf->Set(elems);
214 fTrIndex->Set(0);
215 //
216 Int_t level = 0;
217 Int_t col=0;
218 Int_t row = 0;
73042f01 219 Int_t n=fTracks->fN;
cc80f89e 220 //
73042f01 221 for (i=0;i<n;i++){
cc80f89e 222 //oposite signa means how many unwrited (under threshold) values
223 Int_t num = fTracks->At(i);
224 if (num<0) row-=num; //negative number mean number of zeroes (no tracks of gibven level no need to write to array)
225 else {
a97dda3d 226 num %= 10000000; //PH: take into account the case of underlying events
cc80f89e 227 i++;
73042f01 228 Int_t id = fTracks->At(i);
3789f4fd 229 for (j = 0; j<num; j++,row++) {
230 if (level*all+col*fNrows+row<elems) (*buf)[level*all+col*fNrows+row]=id;
231 }
cc80f89e 232 }
233 if (row>=fNrows) {
234 row=0;
235 col++;
236 }
237 if (col>=fNcols) {
238 col=0;
239 level++;
240 }
241 }//end of loop over digits
242 delete fTracks;
243 fTracks = buf;
244}
245
246void AliSimDigits::CompresTrackBuffer1()
247{
7d855b04 248 /// comress track according algorithm 1 (track id comression independent to the digit compression)
249
cc80f89e 250 fTrBufType = 1;
251
e756ece8 252 TArrayI * buf = new TArrayI; //create new buffer
cc80f89e 253 buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
e756ece8 254 TArrayI * index = new TArrayI;
cc80f89e 255 index->Set(fNcols*fNlevel);
407ff276 256 // Int_t * pindex =
cc80f89e 257
407ff276 258
cc80f89e 259 Int_t icurrent=-1; //current index
260 Int_t izero; //number of zero
73042f01 261 Int_t inum; //number of digits with the same current track id
407ff276 262 Int_t lastID =0; //last track id
263
264 Int_t *cbuff=fTracks->GetArray(); //MI change
265
cc80f89e 266 for (Int_t lev =0; lev<fNlevel; lev++){ //loop over levels
267 for (Int_t col = 0; col<fNcols; col++){ //loop over columns
268 izero = 0;
269 inum = 0;
270 lastID = 0;
271 (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
73042f01 272 Int_t id=0; //current id
407ff276 273 for (Int_t row = 0; row< fNrows;row++){ //loop over rows
274 id = *cbuff; //MI change
275 // id = GetTrackIDFast(row,col,lev);
73042f01 276 if (id <= 0) {
cc80f89e 277 if ( inum> 0 ) { //if we have some tracks in buffer
278 icurrent++;
e756ece8 279 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1); //MI change - allocate +1
cc80f89e 280 (*buf)[icurrent] = inum;
281 icurrent++;
282 (*buf)[icurrent] = lastID;
283 inum = 0;
284 lastID = 0;
285 }
286 izero++;
287 }
288 else
73042f01 289 if (id != lastID)
cc80f89e 290 if ( izero > 0 ) {
291 //if we have currently izero count of non tracks digits
292 icurrent++;
e756ece8 293 if (icurrent>=buf->fN) buf->Set(icurrent*2+1);
cc80f89e 294 (*buf)[icurrent]= -izero; //write how many under zero
295 inum++;
296 izero = 0;
73042f01 297 lastID = id;
cc80f89e 298 }
299 else{
73042f01 300 //if we change track id from another track id
cc80f89e 301 icurrent++;
e756ece8 302 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1);
cc80f89e 303 (*buf)[icurrent] = inum;
304 icurrent++;
305 (*buf)[icurrent] = lastID;
73042f01 306 lastID = id;
cc80f89e 307 inum = 1;
308 izero = 0;
309 }
310 else {
311 inum++;
312 }
407ff276 313 cbuff++; //MI change
314 }//end of loop over row
cc80f89e 315 if ( izero > 0 ) {
316 //if we have currently izero count of non tracks digits
317 icurrent++;
e756ece8 318 if (icurrent>=buf->fN) buf->Set(icurrent*2);
cc80f89e 319 (*buf)[icurrent]= -izero; //write how many under zero
320 }
321 if ( inum> 0 ) { //if we have some tracks in buffer
322 icurrent++;
e756ece8 323 if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2);
cc80f89e 324 (*buf)[icurrent] = inum;
325 icurrent++;
73042f01 326 (*buf)[icurrent] = id;
cc80f89e 327 }
328 }//end of loop over columns
329 }//end of loop over differnet track level
e756ece8 330 buf->Set(icurrent+1);
cc80f89e 331 delete fTracks;
332 fTracks = buf;
333 delete fTrIndex;
334 fTrIndex = index;
335}
336
337
338
339void AliSimDigits::ExpandTrackBuffer2()
340{
7d855b04 341 /// comress track according algorithm 2 (track id comression according digit compression)
342
cc80f89e 343 fTrBufType = 0;
344}
345
346void AliSimDigits::CompresTrackBuffer2()
347{
7d855b04 348 /// comress track according algorithm 2 (track id comression according digit compression)
349
cc80f89e 350 fTrBufType = 2;
351}
352
353
176aff27 354Int_t AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
cc80f89e 355{
7d855b04 356 /// returnb track id of digits - for buffer compresion 2
357
cc80f89e 358 return -2;
359}
360
361
362
363AliH2F * AliSimDigits::DrawTracks( const char *option,Int_t level,
364 Float_t x1, Float_t x2, Float_t y1, Float_t y2)
365{
7d855b04 366 /// draw digits in given array
367 ///
368 /// make digits histo
369
cc80f89e 370 char ch[30];
94e6c6f4 371 //sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
372 snprintf(ch,30,"Track Segment_%d level %d ",GetID(),level );
cc80f89e 373 if ( (fNrows<1)|| (fNcols<1)) {
374 return 0;
375 }
376 AliH2F * his = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
377 ExpandTrackBuffer();
378 //set histogram values
379 for (Int_t i = 0; i<fNrows;i++)
380 for (Int_t j = 0; j<fNcols;j++)
381 his->Fill(i,j,GetTrackIDFast(i,j,level));
382 if (x1>=0) {
383 AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
384 delete his;
385 his=h2fsub;
386 }
387 if (his==0) return 0;
388 if (option!=0) his->Draw(option);
389 else his->Draw();
390 return his;
391}
392
58c45a5e 393void AliSimDigits::GlitchFilter(){
7d855b04 394 /// glitch filter, optionally
395
58c45a5e 396 for (Int_t i=0;i<fNcols;i++){ //pads
397 for(Int_t j=1;j<fNrows-1;j++){ //time bins
398 // first and last time bins are checked separately
399 if(GetDigitFast(j,i)){// nonzero digit
400 if (!GetDigitFast(j-1,i) && !GetDigitFast(j+1,i)) {
401 SetDigitFast(0,j,i);
9ca5325c 402 SetTrackIDFast(-2,j,i,0);
403 SetTrackIDFast(-2,j,i,1);
404 SetTrackIDFast(-2,j,i,2);
58c45a5e 405 }
406 }
407 }//time
408
409 if(GetDigitFast(0,i) && !GetDigitFast(1,i)) {
410 SetDigitFast(0,0,i);
9ca5325c 411 SetTrackIDFast(-2,0,i,0);
412 SetTrackIDFast(-2,0,i,1);
413 SetTrackIDFast(-2,0,i,2);
58c45a5e 414 }
415 if(GetDigitFast(fNrows-1,i) && !GetDigitFast(fNrows-2,i)){
416 SetDigitFast(0,fNrows-1,i);
9ca5325c 417 SetTrackIDFast(-2,fNrows-1,i,0);
418 SetTrackIDFast(-2,fNrows-1,i,1);
419 SetTrackIDFast(-2,fNrows-1,i,2);
58c45a5e 420 }
421 }//pads
422
423}
cc80f89e 424