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