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