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