]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
5b3f37f6 | 2 | |
3 | // Author: Anders Vestbo <mailto:vestbo@fi.uib.no> | |
3e87ef69 | 4 | //*-- Copyright © ALICE HLT Group |
5b3f37f6 | 5 | |
6 | #include "AliL3StandardIncludes.h" | |
3e87ef69 | 7 | |
8 | #include "AliL3Logging.h" | |
9 | #include "AliL3RootTypes.h" | |
5b3f37f6 | 10 | #include "AliL3Transform.h" |
3e87ef69 | 11 | #include "AliL3MemHandler.h" |
5b3f37f6 | 12 | #include "AliL3SpacePointData.h" |
13 | #include "AliL3Compress.h" | |
14 | #include "AliL3TrackArray.h" | |
15 | #include "AliL3ModelTrack.h" | |
bd53cfb7 | 16 | #include "AliL3Benchmark.h" |
3e87ef69 | 17 | #include "AliL3ClusterFitter.h" |
18 | ||
19 | #ifdef use_aliroot | |
20 | #include "AliL3FileHandler.h" | |
5b3f37f6 | 21 | |
3e87ef69 | 22 | #include <AliKalmanTrack.h> |
23 | #include <AliTPCtracker.h> | |
24 | #include <AliTPCcluster.h> | |
5b3f37f6 | 25 | #include <AliTPCParamSR.h> |
26 | #include <AliTPCDigitsArray.h> | |
27 | #include <AliTPCClustersArray.h> | |
28 | #include <AliTPCcluster.h> | |
29 | #include <AliTPCClustersRow.h> | |
30 | #include <AliSimDigits.h> | |
31 | #include <AliTPC.h> | |
32 | #include <AliTPCv2.h> | |
33 | #include <AliRun.h> | |
3e87ef69 | 34 | #endif |
5b3f37f6 | 35 | |
3e87ef69 | 36 | #ifdef use_root |
5b3f37f6 | 37 | #include <TFile.h> |
38 | #include <TMath.h> | |
39 | #include <TDirectory.h> | |
40 | #include <TSystem.h> | |
3e87ef69 | 41 | #include <TH2F.h> |
42 | #endif | |
43 | ||
44 | #include "AliL3DataCompressor.h" | |
45 | ||
46 | #if GCCVERSION == 3 | |
47 | using namespace std; | |
48 | #endif | |
49 | ||
5b3f37f6 | 50 | //_____________________________________________________________ |
51 | // | |
52 | // AliL3DataCompression | |
53 | // | |
54 | // Interface class; binary <-> AliROOT handling of TPC data compression classes. | |
55 | // | |
56 | ||
57 | ||
58 | ClassImp(AliL3DataCompressor) | |
59 | ||
3e87ef69 | 60 | Int_t AliL3DataCompressor::fNumTimeBits = 12; |
61 | Int_t AliL3DataCompressor::fNumPadBits = 12; | |
62 | Int_t AliL3DataCompressor::fNumChargeBits = 14; | |
63 | Int_t AliL3DataCompressor::fNumShapeBits = 14; | |
64 | Float_t AliL3DataCompressor::fXYResidualStep = 0.03; | |
65 | Float_t AliL3DataCompressor::fZResidualStep = 0.05; | |
66 | Float_t AliL3DataCompressor::fXYWidthStep = 0.005; | |
67 | Float_t AliL3DataCompressor::fZWidthStep = 0.005; | |
68 | Int_t AliL3DataCompressor::fClusterCharge = 100; | |
69 | ||
5b3f37f6 | 70 | AliL3DataCompressor::AliL3DataCompressor() |
71 | { | |
bd53cfb7 | 72 | fBenchmark=0; |
3e87ef69 | 73 | fInputTracks=0; |
74 | fKeepRemaining=kTRUE; | |
75 | fEvent=0; | |
76 | fWriteClusterShape=kFALSE; | |
77 | fOutputFile=0; | |
78 | fCompRatioFile=0; | |
79 | memset(fClusters,0,36*6*sizeof(AliL3SpacePointData*)); | |
5b3f37f6 | 80 | } |
81 | ||
3e87ef69 | 82 | AliL3DataCompressor::AliL3DataCompressor(Char_t *path,Bool_t keep,Bool_t writeshape) |
5b3f37f6 | 83 | { |
5b3f37f6 | 84 | strcpy(fPath,path); |
bd53cfb7 | 85 | fBenchmark = new AliL3Benchmark(); |
3e87ef69 | 86 | fInputTracks=0; |
87 | fKeepRemaining=keep; | |
88 | fWriteClusterShape = writeshape; | |
89 | fEvent=0; | |
90 | fOutputFile=0; | |
91 | memset(fClusters,0,36*6*sizeof(AliL3SpacePointData*)); | |
92 | #ifdef use_root | |
93 | Char_t name[1024]; | |
94 | sprintf(name,"rm -f %s/comp/*",path);//Clean the directory | |
95 | gSystem->Exec(name); | |
96 | #endif | |
97 | OpenOutputFile(); | |
5b3f37f6 | 98 | } |
99 | ||
100 | AliL3DataCompressor::~AliL3DataCompressor() | |
101 | { | |
3e87ef69 | 102 | if(fInputTracks) |
103 | delete fInputTracks; | |
bd53cfb7 | 104 | if(fBenchmark) |
105 | delete fBenchmark; | |
3e87ef69 | 106 | if(fClusters) |
107 | { | |
108 | for(Int_t i=0; i<36; i++) | |
109 | for(Int_t j=0; j<6; j++) | |
110 | if(fClusters[i][j]) | |
111 | delete fClusters[i][j]; | |
112 | } | |
113 | CloseOutputFile(); | |
bd53cfb7 | 114 | } |
115 | ||
116 | void AliL3DataCompressor::DoBench(Char_t *fname) | |
117 | { | |
118 | fBenchmark->Analyze(fname); | |
5b3f37f6 | 119 | } |
120 | ||
3e87ef69 | 121 | void AliL3DataCompressor::SetBitNumbers(Int_t pad,Int_t time,Int_t charge,Int_t shape) |
122 | { | |
123 | fNumPadBits = pad; | |
124 | fNumTimeBits = time; | |
125 | fNumChargeBits = charge; | |
126 | fNumShapeBits = shape; | |
127 | } | |
128 | ||
129 | void AliL3DataCompressor::SetResolutions(Float_t xyresidual,Float_t zresidual,Int_t clustercharge,Float_t xywidth,Float_t zwidth) | |
130 | { | |
131 | fXYResidualStep = xyresidual; | |
132 | fZResidualStep = zresidual; | |
133 | fXYWidthStep = xywidth; | |
134 | fZWidthStep = zwidth; | |
135 | fClusterCharge = clustercharge; | |
136 | } | |
137 | ||
138 | void AliL3DataCompressor::OpenOutputFile() | |
5b3f37f6 | 139 | { |
3e87ef69 | 140 | #ifndef use_aliroot |
141 | LOG(AliL3Log::kError,"AliL3DataCompressor::OpenOutputFile","Version") | |
142 | <<"You have to compile with use_aliroot flag in order to use this function"<<ENDLOG; | |
143 | #else | |
144 | Char_t filename[1024]; | |
5b3f37f6 | 145 | |
3e87ef69 | 146 | sprintf(filename,"%s/comp/comprates.txt",fPath); |
147 | fCompRatioFile = new ofstream(filename); | |
148 | ||
149 | if(fOutputFile) | |
150 | if(fOutputFile->IsOpen()) | |
151 | fOutputFile->Close(); | |
152 | ||
153 | sprintf(filename,"%s/alirunfile.root",fPath); | |
154 | TFile *f = TFile::Open(filename); | |
155 | AliTPCParam *param = (AliTPCParam*)f->Get(AliL3Transform::GetParamName()); | |
156 | sprintf(filename,"%s/comp/AliTPCclusters.root",fPath); | |
157 | fOutputFile = TFile::Open(filename,"RECREATE"); | |
158 | param->Write(param->GetTitle()); | |
159 | f->Close(); | |
160 | #endif | |
161 | } | |
162 | ||
163 | void AliL3DataCompressor::CloseOutputFile() | |
164 | { | |
165 | if(fCompRatioFile) | |
5b3f37f6 | 166 | { |
3e87ef69 | 167 | fCompRatioFile->close(); |
168 | delete fCompRatioFile; | |
169 | } | |
170 | ||
171 | if(!fOutputFile) | |
172 | return; | |
173 | #ifdef use_root | |
174 | if(!fOutputFile->IsOpen()) | |
175 | return; | |
176 | fOutputFile->Close(); | |
177 | #else | |
178 | fclose(fOutputFile); | |
179 | #endif | |
180 | fOutputFile=0; | |
181 | } | |
5b3f37f6 | 182 | |
3e87ef69 | 183 | void AliL3DataCompressor::LoadData(Int_t event,Bool_t sp) |
184 | { | |
185 | fSinglePatch=sp; | |
186 | fEvent=event; | |
187 | AliL3MemHandler *clusterfile[36][6]; | |
188 | Char_t fname[1024]; | |
189 | for(Int_t s=0; s<=35; s++) | |
190 | { | |
191 | for(Int_t p=0; p<6; p++) | |
192 | { | |
193 | if(fClusters[s][p]) | |
194 | delete fClusters[s][p]; | |
195 | fClusters[s][p] = 0; | |
196 | clusterfile[s][p] = new AliL3MemHandler(); | |
197 | if(fSinglePatch) | |
198 | sprintf(fname,"%s/cf/points_%d_%d_%d.raw",fPath,fEvent,s,-1); | |
199 | else | |
200 | sprintf(fname,"%s/cf/points_%d_%d_%d.raw",fPath,fEvent,s,p); | |
201 | clusterfile[s][p]->SetBinaryInput(fname); | |
5b3f37f6 | 202 | |
3e87ef69 | 203 | fClusters[s][p] = (AliL3SpacePointData*)clusterfile[s][p]->Allocate(); |
204 | clusterfile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]); | |
205 | clusterfile[s][p]->CloseBinaryInput(); | |
5b3f37f6 | 206 | |
3e87ef69 | 207 | if(fSinglePatch) |
208 | break; | |
5b3f37f6 | 209 | } |
210 | } | |
211 | ||
3e87ef69 | 212 | sprintf(fname,"%s/cf/tracks_%d.raw",fPath,fEvent); |
213 | AliL3MemHandler *tfile = new AliL3MemHandler(); | |
214 | tfile->SetBinaryInput(fname); | |
215 | ||
216 | if(fInputTracks) | |
217 | delete fInputTracks; | |
218 | fInputTracks = new AliL3TrackArray(); | |
219 | tfile->Binary2TrackArray(fInputTracks); | |
220 | tfile->CloseBinaryInput(); | |
221 | delete tfile; | |
5b3f37f6 | 222 | } |
223 | ||
3e87ef69 | 224 | void AliL3DataCompressor::FillData(Int_t min_hits,Bool_t expand) |
5b3f37f6 | 225 | { |
5b3f37f6 | 226 | |
3e87ef69 | 227 | //Fill the track data into track and cluster structures, and write to file. |
228 | //Preparation for compressing it. | |
229 | ||
230 | cout<<"Filling data; "<<fInputTracks->GetNTracks()<<" tracks"<<endl; | |
231 | AliL3TrackArray *comptracks = new AliL3TrackArray("AliL3ModelTrack"); | |
232 | fInputTracks->QSort(); | |
233 | for(Int_t i=0; i<fInputTracks->GetNTracks(); i++) | |
5b3f37f6 | 234 | { |
3e87ef69 | 235 | AliL3Track *intrack = fInputTracks->GetCheckedTrack(i); |
236 | if(!intrack) continue; | |
237 | ||
238 | if(intrack->GetNHits()<min_hits) break; | |
239 | ||
240 | intrack->CalculateHelix(); | |
241 | ||
242 | AliL3ModelTrack *outtrack = (AliL3ModelTrack*)comptracks->NextTrack(); | |
243 | outtrack->SetNHits(intrack->GetNHits()); | |
244 | outtrack->SetRowRange(intrack->GetFirstRow(),intrack->GetLastRow()); | |
245 | outtrack->SetFirstPoint(intrack->GetFirstPointX(),intrack->GetFirstPointY(),intrack->GetFirstPointZ()); | |
246 | outtrack->SetLastPoint(intrack->GetLastPointX(),intrack->GetLastPointY(),intrack->GetLastPointZ()); | |
247 | outtrack->SetPt(intrack->GetPt()); | |
248 | outtrack->SetPsi(intrack->GetPsi()); | |
249 | outtrack->SetTgl(intrack->GetTgl()); | |
250 | outtrack->SetCharge(intrack->GetCharge()); | |
251 | outtrack->CalculateHelix(); | |
252 | Int_t nhits = intrack->GetNHits(); | |
253 | UInt_t *hitids = intrack->GetHitNumbers(); | |
254 | Int_t origslice = (hitids[nhits-1]>>25)&0x7f; | |
255 | outtrack->Init(origslice,-1); | |
256 | for(Int_t j=nhits-1; j>=0; j--) | |
5b3f37f6 | 257 | { |
3e87ef69 | 258 | UInt_t id=hitids[j]; |
259 | Int_t slice = (id>>25)&0x7f; | |
260 | Int_t patch = (id>>22)&0x7; | |
261 | UInt_t pos = id&0x3fffff; | |
262 | ||
263 | //UInt_t size; | |
264 | AliL3SpacePointData *points = fClusters[slice][patch];//->GetDataPointer(size); | |
265 | Float_t xyz[3] = {points[pos].fX,points[pos].fY,points[pos].fZ}; | |
266 | Int_t padrow = points[pos].fPadRow; | |
5b3f37f6 | 267 | |
3e87ef69 | 268 | //Calculate the crossing point between track and padrow |
269 | Float_t angle = 0; //Perpendicular to padrow in local coordinates | |
270 | AliL3Transform::Local2GlobalAngle(&angle,slice); | |
271 | if(!intrack->CalculateReferencePoint(angle,AliL3Transform::Row2X(padrow))) | |
272 | { | |
273 | cerr<<"AliL3DataCompressor::FillData : Error in crossing point calc on slice "<<slice<<" row "<<padrow<<endl; | |
274 | outtrack->Print(kFALSE); | |
275 | exit(5); | |
276 | } | |
277 | ||
278 | Float_t xyz_cross[3] = {intrack->GetPointX(),intrack->GetPointY(),intrack->GetPointZ()}; | |
279 | ||
280 | Int_t sector,row; | |
281 | AliL3Transform::Slice2Sector(slice,padrow,sector,row); | |
282 | AliL3Transform::Global2Raw(xyz_cross,sector,row); | |
283 | AliL3Transform::Global2Raw(xyz,sector,row); | |
284 | ||
285 | outtrack->SetPadHit(padrow,xyz_cross[1]); | |
286 | outtrack->SetTimeHit(padrow,xyz_cross[2]); | |
287 | ||
288 | if(fWriteClusterShape) | |
289 | { | |
290 | Float_t angle = intrack->GetCrossingAngle(padrow,slice); | |
291 | outtrack->SetCrossingAngleLUT(padrow,angle); | |
292 | outtrack->CalculateClusterWidths(padrow,kTRUE); | |
293 | Int_t patch = AliL3Transform::GetPatch(padrow); | |
294 | Float_t sigmaY2 = points[pos].fSigmaY2 / pow(AliL3Transform::GetPadPitchWidth(patch),2); | |
295 | Float_t sigmaZ2 = points[pos].fSigmaZ2 / pow(AliL3Transform::GetZWidth(),2); | |
296 | outtrack->SetCluster(padrow,xyz[1],xyz[2],points[pos].fCharge,sigmaY2,sigmaZ2,3); | |
297 | } | |
298 | else | |
299 | outtrack->SetCluster(padrow,xyz[1],xyz[2],points[pos].fCharge,0,0,3); | |
5b3f37f6 | 300 | |
3e87ef69 | 301 | //IMPORTANT: Set the slice in which cluster is, you need it in AliL3ModelTrack::FillTrack! |
302 | outtrack->GetClusterModel(padrow)->fSlice=slice; | |
303 | points[pos].fCharge = 0;//Mark this cluster as used. | |
5b3f37f6 | 304 | } |
3e87ef69 | 305 | if(!expand) |
306 | outtrack->SetNClusters(AliL3Transform::GetNRows(-1)); | |
5b3f37f6 | 307 | } |
3e87ef69 | 308 | |
309 | if(expand) | |
310 | ExpandTrackData(comptracks); | |
311 | ||
312 | cout<<"Writing "<<comptracks->GetNTracks()<<" tracks to file"<<endl; | |
313 | AliL3Compress *comp = new AliL3Compress(-1,-1,fPath,fWriteClusterShape,fEvent); | |
314 | comp->WriteFile(comptracks); | |
315 | delete comp; | |
316 | delete comptracks; | |
317 | ||
5b3f37f6 | 318 | } |
319 | ||
3e87ef69 | 320 | void AliL3DataCompressor::ExpandTrackData(AliL3TrackArray *tracks) |
5b3f37f6 | 321 | { |
3e87ef69 | 322 | //Loop over tracks and try to assign unused clusters. |
323 | //Only clusters which are closer than the max. residual are taken. | |
5b3f37f6 | 324 | |
3e87ef69 | 325 | cout<<"Expanding "<<tracks->GetNTracks()<<" tracks"<<endl; |
326 | for(Int_t i=0; i<tracks->GetNTracks(); i++) | |
5b3f37f6 | 327 | { |
3e87ef69 | 328 | AliL3ModelTrack *track = (AliL3ModelTrack*)tracks->GetCheckedTrack(i); |
329 | if(!track) continue; | |
330 | if(track->GetNHits() == AliL3Transform::GetNRows()) continue; | |
331 | ||
332 | Int_t nhits = track->GetNHits(); | |
333 | //cout<<"Expanding track with "<<nhits<<" clusters"<<endl; | |
334 | ||
335 | Int_t last_slice=-1; | |
336 | for(Int_t padrow=AliL3Transform::GetNRows()-1; padrow>=0; padrow--) | |
5b3f37f6 | 337 | { |
3e87ef69 | 338 | if(track->IsPresent(padrow)) |
339 | { | |
340 | last_slice = track->GetClusterModel(padrow)->fSlice; | |
341 | continue; | |
342 | } | |
343 | ||
344 | if(last_slice < 0) //the outer cluster is missing, so skip it - it will be written anyhow. | |
345 | continue; | |
346 | ||
347 | //Check the slice of the next padrow: | |
348 | Int_t next_padrow = padrow-1; | |
349 | Int_t next_slice = -1; | |
350 | while(next_padrow >=0) | |
351 | { | |
352 | if(track->IsPresent(next_padrow)) | |
353 | { | |
354 | next_slice = track->GetClusterModel(next_padrow)->fSlice; | |
355 | break; | |
356 | } | |
357 | next_padrow--; | |
358 | } | |
359 | if(next_slice>=0) | |
360 | if(next_slice != last_slice)//The track crosses a slice boundary here | |
361 | continue; | |
362 | ||
363 | //UInt_t size; | |
364 | AliL3SpacePointData *points = fClusters[last_slice][0];//->GetDataPointer(size); | |
365 | ||
366 | Float_t angle = 0; | |
367 | AliL3Transform::Local2GlobalAngle(&angle,last_slice); | |
368 | if(!track->CalculateReferencePoint(angle,AliL3Transform::Row2X(padrow))) | |
369 | continue; | |
370 | Float_t xyz_cross[3] = {track->GetPointX(),track->GetPointY(),track->GetPointZ()}; | |
371 | AliL3Transform::Global2Local(xyz_cross,last_slice,kTRUE); | |
372 | Float_t mindist = 123456789; | |
373 | AliL3SpacePointData *closest=0; | |
374 | for(UInt_t j=0; j<fNcl[last_slice][0]; j++) | |
375 | { | |
376 | if(points[j].fCharge == 0) continue;// || points[j].fPadRow != padrow) continue; | |
377 | if(points[j].fPadRow < padrow) continue; | |
378 | if(points[j].fPadRow > padrow) break; | |
379 | Float_t xyz[3] = {points[j].fX,points[j].fY,points[j].fZ}; | |
380 | AliL3Transform::Global2Local(xyz,last_slice,kTRUE); | |
381 | ||
382 | //Check for overflow: | |
383 | Int_t temp = (Int_t)rint((xyz_cross[1]-xyz[1])/GetXYResidualStep()); | |
384 | if( abs(temp) > 1<<(GetNPadBits()-1)) | |
385 | continue; | |
386 | ||
387 | temp = (Int_t)rint((xyz_cross[2]-xyz[2])/GetZResidualStep()); | |
388 | if( abs(temp) > 1<<(GetNTimeBits()-1)) | |
389 | continue; | |
390 | ||
391 | Float_t dist = sqrt( pow(xyz_cross[1]-xyz[1],2) + pow(xyz_cross[2]-xyz[2],2) ); | |
392 | if(dist < mindist) | |
393 | { | |
394 | closest = &points[j]; | |
395 | mindist = dist; | |
396 | } | |
397 | } | |
398 | if(closest) //there was a cluster assigned | |
399 | { | |
400 | Int_t sector,row; | |
401 | Float_t xyz[3] = {closest->fX,closest->fY,closest->fZ}; | |
402 | AliL3Transform::Slice2Sector(last_slice,padrow,sector,row); | |
403 | AliL3Transform::Local2Raw(xyz_cross,sector,row); | |
404 | AliL3Transform::Global2Raw(xyz,sector,row); | |
405 | ||
406 | track->SetPadHit(padrow,xyz_cross[1]); | |
407 | track->SetTimeHit(padrow,xyz_cross[2]); | |
408 | ||
409 | if(fWriteClusterShape) | |
410 | { | |
411 | Float_t angle = track->GetCrossingAngle(padrow,last_slice); | |
412 | track->SetCrossingAngleLUT(padrow,angle); | |
413 | track->CalculateClusterWidths(padrow,kTRUE); | |
414 | Int_t patch = AliL3Transform::GetPatch(padrow); | |
415 | Float_t sigmaY2 = closest->fSigmaY2 / pow(AliL3Transform::GetPadPitchWidth(patch),2); | |
416 | Float_t sigmaZ2 = closest->fSigmaZ2 / pow(AliL3Transform::GetZWidth(),2); | |
417 | track->SetCluster(padrow,xyz[1],xyz[2],closest->fCharge,sigmaY2,sigmaZ2,3); | |
418 | } | |
419 | else | |
420 | track->SetCluster(padrow,xyz[1],xyz[2],closest->fCharge,0,0,3); | |
421 | nhits++; | |
422 | ||
423 | //IMPORTANT: Set the slice in which cluster is, you need it in AliL3ModelTrack::FillTrack! | |
424 | track->GetClusterModel(padrow)->fSlice=last_slice; | |
425 | closest->fCharge = 0;//Mark this cluster as used. | |
426 | } | |
5b3f37f6 | 427 | } |
3e87ef69 | 428 | track->SetNClusters(AliL3Transform::GetNRows()); |
429 | //cout<<"Track was assigned "<<nhits<<" clusters"<<endl; | |
5b3f37f6 | 430 | } |
431 | ||
432 | } | |
433 | ||
3e87ef69 | 434 | void AliL3DataCompressor::WriteRemaining(Bool_t select) |
5b3f37f6 | 435 | { |
3e87ef69 | 436 | //Write remaining clusters (not assigned to any tracks) to file |
5b3f37f6 | 437 | |
5b3f37f6 | 438 | |
3e87ef69 | 439 | if(!fKeepRemaining) |
440 | return; | |
5b3f37f6 | 441 | |
3e87ef69 | 442 | if(select) |
443 | SelectRemainingClusters(); | |
444 | ||
445 | Char_t filename[1024]; | |
446 | ||
447 | if(!fSinglePatch) | |
5b3f37f6 | 448 | { |
3e87ef69 | 449 | cerr<<"AliL3Compressor::WriteRemaining : You have to modify this function when not running singlepatch"<<endl; |
5b3f37f6 | 450 | return; |
3e87ef69 | 451 | } |
452 | ||
453 | cout<<"Writing remaining clusters "<<endl; | |
454 | Int_t nrows = AliL3Transform::GetNRows(); | |
455 | Int_t *npoints = new Int_t[nrows]; | |
456 | for(Int_t i=0; i<=35; i++) | |
5b3f37f6 | 457 | { |
3e87ef69 | 458 | for(Int_t patch=0; patch < 1; patch++) |
459 | { | |
460 | sprintf(filename,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,i,-1); | |
461 | FILE *outfile = fopen(filename,"w"); | |
462 | if(!outfile) | |
463 | { | |
464 | cerr<<"AliL3DataCompressor::WriteRemaining : Cannot open file "<<filename<<endl; | |
465 | exit(5); | |
466 | } | |
467 | //UInt_t dummy; | |
468 | AliL3SpacePointData *points = fClusters[i][patch];//->GetDataPointer(dummy); | |
469 | ||
470 | memset(npoints,0,nrows*sizeof(Int_t)); | |
471 | ||
472 | for(UInt_t j=0; j<fNcl[i][patch]; j++) | |
473 | { | |
474 | if(points[j].fCharge == 0) continue; //has been used | |
475 | npoints[points[j].fPadRow]++; | |
476 | } | |
477 | Int_t size =0; | |
478 | Byte_t *data = 0; | |
479 | AliL3RemainingRow *tempPt=0; | |
480 | ||
481 | Int_t last_row = -2; | |
482 | Int_t localcounter=0; | |
483 | ||
484 | for(UInt_t j=0; j<fNcl[i][patch]; j++) | |
485 | { | |
486 | if(points[j].fCharge == 0) continue; //has been used | |
487 | ||
488 | Int_t padrow = points[j].fPadRow; | |
489 | if(padrow != last_row) | |
490 | { | |
491 | if(last_row != -2) | |
492 | { | |
493 | if(!tempPt) | |
494 | { | |
495 | cerr<<"AliL3DataCompressor::WriteRemaining : Zero row pointer "<<endl; | |
496 | exit(5); | |
497 | } | |
498 | if(localcounter != tempPt->fNClusters) | |
499 | { | |
500 | cerr<<"AliL3DataCompressor::WriteRemaining : Mismatching clustercounter "<<localcounter<<" " | |
501 | <<(Int_t)tempPt->fNClusters<<endl; | |
502 | exit(5); | |
503 | } | |
504 | //cout<<"Writing row "<<(int)tempPt->fPadRow<<" with "<<(int)tempPt->fNClusters<<" clusters"<<endl; | |
505 | fwrite(tempPt,size,1,outfile); | |
506 | } | |
507 | if(data) | |
508 | delete [] data; | |
509 | size = sizeof(AliL3RemainingRow) + npoints[padrow]*sizeof(AliL3RemainingCluster); | |
510 | data = new Byte_t[size]; | |
511 | tempPt = (AliL3RemainingRow*)data; | |
512 | ||
513 | localcounter=0; | |
514 | tempPt->fPadRow = padrow; | |
515 | tempPt->fNClusters = npoints[padrow]; | |
516 | last_row = padrow; | |
517 | } | |
518 | if(localcounter >= npoints[padrow]) | |
519 | { | |
520 | cerr<<"AliL3DataCompressor::WriteRemaining : Cluster counter out of range: " | |
521 | <<localcounter<<" "<<npoints[padrow]<<endl; | |
522 | exit(5); | |
523 | } | |
524 | ||
525 | Float_t xyz[3] = {points[j].fX,points[j].fY,points[j].fZ}; | |
526 | AliL3Transform::Global2Local(xyz,i,kTRUE); | |
527 | ||
528 | tempPt->fClusters[localcounter].fY = xyz[1]; | |
529 | tempPt->fClusters[localcounter].fZ = xyz[2]; | |
530 | tempPt->fClusters[localcounter].fCharge = points[j].fCharge; | |
531 | tempPt->fClusters[localcounter].fSigmaY2 = points[j].fSigmaY2; | |
532 | tempPt->fClusters[localcounter].fSigmaZ2 = points[j].fSigmaZ2; | |
533 | localcounter++; | |
534 | } | |
535 | //Write the last row: | |
536 | //cout<<"Writing row "<<(int)tempPt->fPadRow<<" with "<<(int)tempPt->fNClusters<<" clusters"<<endl; | |
537 | fwrite(tempPt,size,1,outfile); | |
538 | if(data) | |
539 | delete [] data; | |
540 | fclose(outfile); | |
541 | } | |
5b3f37f6 | 542 | } |
3e87ef69 | 543 | delete [] npoints; |
544 | } | |
545 | ||
546 | void AliL3DataCompressor::SelectRemainingClusters() | |
547 | { | |
548 | //Select which remaining clusters to write in addition to the compressed data. | |
549 | ||
550 | cout<<"Cleaning up clusters"<<endl; | |
551 | Int_t nrows = AliL3Transform::GetNRows(); | |
552 | Int_t gap=(Int_t)(0.125*nrows), shift=(Int_t)(0.5*gap); | |
5b3f37f6 | 553 | |
3e87ef69 | 554 | for(Int_t slice=0; slice<36; slice++) |
555 | { | |
556 | //UInt_t dummy; | |
557 | AliL3SpacePointData *points = fClusters[slice][0];//->GetDataPointer(dummy); | |
558 | for(UInt_t i=0; i<fNcl[slice][0]; i++) | |
559 | { | |
560 | if(points[i].fCharge == 0) continue; //Already removed | |
561 | Int_t padrow = (Int_t)points[i].fPadRow; | |
562 | ||
563 | Float_t xyz[3] = {points[i].fX,points[i].fY,points[i].fZ}; | |
564 | Int_t sector,row; | |
565 | AliL3Transform::Slice2Sector(slice,padrow,sector,row); | |
566 | AliL3Transform::Global2Raw(xyz,sector,row); | |
567 | ||
568 | if(padrow >= nrows-1-gap-shift) continue; | |
569 | //if(padrow >= nrows-1-shift) continue; | |
570 | ||
571 | //Save the clusters at the borders: | |
572 | if(xyz[1] < 3 || xyz[1] >= AliL3Transform::GetNPads(padrow)-4) | |
573 | continue; | |
574 | ||
575 | //Save clusters on padrows used for offline seeding: | |
576 | if(padrow == nrows - 1 || padrow == nrows - 1 - gap || //First seeding | |
577 | padrow == nrows - 1 - shift || padrow == nrows - 1 - gap - shift) //Second seeding | |
578 | continue; | |
579 | ||
580 | //Cluster did not meet any of the above criteria, so disregard it: | |
581 | points[i].fCharge = 0; | |
582 | } | |
583 | } | |
5b3f37f6 | 584 | |
5b3f37f6 | 585 | } |
586 | ||
3e87ef69 | 587 | void AliL3DataCompressor::CompressAndExpand() |
588 | { | |
589 | //Read tracks/clusters from file, compress data and uncompress it. Write compression rates to file. | |
590 | cout<<"Compressing and expanding data"<<endl; | |
591 | AliL3Compress *comp = new AliL3Compress(-1,-1,fPath,fWriteClusterShape,fEvent); | |
592 | comp->CompressFile(); | |
593 | comp->ExpandFile(); | |
594 | comp->PrintCompRatio(fCompRatioFile); | |
595 | delete comp; | |
596 | } | |
597 | ||
598 | ||
5b3f37f6 | 599 | void AliL3DataCompressor::RestoreData() |
600 | { | |
601 | //Restore the uncompressed data together with the remaining clusters, | |
602 | //and write to a final cluster file which serves as an input to the | |
3e87ef69 | 603 | //final offline tracker. |
5b3f37f6 | 604 | |
3e87ef69 | 605 | #ifndef use_aliroot |
606 | LOG(AliL3Log::kError,"AliL3DataCompressor::RestoreData","Version") | |
607 | <<"You have to compile with use_aliroot flag in order to use this function"<<ENDLOG; | |
608 | #else | |
609 | ||
610 | cout<<"Restoring data"<<endl; | |
611 | ||
612 | const Int_t maxpoints=500000; | |
613 | TempCluster **clusters = new TempCluster*[36]; | |
614 | Int_t *ncl = new Int_t[36]; | |
615 | for(Int_t i=0; i<36; i++) | |
616 | { | |
617 | ncl[i]=0; | |
618 | clusters[i] = new TempCluster[maxpoints]; | |
619 | } | |
620 | ||
621 | ReadUncompressedData(clusters,ncl,maxpoints); | |
5b3f37f6 | 622 | |
3e87ef69 | 623 | if(fKeepRemaining) |
624 | ReadRemaining(clusters,ncl,maxpoints); | |
bd53cfb7 | 625 | |
3e87ef69 | 626 | Char_t filename[1024]; |
5b3f37f6 | 627 | sprintf(filename,"%s/digitfile.root",fPath); |
628 | TFile *rootfile = TFile::Open(filename); | |
629 | rootfile->cd(); | |
630 | AliTPCParam *param = (AliTPCParam*)rootfile->Get(AliL3Transform::GetParamName()); | |
3e87ef69 | 631 | |
5b3f37f6 | 632 | AliTPCDigitsArray *darray = new AliTPCDigitsArray(); |
633 | darray->Setup(param); | |
634 | darray->SetClass("AliSimDigits"); | |
3e87ef69 | 635 | sprintf(filename,"TreeD_%s_%d",AliL3Transform::GetParamName(),fEvent); |
5b3f37f6 | 636 | Bool_t ok = darray->ConnectTree(filename); |
637 | if(!ok) | |
638 | { | |
639 | cerr<<"AliL3DataCompressor::RestoreData : Problems connecting tree"<<endl; | |
640 | return; | |
641 | } | |
3e87ef69 | 642 | |
643 | fOutputFile->cd(); | |
644 | ||
645 | AliTPCClustersArray *carray = new AliTPCClustersArray(); | |
646 | carray->Setup(param); | |
647 | carray->SetClusterType("AliTPCcluster"); | |
648 | carray->MakeTree(); | |
5b3f37f6 | 649 | |
3e87ef69 | 650 | Int_t totcounter=0; |
651 | for(Int_t slice=0; slice<=35; slice++) | |
5b3f37f6 | 652 | { |
3e87ef69 | 653 | TempCluster **clPt = new TempCluster*[maxpoints]; |
654 | cout<<"Sorting "<<ncl[slice]<<" clusters in slice "<<slice<<endl; | |
655 | for(Int_t i=0; i<ncl[slice]; i++) | |
656 | clPt[i] = &clusters[slice][i]; | |
657 | ||
658 | QSort(clPt,0,ncl[slice]); | |
659 | ||
660 | //cout<<"padrow "<<clPt[i]->padrow<<" pad "<<clPt[i]->pad<<" time "<<clPt[i]->time<<endl; | |
661 | ||
662 | Int_t falseid=0; | |
663 | Int_t counter=0; | |
664 | for(Int_t padrow=AliL3Transform::GetFirstRow(-1); padrow<=AliL3Transform::GetLastRow(-1); padrow++) | |
5b3f37f6 | 665 | { |
3e87ef69 | 666 | Int_t sec,row; |
667 | AliL3Transform::Slice2Sector(slice,padrow,sec,row); | |
668 | AliTPCClustersRow *clrow=carray->CreateRow(sec,row); | |
669 | AliSimDigits *digits = (AliSimDigits*)darray->LoadRow(sec,row); | |
670 | digits->ExpandBuffer(); | |
671 | digits->ExpandTrackBuffer(); | |
672 | Int_t patch = AliL3Transform::GetPatch(padrow); | |
673 | while(counter < ncl[slice] && clPt[counter]->padrow == padrow) | |
5b3f37f6 | 674 | { |
3e87ef69 | 675 | Float_t temp[3]; |
676 | AliL3Transform::Raw2Local(temp,sec,row,clPt[counter]->pad,clPt[counter]->time); | |
677 | ||
678 | AliTPCcluster *c = new AliTPCcluster(); | |
679 | c->SetY(temp[1]); | |
680 | c->SetZ(temp[2]); | |
681 | c->SetQ(clPt[counter]->charge); | |
682 | ||
683 | c->SetSigmaY2(clPt[counter]->sigmaY2*pow(AliL3Transform::GetPadPitchWidth(patch),2)); | |
684 | c->SetSigmaZ2(clPt[counter]->sigmaZ2*pow(AliL3Transform::GetZWidth(),2)); | |
685 | Int_t pad = TMath::Nint(clPt[counter]->pad); | |
686 | Int_t time = TMath::Nint(clPt[counter]->time); | |
5b3f37f6 | 687 | |
3e87ef69 | 688 | if(pad < 0) |
689 | pad=0; | |
690 | if(pad >= AliL3Transform::GetNPads(padrow)) | |
691 | pad = AliL3Transform::GetNPads(padrow)-1; | |
692 | if(time < 0 || time >= AliL3Transform::GetNTimeBins()) | |
693 | cerr<<"row "<<padrow<<" pad "<<pad<<" time "<<time<<endl; | |
bd53cfb7 | 694 | |
3e87ef69 | 695 | for(Int_t lab=0; lab<3; lab++) |
bd53cfb7 | 696 | { |
3e87ef69 | 697 | Int_t label = digits->GetTrackIDFast(time,pad,lab); |
698 | if(label > 1) | |
699 | c->SetLabel(label-2,lab); | |
700 | else if(label==0) | |
701 | c->SetLabel(-2,lab); | |
702 | else | |
703 | c->SetLabel(-1,lab); | |
704 | if(lab==0 && c->GetLabel(0) < 0) | |
bd53cfb7 | 705 | { |
3e87ef69 | 706 | falseid++; |
707 | //AliL3Transform::Local2Global(temp,slice); | |
708 | //cout<<"slice "<<slice<<" padrow "<<padrow<<" y "<<temp[1]<<" z "<<temp[2]<<" label "<<c->GetLabel(0)<<endl; | |
bd53cfb7 | 709 | } |
bd53cfb7 | 710 | } |
3e87ef69 | 711 | //cout<<"row "<<padrow<<" pad "<<clPt[counter]->pad<<" time "<<clPt[counter]->time<<" sigmaY2 "<<c->GetSigmaY2()<<" sigmaZ2 "<<c->GetSigmaZ2()<<endl; |
712 | clrow->InsertCluster(c); | |
713 | delete c; | |
714 | counter++; | |
715 | totcounter++; | |
716 | } | |
717 | carray->StoreRow(sec,row); | |
718 | carray->ClearRow(sec,row); | |
719 | darray->ClearRow(sec,row); | |
720 | } | |
721 | //cerr<<"Slice "<<slice<<" nclusters "<<counter<<" falseones "<<falseid<<endl; | |
722 | if(counter != ncl[slice]) | |
723 | cerr<<"AliLDataCompressor::RestoreData : Mismatching cluster count :"<<counter<<" "<<ncl[slice]<<endl; | |
724 | delete [] clPt; | |
725 | } | |
726 | ||
727 | cout<<"Writing "<<totcounter<<" clusters to rootfile "<<endl; | |
728 | ||
729 | sprintf(filename,"TreeC_TPC_%d",fEvent); | |
730 | carray->GetTree()->SetName(filename); | |
731 | carray->GetTree()->Write(); | |
732 | delete carray; | |
733 | delete darray; | |
734 | rootfile->Close(); | |
735 | ||
736 | for(Int_t i=0; i<36; i++) | |
737 | delete [] clusters[i]; | |
738 | delete [] clusters; | |
739 | delete [] ncl; | |
740 | #endif | |
741 | } | |
742 | ||
743 | void AliL3DataCompressor::ReadUncompressedData(TempCluster **clusters,Int_t *ncl,const Int_t maxpoints) | |
744 | { | |
745 | ||
746 | cout<<"Reading uncompressed tracks "<<endl; | |
747 | AliL3Compress *comp = new AliL3Compress(-1,-1,fPath,fWriteClusterShape,fEvent); | |
748 | ||
749 | if(!comp->ReadFile('u')) | |
750 | return; | |
751 | ||
752 | AliL3TrackArray *tracks = comp->GetTracks(); | |
753 | ||
754 | Int_t charge; | |
755 | Float_t pad,time,sigmaY2,sigmaZ2; | |
756 | for(Int_t i=0; i<tracks->GetNTracks(); i++) | |
757 | { | |
758 | AliL3ModelTrack *track = (AliL3ModelTrack*)tracks->GetCheckedTrack(i); | |
759 | if(!track) continue; | |
760 | for(Int_t padrow=0; padrow < AliL3Transform::GetNRows(-1); padrow++) | |
761 | { | |
762 | if(!track->IsPresent(padrow)) continue; | |
763 | track->GetPad(padrow,pad); | |
764 | track->GetTime(padrow,time); | |
765 | track->GetClusterCharge(padrow,charge); | |
766 | track->GetXYWidth(padrow,sigmaY2); | |
767 | track->GetZWidth(padrow,sigmaZ2); | |
768 | Int_t slice = track->GetClusterModel(padrow)->fSlice; | |
769 | /* | |
770 | if(pad < -1 || pad > AliL3Transform::GetNPads(padrow) || time < -1 || time > AliL3Transform::GetNTimeBins()) | |
771 | { | |
772 | cerr<<"AliL3DataCompressor::ReadUncompressData : Wrong pad "<<pad<<" or time "<<time<<" on row "<<padrow<<" track index "<<i<<endl; | |
773 | track->Print(); | |
774 | exit(5); | |
775 | } | |
776 | */ | |
777 | if(ncl[slice] >= maxpoints) | |
778 | { | |
779 | cerr<<"AliL3DataCompressor::ReadUncompressedData : Too many clusters"<<endl; | |
780 | exit(5); | |
781 | } | |
782 | clusters[slice][ncl[slice]].pad = pad; | |
783 | clusters[slice][ncl[slice]].time = time; | |
784 | clusters[slice][ncl[slice]].charge = charge; | |
785 | clusters[slice][ncl[slice]].sigmaY2 = sigmaY2; | |
786 | clusters[slice][ncl[slice]].sigmaZ2 = sigmaZ2; | |
787 | clusters[slice][ncl[slice]].padrow = padrow; | |
788 | //cout<<"row "<<padrow<<" pad "<<pad<<" time "<<time<<" charge "<<charge<<" sigmas "<<sigmaY2<<" "<<sigmaZ2<<endl; | |
789 | ncl[slice]++; | |
790 | } | |
791 | } | |
792 | ||
793 | delete comp; | |
794 | } | |
795 | ||
796 | void AliL3DataCompressor::ReadRemaining(TempCluster **clusters,Int_t *ncl,const Int_t maxpoints) | |
797 | { | |
798 | ||
799 | Char_t filename[1024]; | |
800 | cout<<"Reading remaining clusters "<<endl; | |
801 | AliL3MemHandler mem; | |
802 | ||
803 | for(Int_t slice=0; slice<=35; slice++) | |
804 | { | |
805 | for(Int_t p=0; p<1; p++) | |
806 | { | |
807 | sprintf(filename,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,slice,-1); | |
808 | ||
809 | mem.SetBinaryInput(filename); | |
810 | AliL3RemainingRow *tempPt = (AliL3RemainingRow*)mem.Allocate(); | |
811 | ||
812 | Int_t nrows=0; | |
813 | FILE *infile = mem.GetFilePointer(); | |
814 | while(!feof(infile)) | |
815 | { | |
816 | Byte_t *dPt = (Byte_t*)tempPt; | |
817 | if(fread(tempPt,sizeof(AliL3RemainingRow),1,infile)!=1) break; | |
bd53cfb7 | 818 | |
3e87ef69 | 819 | dPt += sizeof(AliL3RemainingRow); |
820 | ||
821 | Int_t size = sizeof(AliL3RemainingCluster)*tempPt->fNClusters; | |
822 | ||
823 | fread(dPt,size,1,infile); | |
824 | dPt += size; | |
825 | tempPt = (AliL3RemainingRow*)dPt; | |
826 | nrows++; | |
827 | } | |
828 | ||
829 | mem.CloseBinaryInput(); | |
830 | UInt_t dummy; | |
831 | tempPt = (AliL3RemainingRow*)mem.GetDataPointer(dummy); | |
832 | ||
833 | for(Int_t i=0; i<nrows; i++) | |
834 | { | |
835 | AliL3RemainingCluster *points = tempPt->fClusters; | |
836 | Int_t padrow = (Int_t)tempPt->fPadRow; | |
837 | Int_t patch = AliL3Transform::GetPatch(padrow); | |
838 | Int_t sector,row; | |
839 | AliL3Transform::Slice2Sector(slice,padrow,sector,row); | |
840 | //cout<<"Loading slice "<<slice<<" row "<<padrow<<" with "<<(Int_t)tempPt->fNClusters<<" clusters "<<endl; | |
841 | for(Int_t j=0; j<tempPt->fNClusters; j++) | |
5b3f37f6 | 842 | { |
5b3f37f6 | 843 | |
3e87ef69 | 844 | Float_t xyz[3] = {AliL3Transform::Row2X(padrow),points[j].fY,points[j].fZ}; |
5b3f37f6 | 845 | |
3e87ef69 | 846 | AliL3Transform::Local2Raw(xyz,sector,row); |
bd53cfb7 | 847 | |
3e87ef69 | 848 | if(ncl[slice] >= maxpoints) |
5b3f37f6 | 849 | { |
3e87ef69 | 850 | cerr<<"AliL3DataCompressor::ReadRemaining : Too many clusters"<<endl; |
851 | exit(5); | |
5b3f37f6 | 852 | } |
3e87ef69 | 853 | //cout<<"slice "<<slice<<" padrow "<<padrow<<" pad "<<xyz[1]<<" time "<<xyz[2]<<endl; |
854 | clusters[slice][ncl[slice]].pad = xyz[1]; | |
855 | clusters[slice][ncl[slice]].time = xyz[2]; | |
856 | clusters[slice][ncl[slice]].charge = points[j].fCharge; | |
857 | clusters[slice][ncl[slice]].sigmaY2 = points[j].fSigmaY2/pow(AliL3Transform::GetPadPitchWidth(patch),2); | |
858 | clusters[slice][ncl[slice]].sigmaZ2 = points[j].fSigmaZ2/pow(AliL3Transform::GetZWidth(),2); | |
859 | clusters[slice][ncl[slice]].padrow = padrow; | |
860 | ncl[slice]++; | |
bd53cfb7 | 861 | } |
3e87ef69 | 862 | Byte_t *dPt = (Byte_t*)tempPt; |
863 | Int_t size = sizeof(AliL3RemainingRow) + tempPt->fNClusters*sizeof(AliL3RemainingCluster); | |
864 | dPt += size; | |
865 | tempPt = (AliL3RemainingRow*)dPt; | |
5b3f37f6 | 866 | } |
3e87ef69 | 867 | |
868 | mem.Free(); | |
5b3f37f6 | 869 | } |
870 | } | |
3e87ef69 | 871 | } |
872 | ||
873 | void AliL3DataCompressor::QSort(TempCluster **a, Int_t first, Int_t last) | |
874 | { | |
875 | static TempCluster *tmp; | |
876 | static int i; // "static" to save stack space | |
877 | int j; | |
878 | ||
879 | while (last - first > 1) { | |
880 | i = first; | |
881 | j = last; | |
882 | for (;;) { | |
883 | while (++i < last && Compare(a[i], a[first]) < 0) | |
884 | ; | |
885 | while (--j > first && Compare(a[j], a[first]) > 0) | |
886 | ; | |
887 | if (i >= j) | |
888 | break; | |
889 | ||
890 | tmp = a[i]; | |
891 | a[i] = a[j]; | |
892 | a[j] = tmp; | |
893 | } | |
894 | if (j == first) { | |
895 | ++first; | |
896 | continue; | |
897 | } | |
898 | tmp = a[first]; | |
899 | a[first] = a[j]; | |
900 | a[j] = tmp; | |
901 | if (j - first < last - (j + 1)) { | |
902 | QSort(a, first, j); | |
903 | first = j + 1; // QSort(j + 1, last); | |
904 | } else { | |
905 | QSort(a, j + 1, last); | |
906 | last = j; // QSort(first, j); | |
907 | } | |
908 | } | |
909 | } | |
910 | ||
911 | Int_t AliL3DataCompressor::Compare(TempCluster *a,TempCluster *b) | |
912 | { | |
913 | /* | |
914 | if(a->padrow < 0 || a->padrow > AliL3Transform::GetNRows(-1) || | |
915 | b->padrow < 0 || b->padrow > AliL3Transform::GetNRows(-1)) | |
916 | { | |
917 | cerr<<"AliL3Compressor::Compare : Wrong padrows "<<a->padrow<<" "<<b->padrow<<endl; | |
918 | exit(5); | |
919 | } | |
920 | else if(a->pad < 0 || a->pad > AliL3Transform::GetNPads(a->padrow) || | |
921 | b->pad < 0 || b->pad > AliL3Transform::GetNPads(b->padrow)) | |
922 | { | |
923 | cerr<<"AliL3Compressor::Compare : Wrong pads "<<a->pad<<" "<<b->pad<<endl; | |
924 | exit(5); | |
925 | } | |
926 | else if(a->time < 0 || a->time > AliL3Transform::GetNTimeBins() || | |
927 | b->time < 0 || b->time > AliL3Transform::GetNTimeBins()) | |
928 | { | |
929 | cerr<<"AliL3Compressor::Compare : Wrong timebins "<<a->time<<" "<<b->time<<endl; | |
930 | exit(5); | |
931 | } | |
932 | */ | |
933 | if(a->padrow < b->padrow) return -1; | |
934 | if(a->padrow > b->padrow) return 1; | |
935 | ||
936 | if(rint(a->pad) == rint(b->pad) && rint(a->time) == rint(b->time)) return 0; | |
5b3f37f6 | 937 | |
3e87ef69 | 938 | if(rint(a->pad) < rint(b->pad)) return -1; |
939 | if(rint(a->pad) == rint(b->pad) && rint(a->time) < rint(b->time)) return -1; | |
5b3f37f6 | 940 | |
3e87ef69 | 941 | return 1; |
5b3f37f6 | 942 | } |
943 | ||
3e87ef69 | 944 | void AliL3DataCompressor::LoadOfflineData(Int_t event) |
5b3f37f6 | 945 | { |
3e87ef69 | 946 | //Take offline reconstructed tracks as an input. |
947 | //In this case, no remaining clusters are written. | |
5b3f37f6 | 948 | |
3e87ef69 | 949 | #ifndef use_aliroot |
950 | LOG(AliL3Log::kError,"AliL3DataCompressor::LoadOfflineData","Version") | |
951 | <<"You have to compile with use_aliroot flag in order to use this function"<<ENDLOG; | |
952 | #else | |
953 | ||
954 | char filename[1024]; | |
955 | ||
956 | AliKalmanTrack::SetConvConst(1000/0.299792458/AliL3Transform::GetSolenoidField()); | |
957 | sprintf(filename,"%s/offline/AliTPCclusters.root",fPath); | |
958 | ||
959 | TFile *in = TFile::Open(filename); | |
960 | AliTPCParam *param=(AliTPCParam*)in->Get("75x40_100x60_150x60"); | |
961 | ||
962 | AliTPCtracker *tracker = new AliTPCtracker(param); | |
963 | tracker->SetEventNumber(event); | |
964 | tracker->LoadClusters(); | |
965 | ||
966 | const Int_t MAX=20000; | |
967 | Int_t nentr=0,i=0; TObjArray tarray(MAX); | |
968 | sprintf(filename,"%s/offline/AliTPCtracks.root",fPath); | |
969 | TFile *tf=TFile::Open(filename); | |
970 | ||
971 | char tname[100]; sprintf(tname,"TreeT_TPC_%d",event); | |
972 | TTree *tracktree=(TTree*)tf->Get(tname); | |
973 | ||
974 | TBranch *tbranch=tracktree->GetBranch("tracks"); | |
975 | nentr=(Int_t)tracktree->GetEntries(); | |
976 | AliTPCtrack *iotrack=0; | |
977 | ||
978 | for (i=0; i<nentr; i++) { | |
979 | iotrack=new AliTPCtrack; | |
980 | tbranch->SetAddress(&iotrack); | |
981 | tracktree->GetEvent(i); | |
982 | tarray.AddLast(iotrack); | |
983 | } | |
984 | delete tracktree; | |
985 | tf->Close(); | |
986 | ||
987 | AliL3TrackArray *comptracks = new AliL3TrackArray("AliL3ModelTrack"); | |
988 | cout<<"Loaded "<<nentr<<" offline tracks"<<endl; | |
989 | Int_t slice,padrow; | |
990 | Int_t totcounter=0; | |
991 | for(i=0; i<nentr; i++) | |
992 | { | |
993 | ||
994 | AliTPCtrack *track=(AliTPCtrack*)tarray.UncheckedAt(i); | |
995 | Int_t nhits = track->GetNumberOfClusters(); | |
996 | Int_t idx = track->GetClusterIndex(nhits-1); | |
997 | Int_t sec=(idx&0xff000000)>>24, row=(idx&0x00ff0000)>>16; | |
998 | ||
999 | if(sec >= 18) | |
1000 | sec += 18; | |
1001 | ||
1002 | AliL3Transform::Sector2Slice(slice,padrow,sec,row); | |
1003 | Double_t par[5],xk=AliL3Transform::Row2X(padrow); | |
1004 | track->PropagateTo(xk); | |
1005 | track->GetExternalParameters(xk,par); | |
1006 | Double_t psi = TMath::ASin(par[2]) + track->GetAlpha(); | |
1007 | if (psi<-TMath::Pi()) psi+=2*TMath::Pi(); | |
1008 | if (psi>=TMath::Pi()) psi-=2*TMath::Pi(); | |
1009 | Float_t pt_1=TMath::Abs(par[4]); | |
1010 | Int_t charge = 1; | |
1011 | if(par[4] > 0) | |
1012 | charge=-1; | |
1013 | ||
1014 | Float_t first[3]; | |
1015 | AliCluster *fcl = tracker->GetCluster(idx); | |
1016 | first[0] = xk; | |
1017 | first[1] = fcl->GetY(); | |
1018 | first[2] = fcl->GetZ(); | |
1019 | ||
1020 | AliL3Transform::Local2Global(first,slice); | |
1021 | ||
1022 | AliL3ModelTrack *outtrack = (AliL3ModelTrack*)comptracks->NextTrack(); | |
1023 | outtrack->SetNHits(nhits); | |
1024 | outtrack->SetFirstPoint(first[0],first[1],first[2]); | |
1025 | outtrack->SetPt(1/pt_1); | |
1026 | outtrack->SetPsi(psi); | |
1027 | outtrack->SetTgl(par[3]); | |
1028 | outtrack->SetCharge(charge); | |
1029 | outtrack->CalculateHelix(); | |
1030 | outtrack->Init(0,-1); | |
bd53cfb7 | 1031 | |
3e87ef69 | 1032 | //for(int j=0; j<nhits; j++) |
1033 | for(int j=nhits-1; j>=0; j--) | |
1034 | { | |
1035 | Int_t index = track->GetClusterIndex(j); | |
1036 | ||
1037 | Float_t xyz[3]; | |
1038 | Int_t clustercharge =0; | |
1039 | ||
1040 | AliTPCcluster *cluster = (AliTPCcluster*)tracker->GetCluster(index); | |
1041 | xyz[1] = cluster->GetY(); | |
1042 | xyz[2] = cluster->GetZ(); | |
1043 | clustercharge = (Int_t)cluster->GetQ(); | |
1044 | ||
1045 | cluster->SetQ(-clustercharge);//Set as used | |
1046 | ||
1047 | sec=(index&0xff000000)>>24; row=(index&0x00ff0000)>>16; | |
1048 | ||
1049 | //This we do because the sector numbering of course are different internally | |
1050 | //in the fucked up AliTPCtracker class. | |
1051 | if(sec >= 18) | |
1052 | sec += 18; | |
1053 | ||
1054 | if(xyz[2] < 0) | |
1055 | sec += 18; | |
1056 | ||
1057 | //cout<<"sector "<<sec<<" row "<<row<<endl; | |
1058 | if(!AliL3Transform::Sector2Slice(slice,padrow,sec,row)) | |
1059 | exit(5); | |
1060 | xyz[0] = AliL3Transform::Row2X(padrow); | |
1061 | ||
1062 | //cout<<"Hit in slice "<<slice<<" padrow "<<padrow<<" y "<<cluster->GetY()<<" z "<<cluster->GetZ()<<endl; | |
1063 | AliL3Transform::Local2Raw(xyz,sec,row); | |
1064 | //cout<<"slice "<<slice<<" padrow "<<padrow<<" pad "<<xyz[1]<<" time "<<xyz[2]<<endl; | |
1065 | ||
1066 | if(xyz[1] < -1 || xyz[1] > AliL3Transform::GetNPads(padrow) || | |
1067 | xyz[2] < -1 || xyz[2] > AliL3Transform::GetNTimeBins()) | |
1068 | { | |
1069 | cerr<<"AliL3DataCompressor::FillOfflineData : Wrong time "<<xyz[2]<<" in slice " | |
1070 | <<slice<<" padrow "<<padrow<<endl; | |
1071 | cout<<"sector "<<sec<<" row "<<row<<endl; | |
1072 | //cout<<"Hit in slice "<<slice<<" padrow "<<padrow<<" y "<<cluster->GetY()<<" z "<<cluster->GetZ()<<endl; | |
1073 | cout<<"Track hit "<<xyz[0]<<" "<<xyz[1]<<" "<<xyz[2]<<endl; | |
1074 | exit(5); | |
1075 | } | |
1076 | ||
1077 | Float_t angle = 0; | |
1078 | AliL3Transform::Local2GlobalAngle(&angle,slice); | |
1079 | if(!outtrack->CalculateReferencePoint(angle,AliL3Transform::Row2X(padrow))) | |
1080 | { | |
1081 | cerr<<"AliL3DataCompressor::FillOfflineData : Error in crossing point calc on slice " | |
1082 | <<slice<<" row "<<padrow<<endl; | |
1083 | exit(5); | |
1084 | } | |
1085 | Float_t xyz_cross[3] = {outtrack->GetPointX(),outtrack->GetPointY(),outtrack->GetPointZ()}; | |
1086 | AliL3Transform::Global2Raw(xyz_cross,sec,row); | |
1087 | /* | |
1088 | if(fabs(xyz_cross[1] - xyz[1]) > 10 || | |
1089 | fabs(xyz_cross[2] - xyz[2]) > 10) | |
1090 | { | |
1091 | cout<<"AliL3DataCompressor::FillOfflineData : Wrong crossing slice "<<slice<<" padrow " | |
1092 | <<padrow<<" pad "<<xyz[1]<<" padhit "<<xyz_cross[1]<<" time "<<xyz[2]<<" timehit "<<xyz_cross[2]<<endl; | |
1093 | outtrack->Print(); | |
1094 | exit(5); | |
1095 | } | |
1096 | */ | |
1097 | //cout<<" crossing "<<xyz_cross[0]<<" "<<xyz_cross[1]<<" "<<xyz_cross[2]<<endl; | |
1098 | outtrack->SetPadHit(padrow,xyz_cross[1]); | |
1099 | outtrack->SetTimeHit(padrow,xyz_cross[2]); | |
1100 | ||
1101 | if(fWriteClusterShape) | |
1102 | { | |
1103 | Float_t angle = outtrack->GetCrossingAngle(padrow,slice); | |
1104 | outtrack->SetCrossingAngleLUT(padrow,angle); | |
1105 | outtrack->CalculateClusterWidths(padrow,kTRUE); | |
1106 | Int_t patch = AliL3Transform::GetPatch(padrow); | |
1107 | Float_t sigmaY2 = cluster->GetSigmaY2() / pow(AliL3Transform::GetPadPitchWidth(patch),2); | |
1108 | Float_t sigmaZ2 = cluster->GetSigmaZ2() / pow(AliL3Transform::GetZWidth(),2); | |
1109 | outtrack->SetCluster(padrow,xyz[1],xyz[2],clustercharge,sigmaY2,sigmaZ2,3); | |
1110 | } | |
1111 | else | |
1112 | outtrack->SetCluster(padrow,xyz[1],xyz[2],clustercharge,0,0,3); | |
1113 | totcounter++; | |
1114 | outtrack->GetClusterModel(padrow)->fSlice = slice; | |
1115 | } | |
1116 | /* | |
1117 | int label = track->GetLabel(); | |
1118 | if(label == 10019 || label==6281 || label== 5326 || label==3054 || label==1366 || label==1005) | |
1119 | outtrack->Print(); | |
1120 | */ | |
1121 | } | |
1122 | ||
1123 | tracker->UnloadClusters(); | |
1124 | ||
1125 | cout<<"AliL3DataCompressor::FillOfflineData : Wrote "<<totcounter<<" clusters"<<endl; | |
1126 | //Write tracks to file | |
1127 | AliL3Compress *comp = new AliL3Compress(-1,-1,fPath,fWriteClusterShape,fEvent); | |
1128 | comp->WriteFile(comptracks); | |
1129 | delete comp; | |
1130 | delete comptracks; | |
1131 | delete tracker; | |
1132 | #endif | |
1133 | } |