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