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