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