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