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