]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/Base/AliSimDigits.cxx
Better layout of documentation pages
[u/mrichter/AliRoot.git] / TPC / Base / AliSimDigits.cxx
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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  Alice segment manager object                                             //
21 //  AliSimDigits object   (derived from AliDigits)                           //
22 //  provide additional track information to digit                            //
23 //   Origin: Marian Ivanov  GSI Darmstadt                                    //
24 //                                                                           //
25 //                                                                           //
26 ///////////////////////////////////////////////////////////////////////////////
27
28 #include "TClass.h"
29 #include <Riostream.h>
30 #include "TError.h"
31 #include "AliSegmentID.h"
32 #include "AliH2F.h"
33 #include "TArrayI.h"
34 #include "AliDigits.h"
35 #include "AliSimDigits.h"
36 #include <TClonesArray.h>
37
38
39
40 //_____________________________________________________________________________
41 //_____________________________________________________________________________
42 //_____________________________________________________________________________
43 ClassImp(AliSimDigits)
44
45 AliSimDigits::AliSimDigits()
46              :AliDigits(),
47               fTracks(0),
48               fTrIndex(0),
49               fNlevel(0),
50               fTrBufType(0)  
51 {
52   //  AliDigits::Invalite();
53  
54   InvalidateTrack();
55 }
56 //
57 AliSimDigits::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 //
70 AliSimDigits::~AliSimDigits()
71 {
72
73   if (fTracks != 0) {
74     delete fTracks;
75   }
76   if (fTrIndex != 0) { 
77     delete fTrIndex;
78   } 
79
80 }
81 AliSimDigits & AliSimDigits::operator =(const AliSimDigits & param)
82 {
83   //
84   // assignment operator - dummy
85   //
86   if(this!=&param){
87     fTrIndex=param.fTrIndex;
88   }
89   return (*this);
90 }
91
92 //__________________________________________________________________
93 void AliSimDigits::InvalidateTrack() 
94
95   //
96   //set default (invalid parameters)
97   if ( fTracks != 0) delete fTracks;
98   fTracks = new TArrayI;
99   if ( fTrIndex  != 0) delete fTrIndex;
100   fTrIndex = new TArrayI;
101
102   for (Int_t i = 0; i<3; i++){
103     fTracks->Set(0);
104     fTrIndex->Set(0);
105   }
106 }
107
108 void  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
120 Int_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
130 void 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
144 void 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
167 Int_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;
178   Int_t id;
179   for (i = n1;(i<n2);i++){
180     id = 0;
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++;
190         id = fTracks->At(i);
191       }
192     }
193     else {
194       rowold = rownew;
195       rownew+=num;
196       i++;
197       id = fTracks->At(i);
198     }
199     id-=2;
200     if ( (row>=rowold) && (row<rownew) ) return id;
201     if (row < rownew ) return -2; //empty track
202   }
203   return -2;
204 }
205
206 void  AliSimDigits::ExpandTrackBuffer1()
207 {
208   //
209   //expand  track compressed according algorithm 1 (track id comression independent to the digit compression)
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
217   TArrayI * buf = new TArrayI;
218   buf->Set(elems);
219   fTrIndex->Set(0);
220   //
221   Int_t level = 0;
222   Int_t col=0;
223   Int_t row = 0;
224   Int_t n=fTracks->fN;
225   //
226   for (i=0;i<n;i++){
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 {
231       num %= 10000000; //PH: take into account the case of underlying events
232       i++;
233       Int_t id =  fTracks->At(i);
234       for (j = 0; j<num; j++,row++) {
235         if (level*all+col*fNrows+row<elems) (*buf)[level*all+col*fNrows+row]=id;       
236       }
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
251 void  AliSimDigits::CompresTrackBuffer1()
252 {
253   //
254   //comress track according algorithm 1 (track id comression independent to the digit compression)
255   //
256   fTrBufType = 1;  
257
258   TArrayI *  buf = new TArrayI;   //create  new buffer 
259   buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
260   TArrayI *  index = new TArrayI;
261   index->Set(fNcols*fNlevel);
262   //  Int_t * pindex = 
263
264   
265   Int_t icurrent=-1;  //current index
266   Int_t izero;      //number of zero
267   Int_t inum;      //number of digits  with the same current track id  
268   Int_t lastID =0;  //last track id  
269   
270   Int_t *cbuff=fTracks->GetArray(); //MI change
271
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
278       Int_t id=0;  //current id
279       for (Int_t row = 0; row< fNrows;row++){ //loop over rows        
280         id = *cbuff;  //MI change
281         //      id = GetTrackIDFast(row,col,lev);
282         if (id <= 0) {
283           if ( inum> 0 ) { //if we have some tracks in buffer
284             icurrent++;
285             if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1); //MI change - allocate +1
286             (*buf)[icurrent] = inum;
287             icurrent++;
288             (*buf)[icurrent] = lastID;  
289             inum = 0;      
290             lastID = 0;
291           }
292           izero++;
293         }
294         else
295           if (id != lastID) 
296             if ( izero > 0 ) { 
297               //if we have currently izero count of non tracks digits
298               icurrent++;         
299               if (icurrent>=buf->fN) buf->Set(icurrent*2+1);
300               (*buf)[icurrent]= -izero;  //write how many under zero
301               inum++;
302               izero = 0;             
303               lastID = id;
304             }
305             else{ 
306               //if we change track id from another track id         
307               icurrent++;         
308               if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1);
309               (*buf)[icurrent] = inum;
310               icurrent++;
311               (*buf)[icurrent] = lastID;        
312               lastID = id;
313               inum = 1;      
314               izero = 0;
315             }   
316           else {          
317             inum++;
318           }
319         cbuff++;  //MI change
320       }//end of loop over row
321       if ( izero > 0 ) { 
322         //if we have currently izero count of non tracks digits
323         icurrent++;       
324         if (icurrent>=buf->fN) buf->Set(icurrent*2);
325         (*buf)[icurrent]= -izero;  //write how many under zero  
326       }
327       if ( inum> 0 ) { //if we have some tracks in buffer
328         icurrent++;
329         if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2);
330         (*buf)[icurrent] = inum;
331         icurrent++;
332         (*buf)[icurrent] = id;  
333       }      
334     }//end of loop over columns
335   }//end of loop over differnet track level  
336   buf->Set(icurrent+1);
337   delete fTracks;
338   fTracks = buf;
339   delete fTrIndex;
340   fTrIndex = index;
341 }
342
343
344
345 void  AliSimDigits::ExpandTrackBuffer2()
346 {
347   //
348   //comress track according algorithm 2 (track id comression according  digit compression)
349   fTrBufType = 0;
350 }
351
352 void  AliSimDigits::CompresTrackBuffer2()
353 {
354   //
355   //comress track according algorithm 2 (track id comression according  digit compression)
356   fTrBufType = 2;
357 }
358
359
360 Int_t  AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
361 {
362   //returnb track id of digits - for buffer compresion 2
363   return -2;
364 }
365
366
367
368 AliH2F *  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];
376   //sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
377   snprintf(ch,30,"Track Segment_%d level %d ",GetID(),level );
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
398 void 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);
409           SetTrackIDFast(-2,j,i,0);
410           SetTrackIDFast(-2,j,i,1);
411           SetTrackIDFast(-2,j,i,2);
412         }
413       }
414     }//time
415    
416     if(GetDigitFast(0,i) && !GetDigitFast(1,i)) {
417         SetDigitFast(0,0,i);
418         SetTrackIDFast(-2,0,i,0);
419         SetTrackIDFast(-2,0,i,1);
420         SetTrackIDFast(-2,0,i,2);
421     }
422     if(GetDigitFast(fNrows-1,i) && !GetDigitFast(fNrows-2,i)){ 
423        SetDigitFast(0,fNrows-1,i);
424        SetTrackIDFast(-2,fNrows-1,i,0);
425        SetTrackIDFast(-2,fNrows-1,i,1);
426        SetTrackIDFast(-2,fNrows-1,i,2);    
427     }
428   }//pads
429  
430 }
431