]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/comp/AliL3Compress.cxx
Moved to the latest version of the HLT code in Bergen.
[u/mrichter/AliRoot.git] / HLT / comp / AliL3Compress.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
5bf93292 2
3// Author: Anders Vestbo <mailto:vestbo$fi.uib.no>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
5bf93292 5
4994a25d 6#include "AliL3StandardIncludes.h"
5bf93292 7
3e87ef69 8#include "bitio.h"
9#include "AliL3RootTypes.h"
10#include "AliL3Models.h"
11#include "AliL3DigitData.h"
4994a25d 12#include "AliL3Logging.h"
5bf93292 13#include "AliL3TrackArray.h"
14#include "AliL3ModelTrack.h"
029912b7 15#include "AliL3Transform.h"
16#include "AliL3MemHandler.h"
1f1942b8 17#include "AliL3DataCompressorHelper.h"
3e87ef69 18#include "AliL3DataCompressor.h"
6f388e0d 19#include "AliL3SpacePointData.h"
3e87ef69 20
21#if 0
22#ifdef use_root
23#include <TH1.h>
24#include <TH2.h>
25#include <TRandom.h>
26#endif
92a876e2 27#ifdef use_aliroot
be6ddb10 28#include "AliL3FileHandler.h"
92a876e2 29#endif
3e87ef69 30#endif
31
32#include "AliL3Compress.h"
33
34#if GCCVERSION == 3
35using namespace std;
36#endif
5bf93292 37
029912b7 38//_____________________________________________________________
39//
40// AliL3Compress
41//
42// Class for compressing and uncompressing data.
43
5bf93292 44ClassImp(AliL3Compress)
45
46AliL3Compress::AliL3Compress()
47{
95a00d93 48 fTracks=0;
029912b7 49 fSlice =0;
50 fPatch=0;
2357bb38 51 fWriteShape=kFALSE;
3e87ef69 52 fEvent=-1;
029912b7 53}
54
3e87ef69 55AliL3Compress::AliL3Compress(Int_t slice,Int_t patch,Char_t *path,Bool_t writeshape,Int_t event)
029912b7 56{
3e87ef69 57 fEvent=event;
029912b7 58 fSlice=slice;
59 fPatch=patch;
029912b7 60 fTracks=0;
be6ddb10 61 sprintf(fPath,"%s",path);
2357bb38 62 fWriteShape=writeshape;
5bf93292 63}
64
65AliL3Compress::~AliL3Compress()
66{
95a00d93 67 if(fTracks)
68 delete fTracks;
029912b7 69}
70
3e87ef69 71Bool_t AliL3Compress::WriteFile(AliL3TrackArray *tracks,Char_t *filename)
029912b7 72{
3e87ef69 73 Char_t fname[1024];
74 if(filename)
75 sprintf(fname,"%s/comp/%s",fPath,filename);
76 else if(fEvent<0)
77 sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch);
78 else
79 sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
5bf93292 80
be6ddb10 81 FILE *file = fopen(fname,"w");
2357bb38 82 if(!file)
83 {
84 cerr<<"AliL3Compress::WriteFile : Error opening file "<<fname<<endl;
3e87ef69 85 return kFALSE;
2357bb38 86 }
5bf93292 87 Short_t ntracks = tracks->GetNTracks();
95a00d93 88
89 Int_t count=0;
90 AliL3ClusterModel *clusters=0;
91 AliL3TrackModel *model=0;
5bf93292 92 for(Int_t i=0; i<ntracks; i++)
93 {
94 AliL3ModelTrack *track = (AliL3ModelTrack*)tracks->GetCheckedTrack(i);
95 if(!track) continue;
3e87ef69 96
4a838220 97 //Do not save useless tracks or clusters:
3e87ef69 98 //if(track->GetNPresentClusters() == 0)
99 //continue;
4a838220 100
029912b7 101 track->FillModel();
95a00d93 102 model = track->GetModel();
0a86fbb7 103 //if(model->fNClusters==0) continue;
95a00d93 104 clusters = track->GetClusters();
5bf93292 105 if(fwrite(model,sizeof(AliL3TrackModel),1,file)!=1) break;
0a86fbb7 106 //if(fwrite(clusters,model->fNClusters*sizeof(AliL3ClusterModel),1,file)!=1) break;
107 if(fwrite(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,file)!=1) break;
95a00d93 108 count++;
029912b7 109
5bf93292 110 }
111 fclose(file);
3e87ef69 112 return kTRUE;
5bf93292 113}
114
3e87ef69 115Bool_t AliL3Compress::ReadFile(Char_t which,Char_t *filename)
5bf93292 116{
be6ddb10 117 //Read the trackfile.
118
3e87ef69 119 Char_t fname[1024];
120 if(filename)
121 sprintf(fname,"%s/comp/%s",fPath,filename);
be6ddb10 122 else
123 {
3e87ef69 124 if(which == 'm')
125 {
126 if(fEvent<0)
127 sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch);
128 else
129 sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
130 }
131 else if(which == 'u')
132 {
133 if(fEvent<0)
134 sprintf(fname,"%s/comp/tracks_u_%d_%d.raw",fPath,fSlice,fPatch);
135 else
136 sprintf(fname,"%s/comp/tracks_u_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
137 }
138 else
139 {
140 cerr<<"AliL3Compress::ReadFile() : Wrong option"<<endl;
141 return kFALSE;
142 }
be6ddb10 143 }
144
145 FILE *file = fopen(fname,"r");
029912b7 146 if(!file)
147 {
2357bb38 148 cerr<<"AliL3Compress::ReadFile : Cannot open file "<<fname<<endl;
3e87ef69 149 return kFALSE;
029912b7 150 }
151
95a00d93 152 if(fTracks)
153 delete fTracks;
154 fTracks = new AliL3TrackArray("AliL3ModelTrack");
5bf93292 155
156 while(!feof(file))
157 {
95a00d93 158 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->NextTrack();
029912b7 159 track->Init(fSlice,fPatch);
5bf93292 160 AliL3TrackModel *model = track->GetModel();
161 AliL3ClusterModel *clusters = track->GetClusters();
162 if(fread(model,sizeof(AliL3TrackModel),1,file)!=1) break;
0a86fbb7 163 //if(fread(clusters,model->fNClusters*sizeof(AliL3ClusterModel),1,file)!=1) break;
164 if(fread(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,file)!=1) break;
029912b7 165 track->FillTrack();
5bf93292 166 }
029912b7 167
168 fTracks->RemoveLast();
5bf93292 169 fclose(file);
3e87ef69 170 return kTRUE;
5bf93292 171}
172
3e87ef69 173Bool_t AliL3Compress::CompressFile()
5bf93292 174{
be6ddb10 175 Char_t fname[100];
3e87ef69 176 if(fEvent<0)
177 sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch);
178 else
179 sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
be6ddb10 180 BIT_FILE *output = OpenOutputBitFile(fname);
181
3e87ef69 182 if(fEvent<0)
183 sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch);
184 else
185 sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
186
be6ddb10 187 FILE *input = fopen(fname,"r");
188 if(!input)
189 {
190 cerr<<"AliL3Compress::CompressFile() : Error opening file: "<<fname<<endl;
3e87ef69 191 return kFALSE;
be6ddb10 192 }
5bf93292 193
194 AliL3TrackModel track;
195 AliL3ClusterModel cluster;
196 Int_t temp;
2357bb38 197 Int_t power;
029912b7 198
6f388e0d 199 Int_t timeo,pado,chargeo,padshapeo,timeshapeo;
200 timeo=pado=chargeo=padshapeo=timeshapeo=0;
5bf93292 201 while(!feof(input))
202 {
203 if(fread(&track,sizeof(AliL3TrackModel),1,input)!=1) break;
95a00d93 204
205 if(output->mask != 0x80) //Write the current byte to file.
206 {
92a876e2 207 //cerr<<"\nAliL3Compress::CompressFile() : Writing overhead bits!!!"<<endl;
95a00d93 208 if(putc(output->rack,output->file )!=output->rack)
209 cerr<<"AliL3Compress::ComressFile : Error writing to bitfile"<<endl;
210 output->mask=0x80;
029912b7 211 output->rack=0;
95a00d93 212 }
029912b7 213
214 //Write track parameters:
5bf93292 215 fwrite(&track,sizeof(AliL3TrackModel),1,output->file);
3e87ef69 216
217 Int_t origslice=-1,slice,clustercount=0;
0a86fbb7 218 for(Int_t i=0; i<AliL3Transform::GetNRows(fPatch); i++)
5bf93292 219 {
220 if(fread(&cluster,sizeof(AliL3ClusterModel),1,input)!=1) break;
029912b7 221
222 //Write empty flag:
223 temp = (Int_t)cluster.fPresent;
224 OutputBit(output,temp);
225 if(!temp) continue;
226
3e87ef69 227 if(cluster.fSlice<0 || cluster.fSlice>35)
228 {
229 cerr<<"AliL3DataCompress::CompressFile : Fucked up slice number :"<<cluster.fSlice<<endl;
230 exit(5);
231 }
232
233 //Write slice number of first point
234 if(clustercount==0)
235 {
236 origslice = cluster.fSlice;
237 OutputBits(output,origslice,6); //Need 6 bits to encode slice number
238 }
239 else
240 {
241 slice = cluster.fSlice;
242 if(slice == origslice)
6f388e0d 243 OutputBit(output,0); //No change of slice
3e87ef69 244 else
245 {
246 OutputBit(output,1);
247 OutputBits(output,slice,6);
248 origslice=slice;
249 }
250 }
251
029912b7 252 //Write time information:
3e87ef69 253 temp = (Int_t)rint(cluster.fDTime);
5bf93292 254 if(temp<0)
255 OutputBit(output,0);
256 else
257 OutputBit(output,1);
1f1942b8 258 power = 1<<(AliL3DataCompressorHelper::GetNTimeBits()-1);
029912b7 259 if(abs(temp)>=power)
260 {
1f1942b8 261 //cout<<abs(temp)<<" "<<power<<endl;
029912b7 262 timeo++;
263 temp=power - 1;
264 }
1f1942b8 265 OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNTimeBits()-1));
029912b7 266
267 //Write pad information:
3e87ef69 268 temp = (Int_t)rint(cluster.fDPad);
5bf93292 269 if(temp<0)
270 OutputBit(output,0);
271 else
272 OutputBit(output,1);
1f1942b8 273 power = 1<<(AliL3DataCompressorHelper::GetNPadBits()-1);
029912b7 274 if(abs(temp)>=power)
275 {
276 pado++;
277 temp=power - 1;
278 }
1f1942b8 279 OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNPadBits()-1));
029912b7 280
281 //Write charge information:
5bf93292 282 temp = (Int_t)cluster.fDCharge;
1f1942b8 283 power = 1<<(AliL3DataCompressorHelper::GetNChargeBits());
029912b7 284 if(abs(temp)>=power)
285 {
286 chargeo++;
287 temp=power - 1;
288 }
1f1942b8 289 OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNChargeBits()));
029912b7 290
2357bb38 291 if(fWriteShape)
029912b7 292 {
2357bb38 293 //Write shape information:
1f1942b8 294 temp = (Int_t)cluster.fDSigmaY;
2357bb38 295 if(temp<0)
296 OutputBit(output,0);
297 else
298 OutputBit(output,1);
1f1942b8 299 power = 1<<(AliL3DataCompressorHelper::GetNShapeBits()-1);
2357bb38 300 if(abs(temp) >= power)
301 {
6f388e0d 302 padshapeo++;
2357bb38 303 temp = power - 1;
304 }
1f1942b8 305 OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNShapeBits()-1));
2357bb38 306
1f1942b8 307 temp = (Int_t)cluster.fDSigmaZ;
2357bb38 308 if(temp<0)
309 OutputBit(output,0);
310 else
311 OutputBit(output,1);
1f1942b8 312 power = 1<<(AliL3DataCompressorHelper::GetNShapeBits()-1);
2357bb38 313 if(abs(temp) >= power)
314 {
6f388e0d 315 timeshapeo++;
2357bb38 316 temp=power - 1;
317 }
1f1942b8 318 OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNShapeBits()-1));
029912b7 319 }
3e87ef69 320
321 clustercount++;
5bf93292 322 }
5bf93292 323 }
95a00d93 324
5bf93292 325 fclose(input);
326 CloseOutputBitFile(output);
6f388e0d 327 if(pado || timeo || chargeo || padshapeo || timeshapeo)
f64c4364 328 {
329 cout<<endl<<"Saturations: "<<endl
330 <<"Pad "<<pado<<endl
331 <<"Time "<<timeo<<endl
332 <<"Charge "<<chargeo<<endl
6f388e0d 333 <<"Padshape "<<padshapeo<<endl
334 <<"Timeshape "<<timeshapeo<<endl<<endl;
f64c4364 335 }
3e87ef69 336 return kTRUE;
5bf93292 337}
338
3e87ef69 339Bool_t AliL3Compress::ExpandFile()
5bf93292 340{
be6ddb10 341 Char_t fname[100];
3e87ef69 342 if(fEvent<0)
343 sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch);
344 else
345 sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
be6ddb10 346 BIT_FILE *input = OpenInputBitFile(fname);
347
3e87ef69 348 if(fEvent<0)
349 sprintf(fname,"%s/comp/tracks_u_%d_%d.raw",fPath,fSlice,fPatch);
350 else
351 sprintf(fname,"%s/comp/tracks_u_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
be6ddb10 352 FILE *output = fopen(fname,"w");
353 if(!output)
354 {
355 cerr<<"AliL3Compress::ExpandFile() : Error opening file: "<<fname<<endl;
3e87ef69 356 return kFALSE;
be6ddb10 357 }
95a00d93 358
359 AliL3TrackModel trackmodel;
360 AliL3ClusterModel *clusters=0;
029912b7 361 Int_t count=0;
5bf93292 362
4a838220 363 clusters = new AliL3ClusterModel[(AliL3Transform::GetNRows(fPatch))];
95a00d93 364 while(!feof(input->file))
5bf93292 365 {
029912b7 366 input->mask=0x80;//make sure we read a new byte from file.
95a00d93 367
029912b7 368 //Read and write track:
95a00d93 369 if(fread(&trackmodel,sizeof(AliL3TrackModel),1,input->file)!=1) break;
370 fwrite(&trackmodel,sizeof(AliL3TrackModel),1,output);
2357bb38 371
372 memset(clusters,0,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel));
3e87ef69 373 Int_t origslice=-1,clustercount=0;
0a86fbb7 374 for(Int_t i=0; i<AliL3Transform::GetNRows(fPatch); i++)
95a00d93 375 {
376 Int_t temp,sign;
029912b7 377
378 //Read empty flag:
95a00d93 379 temp = InputBit(input);
380 if(!temp)
381 {
382 clusters[i].fPresent=kFALSE;
383 continue;
384 }
385 clusters[i].fPresent=kTRUE;
029912b7 386
3e87ef69 387 //Read slice information
388 if(clustercount==0)
389 {
390 temp = InputBits(input,6);
391 clusters[i].fSlice = temp;
392 origslice = temp;
393 }
394 else
395 {
396 temp = InputBit(input);
397 if(!temp)//no change
398 clusters[i].fSlice = origslice;
399 else
400 {
401 temp = InputBits(input,6);//read new slice
402 clusters[i].fSlice = temp;
403 origslice = temp;//store new slice
404 }
405 }
406
029912b7 407 //Read time information:
95a00d93 408 sign=InputBit(input);
1f1942b8 409 temp = InputBits(input,(AliL3DataCompressorHelper::GetNTimeBits()-1));
95a00d93 410 if(!sign)
411 temp*=-1;
412 clusters[i].fDTime = temp;
029912b7 413
414 //Read pad information:
95a00d93 415 sign=InputBit(input);
1f1942b8 416 temp = InputBits(input,(AliL3DataCompressorHelper::GetNPadBits()-1));
95a00d93 417 if(!sign)
418 temp*=-1;
419 clusters[i].fDPad = temp;
029912b7 420
421 //Read charge information:
1f1942b8 422 temp=InputBits(input,(AliL3DataCompressorHelper::GetNChargeBits()));
95a00d93 423 clusters[i].fDCharge = temp;
029912b7 424
2357bb38 425 if(fWriteShape)
426 {
427 //Read shape information:
428 sign = InputBit(input);
1f1942b8 429 temp = InputBits(input,(AliL3DataCompressorHelper::GetNShapeBits()-1));
2357bb38 430 if(!sign)
431 temp*=-1;
1f1942b8 432 clusters[i].fDSigmaY = temp;
2357bb38 433
434 sign = InputBit(input);
1f1942b8 435 temp = InputBits(input,(AliL3DataCompressorHelper::GetNShapeBits()-1));
2357bb38 436 if(!sign)
437 temp*=-1;
1f1942b8 438 clusters[i].fDSigmaZ = temp;
2357bb38 439 }
3e87ef69 440 clustercount++;
95a00d93 441 }
029912b7 442 count++;
0a86fbb7 443 //fwrite(clusters,(trackmodel.fNClusters)*sizeof(AliL3ClusterModel),1,output);
444 fwrite(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,output);
5bf93292 445 }
029912b7 446
447 delete [] clusters;
95a00d93 448 fclose(output);
5bf93292 449 CloseInputBitFile(input);
3e87ef69 450 return kTRUE;
5bf93292 451}
029912b7 452
6f388e0d 453void AliL3Compress::CompressRemaining(AliL3SpacePointData *clusters[36][6],UInt_t nclusters[36][6])
454{
455 //Write the remaining clusters in a compressed format.
456
457 Char_t filename[1024];
458 Int_t nrows = AliL3Transform::GetNRows();
459 Int_t *npoints = new Int_t[nrows];
460 for(Int_t slice=0; slice<=35; slice++)
461 {
462 for(Int_t patch=0; patch < 1; patch++)
463 {
464 sprintf(filename,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,slice,-1);
465 BIT_FILE *output = OpenOutputBitFile(filename);
466 if(!output)
467 {
468 cerr<<"AliL3Compress::CompressRemaining : Cannot open file "<<filename<<endl;
469 exit(5);
470 }
471 AliL3SpacePointData *cl = clusters[slice][patch];
472 memset(npoints,0,nrows*sizeof(Int_t));
473
474 UInt_t i;
475 for(i=0; i<nclusters[slice][patch]; i++)
476 {
477 if(cl[i].fCharge == 0) continue; //has been used
478 npoints[cl[i].fPadRow]++;
479 }
480 Int_t rowspresent=0;
481 for(Int_t j=0; j<nrows; j++)
482 {
483 if(!npoints[j]) continue;
484 rowspresent++;
485 }
486
487 //Write number of padrows with clusters
488 OutputBits(output,rowspresent,8);
489
490 Int_t last_padrow=-1;
491 for(i=0; i<nclusters[slice][patch]; i++)
492 {
493 if(cl[i].fCharge == 0) continue; //has been used
494 Int_t padrow = cl[i].fPadRow;
495 if(padrow != last_padrow)
496 {
497 OutputBits(output,padrow,8);//Write padrow #
498 if(npoints[padrow] >= 1<<10)
499 {
500 cerr<<"AliL3Compress::CompressRemaining : Too many remaining clusters "<<npoints[padrow]<<endl;
501 exit(5);
502 }
503 OutputBits(output,npoints[padrow],10);//Write number of clusters on this padrow
504 last_padrow = padrow;
505 }
506
507 Float_t xyz[3] = {cl[i].fX,cl[i].fY,cl[i].fZ};
508 Int_t sector,row,buff;
509 AliL3Transform::Slice2Sector(slice,padrow,sector,row);
510 AliL3Transform::Global2Raw(xyz,sector,row);
511
1f1942b8 512 Float_t padw = sqrt(cl[i].fSigmaY2) / AliL3Transform::GetPadPitchWidth(AliL3Transform::GetPatch(padrow));
513 Float_t timew = sqrt(cl[i].fSigmaZ2) / AliL3Transform::GetZWidth();
6f388e0d 514
515 //Write pad
516 buff = (Int_t)rint(xyz[1]*10);
517 if(buff<0)
518 {
519 cerr<<"AliL3Compress:CompressRemaining : Wrong pad value "<<buff<<endl;
520 exit(5);
521 }
522 OutputBits(output,buff,11);
523
524 //Write time
525 buff = (Int_t)rint(xyz[2]*10);
526 if(buff<0)
527 {
528 cerr<<"AliL3Compress:CompressRemaining : Wrong time value "<<buff<<endl;
529 exit(5);
530 }
531 OutputBits(output,buff,13);
532
533 //Write widths
534 buff = (Int_t)rint(padw*100);
535 OutputBits(output,buff,8);
536 buff = (Int_t)rint(timew*100);
537 OutputBits(output,buff,8);
538
539 //Write charge
540 buff = cl[i].fCharge;
541 if(buff >= 1<<14)
542 buff = (1<<14)-1;
543 OutputBits(output,buff,14);
544 }
545
546 CloseOutputBitFile(output);
547 }
548
549 }
550 delete [] npoints;
551}
552
553void AliL3Compress::ExpandRemaining(TempCluster **clusters,Int_t *ncl,const Int_t maxpoints)
554{
555 //Expand the remaining clusters stored using function CompressRemaining
556
557 Char_t filename[1024];
558 Int_t buff;
559 for(Int_t slice=0; slice<=35; slice++)
560 {
561 for(Int_t p=0; p<1; p++)
562 {
563 sprintf(filename,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,slice,-1);
564 BIT_FILE *input = OpenInputBitFile(filename);
565
566 //Read number of padrows
567 buff = InputBits(input,8);
568 Int_t nrows = buff;
569
570 for(Int_t i=0; i<nrows; i++)
571 {
572 //Read padrow
573 buff = InputBits(input,8);
574 Int_t padrow = buff;
575
576 //Read nclusters;
577 buff = InputBits(input,10);
578 Int_t npoints = buff;
579
580 for(Int_t i=0; i<npoints; i++)
581 {
582 clusters[slice][ncl[slice]].padrow = padrow;
583
584 //Read pad
585 buff = InputBits(input,11);
586 clusters[slice][ncl[slice]].pad = (Float_t)buff/10.;
587
588 //Read time
589 buff = InputBits(input,13);
590 clusters[slice][ncl[slice]].time = (Float_t)buff/10.;
591
592 //Read widths
593 buff = InputBits(input,8);
1f1942b8 594 clusters[slice][ncl[slice]].sigmaY2 = pow((Float_t)buff/100.,2);
6f388e0d 595 buff = InputBits(input,8);
1f1942b8 596 clusters[slice][ncl[slice]].sigmaZ2 = pow((Float_t)buff/100.,2);
6f388e0d 597
598 //Read charge
599 buff = InputBits(input,14);
600 clusters[slice][ncl[slice]].charge = buff;
601 //cout<<"padrow "<<padrow<<" pad "<<clusters[slice][ncl[slice]].pad<<" time "<<clusters[slice][ncl[slice]].time<<" charge "<<clusters[slice][ncl[slice]].charge<<" widths "<<clusters[slice][ncl[slice]].sigmaY2<<" "<<clusters[slice][ncl[slice]].sigmaZ2<<endl;
602 ncl[slice]++;
603 }
604
605 }
606 CloseInputBitFile(input);
607 }
608 }
609}
610
3e87ef69 611void AliL3Compress::PrintCompRatio(ofstream *outfile)
029912b7 612{
029912b7 613 AliL3MemHandler *mem = new AliL3MemHandler();
3e87ef69 614 Char_t fname[1024];
615 UInt_t remain_size=0,digit_size=0;
616 for(Int_t i=0; i<36; i++)
029912b7 617 {
3e87ef69 618 if(fEvent<0)
619 sprintf(fname,"%s/comp/remains_%d_%d.raw",fPath,i,-1);
620 else
621 sprintf(fname,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,i,-1);
622 mem->SetBinaryInput(fname);
623 remain_size += mem->GetFileSize();
624 mem->CloseBinaryInput();
625
626 sprintf(fname,"%s/binaries/digits_c8_%d_%d_%d.raw",fPath,fEvent,i,-1);
627 mem->SetBinaryInput(fname);
628 digit_size += mem->GetFileSize();
629 mem->CloseBinaryInput();
029912b7 630 }
631
4a838220 632
3e87ef69 633 if(fEvent<0)
634 sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch);
635 else
636 sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch);
029912b7 637
3e87ef69 638 mem->SetBinaryInput(fname);
639 UInt_t compress_size = mem->GetFileSize();
92a876e2 640 mem->CloseBinaryInput();
92a876e2 641
3e87ef69 642 if(digit_size==0)
92a876e2 643 {
0a86fbb7 644 cerr<<"AliL3Compress::PrintCompRatio : Zero digit size, not able to obtain comp. ratios!"<<endl;
645 return;
92a876e2 646 }
92a876e2 647
3e87ef69 648 Float_t compratio = (Float_t)(compress_size + remain_size)/(Float_t)digit_size;
1f1942b8 649 Float_t entropy[2];
650 GetEntropy(entropy[0],entropy[1]);
f64c4364 651 if(outfile)
f64c4364 652 {
3e87ef69 653 ofstream &out = *outfile;
1f1942b8 654 out<<compress_size<<' '<<remain_size<<' '<<digit_size<<' '<<entropy[0]<<' '<<entropy[1]<<endl;
f64c4364 655 }
1f1942b8 656
3e87ef69 657 cout<<"=========================================="<<endl;
658 cout<<"Original digits size : "<<digit_size/1000<<" kByte ( 100 % )"<<endl;
659 cout<<"Compressed file size : "<<compress_size/1000<<" kByte ( "<<(Float_t)compress_size*100/(Float_t)digit_size<<" % )"<<endl;
1f1942b8 660 cout<<"Entropy of residuals : "<<entropy[0]<<" "<<entropy[1]<<endl;
3e87ef69 661 cout<<"Remainig file size : "<<remain_size/1000<<" kByte ( "<<(Float_t)remain_size*100/(Float_t)digit_size<<" % )"<<endl;
662 cout<<"---------------------- "<<endl;
663 cout<<"Compression ratio : "<<compratio*100<<" %"<<endl;
664 cout<<"=========================================="<<endl;
be6ddb10 665}
1f1942b8 666
667void AliL3Compress::GetEntropy(Float_t &pad_entropy,Float_t &time_entropy)
668{
669 //Calculate the entropy of the quantized residuals in both directions
670
671 if(!ReadFile('m'))
672 return;
673 const Int_t nmax=100000;
674 Float_t pads[nmax];
675 Float_t times[nmax];
676 memset(&pads[0],0,nmax*sizeof(Float_t));
677 memset(&times[0],0,nmax*sizeof(Float_t));
678 Float_t counter=0;
679
680 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
681 {
682 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
683 if(!track) continue;
684 for(Int_t padrow=0; padrow<AliL3Transform::GetNRows(); padrow++)
685 {
686 if(!track->IsPresent(padrow)) continue;
687 Int_t dpad = abs((Int_t)rint(track->GetClusterModel(padrow)->fDPad));
688 Int_t dtime = abs((Int_t)rint(track->GetClusterModel(padrow)->fDTime));
689 if(dpad >= nmax || dtime >= nmax)
690 {
691 cerr<<"AliL3Compress::GetEntropy : Quantization out of range: "<<dpad<<" "<<dtime<<endl;
692 break;
693 }
694 pads[dpad]++;
695 times[dtime]++;
696 counter++;
697 }
698 }
699 pad_entropy=time_entropy=0;
700 for(Int_t i=0; i<nmax; i++)
701 {
702 if(pads[i]>0)
703 pad_entropy += (pads[i]/counter)*(log(pads[i]/counter)/log(2.0));
704 if(times[i]>0)
705 time_entropy += (times[i]/counter)*(log(times[i]/counter)/log(2.0));
706 }
707
708 pad_entropy*=-1;
709 time_entropy*=-1;
710}